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

proper handling of undefined project id when searching for micro rnas

parent ac1f3411
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.MiRNASearchException;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.*;
@RestController
@RequestMapping(value = "/projects/{projectId}/", produces = MediaType.APPLICATION_JSON_VALUE)
......@@ -43,7 +42,7 @@ public class MiRnaController extends BaseController {
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
@GetMapping(value = "miRnas/suggestedQueryList")
public List<String> getSuggestedQueryList(@PathVariable(value = "projectId") String projectId)
throws MiRNASearchException {
throws MiRNASearchException, ObjectNotFoundException {
return miRnaController.getSuggestedQueryList(projectId);
}
......
......@@ -42,7 +42,7 @@ public class MiRnaRestImpl extends BaseRestImpl {
throws QueryException {
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);
......@@ -103,7 +103,7 @@ public class MiRnaRestImpl extends BaseRestImpl {
String columns) throws QueryException {
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);
......@@ -144,8 +144,11 @@ public class MiRnaRestImpl extends BaseRestImpl {
return result;
}
public List<String> getSuggestedQueryList(String projectId) throws MiRNASearchException {
public List<String> getSuggestedQueryList(String projectId) throws MiRNASearchException, ObjectNotFoundException {
Project project = getProjectService().getProjectByProjectId(projectId);
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist");
}
return miRNAParser.getSuggestedQueryList(project);
}
......
......@@ -50,6 +50,30 @@ public class MiRnaControllerIntegrationTest extends ControllerIntegrationTest {
.andExpect(status().is2xxSuccessful());
}
@Test
public void testSearchMiRnasInUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/miRnas:search?query=xyz")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
@Test
public void testSearchMiRnasByTargetInUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/miRnas: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);
......@@ -61,5 +85,17 @@ public class MiRnaControllerIntegrationTest extends ControllerIntegrationTest {
mockMvc.perform(request)
.andExpect(status().is2xxSuccessful());
}
@Test
public void testGetSuggestedListForUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/miRnas/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