Gitlab is now using https://gitlab.lcsb.uni.lu as it's primary address. Please update your bookmarks. FAQ.

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

issue with copy command

parent 624a6991
Pipeline #43229 passed with stage
in 19 minutes and 36 seconds
......@@ -15,6 +15,8 @@ minerva (16.0.0~beta.1) stable; urgency=medium
* Bug fix: problem with adding comments (#1495)
* Bug fix: project with invalid data might cause problem on
create/update/delete (#1509)
* Bug fix: exporting part of map as image caused removing not drawn species
from the database (#1508)
-- Piotr Gawron <piotr.gawron@uni.lu> Wed, 9 Jun 2021 15:00:00 +0200
......
......@@ -6,6 +6,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.MiriamData;
import lcsb.mapviewer.model.map.compartment.Compartment;
......@@ -21,9 +22,7 @@ import lcsb.mapviewer.model.map.species.*;
*/
public class CopyCommand extends NewModelCommand {
/**
* Defaul class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = LogManager.getLogger();
......@@ -71,6 +70,7 @@ public class CopyCommand extends NewModelCommand {
}
for (Model modelCopy : copies.values()) {
try {
result.getProject().addModel(modelCopy);
assignModelCopies(modelCopy, copies);
} catch (InvalidModelException e) {
throw new InvalidArgumentException(e);
......@@ -208,7 +208,7 @@ public class CopyCommand extends NewModelCommand {
}
assignSimpleDataToCopy(result, model);
result.setProject(model.getProject());
new Project().addModel(result);
for (Element element : result.getElements()) {
updateElementReferences(element, result, model);
......
......@@ -367,4 +367,15 @@ public class CopyCommandTest extends CommandTestFunctions {
}
@Test
public void testCopyModelWithProject() throws Exception {
Model originalModel = getModelForFile("testFiles/sample.xml", false);
Project project = new Project();
project.addModel(originalModel);
Model colorModel = new CopyCommand(originalModel).execute();
assertNotEquals(originalModel.getProject(), colorModel.getProject());
}
}
......@@ -16,8 +16,8 @@ import lcsb.mapviewer.api.BaseRestImpl;
import lcsb.mapviewer.commands.*;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params;
import lcsb.mapviewer.converter.*;
import lcsb.mapviewer.converter.graphics.AbstractImageGenerator.Params;
import lcsb.mapviewer.converter.graphics.DrawingException;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.model.Project;
......@@ -28,8 +28,6 @@ import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.model.*;
import lcsb.mapviewer.model.overlay.*;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.ObjectNotFoundException;
import lcsb.mapviewer.services.QueryException;
......@@ -278,7 +276,9 @@ public class ModelRestImpl extends BaseRestImpl {
}
Model originalModel = getModelService().getAndFetchModelByMapId(projectId, mapId);
Model colorModel = new CopyCommand(originalModel).execute();
if (background != null) {
if (Objects.equals(background.getName(), BuildInBackgrounds.CLEAN.getName())) {
// this might not return true if we change CLEAN.title in future...
......@@ -299,6 +299,7 @@ public class ModelRestImpl extends BaseRestImpl {
Path2D polygon = stringToPolygon(polygonString, colorModel);
SubModelCommand subModelCommand = new SubModelCommand(colorModel, polygon);
Model part = subModelCommand.execute();
Double minX = originalModel.getWidth();
......@@ -323,6 +324,9 @@ public class ModelRestImpl extends BaseRestImpl {
minX = Math.max(0.0, minX);
minY = Math.max(0.0, minY);
maxX = Math.max(minX + 1, maxX);
maxY = Math.max(minY + 1, maxY);
double scale = Math.max(originalModel.getHeight(), originalModel.getWidth())
/ (originalModel.getTileSize());
......@@ -339,7 +343,8 @@ public class ModelRestImpl extends BaseRestImpl {
}
List<Integer> visibleDataOverlaysIds = deserializeIdList(overlayIds);
for (Integer integer : visibleDataOverlaysIds) {
List<Pair<? extends BioEntity, DataOverlayEntry>> map = dataOverlayService.getBioEntitiesForDataOverlay(projectId, mapId,
List<Pair<? extends BioEntity, DataOverlayEntry>> map = dataOverlayService.getBioEntitiesForDataOverlay(projectId,
mapId,
integer);
params.addVisibleDataOverlay(map);
}
......
......@@ -9,6 +9,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.apache.commons.lang3.StringUtils;
......@@ -20,11 +21,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.restdocs.request.PathParametersSnippet;
import org.springframework.restdocs.request.RequestParametersSnippet;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.RequestBuilder;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonParser;
import lcsb.mapviewer.api.ElementIdentifierType;
......@@ -37,6 +41,7 @@ import lcsb.mapviewer.converter.graphics.PngImageGenerator;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.model.sbgnml.SbgnmlXmlConverter;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.layout.ProjectBackground;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.security.PrivilegeType;
......@@ -58,6 +63,9 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
@Autowired
private ReactionsRestImpl reactionRestImpl;
@Autowired
private ObjectMapper objectMapper;
private User anonymous;
private Project project;
......@@ -351,8 +359,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
String response = mockMvc.perform(request)
.andDo(document("projects/project_maps/get_elements_by_type",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
getAllElementsFilter(),
listOfElementsResponseFields()))
.andExpect(status().is2xxSuccessful())
......@@ -386,8 +393,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
String response = mockMvc.perform(request)
.andDo(document("projects/project_maps/get_reactions",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
getAllReactionsFilter(),
listOfReactionResponseFields()))
.andExpect(status().is2xxSuccessful())
......@@ -407,8 +413,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
String response = mockMvc.perform(request)
.andDo(document("projects/project_maps/get_reactions_limited_columns",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
getAllReactionsFilter(),
listOfReactionResponseFields()))
.andExpect(status().is2xxSuccessful())
......@@ -432,8 +437,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andDo(document("projects/project_maps/search_by_coordinates",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
getSearchParameters(),
listSearchResults()))
.andExpect(status().is2xxSuccessful());
......@@ -505,8 +509,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andDo(document("projects/project_maps/search_by_query",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
getSearchParameters(),
listSearchResults()))
.andExpect(status().is2xxSuccessful());
......@@ -531,8 +534,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andDo(document("projects/project_maps/suggested_query_list",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
responseFields(
fieldWithPath("[]")
.description("list of all full search queries that could be used for quering the map")
......@@ -609,8 +611,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful())
.andDo(document("projects/project_maps/update",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
mapPathParameters(),
requestFields(
fieldWithPath("model.defaultCenterX").description("default x center used in frontend visualization")
.type("number"),
......@@ -646,9 +647,40 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andDo(document("projects/project_maps/download_image_simple",
downloadImageRequestParameters(),
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier"))))
mapPathParameters()))
.andExpect(status().is2xxSuccessful());
}
@Test
public void testDownloadInfluenceMap() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder elementRequest = get("/projects/{projectId}/models/*/bioEntities/elements/",
TEST_PROJECT)
.session(session);
String content = mockMvc.perform(elementRequest).andReturn().getResponse().getContentAsString();
RequestBuilder request = get("/projects/{projectId}/models/{mapId}:downloadImage?" +
"handlerClass=" + PngImageGenerator.class.getCanonicalName() +
"&polygonString=10000,10000;10001,10000;10000,10001",
TEST_PROJECT, map.getId())
.session(session);
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
String afterImageDownloadContent = mockMvc.perform(elementRequest).andReturn().getResponse().getContentAsString();
List<Map<String, Object>> originalElements = objectMapper.readValue(content,
new TypeReference<List<Map<String, Object>>>() {
});
List<Map<String, Object>> afterImageDownloadElements = objectMapper.readValue(afterImageDownloadContent,
new TypeReference<List<Map<String, Object>>>() {
});
assertEquals("Some elements were removed during image generation",
originalElements.size(), afterImageDownloadElements.size());
}
@Test
......@@ -663,8 +695,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andDo(document("projects/project_maps/download_image_polygon",
downloadImageRequestParameters(),
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier"))))
mapPathParameters()))
.andExpect(status().is2xxSuccessful());
}
......@@ -745,4 +776,9 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().isNotFound());
}
private PathParametersSnippet mapPathParameters() {
return pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier"));
}
}
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