Commit f9ec8d8d authored by Matija Obreza's avatar Matija Obreza
Browse files

REST /api/v0/acn/{instCode}/check returns accessions IDs if acn exists

parent c7f90072
......@@ -40,6 +40,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
@Controller("restAccessionController")
......@@ -79,6 +80,58 @@ public class AccessionController extends RestController {
* @throws IOException
* @throws JsonProcessingException
*/
@RequestMapping(value = "/{instCode}/check", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
JsonNode check(@PathVariable("instCode") String instCode, @RequestBody String content) throws JsonProcessingException, IOException {
// TODO Check user's permissions to update this WIEWS institute.
JsonNode json = mapper.readTree(content);
Map<DataJson, ObjectNode> batch = new HashMap<DataJson, ObjectNode>();
if (json.isArray()) {
for (JsonNode j : json) {
DataJson dataJson = readAid3(j);
if (!instCode.equals(dataJson.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + dataJson);
}
batch.put(dataJson, (ObjectNode) j);
}
} else {
DataJson dataJson = readAid3(json);
if (!instCode.equals(dataJson.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + dataJson);
}
batch.put(dataJson, (ObjectNode) json);
}
LOG.info("Batch processing " + batch.size() + " entries");
ArrayNode rets = mapper.createArrayNode();
for (DataJson dataJson : batch.keySet()) {
if (LOG.isDebugEnabled())
LOG.debug("Loading accession " + dataJson);
ObjectNode ret = mapper.createObjectNode();
ret.put("instCode", dataJson.instCode);
ret.put("genus", dataJson.genus);
ret.put("acceNumb", dataJson.acceNumb);
Accession accession = genesysService.getAccession(dataJson.instCode, dataJson.genus, dataJson.acceNumb);
ret.put("id", accession != null ? accession.getId() : null);
rets.add(ret);
}
return rets;
}
/**
* Update accessions in the system
*
* @return
* @throws IOException
* @throws JsonProcessingException
*/
@RequestMapping(value = "/{instCode}/update", method = { RequestMethod.POST, RequestMethod.PUT }, produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody
boolean updateInstituteAccession(@PathVariable("instCode") String instCode, @RequestBody String content) throws JsonProcessingException, IOException {
......
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