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

fetching information about models properly handles unknown project

parent 694da1c7
No related branches found
No related tags found
1 merge request!895Resolve "Curator can not set the overlay public or change the owner"
package lcsb.mapviewer.converter.graphics; package lcsb.mapviewer.converter.graphics;
import java.awt.*; import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -160,6 +160,15 @@ public class ImageGenerators { ...@@ -160,6 +160,15 @@ public class ImageGenerators {
throw new InvalidArgumentException("Unknown class type: " + generatorClass); throw new InvalidArgumentException("Unknown class type: " + generatorClass);
} }
public boolean isValidClassName(String generatorClass) {
for (Pair<String, Class<? extends AbstractImageGenerator>> element : availableGenerators) {
if (element.getRight().getCanonicalName().equals(generatorClass)) {
return true;
}
}
return false;
}
/** /**
* Returns file extension that should be used for files generated by * Returns file extension that should be used for files generated by
* implementation of {@link AbstractImageGenerator} class. * implementation of {@link AbstractImageGenerator} class.
......
package lcsb.mapviewer.api.projects.models; package lcsb.mapviewer.api.projects.models;
import java.awt.Color;
import java.awt.geom.*; import java.awt.geom.*;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
...@@ -27,7 +26,6 @@ import lcsb.mapviewer.model.cache.UploadedFileEntry; ...@@ -27,7 +26,6 @@ import lcsb.mapviewer.model.cache.UploadedFileEntry;
import lcsb.mapviewer.model.map.InconsistentModelException; import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.layout.*; import lcsb.mapviewer.model.map.layout.*;
import lcsb.mapviewer.model.map.model.*; import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.User; import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.interfaces.ILayoutService; import lcsb.mapviewer.services.interfaces.ILayoutService;
import lcsb.mapviewer.services.utils.ColorSchemaReader; import lcsb.mapviewer.services.utils.ColorSchemaReader;
...@@ -72,6 +70,9 @@ public class ModelRestImpl extends BaseRestImpl { ...@@ -72,6 +70,9 @@ public class ModelRestImpl extends BaseRestImpl {
throw new QueryException("Invalid modelId: " + modelId); throw new QueryException("Invalid modelId: " + modelId);
} }
Model model = getModelService().getLastModelByProjectId(projectId); Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
Model submodel = model.getSubmodelById(modelId); Model submodel = model.getSubmodelById(modelId);
if (submodel == null) { if (submodel == null) {
return null; return null;
...@@ -193,7 +194,7 @@ public class ModelRestImpl extends BaseRestImpl { ...@@ -193,7 +194,7 @@ public class ModelRestImpl extends BaseRestImpl {
if (overlayIdsList.length > 0) { if (overlayIdsList.length > 0) {
new ClearColorModelCommand(part).execute(); new ClearColorModelCommand(part).execute();
} }
if (!backgroundOverlayId.equals("")) { if (!backgroundOverlayId.equals("")) {
Layout overlay = project.getLayoutByIdentifier(Integer.valueOf(backgroundOverlayId)); Layout overlay = project.getLayoutByIdentifier(Integer.valueOf(backgroundOverlayId));
...@@ -205,10 +206,9 @@ public class ModelRestImpl extends BaseRestImpl { ...@@ -205,10 +206,9 @@ public class ModelRestImpl extends BaseRestImpl {
// if it's clean then remove coloring // if it's clean then remove coloring
new ClearColorModelCommand(part).execute(); new ClearColorModelCommand(part).execute();
} }
} }
// Color with overlays // Color with overlays
for (String overlayId : overlayIdsList) { for (String overlayId : overlayIdsList) {
Layout overlay = layoutService.getLayoutById(Integer.parseInt(overlayId.trim())); Layout overlay = layoutService.getLayoutById(Integer.parseInt(overlayId.trim()));
...@@ -367,6 +367,9 @@ public class ModelRestImpl extends BaseRestImpl { ...@@ -367,6 +367,9 @@ public class ModelRestImpl extends BaseRestImpl {
} }
ImageGenerators imageGenerator = new ImageGenerators(); ImageGenerators imageGenerator = new ImageGenerators();
if (!imageGenerator.isValidClassName(handlerClass)) {
throw new QueryException("Invalid handlerClass");
}
String extension = imageGenerator.getExtension(handlerClass); String extension = imageGenerator.getExtension(handlerClass);
File file = File.createTempFile("map", "." + extension); File file = File.createTempFile("map", "." + extension);
......
...@@ -179,6 +179,7 @@ abstract public class ControllerIntegrationTest { ...@@ -179,6 +179,7 @@ abstract public class ControllerIntegrationTest {
protected Project createProject(String projectId) { protected Project createProject(String projectId) {
Project project = new Project(projectId); Project project = new Project(projectId);
ModelData map = new ModelData(); ModelData map = new ModelData();
map.setTileSize(256);
map.setWidth(100); map.setWidth(100);
map.setHeight(100); map.setHeight(100);
...@@ -187,6 +188,10 @@ abstract public class ControllerIntegrationTest { ...@@ -187,6 +188,10 @@ abstract public class ControllerIntegrationTest {
reaction.setLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(10, 0))); reaction.setLine(new PolylineData(new Point2D.Double(0, 0), new Point2D.Double(10, 0)));
map.addReaction(reaction); map.addReaction(reaction);
Element element = new GenericProtein("p1"); Element element = new GenericProtein("p1");
element.setWidth(100.0);
element.setHeight(20.0);
element.setX(10);
element.setX(20);
element.setZ(2); element.setZ(2);
map.addElement(element); map.addElement(element);
......
...@@ -3,6 +3,7 @@ package lcsb.mapviewer.web; ...@@ -3,6 +3,7 @@ package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
...@@ -20,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -20,6 +21,8 @@ import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.converter.graphics.PngImageGenerator;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.Project; import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.security.PrivilegeType; import lcsb.mapviewer.model.security.PrivilegeType;
...@@ -81,7 +84,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest { ...@@ -81,7 +84,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
public void testGetAllElementsForUndefinedProject() throws Exception { public void testGetAllElementsForUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN, MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD); ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/*/bioEntities/elements/") RequestBuilder request = get("/projects/*/models/*/bioEntities/elements/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session); .session(session);
...@@ -171,7 +174,6 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest { ...@@ -171,7 +174,6 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN, MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD); ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get( RequestBuilder request = get(
"/projects/*/models/*/bioEntities/suggestedQueryList") "/projects/*/models/*/bioEntities/suggestedQueryList")
.contentType(MediaType.APPLICATION_FORM_URLENCODED) .contentType(MediaType.APPLICATION_FORM_URLENCODED)
...@@ -199,4 +201,103 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest { ...@@ -199,4 +201,103 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
assertEquals((int) map.getId(), mapId); assertEquals((int) map.getId(), mapId);
} }
@Test
public void testGetMapByIdWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/" + map.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testGetMapsWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testUpdateMapWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
String content = "{}";
RequestBuilder request = patch("/projects/*/models/" + map.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session)
.content(content);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testDownloadImage() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/models/" + map.getId() + ":downloadImage?" +
"handlerClass=" + PngImageGenerator.class.getCanonicalName())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
}
@Test
public void testDownloadImageWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/" + map.getId() + ":downloadImage?" +
"handlerClass=" + PngImageGenerator.class.getCanonicalName())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testDownloadModel() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/models/" + map.getId() + ":downloadModel?" +
"handlerClass=" + CellDesignerXmlParser.class.getCanonicalName())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
}
@Test
public void testDownloadModelWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/" + map.getId() + ":downloadModel?" +
"handlerClass=" + CellDesignerXmlParser.class.getCanonicalName())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
} }
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