Commit 78ebbdbf authored by Piotr Gawron's avatar Piotr Gawron
Browse files

documentation for get list of elements API call

parent 20ad681a
......@@ -316,33 +316,38 @@ public class ElementsRestImpl extends BaseRestImpl {
return result;
}
public List<String> getAvailableElementColumns() {
List<String> result = new ArrayList<>();
result.add("id");
result.add("elementId");
result.add("modelId");
result.add("name");
result.add("type");
result.add("notes");
result.add("symbol");
result.add("complexId");
result.add("compartmentId");
result.add("fullName");
result.add("abbreviation");
result.add("formula");
result.add("synonyms");
result.add("formerSymbols");
result.add("references");
result.add("bounds");
result.add("hierarchyVisibilityLevel");
result.add("transparencyLevel");
result.add("linkedSubmodel");
result.add("other");
result.add("initialConcentration");
result.add("boundaryCondition");
result.add("constant");
result.add("initialAmount");
return result;
}
private Set<String> createElementColumnSet(String columns) {
Set<String> columnsSet = new LinkedHashSet<>();
if (columns.equals("")) {
columnsSet.add("id");
columnsSet.add("elementId");
columnsSet.add("modelId");
columnsSet.add("name");
columnsSet.add("type");
columnsSet.add("notes");
columnsSet.add("symbol");
columnsSet.add("complexId");
columnsSet.add("compartmentId");
columnsSet.add("fullName");
columnsSet.add("abbreviation");
columnsSet.add("formula");
columnsSet.add("synonyms");
columnsSet.add("formerSymbols");
columnsSet.add("references");
columnsSet.add("bounds");
columnsSet.add("hierarchyVisibilityLevel");
columnsSet.add("transparencyLevel");
columnsSet.add("linkedSubmodel");
columnsSet.add("other");
columnsSet.add("initialConcentration");
columnsSet.add("boundaryCondition");
columnsSet.add("constant");
columnsSet.add("initialAmount");
columnsSet.addAll(getAvailableElementColumns());
} else {
columnsSet.addAll(Arrays.asList(columns.split(",")));
}
......
......@@ -101,3 +101,24 @@ include::{snippets}/projects/project_maps/download_image_simple/curl-request.ado
=== CURL sample 2
include::{snippets}/projects/project_maps/download_image_polygon/curl-request.adoc[]
== Get elements
Get list of elements.
=== Path Parameters
include::{snippets}/projects/project_maps/get_elements/path-parameters.adoc[]
=== Request Parameters
include::{snippets}/projects/project_maps/get_elements/request-parameters.adoc[]
=== Response Fields
include::{snippets}/projects/project_maps/get_elements/response-fields.adoc[]
=== CURL sample 1
include::{snippets}/projects/project_maps/get_elements/curl-request.adoc[]
=== Sample Response 1
include::{snippets}/projects/project_maps/get_elements/response-body.adoc[]
=== CURL sample 2
include::{snippets}/projects/project_maps/get_elements_by_type/curl-request.adoc[]
package lcsb.mapviewer.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.patch;
......@@ -9,6 +8,7 @@ import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
......@@ -26,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser;
import lcsb.mapviewer.api.projects.models.bioEntities.elements.ElementsRestImpl;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.converter.graphics.PdfImageGenerator;
......@@ -60,7 +61,10 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
private ModelData map;
@Autowired
ProjectSnippets snippets;
private ProjectSnippets snippets;
@Autowired
private ElementsRestImpl elementRestImpl;
@Before
public void setup() {
......@@ -78,10 +82,14 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
public void testGetAllElements() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get("/projects/" + TEST_PROJECT + "/models/*/bioEntities/elements/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
RequestBuilder request = get("/projects/{projectId}/models/{mapId}/bioEntities/elements/", TEST_PROJECT, "*");
String response = mockMvc.perform(request)
.andDo(document("projects/project_maps/get_elements",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
getAllElementsFilter(),
listyOfElementsResponseFields()))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
......@@ -92,14 +100,161 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
assertTrue("user should be able to access elements", elements > 0);
}
private ResponseFieldsSnippet listyOfElementsResponseFields() {
return responseFields(
fieldWithPath("[].id")
.description("unique element identifier")
.type("number")
.optional(),
fieldWithPath("[].elementId")
.description("element identifier taken from source file")
.type("string")
.optional(),
fieldWithPath("[].name")
.description("name")
.type("string")
.optional(),
fieldWithPath("[].modelId")
.description("bmap identifier")
.type("number")
.optional(),
fieldWithPath("[].complexId")
.description("identifier of a complex in which element is located")
.type("number")
.optional(),
fieldWithPath("[].compartmentId")
.description("identifier of a compartment in which element is located")
.type("number")
.optional(),
fieldWithPath("[].linkedSubmodel")
.description("identifier of a submap to which this element is an entry point (anchor)")
.type("number")
.optional(),
fieldWithPath("[].type")
.description("element type")
.type("string")
.optional(),
subsectionWithPath("[].bounds")
.description("coordinates and the dimension of the element on the map")
.type("Object")
.optional(),
fieldWithPath("[].hierarchyVisibilityLevel")
.description("at what zoom level this element becomes visible in hierarchical view")
.type("string")
.optional(),
fieldWithPath("[].transparencyLevel")
.description("at what zoom level this element becomes transparent in hierarchical view")
.type("string")
.optional(),
subsectionWithPath("[].synonyms")
.description("list of synonyms")
.type("Array<String>")
.optional(),
subsectionWithPath("[].formerSymbols")
.description("list of former symbols")
.type("Array<String>")
.optional(),
subsectionWithPath("[].references")
.description("list of references")
.type("Array<Reference>")
.optional(),
fieldWithPath("[].notes")
.description("notes and description")
.type("string")
.optional(),
fieldWithPath("[].symbol")
.description("symbol")
.type("string")
.optional(),
fieldWithPath("[].fullName")
.description("full name")
.type("string")
.optional(),
fieldWithPath("[].abbreviation")
.description("abbreviation")
.type("string")
.optional(),
fieldWithPath("[].formula")
.description("formula")
.type("string")
.optional(),
fieldWithPath("[].boundaryCondition")
.description("SBML kinetics is boundary condition")
.type("boolean")
.optional(),
fieldWithPath("[].constant")
.description("SBML kinetics is constant")
.type("boolean")
.optional(),
fieldWithPath("[].initialAmount")
.description("SBML kinetics initial amount")
.type("number")
.optional(),
fieldWithPath("[].initialConcentration")
.description("SBML kinetics initial concentration")
.type("boolean")
.optional(),
subsectionWithPath("[].other")
.description("list of oher properties")
.type("Object")
.optional());
}
private RequestParametersSnippet getAllElementsFilter() {
return requestParameters(
parameterWithName("id")
.description("set of database ids (all by default)")
.optional(),
parameterWithName("columns")
.description("set of columns (all by default). Available options: "
+ StringUtils.join(elementRestImpl.getAvailableElementColumns(), ", "))
.optional(),
parameterWithName("includedCompartmentIds")
.description("set of database compartment ids (all by default)")
.optional(),
parameterWithName("excludedCompartmentIds")
.description("set of database compartment ids (none by default)")
.optional(),
parameterWithName("type")
.description("element type (all by default). Available options: "
+ StringUtils.join(snippets.getElementStringTypes(), ", "))
.optional());
}
@Test
public void testGetAllElementsFiltereByType() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get("/projects/{projectId}/models/{mapId}/bioEntities/elements/?columns=name,complexId&type=Protein",
TEST_PROJECT, "*");
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")),
getAllElementsFilter(),
listyOfElementsResponseFields()))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
String name = new JsonParser()
.parse(response)
.getAsJsonArray().get(0).getAsJsonObject().get("name").getAsString();
assertNotNull(name);
assertNull(new JsonParser()
.parse(response)
.getAsJsonArray().get(0).getAsJsonObject().get("id"));
}
@Test
public void testGetAllElementsForUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/*/bioEntities/elements/")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
RequestBuilder request = get("/projects/*/models/*/bioEntities/elements/").session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
......@@ -110,8 +265,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/" + map.getId() + "/bioEntities:search?coordinates=104.36,182.81")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
"/projects/" + TEST_PROJECT + "/models/" + map.getId() + "/bioEntities:search?coordinates=104.36,182.81");
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
......@@ -124,7 +278,6 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
RequestBuilder request = get(
"/projects/*/models/" + map.getId() + "/bioEntities:search?coordinates=104.36,182.81")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
......@@ -138,7 +291,6 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
RequestBuilder request = get(
"/projects/*/models/" + map.getId() + "/bioEntities:search?query=s1")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
......@@ -150,8 +302,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/-1/bioEntities:search?coordinates=104.36,182.81")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
"/projects/" + TEST_PROJECT + "/models/-1/bioEntities:search?coordinates=104.36,182.81");
mockMvc.perform(request)
.andExpect(status().isNotFound());
......@@ -162,8 +313,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/-1/bioEntities:search?query=s1")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
"/projects/" + TEST_PROJECT + "/models/-1/bioEntities:search?query=s1");
mockMvc.perform(request)
.andExpect(status().isNotFound());
......@@ -174,8 +324,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get(
"/projects/" + TEST_PROJECT + "/models/*/bioEntities:search?query=s1")
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
"/projects/" + TEST_PROJECT + "/models/*/bioEntities:search?query=s1");
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
......@@ -186,10 +335,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get(
"/projects/*/models/*/bioEntities/suggestedQueryList")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
RequestBuilder request = get("/projects/*/models/*/bioEntities/suggestedQueryList").session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
......@@ -244,9 +390,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
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);
RequestBuilder request = get("/projects/*/models/" + map.getId()).session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
......@@ -257,8 +401,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/models/")
.session(session);
RequestBuilder request = get("/projects/*/models/").session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
......@@ -326,7 +469,6 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
String content = "{\"model\":{}}";
RequestBuilder request = patch("/projects/*/models/" + map.getId())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session)
.content(content);
......
package lcsb.mapviewer.web;
import static org.mockito.Mockito.CALLS_REAL_METHODS;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import java.util.*;
import org.apache.commons.lang3.StringUtils;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.stereotype.Component;
......@@ -15,6 +17,8 @@ import lcsb.mapviewer.converter.graphics.AbstractImageGenerator;
import lcsb.mapviewer.converter.graphics.ImageGenerators;
import lcsb.mapviewer.model.ProjectStatus;
import lcsb.mapviewer.model.graphics.MapCanvasType;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.modelutils.map.ElementUtils;
@Component
public class ProjectSnippets {
......@@ -112,4 +116,14 @@ public class ProjectSnippets {
return StringUtils.join(options, ", ");
}
public List<String> getElementStringTypes() {
Set<String> types = new HashSet<>();
for (Class<? extends Element> clazz : new ElementUtils().getAvailableElementSubclasses()) {
types.add(Mockito.mock(clazz, CALLS_REAL_METHODS).getStringType());
}
List<String> result = new ArrayList<>(types);
Collections.sort(result);
return result;
}
}
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