Skip to content
Snippets Groups Projects
Commit 051815d4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

glyph input is processed properly and proper exception returned when there is a problem with input

parent 21b28450
No related branches found
No related tags found
1 merge request!768Resolve "Custom images as overlay levels or background"
......@@ -30,6 +30,7 @@ import lcsb.mapviewer.api.projects.models.publications.PublicationsRestImpl;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.zip.GlyphZipEntryFile;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
import lcsb.mapviewer.converter.zip.LayoutZipEntryFile;
import lcsb.mapviewer.converter.zip.ModelZipEntryFile;
......@@ -429,7 +430,7 @@ public class ProjectRestImpl extends BaseRestImpl {
return path + "/../map_images/" + md5(projectId + "-" + id) + "/";
}
protected List<ZipEntryFile> extractZipEntries(MultiValueMap<String, Object> data) {
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) {
......@@ -455,8 +456,10 @@ public class ProjectRestImpl extends BaseRestImpl {
entry = new LayoutZipEntryFile(filename, name, description);
} else if ("IMAGE".equalsIgnoreCase(entryType)) {
entry = new ImageZipEntryFile(filename);
} else if ("GLYPH".equalsIgnoreCase(entryType)) {
entry = new GlyphZipEntryFile(filename);
} else {
throw new Error("Unknown entry type: " + entryType);
throw new QueryException("Unknown entry type: " + entryType);
}
fileIndex++;
result.add(entry);
......
......@@ -25,6 +25,7 @@ import org.springframework.util.MultiValueMap;
import com.google.gson.Gson;
import lcsb.mapviewer.api.ObjectNotFoundException;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.RestTestFunctions;
import lcsb.mapviewer.converter.zip.ImageZipEntryFile;
import lcsb.mapviewer.converter.zip.LayoutZipEntryFile;
......@@ -57,8 +58,9 @@ public class ProjectRestImplTest extends RestTestFunctions {
public void before() {
_projectRestImpl.setModelService(modelService);
_projectRestImpl.setProjectService(projectService);
}
@Test
public void testGetModelDataDependencies() throws Exception {
try {
......@@ -91,9 +93,9 @@ public class ProjectRestImplTest extends RestTestFunctions {
project.setProjectId(projectId);
projectDao.add(project);
User user = userService.getUserByToken(token);
userService.setUserPrivilege(user, PrivilegeType.VIEW_PROJECT,1, project.getId(), adminToken);
userService.setUserPrivilege(user, PrivilegeType.VIEW_PROJECT, 1, project.getId(), adminToken);
userService.setUserPrivilege(user, PrivilegeType.PROJECT_MANAGEMENT, 1);
// userService.setUserPrivilege(user, PrivilegeType.VIEW_PROJECT, 1);
// userService.setUserPrivilege(user, PrivilegeType.VIEW_PROJECT, 1);
_projectRestImpl.removeProject(token, projectId, null);
} catch (Exception e) {
e.printStackTrace();
......@@ -236,6 +238,20 @@ public class ProjectRestImplTest extends RestTestFunctions {
}
}
@Test(expected = QueryException.class)
public void testExtractZipEntriesWithInvalidType() throws Exception {
try {
MultiValueMap<String, Object> data = new LinkedMultiValueMap<>();
data.put("zip-entries[0][_type]", createLinkedList("MAPX"));
data.put("zip-entries[0][_filename]", createLinkedList("main.xml"));
_projectRestImpl.extractZipEntries(data);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testExtractZipEntriesWithNoMapType() throws Exception {
try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment