Commit 921e0fb4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fetching list of suggested drug list returns NotFound when project is not defined

parent 9c5343a4
......@@ -8,8 +8,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import lcsb.mapviewer.annotation.services.ChemicalSearchException;
import lcsb.mapviewer.api.BaseController;
import lcsb.mapviewer.api.QueryException;
import lcsb.mapviewer.api.*;
@RestController
@RequestMapping(value = "/projects", produces = MediaType.APPLICATION_JSON_VALUE)
......@@ -43,7 +42,7 @@ public class ChemicalController extends BaseController {
@PreAuthorize("hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)")
@GetMapping(value = "/{projectId}/chemicals/suggestedQueryList")
public List<String> getSuggestedQueryList(@PathVariable(value = "projectId") String projectId)
throws ChemicalSearchException {
throws ChemicalSearchException, ObjectNotFoundException {
return chemicalController.getSuggestedQueryList(projectId);
}
}
\ No newline at end of file
......@@ -200,8 +200,11 @@ public class ChemicalRestImpl extends BaseRestImpl {
return result;
}
public List<String> getSuggestedQueryList(String projectId) throws ChemicalSearchException {
public List<String> getSuggestedQueryList(String projectId) throws ChemicalSearchException, ObjectNotFoundException {
Project project = getProjectService().getProjectByProjectId(projectId);
if (project == null) {
throw new ObjectNotFoundException("Project with given id doesn't exist: " + projectId);
}
return chemicalParser.getSuggestedQueryList(project, project.getDisease());
}
}
......@@ -86,4 +86,16 @@ public class ChemicalControllerIntegrationTest extends ControllerIntegrationTest
.andExpect(status().is2xxSuccessful());
}
@Test
public void testgGetSuggestedListForUndefinedProject() throws Exception {
MockHttpSession session = createSession(TEST_ADMIN_LOGIN, TEST_ADMIN_PASSWORD);
RequestBuilder request = get("/projects/*/chemicals/suggestedQueryList")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.session(session);
mockMvc.perform(request)
.andExpect(status().isNotFound());
}
}
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