diff --git a/src/main/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateController.java b/src/main/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateController.java index 095bb22..bb56e98 100644 --- a/src/main/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateController.java +++ b/src/main/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateController.java @@ -1,6 +1,7 @@ package org.ihtsdo.otf.transformationandtemplate.rest; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -28,6 +29,7 @@ import org.snomed.authoringtemplate.domain.ConceptTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -71,15 +73,22 @@ public ResponseEntity createTemplate(@RequestParam String templateName, return ControllerHelper.getCreatedResponse(templateName); } - @RequestMapping(value = "/templates/{templateName}", method = RequestMethod.PUT, produces = "application/json") + @RequestMapping(value = "/templates", method = RequestMethod.PUT, produces = "application/json") @ResponseBody - public ConceptTemplate updateTemplate(@PathVariable String templateName, @RequestBody ConceptTemplate conceptTemplate) throws IOException, ServiceException { + public ConceptTemplate updateTemplate(@RequestParam String templateName, @RequestBody ConceptTemplate conceptTemplate) throws IOException, ServiceException { return templateService.update(templateName, conceptTemplate); } @RequestMapping(value = "/templates", method = RequestMethod.GET, produces = "application/json") @ResponseBody - public Set listTemplates() throws IOException { + public Set listTemplates(@RequestParam(required = false) String templateName) throws IOException { + if (StringUtils.hasLength(templateName)) { + ConceptTemplate template = templateService.load(templateName); + if (template == null) { + throw new ResourceNotFoundException("Template", templateName); + } + return Collections.singleton(template); + } return templateService.listAll(); } @@ -92,29 +101,19 @@ public Set listTemplates(@PathVariable String branchPath, descendantOf, ancestorOf); } - @RequestMapping(value = "/templates/{templateName}", method = RequestMethod.GET, produces = "application/json") - @ResponseBody - public ConceptTemplate getTemplate(@PathVariable String templateName) throws ResourceNotFoundException, IOException { - ConceptTemplate template = templateService.load(templateName); - if (template == null) { - throw new ResourceNotFoundException("Template", templateName); - } - return template; - } - - @RequestMapping(value = "/{branchPath}/templates/{templateName}/empty-input-file", method = RequestMethod.GET, + @RequestMapping(value = "/templates/empty-input-file", method = RequestMethod.GET, produces = "text/tab-separated-values; charset=utf-8") - public void getEmptyInputFile(@PathVariable String branchPath, @PathVariable String templateName, + public void getEmptyInputFile(@RequestParam String templateName, HttpServletResponse response) throws IOException, ResourceNotFoundException { response.setContentType("text/tab-separated-values; charset=utf-8"); templateService.writeEmptyInputFile(templateName, response.getOutputStream()); } - @RequestMapping(value = "/{branchPath}/templates/{templateName}/generate", method = RequestMethod.POST, consumes = "multipart/form-data") + @RequestMapping(value = "/{branchPath}/templates/generate", method = RequestMethod.POST, consumes = "multipart/form-data") @ResponseBody public List generateConcepts(@PathVariable String branchPath, - @PathVariable String templateName, + @RequestParam String templateName, @Parameter(description = "tsvFile") MultipartFile tsvFile) throws IOException, ServiceException { branchPath = BranchPathUriUtil.decodePath(branchPath); setBatchChangeFlagOnBranch(branchPath); @@ -126,10 +125,10 @@ public void reloadCache() throws IOException, ServiceException { templateService.reloadCache(); } - @RequestMapping(value = "/{branchPath}/templates/{templateName}/concepts", method = RequestMethod.GET, produces = "application/json") + @RequestMapping(value = "/{branchPath}/templates/concept-search", method = RequestMethod.GET, produces = "application/json") @ResponseBody public Set searchConcepts(@PathVariable String branchPath, - @PathVariable String templateName, + @RequestParam String templateName, @RequestParam Boolean logicalMatch, @RequestParam(required=false) Boolean lexicalMatch, @RequestParam(defaultValue="true") boolean stated) throws ServiceException { diff --git a/src/test/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateControllerTest.java b/src/test/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateControllerTest.java index 176a0ea..69ffb32 100644 --- a/src/test/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateControllerTest.java +++ b/src/test/java/org/ihtsdo/otf/transformationandtemplate/rest/TemplateControllerTest.java @@ -45,14 +45,14 @@ public void setup() throws IOException, ServiceException { @Test public void getTemplate() throws Exception { - mockMvc.perform(get("/templates/a%2Fb")) + mockMvc.perform(get("/templates?templateName=a%2Fb")) .andExpect(status().isOk()); } @Test public void getTemplateNameWithBracket() throws Exception { - mockMvc.perform(get("/templates/Allergy to [substance] (finding)")) + mockMvc.perform(get("/templates?templateName=Allergy to [substance] (finding)")) .andExpect(status().isOk()); }