Commit 50c0b09c authored by Matija Obreza's avatar Matija Obreza

FIX Taxonomy also updated when only sub-elements are provided for update

(e.g. only spauthor)
parent 611c201d
...@@ -66,6 +66,19 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel { ...@@ -66,6 +66,19 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy") @OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy")
private List<CropTaxonomy> cropTaxonomies; private List<CropTaxonomy> cropTaxonomies;
public Taxonomy2() {
}
public Taxonomy2(Taxonomy2 taxonomy) {
if (taxonomy != null) {
this.genus = taxonomy.genus;
this.species = taxonomy.species;
this.spAuthor = taxonomy.spAuthor;
this.subtaxa = taxonomy.subtaxa;
this.subtAuthor = taxonomy.subtAuthor;
}
}
@PrePersist @PrePersist
private void prePersist() { private void prePersist() {
this.taxonName = getTaxonName(); this.taxonName = getTaxonName();
...@@ -166,7 +179,8 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel { ...@@ -166,7 +179,8 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@Override @Override
public String toString() { public String toString() {
return MessageFormat.format("Tax id={0} taxonName={1} genus={2} sp={3} spauthor={4} subtaxa={5} subtauthor={6}", id, getTaxonName(), genus, species, spAuthor, subtaxa, subtAuthor); return MessageFormat.format("Tax id={0} taxonName={1} genus={2} sp={3} spauthor={4} subtaxa={5} subtauthor={6}", id, getTaxonName(), genus, species,
spAuthor, subtaxa, subtAuthor);
} }
} }
...@@ -21,12 +21,17 @@ public class GenesysJsonFactory { ...@@ -21,12 +21,17 @@ public class GenesysJsonFactory {
aj.setUuid(accession.getUuid()); aj.setUuid(accession.getUuid());
Taxonomy2 tax = accession.getTaxonomy(); Taxonomy2 tax = accession.getTaxonomy();
aj.setGenus(tax.getGenus()); if (tax != null) {
aj.setSpecies(tax.getSpecies()); aj.setGenus(tax.getGenus());
aj.setSpauthor(tax.getSpAuthor()); aj.setSpecies(tax.getSpecies());
aj.setSubtaxa(tax.getSubtaxa()); aj.setSpauthor(tax.getSpAuthor());
aj.setSubtauthor(tax.getSubtAuthor()); aj.setSubtaxa(tax.getSubtaxa());
aj.setOrgCty(accession.getCountryOfOrigin().getCode3()); aj.setSubtauthor(tax.getSubtAuthor());
}
if (accession.getCountryOfOrigin() != null) {
aj.setOrgCty(accession.getCountryOfOrigin().getCode3());
}
aj.setAcqDate(accession.getAcquisitionDate()); aj.setAcqDate(accession.getAcquisitionDate());
aj.setMlsStat(accession.getMlsStatus()); aj.setMlsStat(accession.getMlsStatus());
aj.setInTrust(accession.getInTrust()); aj.setInTrust(accession.getInTrust());
......
...@@ -444,11 +444,9 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -444,11 +444,9 @@ public class BatchRESTServiceImpl implements BatchRESTService {
boolean updated = false; boolean updated = false;
// Do not persist this one, temporary use // Do not persist this one, temporary use
Taxonomy2 current = new Taxonomy2();
Taxonomy2 taxonomy = accession.getTaxonomy(); Taxonomy2 taxonomy = accession.getTaxonomy();
Taxonomy2 current = new Taxonomy2(taxonomy);
// Load JSON values into "current" // Load JSON values into "current"
if (taxonomy!=null)
current.setId(taxonomy.getId());
current.setGenus(stringIfProvided(accnJson.get("genus"), current.getGenus())); current.setGenus(stringIfProvided(accnJson.get("genus"), current.getGenus()));
current.setGenus(stringIfProvided(accnJson.get("newGenus"), current.getGenus())); current.setGenus(stringIfProvided(accnJson.get("newGenus"), current.getGenus()));
current.setSpecies(stringIfProvided(accnJson.get("species"), current.getSpecies())); current.setSpecies(stringIfProvided(accnJson.get("species"), current.getSpecies()));
...@@ -459,7 +457,7 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -459,7 +457,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
Taxonomy2 ensuredTaxonomy = taxonomyService.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(), Taxonomy2 ensuredTaxonomy = taxonomyService.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(),
current.getSubtaxa(), current.getSubtAuthor()); current.getSubtaxa(), current.getSubtAuthor());
if (!(ensuredTaxonomy.sameAs(current))) { if (!(ensuredTaxonomy.sameAs(taxonomy))) {
accession.setTaxonomy(ensuredTaxonomy); accession.setTaxonomy(ensuredTaxonomy);
accession.setTaxGenus(ensuredTaxonomy.getTaxGenus()); accession.setTaxGenus(ensuredTaxonomy.getTaxGenus());
...@@ -485,6 +483,7 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -485,6 +483,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// We expect a String node // We expect a String node
throw new RESTApiDataTypeException("Not a String"); throw new RESTApiDataTypeException("Not a String");
} }
if (jsonNode.isNull()) return null;
return StringUtils.defaultIfBlank(jsonNode.textValue(), currentValue); return StringUtils.defaultIfBlank(jsonNode.textValue(), currentValue);
} }
return currentValue; return currentValue;
......
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