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