From ab5c882de193f0b7a821ba71686361d8033618ac Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Mon, 12 Nov 2018 16:29:58 +0100 Subject: [PATCH] bug during refactor - project was not defined when creating overlays --- .../projects/overlays/OverlayRestImpl.java | 13 +++-- .../api/projects/AllProjectTests.java | 2 + .../overlays/OverlayRestImplTest.java | 49 +++++++++++++++++++ .../services/impl/LayoutService.java | 8 +++ .../services/interfaces/ILayoutService.java | 3 ++ 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java index 263538def8..b26d2a2bc0 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImpl.java @@ -359,9 +359,16 @@ public class OverlayRestImpl extends BaseRestImpl { } Layout layout = layoutService - .createLayout(new CreateLayoutParams().async(false).colorInputStream(stream).description(description) - .layoutFileName(filename).name(name).user(user).colorSchemaType(colorSchemaType) - .directory(".").googleLicenseConsent(googleLicenseConsent.equalsIgnoreCase("true"))); + .createLayout(new CreateLayoutParams() + .async(false) + .colorInputStream(stream) + .description(description) + .layoutFileName(filename) + .name(name).user(user) + .colorSchemaType(colorSchemaType) + .directory(".") + .project(project) + .googleLicenseConsent(googleLicenseConsent.equalsIgnoreCase("true"))); int count = layoutService.getCustomLayouts(project, token, false, user).size(); layout.setOrderIndex(count); diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/AllProjectTests.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/AllProjectTests.java index dc06efddf7..b9d9c70c43 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/AllProjectTests.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/AllProjectTests.java @@ -9,6 +9,7 @@ import lcsb.mapviewer.api.projects.comments.AllCommentTests; import lcsb.mapviewer.api.projects.drugs.AllDrugTests; import lcsb.mapviewer.api.projects.mirnas.AllMiRnaTests; import lcsb.mapviewer.api.projects.models.AllModelsTests; +import lcsb.mapviewer.api.projects.overlays.OverlayRestImplTest; @RunWith(Suite.class) @SuiteClasses({ AllChemicalTests.class, @@ -16,6 +17,7 @@ import lcsb.mapviewer.api.projects.models.AllModelsTests; AllDrugTests.class, AllMiRnaTests.class, AllModelsTests.class, + OverlayRestImplTest.class, ProjectRestImplTest.class }) public class AllProjectTests { diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java new file mode 100644 index 0000000000..fd9ac2c7c7 --- /dev/null +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/overlays/OverlayRestImplTest.java @@ -0,0 +1,49 @@ +package lcsb.mapviewer.api.projects.overlays; + +import static org.junit.Assert.assertNotNull; + +import java.util.Map; + +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.gson.Gson; + +import lcsb.mapviewer.api.RestTestFunctions; +import lcsb.mapviewer.model.Project; +import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.persist.dao.ProjectDao; +import lcsb.mapviewer.services.utils.data.ColorSchemaType; + +public class OverlayRestImplTest extends RestTestFunctions { + + @Autowired + OverlayRestImpl overlayRest; + + @Autowired + ProjectDao projectDao; + + String projectId = "test_id"; + + @Test + public void testAddDataOverlay() throws Exception { + try { + createProject("testFiles/model/sample.xml", projectId); + Map<String, Object> result = overlayRest.addOverlay(adminToken, projectId, "x", "desc", "s1", null, null, + ColorSchemaType.GENERIC.name(), "true"); + Gson gson = new Gson(); + assertNotNull(gson.toJson(result)); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + private void createProject(String string, String projectId) throws Exception { + Project project = new Project(projectId); + Model model = super.getModelForFile(string, true); + project.addModel(model); + projectDao.add(project); + } + +} diff --git a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java index ecd3c112a6..5e48bc293e 100644 --- a/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/impl/LayoutService.java @@ -952,4 +952,12 @@ public class LayoutService implements ILayoutService { User user = userService.getUserByToken(authenticationToken); return userCanRemoveLayout(layout, user); } + + public LayoutDao getLayoutDao() { + return layoutDao; + } + + public void setLayoutDao(LayoutDao layoutDao) { + this.layoutDao = layoutDao; + } } diff --git a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java index bb4b02d366..11f129385e 100644 --- a/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java +++ b/service/src/main/java/lcsb/mapviewer/services/interfaces/ILayoutService.java @@ -17,6 +17,7 @@ import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.user.User; +import lcsb.mapviewer.persist.dao.map.LayoutDao; import lcsb.mapviewer.services.SecurityException; import lcsb.mapviewer.services.utils.EmailSender; import lcsb.mapviewer.services.utils.data.ColorSchemaType; @@ -493,4 +494,6 @@ public interface ILayoutService { boolean userCanRemoveLayout(Layout layout, String authenticationToken) throws SecurityException; + void setLayoutDao(LayoutDao layoutDao); + } -- GitLab