Commit e48e63f0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unused code removed

parent fd009c44
......@@ -15,6 +15,13 @@ import lcsb.mapviewer.model.map.model.SubmodelType;
public class ZipEntryFileDeserializer extends StdDeserializer<ZipEntryFile> {
public static enum ZipEntryFileType {
MAP,
OVERLAY,
IMAGE,
GLYPH;
}
/**
*
*/
......@@ -36,8 +43,8 @@ public class ZipEntryFileDeserializer extends StdDeserializer<ZipEntryFile> {
String filename = rootNode.get("_filename").asText();
String name = getValue(rootNode, "_data.name", "");
switch (rootNode.get("_type").asText()) {
case ("MAP"): {
switch (ZipEntryFileType.valueOf(getValue(rootNode,"_type",null))) {
case MAP: {
String submodelTypeKey = getValue(rootNode, "_data.type.id", SubmodelType.UNKNOWN.name());
String rootKey = getValue(rootNode, "_data.root", "false");
String mappingKey = getValue(rootNode, "_data.mapping", "false");
......@@ -49,17 +56,17 @@ public class ZipEntryFileDeserializer extends StdDeserializer<ZipEntryFile> {
return new ModelZipEntryFile(filename, name, root, mapping, mapType);
}
case ("OVERLAY"): {
case OVERLAY: {
String description = getValue(rootNode, "_data.description", "");
if (name.trim().isEmpty()) {
throw new DeserializationException("overlay name cannot be empty");
}
return new LayoutZipEntryFile(filename, name, description);
}
case ("IMAGE"): {
case IMAGE: {
return new ImageZipEntryFile(filename);
}
case ("GLYPH"): {
case GLYPH: {
return new GlyphZipEntryFile(filename);
}
default:
......
......@@ -9,30 +9,20 @@ import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Hibernate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.MultiValueMap;
import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.api.OperationNotAllowedException;
import lcsb.mapviewer.common.comparator.StringComparator;
import lcsb.mapviewer.converter.zip.GlyphZipEntryFile;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
import lcsb.mapviewer.converter.zip.LayoutZipEntryFile;
import lcsb.mapviewer.converter.zip.ModelZipEntryFile;
import lcsb.mapviewer.converter.zip.ZipEntryFile;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
import lcsb.mapviewer.model.cache.FileEntry;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.ConfigurationElementType;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.map.species.ElementProperty;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
......@@ -43,36 +33,12 @@ import lcsb.mapviewer.services.interfaces.IReactionService;
@Service
public class ProjectRestImpl extends BaseRestImpl {
public static enum ZipEntryFileType {
MAP,
OVERLAY,
IMAGE,
GLYPH;
public static ZipEntryFileType getType(String entryType) {
for (ZipEntryFileType type : ZipEntryFileType.values()) {
if (type.name().equals(entryType)) {
return type;
}
}
return null;
}
}
/**
* Default class logger.
*/
private Logger logger = LogManager.getLogger();
private IElementService elementService;
private IReactionService reactionService;
private ProjectDao projectDao;
public ProjectRestImpl(ProjectDao projectDao,
public ProjectRestImpl(
IElementService elementService,
IReactionService reactionService) {
this.projectDao = projectDao;
this.elementService = elementService;
this.reactionService = reactionService;
}
......@@ -113,94 +79,6 @@ public class ProjectRestImpl extends BaseRestImpl {
return result;
}
protected List<ZipEntryFile> extractZipEntries(MultiValueMap<String, Object> data) throws QueryException {
int fileIndex = 0;
List<ZipEntryFile> result = new ArrayList<>();
while (data.get("zip-entries[" + fileIndex + "][_filename]") != null) {
ZipEntryFile entry = null;
String entryType = (String) data.get("zip-entries[" + fileIndex + "][_type]").get(0);
String filename = (String) data.get("zip-entries[" + fileIndex + "][_filename]").get(0);
String name;
ZipEntryFileType type = ZipEntryFileType.getType(entryType);
if (type == null) {
throw new QueryException("Unknown type for zip entry: zip-entries[" + fileIndex + "]");
}
switch (type) {
case MAP:
String submodelTypeKey = "zip-entries[" + fileIndex + "][_data][type][id]";
String rootKey = "zip-entries[" + fileIndex + "][_data][root]";
String mappingKey = "zip-entries[" + fileIndex + "][_data][mapping]";
String mapTypeString = getStringValue(data.get(submodelTypeKey), SubmodelType.UNKNOWN.name());
SubmodelType mapType = SubmodelType.valueOf(mapTypeString);
name = (String) data.get("zip-entries[" + fileIndex + "][_data][name]").get(0);
Boolean root = getBoolValue(data.get(rootKey), false);
Boolean mapping = getBoolValue(data.get(mappingKey), false);
entry = new ModelZipEntryFile(filename, name, root, mapping, mapType);
break;
case OVERLAY:
name = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][name]");
String description = getFirstEntry(data, "zip-entries[" + fileIndex + "][_data][description]");
if (name == null || name.trim().isEmpty()) {
throw new QueryException("zip-entries[" + fileIndex + "][_data][name] cannot be empty");
}
entry = new LayoutZipEntryFile(filename, name, description);
break;
case IMAGE:
entry = new ImageZipEntryFile(filename);
break;
case GLYPH:
entry = new GlyphZipEntryFile(filename);
break;
default:
throw new QueryException("Unknown entry type: " + entryType);
}
fileIndex++;
result.add(entry);
}
return result;
}
@SuppressWarnings("unchecked")
private <T> T getFirstEntry(MultiValueMap<String, Object> data, String string) {
if (data.get(string) != null) {
return (T) data.get(string).get(0);
} else {
return null;
}
}
private Boolean getBoolValue(List<Object> list, boolean defaultValue) {
if (list == null) {
return defaultValue;
}
Object obj = list.get(0);
if (obj instanceof Boolean) {
return (Boolean) list.get(0);
} else {
return "true".equalsIgnoreCase((String) obj);
}
}
private String getStringValue(List<Object> list, String defaultValue) {
if (list == null) {
return defaultValue;
}
if (list.size() == 0) {
return defaultValue;
}
Object obj = list.get(0);
if (obj instanceof String) {
return (String) list.get(0);
} else {
return obj.toString();
}
}
public Project removeProject(String projectId, String path) throws QueryException {
Project project = getProjectByProjectId(projectId);
if (getConfigurationService().getConfigurationValue(ConfigurationElementType.DEFAULT_MAP)
......
package lcsb.mapviewer.api.projects;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.*;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -10,20 +12,18 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.google.gson.Gson;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.converter.zip.*;
import lcsb.mapviewer.model.*;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectLogEntry;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.MiriamType;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.persist.dao.ProjectDao;
import lcsb.mapviewer.persist.dao.user.UserDao;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IProjectService;
......@@ -88,57 +88,6 @@ public class ProjectRestImplTest extends RestTestFunctions {
assertEquals(reactionAnnotations.get(MiriamType.PUBMED), 1);
}
@Test
public void testExtractZipEntries() throws Exception {
MultiValueMap<String, Object> data = new LinkedMultiValueMap<>();
data.put("zip-entries[0][_type]", createLinkedList("MAP"));
data.put("zip-entries[0][_filename]", createLinkedList("main.xml"));
data.put("zip-entries[0][_data][root]", createLinkedList("true"));
data.put("zip-entries[0][_data][name]", createLinkedList("main"));
data.put("zip-entries[0][_data][type][id]", createLinkedList("UNKNOWN"));
data.put("zip-entries[0][_data][type][name]", createLinkedList("Unknown"));
data.put("zip-entries[1][_type]", createLinkedList("OVERLAY"));
data.put("zip-entries[1][_filename]", createLinkedList("layouts/goodschema.txt"));
data.put("zip-entries[1][_data][name]", createLinkedList("example name"));
data.put("zip-entries[1][_data][description]", createLinkedList("layout description"));
data.put("zip-entries[2][_type]", createLinkedList("IMAGE"));
data.put("zip-entries[2][_filename]", createLinkedList("images/test.png"));
List<ZipEntryFile> result = projectRest.extractZipEntries(data);
assertNotNull(result);
assertEquals(3, result.size());
assertTrue(result.get(0) instanceof ModelZipEntryFile);
assertTrue(result.get(1) instanceof LayoutZipEntryFile);
assertTrue(result.get(2) instanceof ImageZipEntryFile);
}
@Test(expected = QueryException.class)
public void testExtractZipEntriesWithInvalidType() throws Exception {
MultiValueMap<String, Object> data = new LinkedMultiValueMap<>();
data.put("zip-entries[0][_type]", createLinkedList("MAPX"));
data.put("zip-entries[0][_filename]", createLinkedList("main.xml"));
projectRest.extractZipEntries(data);
}
@Test
public void testExtractZipEntriesWithNoMapType() throws Exception {
MultiValueMap<String, Object> data = new LinkedMultiValueMap<>();
data.put("zip-entries[0][_type]", createLinkedList("MAP"));
data.put("zip-entries[0][_filename]", createLinkedList("main.xml"));
data.put("zip-entries[0][_data][root]", createLinkedList("true"));
data.put("zip-entries[0][_data][name]", createLinkedList("main"));
List<ZipEntryFile> result = projectRest.extractZipEntries(data);
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(result.get(0) instanceof ModelZipEntryFile);
}
private LinkedList<Object> createLinkedList(Object string) {
LinkedList<Object> result = new LinkedList<>();
result.add(string);
return result;
}
private void createMockProjectRest(String string) throws Exception {
Model model = null;
Project project = null;
......
......@@ -48,6 +48,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonParser;
import lcsb.mapviewer.api.projects.ProjectRestImpl;
import lcsb.mapviewer.converter.zip.ZipEntryFileDeserializer;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.cache.UploadedFileEntry;
......@@ -700,7 +701,7 @@ public class ProjectControllerIntegrationTest extends ControllerIntegrationTest
.and(createArrayParameters("zip-entries[{number}][_filename]", "name of the file"))
.and(createArrayParameters("zip-entries[{number}][_type]",
"type of the file. Possible values: "
+ snippets.getOptionsAsString(ProjectRestImpl.ZipEntryFileType.class)))
+ snippets.getOptionsAsString(ZipEntryFileDeserializer.ZipEntryFileType.class)))
.and(createArrayParameters("zip-entries[{number}][_data][name]", "name of the map/name of the overlay"))
.and(createArrayParameters("zip-entries[{number}][_data][mapping]",
"for submaps - is this map a mapping file (true/false)"))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment