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 {
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy")
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
private void prePersist() {
this.taxonName = getTaxonName();
......@@ -166,7 +179,8 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@Override
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 {
aj.setUuid(accession.getUuid());
Taxonomy2 tax = accession.getTaxonomy();
aj.setGenus(tax.getGenus());
aj.setSpecies(tax.getSpecies());
aj.setSpauthor(tax.getSpAuthor());
aj.setSubtaxa(tax.getSubtaxa());
aj.setSubtauthor(tax.getSubtAuthor());
aj.setOrgCty(accession.getCountryOfOrigin().getCode3());
if (tax != null) {
aj.setGenus(tax.getGenus());
aj.setSpecies(tax.getSpecies());
aj.setSpauthor(tax.getSpAuthor());
aj.setSubtaxa(tax.getSubtaxa());
aj.setSubtauthor(tax.getSubtAuthor());
}
if (accession.getCountryOfOrigin() != null) {
aj.setOrgCty(accession.getCountryOfOrigin().getCode3());
}
aj.setAcqDate(accession.getAcquisitionDate());
aj.setMlsStat(accession.getMlsStatus());
aj.setInTrust(accession.getInTrust());
......
......@@ -444,11 +444,9 @@ public class BatchRESTServiceImpl implements BatchRESTService {
boolean updated = false;
// Do not persist this one, temporary use
Taxonomy2 current = new Taxonomy2();
Taxonomy2 taxonomy = accession.getTaxonomy();
Taxonomy2 current = new Taxonomy2(taxonomy);
// 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("newGenus"), current.getGenus()));
current.setSpecies(stringIfProvided(accnJson.get("species"), current.getSpecies()));
......@@ -459,7 +457,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
Taxonomy2 ensuredTaxonomy = taxonomyService.ensureTaxonomy2(current.getGenus(), current.getSpecies(), current.getSpAuthor(),
current.getSubtaxa(), current.getSubtAuthor());
if (!(ensuredTaxonomy.sameAs(current))) {
if (!(ensuredTaxonomy.sameAs(taxonomy))) {
accession.setTaxonomy(ensuredTaxonomy);
accession.setTaxGenus(ensuredTaxonomy.getTaxGenus());
......@@ -485,6 +483,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// We expect a String node
throw new RESTApiDataTypeException("Not a String");
}
if (jsonNode.isNull()) return null;
return StringUtils.defaultIfBlank(jsonNode.textValue(), 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