diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsController.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsController.java index 8fd5ac43cf5e07240c13d8ee38592f273dad1f00..21b5336199ad0f71bc68dd588c58abfa50d53081 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsController.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsController.java @@ -27,10 +27,11 @@ public class ElementsController extends BaseController { @PathVariable(value = "projectId") String projectId, // @PathVariable(value = "modelId") String modelId, // @RequestParam(value = "id", defaultValue = "") String id, // + @RequestParam(value = "type", defaultValue = "") String type, // @RequestParam(value = "columns", defaultValue = "") String columns, // @CookieValue(value = Configuration.AUTH_TOKEN) String token// ) throws SecurityException { - return projectController.getElements(projectId, id, columns, modelId, token); + return projectController.getElements(projectId, id, columns, modelId, token, type); } } \ No newline at end of file diff --git a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java index bf3a78dd78cf028390517c5a86ea342d423ad51f..ad53a6b99e3b330b2d6eddba2902b35efbe14bc4 100644 --- a/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java +++ b/rest-api/src/main/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementsRestImpl.java @@ -39,7 +39,7 @@ public class ElementsRestImpl extends BaseRestImpl { @Autowired private OverviewImageViewFactory factory; - public List<Map<String, Object>> getElements(String projectId, String id, String columns, String modelId, String token) + public List<Map<String, Object>> getElements(String projectId, String id, String columns, String modelId, String token, String type) throws UserAccessException, SecurityException { Set<Integer> ids = new HashSet<>(); if (!id.equals("")) { @@ -56,7 +56,9 @@ public class ElementsRestImpl extends BaseRestImpl { for (Model model2 : models) { for (Element element : model2.getElements()) { if (ids.size() == 0 || ids.contains(element.getId())) { - result.add(preparedElement(element, columnsSet)); + if (type.isEmpty() || element.getStringType().equalsIgnoreCase(type)) { + result.add(preparedElement(element, columnsSet)); + } } } } diff --git a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java index f3c30757319e0f2098957d09eb3da05e0b809b58..8cc6d689ba44e9c600f646ff1290167135c709d9 100644 --- a/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java +++ b/rest-api/src/test/java/lcsb/mapviewer/api/projects/models/bioEntities/elements/ElementRestImplTest.java @@ -1,5 +1,6 @@ package lcsb.mapviewer.api.projects.models.bioEntities.elements; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.mockito.Matchers.any; @@ -8,6 +9,7 @@ import static org.mockito.Matchers.anyString; import java.util.List; import java.util.Map; +import org.apache.log4j.Logger; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -19,14 +21,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lcsb.mapviewer.api.RestTestFunctions; import lcsb.mapviewer.model.map.model.Model; +import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.services.interfaces.IModelService; public class ElementRestImplTest extends RestTestFunctions { + Logger logger = Logger.getLogger(RestTestFunctions.class); @Autowired ElementsRestImpl _elementsRestImpl; - ObjectMapper mapper = new ObjectMapper(); + ObjectMapper mapper = new ObjectMapper(); @AfterClass public static void tearDownAfterClass() throws Exception { @@ -44,7 +48,7 @@ public class ElementRestImplTest extends RestTestFunctions { public void testGetElementsProcessAllColumns() throws Exception { try { ElementsRestImpl projectRest = createMockProjectRest("testFiles/model/sample.xml"); - List<Map<String, Object>> result = projectRest.getElements("sample", "", "", "*", token.getId()); + List<Map<String, Object>> result = projectRest.getElements("sample", "", "", "*", token.getId(), ""); for (Map<String, Object> element : result) { for (String paramName : element.keySet()) { Object val = element.get(paramName); @@ -57,7 +61,21 @@ public class ElementRestImplTest extends RestTestFunctions { } String json = mapper.writeValueAsString(result); assertNotNull(json); - + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetElementsByType() throws Exception { + try { + String proteinType = new GenericProtein("1").getStringType(); + ElementsRestImpl projectRest = createMockProjectRest("testFiles/model/sample.xml"); + List<Map<String, Object>> result = projectRest.getElements("sample", "", "", "*", token.getId(), proteinType); + assertEquals(12, result.size()); + } catch (Exception e) { e.printStackTrace(); throw e;