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

proper handling of bioEntities requests with undefined project

parent 6b4774c9
......@@ -8,8 +8,7 @@ import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.*;
@RestController
@RequestMapping(value = "/projects/{projectId}/models/{modelId}/", produces = MediaType.APPLICATION_JSON_VALUE)
......@@ -67,7 +66,7 @@ public class BioEntitiesController extends BaseController {
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
@RequestMapping(value = "bioEntities/suggestedQueryList", method = { RequestMethod.GET, RequestMethod.POST })
public String[] getSuggestedQueryList(@PathVariable(value = "projectId") String projectId) {
public String[] getSuggestedQueryList(@PathVariable(value = "projectId") String projectId) throws ObjectNotFoundException {
return bioEntitiesRestImpl.getSuggestedQueryList(projectId);
}
......
......@@ -38,6 +38,9 @@ public class BioEntitiesRestImpl extends BaseRestImpl {
List<Map<String, Object>> resultMap = new ArrayList<>();
Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
Model submodel = model.getSubmodelById(modelId);
......@@ -66,6 +69,10 @@ public class BioEntitiesRestImpl extends BaseRestImpl {
List<Map<String, Object>> resultMap = new ArrayList<>();
Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
if (!modelId.equals("*")) {
model = model.getSubmodelById(modelId);
}
......@@ -82,8 +89,11 @@ public class BioEntitiesRestImpl extends BaseRestImpl {
return resultMap;
}
public String[] getSuggestedQueryList(String projectId) {
public String[] getSuggestedQueryList(String projectId) throws ObjectNotFoundException {
Model model = getModelService().getLastModelByProjectId(projectId);
if (model==null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
return searchService.getSuggestedQueryList(model);
}
......
......@@ -102,6 +102,34 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void testSearchBioEntitiesByCoordinatesWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get(
"/projects/*/models/" + map.getId() + "/bioEntities:search?coordinates=104.36,182.81")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testSearchBioEntitiesByQueryWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_LOGIN,
ControllerIntegrationTest.BUILT_IN_TEST_ADMIN_PASSWORD);
RequestBuilder request = get(
"/projects/*/models/" + map.getId() + "/bioEntities:search?query=s1")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testSearchBioEntitiesByCoordinatesWithInvalidModelId() throws Exception {
userService.grantUserPrivilege(anonymous, PrivilegeType.READ_PROJECT, project.getProjectId());
......@@ -138,6 +166,21 @@ public class MapControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void testSuggestedQueryListWithUndefinedProject() throws Exception {
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);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testGetMapById() 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