Skip to content
Snippets Groups Projects
Commit ac1f3411 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

proper handling for undefined project id when searching for drugs

parent d29bceb6
No related branches found
No related tags found
1 merge request!895Resolve "Curator can not set the overlay public or change the owner"
......@@ -8,8 +8,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.annotation.services.DrugSearchException;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.*;
@RestController
@RequestMapping(value = "/projects/{projectId}/", produces = MediaType.APPLICATION_JSON_VALUE)
......@@ -28,7 +27,7 @@ public class DrugController extends BaseController {
@PathVariable(value = "projectId") String projectId,
@RequestParam(value = "columns", defaultValue = "") String columns,
@RequestParam(value = "query", defaultValue = "") String query,
@RequestParam(value = "target", defaultValue = "") String target) throws QueryException {
@RequestParam(value = "target", defaultValue = "") String target) throws QueryException, ObjectNotFoundException {
if (!query.equals("")) {
return drugController.getDrugsByQuery(projectId, columns, query);
} else if (target.contains(":")) {
......@@ -43,7 +42,7 @@ public class DrugController extends BaseController {
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
@GetMapping(value = "drugs/suggestedQueryList")
public List<String> getSuggestedQueryList(@PathVariable(value = "projectId") String projectId)
throws DrugSearchException {
throws DrugSearchException, ObjectNotFoundException {
return drugController.getSuggestedQueryList(projectId);
}
......
......@@ -41,10 +41,10 @@ public class DrugRestImpl extends BaseRestImpl {
}
public List<Map<String, Object>> getDrugsByQuery(String projectId, String columns, String query)
throws QueryException {
throws QueryException, ObjectNotFoundException {
Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
Project project = getProjectService().getProjectByProjectId(projectId);
......@@ -128,10 +128,10 @@ public class DrugRestImpl extends BaseRestImpl {
}
public List<Map<String, Object>> getDrugsByTarget(String projectId, String targetType, String targetId,
String columns) throws QueryException {
String columns) throws QueryException, ObjectNotFoundException {
Model model = getModelService().getLastModelByProjectId(projectId);
if (model == null) {
throw new QueryException("Project with given id doesn't exist");
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
Project project = getProjectService().getProjectByProjectId(projectId);
......@@ -176,8 +176,11 @@ public class DrugRestImpl extends BaseRestImpl {
return targets;
}
public List<String> getSuggestedQueryList(String projectId) throws DrugSearchException {
public List<String> getSuggestedQueryList(String projectId) throws DrugSearchException, ObjectNotFoundException {
Project project = getProjectService().getProjectByProjectId(projectId);
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
return drugService.getSuggestedQueryList(project, project.getOrganism());
}
......
......@@ -50,6 +50,30 @@ public class DrugControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void testSearchDrugsInUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/drugs:search?query=xyz")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testSearchDrugsByTargetInUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/drugs:search?target=ALIAS:123")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testGetSuggestedList() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
......@@ -62,4 +86,16 @@ public class DrugControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void testGetSuggestedListWithUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/drugs/suggestedQueryList")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment