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

Fixed NPE when JSON cannot be parsed to Accession

parent 57c7445c
......@@ -132,31 +132,31 @@ public class AccessionUploader implements InitializingBean {
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);
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()));
}
}
List<Accession> forUpdate = new ArrayList<>(accessions.size());
forUpdate.addAll(accessions);
// Security check
for (int i = 0; i < accessions.size(); i++) {
Accession accession = accessions.get(i);
if (accession == null) {
continue;
}
if (!institute.getCode().equals(accession.getInstituteCode())) {
throw new InvalidApiUsageException("Accession does not belong to institute " + institute.getCode());
}
}
List<Accession> existingAccessions = accessionRepository.find(forUpdate);
LOG.debug("Have {} accessions for update and {} exist", forUpdate.size(), existingAccessions.size());
List<Accession> existingAccessions = accessionRepository.find(accessions);
LOG.debug("Have {} accessions for update and {} exist", accessions.size(), existingAccessions.size());
for (int i = 0; i < forUpdate.size(); i++) {
for (int i = 0; i < accessions.size(); i++) {
final JsonNode update = updates.get(i);
// Should we?
final Accession forU = forUpdate.get(i);
final Accession forU = accessions.get(i);
if (forU == null) {
LOG.debug("Skipping update of {}", update);
continue;
......
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