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

REST: Taxonomy updated conditionally

parent 8f9f5874
...@@ -87,7 +87,7 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity, ...@@ -87,7 +87,7 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
private Double latitude; private Double latitude;
private Double longitude; private Double longitude;
private Double elevation; private Double elevation;
private boolean uniqueAcceNumbs; private boolean uniqueAcceNumbs = true;
public FaoInstitute() { public FaoInstitute() {
} }
...@@ -215,7 +215,7 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity, ...@@ -215,7 +215,7 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
public boolean hasUniqueAcceNumbs() { public boolean hasUniqueAcceNumbs() {
return this.uniqueAcceNumbs; return this.uniqueAcceNumbs;
} }
public void setUniqueAcceNumbs(boolean uniqueAcceNumbs) { public void setUniqueAcceNumbs(boolean uniqueAcceNumbs) {
this.uniqueAcceNumbs = uniqueAcceNumbs; this.uniqueAcceNumbs = uniqueAcceNumbs;
} }
......
...@@ -130,13 +130,19 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -130,13 +130,19 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated = true; updated = true;
} }
if (accession.getId() == null || (useUniqueAcceNumbs && accnJson.get("genus") != null) || accnJson.get("newGenus") != null
|| accnJson.get("species") != null || accnJson.get("spauthor") != null || accnJson.get("subtaxa") != null
|| accnJson.get("subtauthor") != null) {
updated |= updateTaxonomy(accession, accnJson);
}
updated |= updateAcceNumb(accession, accnJson.get("newAcceNumb")); updated |= updateAcceNumb(accession, accnJson.get("newAcceNumb"));
updated |= updateTaxonomy(accession, accnJson);
updated |= updateOrgCty(accession, accnJson.get("orgCty")); updated |= updateOrgCty(accession, accnJson.get("orgCty"));
updated |= updateUuid(accession, accnJson.get("uuid")); updated |= updateUuid(accession, accnJson.get("uuid"));
// TODO Move other setters to methods // TODO Move other setters to methods
JsonNode value = accnJson.get("acqDate"); JsonNode value = accnJson.get("acqDate");
if (value != null) { if (value != null) {
String acqDate = value.isNull() ? null : value.textValue(); String acqDate = value.isNull() ? null : value.textValue();
...@@ -375,7 +381,7 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -375,7 +381,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
throw new RESTApiValueException("newAcceNumb cannot be null"); throw new RESTApiValueException("newAcceNumb cannot be null");
} }
String newAcceNumb=value.textValue(); String newAcceNumb = value.textValue();
if (!StringUtils.equals(newAcceNumb, accession.getAccessionName())) { if (!StringUtils.equals(newAcceNumb, accession.getAccessionName())) {
accession.setAccessionName(newAcceNumb); accession.setAccessionName(newAcceNumb);
return true; return true;
...@@ -444,12 +450,12 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -444,12 +450,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
} }
// Load JSON values into "current" // Load JSON values into "current"
current.setGenus(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("genus")), current.getGenus())); current.setGenus(stringIfProvided(accnJson.get("genus"), current.getGenus()));
current.setGenus(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("newGenus")), current.getGenus())); current.setGenus(stringIfProvided(accnJson.get("newGenus"), current.getGenus()));
current.setSpecies(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("species")), current.getSpecies())); current.setSpecies(stringIfProvided(accnJson.get("species"), current.getSpecies()));
current.setSpAuthor(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("spauthor")), current.getSpAuthor())); current.setSpAuthor(stringIfProvided(accnJson.get("spauthor"), current.getSpAuthor()));
current.setSubtaxa(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("subtaxa")), current.getSubtaxa())); current.setSubtaxa(stringIfProvided(accnJson.get("subtaxa"), current.getSubtaxa()));
current.setSubtAuthor(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("subtauthor")), current.getSubtAuthor())); current.setSubtAuthor(stringIfProvided(accnJson.get("subtauthor"), current.getSubtAuthor()));
Taxonomy2 ensuredTaxonomy = null; Taxonomy2 ensuredTaxonomy = null;
if (current.getId() == null if (current.getId() == null
...@@ -470,21 +476,19 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -470,21 +476,19 @@ public class BatchRESTServiceImpl implements BatchRESTService {
* Return * Return
* *
* @param jsonNode * @param jsonNode
* @param currentValue
* @return * @return
* @throws RESTApiDataTypeException * @throws RESTApiDataTypeException
*/ */
private String stringIfProvided(JsonNode jsonNode) throws RESTApiException { private String stringIfProvided(JsonNode jsonNode, String currentValue) throws RESTApiException {
if (jsonNode != null) { if (jsonNode != null) {
if (!jsonNode.isTextual()) { if (!jsonNode.isNull() && !jsonNode.isTextual()) {
// We expect a String node // We expect a String node
throw new RESTApiDataTypeException("Not a String"); throw new RESTApiDataTypeException("Not a String");
} }
if (StringUtils.isBlank(jsonNode.textValue())) { return StringUtils.defaultIfBlank(jsonNode.textValue(), currentValue);
throw new RESTApiValueException("Value cannot be a blank String");
}
return StringUtils.defaultIfBlank(jsonNode.textValue(), null);
} }
return null; return currentValue;
} }
private String arrayToString(ArrayNode arr) { private String arrayToString(ArrayNode arr) {
......
...@@ -21,7 +21,7 @@ db.driverClassName=com.mysql.jdbc.Driver ...@@ -21,7 +21,7 @@ db.driverClassName=com.mysql.jdbc.Driver
db.dialect=org.hibernate.dialect.MySQL5Dialect db.dialect=org.hibernate.dialect.MySQL5Dialect
db.username=root db.username=root
db.password= db.password=
db.showSql=true db.showSql=false
db.hbm2ddl=do-nothing db.hbm2ddl=do-nothing
c3p0.acquireIncrement=1 c3p0.acquireIncrement=1
......
Supports Markdown
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