API v1 delete accession
We upgraded the uploader code for API v1 to use the new JSON field names, matching the Java model. Anno project already sends the new JSON:
[
{
"instituteCode": ...,
"accessionNumber": ....,
"taxonomy": { "genus": .... } }
...
]
Updating accession data works well, but we forgot to fix the code for deleteAccessions
. It still receives @RequestBody List<AccessionHeaderJson> batch
.
Please update the delete code (implementation should be based on upsert code):
ObjectReader reader = objectMapper.readerFor(Accession.class);
Date batchDate = new Date();
final List<Accession> accessions = new ArrayList<>(updates.size());
final List<AccessionOpResponse> responses = new ArrayList<>(updates.size());
List<Accession> toSave = new ArrayList<>(updates.size());
for (JsonNode accn : updates) {
LOG.trace("Received: {}", accn);
try {
Accession accession = reader.readValue(accn);
if (accession.getInstituteCode() == null || (accession.getDoi() == null && accession.getAccessionNumber() == null)) {
throw new InvalidApiUsageException("instituteCode, accessionNumber OR doi missing in " + accn);
}
accessions.add(accession);
responses.add(new AccessionOpResponse(accession.getInstituteCode(), accession.getAccessionNumber(), accession.getTaxonomy().getGenus()));
} catch (IOException e) {
LOG.error("Could not parse input: {}", e.getMessage(), e);
accessions.add(null); // need to match get(index) with responses and updates
responses.add(new AccessionOpResponse(accn.get("instituteCode").asText(), accn.get("accessionNumber").asText(), accn.get("taxonomy").get("genus").asText())
.setResult(new UpsertResult(UpsertResult.Type.ERROR)).setError(e.getMessage()));
}
}
LOG.debug("Processsed incoming JSON for {} accessions in {}ms", updates.size(), stopWatch.getTime());
List<Accession> existingAccessions = accessionRepository.find(! institute.hasUniqueAcceNumbs(), accessions);
LOG.debug("Have {} accessions for update and {} exist in {}ms", accessions.size(), existingAccessions.size(), stopWatch.getTime());
// Add code to remove existing accessions
// Missing accessions should have OP error message set to "Record not found"