Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • Genesys Backend Genesys Backend
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 23
    • Issues 23
    • List
    • Boards
    • Service Desk
    • Milestones
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Genesys PGR
  • Genesys BackendGenesys Backend
  • Issues
  • #464

Closed
Open
Created Sep 02, 2019 by Matija Obreza@mobrezaOwner

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"
Assignee
Assign to
Time tracking