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

documentation for get list of reaction API call

parent 78ebbdbf
Pipeline #20994 failed with stage
in 24 minutes and 40 seconds
......@@ -258,25 +258,32 @@ public class ReactionsRestImpl extends BaseRestImpl {
return result;
}
public List<String> getAvailableReactionColumns() {
List<String> result = new ArrayList<>();
result.add("id");
result.add("reactionId");
result.add("modelId");
result.add("type");
result.add("lines");
result.add("kineticLaw");
result.add("centerPoint");
result.add("products");
result.add("reactants");
result.add("modifiers");
result.add("hierarchyVisibilityLevel");
result.add("references");
result.add("notes");
return result;
}
private Set<String> createReactionColumnSet(String columns) {
Set<String> columnsSet = new LinkedHashSet<>();
if (columns.equals("")) {
columnsSet.add("id");
columnsSet.add("reactionId");
columnsSet.add("modelId");
columnsSet.add("type");
columnsSet.add("lines");
columnsSet.add("kineticLaw");
columnsSet.add("centerPoint");
columnsSet.add("products");
columnsSet.add("reactants");
columnsSet.add("modifiers");
columnsSet.add("hierarchyVisibilityLevel");
columnsSet.add("references");
columnsSet.add("notes");
columnsSet.addAll(getAvailableReactionColumns());
} else {
Collections.addAll(columnsSet, columns.split(","));
}
return columnsSet;
}
}
......@@ -102,6 +102,7 @@ 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.
......@@ -122,3 +123,25 @@ 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[]
== Get reactions
Get list of reactions.
=== Path Parameters
include::{snippets}/projects/project_maps/get_reactions/path-parameters.adoc[]
=== Request Parameters
include::{snippets}/projects/project_maps/get_reactions/request-parameters.adoc[]
=== Response Fields
include::{snippets}/projects/project_maps/get_reactions/response-fields.adoc[]
=== CURL sample 1
include::{snippets}/projects/project_maps/get_reactions/curl-request.adoc[]
=== Sample Response 1
include::{snippets}/projects/project_maps/get_reactions/response-body.adoc[]
=== CURL sample 2
include::{snippets}/projects/project_maps/get_reactions_limited_columns/curl-request.adoc[]
......@@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.google.gson.JsonParser;
import lcsb.mapviewer.api.projects.models.bioEntities.elements.ElementsRestImpl;
import lcsb.mapviewer.api.projects.models.bioEntities.reactions.ReactionsRestImpl;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.MimeType;
import lcsb.mapviewer.converter.graphics.PdfImageGenerator;
......@@ -66,6 +67,9 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
@Autowired
private ElementsRestImpl elementRestImpl;
@Autowired
private ReactionsRestImpl reactionRestImpl;
@Before
public void setup() {
project = createProject(TEST_PROJECT);
......@@ -89,7 +93,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
getAllElementsFilter(),
listyOfElementsResponseFields()))
listOfElementsResponseFields()))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
......@@ -100,7 +104,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
assertTrue("user should be able to access elements", elements > 0);
}
private ResponseFieldsSnippet listyOfElementsResponseFields() {
private ResponseFieldsSnippet listOfElementsResponseFields() {
return responseFields(
fieldWithPath("[].id")
.description("unique element identifier")
......@@ -115,7 +119,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.type("string")
.optional(),
fieldWithPath("[].modelId")
.description("bmap identifier")
.description("map identifier")
.type("number")
.optional(),
fieldWithPath("[].complexId")
......@@ -200,6 +204,66 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.optional());
}
private ResponseFieldsSnippet listOfReactionResponseFields() {
return responseFields(
fieldWithPath("[].id")
.description("unique element identifier")
.type("number")
.optional(),
fieldWithPath("[].reactionId")
.description("reaction identifier taken from source file")
.type("string")
.optional(),
fieldWithPath("[].modelId")
.description("map identifier")
.type("number")
.optional(),
fieldWithPath("[].type")
.description("reaction type")
.type("string")
.optional(),
subsectionWithPath("[].centerPoint")
.description("center point")
.type("Point")
.optional(),
subsectionWithPath("[].lines")
.description("list of lines used to draw reaction")
.type("Array<Line>")
.optional(),
fieldWithPath("[].hierarchyVisibilityLevel")
.description("at what zoom level this element becomes visible in hierarchical view")
.type("string")
.optional(),
subsectionWithPath("[].references")
.description("list of references")
.type("Array<Reference>")
.optional(),
subsectionWithPath("[].modifiers")
.description("list of modifiers")
.type("Array<Object>")
.optional(),
subsectionWithPath("[].reactants")
.description("list of reactants")
.type("Array<Object>")
.optional(),
subsectionWithPath("[].products")
.description("list of products")
.type("Array<Object>")
.optional(),
fieldWithPath("[].notes")
.description("notes and description")
.type("string")
.optional(),
fieldWithPath("[].kineticLaw")
.description("SBML kinetics law")
.type("Object")
.optional(),
subsectionWithPath("[].other")
.description("list of oher properties")
.type("Object")
.optional());
}
private RequestParametersSnippet getAllElementsFilter() {
return requestParameters(
parameterWithName("id")
......@@ -221,11 +285,27 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.optional());
}
private RequestParametersSnippet getAllReactionsFilter() {
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(reactionRestImpl.getAvailableReactionColumns(), ", "))
.optional(),
parameterWithName("participantId")
.description("set of element identifiers for which reaction we are looking for "
+ "(only reactions with at least one participant will be returned)")
.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",
RequestBuilder request = get(
"/projects/{projectId}/models/{mapId}/bioEntities/elements/?columns=name,complexId&type=Protein",
TEST_PROJECT, "*");
String response = mockMvc.perform(request)
......@@ -233,7 +313,7 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
getAllElementsFilter(),
listyOfElementsResponseFields()))
listOfElementsResponseFields()))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
......@@ -260,6 +340,54 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().isNotFound());
}
@Test
public void testGetAllReactions() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get("/projects/{projectId}/models/{mapId}/bioEntities/reactions/", TEST_PROJECT, "*");
String response = mockMvc.perform(request)
.andDo(document("projects/project_maps/get_reactions",
pathParameters(parameterWithName("projectId").description("project identifier"),
parameterWithName("mapId").description("map identifier")),
getAllReactionsFilter(),
listOfReactionResponseFields()))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
int elements = new JsonParser()
.parse(response)
.getAsJsonArray().size();
assertTrue("user should be able to access elements", elements > 0);
}
@Test
public void testGetAllReactionsWithFilteredColumns() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
RequestBuilder request = get("/projects/{projectId}/models/{mapId}/bioEntities/reactions/?columns=id,notes", TEST_PROJECT, "*");
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")),
getAllReactionsFilter(),
listOfReactionResponseFields()))
.andExpect(status().is2xxSuccessful())
.andReturn().getResponse().getContentAsString();
String id = new JsonParser()
.parse(response)
.getAsJsonArray().get(0).getAsJsonObject().get("id").getAsString();
assertNotNull(id);
assertNull(new JsonParser()
.parse(response)
.getAsJsonArray().get(0).getAsJsonObject().get("modifiers"));
}
@Test
public void testSearchBioEntitiesAsAnonymous() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
......
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