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

REST API v1 constants

parent b8eca179
......@@ -16,34 +16,63 @@
package org.genesys2.server.model.json;
import org.genesys2.server.model.json.Api1Constants.Accession;
import com.fasterxml.jackson.annotation.JsonProperty;
public class AccessionJson {
private long version = 0;
private Long genesysId;
@JsonProperty(value = Accession.INSTCODE)
private String instCode;
@JsonProperty(value = Accession.ACCENUMB)
private String acceNumb;
@JsonProperty(value = Accession.GENUS)
private String genus;
@JsonProperty(value = Accession.SPECIES)
private String species;
@JsonProperty(value = Accession.SPAUTHOR)
private String spauthor;
@JsonProperty(value = Accession.SUBTAXA)
private String subtaxa;
@JsonProperty(value = Accession.SUBTAUTHOR)
private String subtauthor;
@JsonProperty(value = Accession.UUID)
private String uuid;
@JsonProperty(value = Accession.ORIGCTY)
private String orgCty;
@JsonProperty(value = Accession.ACQDATE)
private String acqDate;
@JsonProperty(value = Accession.MLSSTAT)
private Boolean mlsStat;
@JsonProperty(value = Accession.INTRUST)
private Boolean inTrust;
@JsonProperty(value = Accession.AVAILABLE)
private Boolean available;
@JsonProperty(value = Accession.STORAGE)
private Integer[] storage;
@JsonProperty(value = Accession.SAMPSTAT)
private Integer sampStat;
@JsonProperty(value = Accession.DUPLSITE)
private String[] duplSite;
@JsonProperty(value = Accession.BREDCODE)
private String bredCode;
@JsonProperty(value = Accession.ANCEST)
private String ancest;
@JsonProperty(value = Accession.DONORCODE)
private String donorCode;
@JsonProperty(value = Accession.DONORNUMB)
private String donorNumb;
@JsonProperty(value = Accession.DONORNAME)
private String donorName;
@JsonProperty(value = Accession.COLL)
private CollectingJson coll;
@JsonProperty(value = Accession.GEO)
private GeoJson geo;
@JsonProperty(value = Accession.REMARKS)
private Remark[] remarks;
@JsonProperty(value = Accession.HISTORIC)
private boolean historic;
public long getVersion() {
......@@ -249,15 +278,15 @@ public class AccessionJson {
public Remark[] getRemarks() {
return remarks;
}
public void setRemarks(Remark[] remarks) {
this.remarks = remarks;
}
public void setHistoric(boolean historic) {
this.historic=historic;
this.historic = historic;
}
public boolean getHistoric() {
return this.historic;
}
......
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model.json;
/**
* @author mobreza
*/
public interface Api1Constants {
public static interface Accession {
/**
* WIEWS code of accession holding institute.
*/
public static final String INSTCODE = "instCode";
/**
* Accession number.
*/
public static final String ACCENUMB = "acceNumb";
/**
* Used to assign new ACCENUMB
*/
public static final String ACCENUMB_NEW = "newAcceNumb";
/**
* Reported genus of accession.
*/
public static final String GENUS = "genus";
/**
* May be used to assign a different genus.
*/
public static final String GENUS_NEW = "newGenus";
/**
* Specific epithet portion of the scientific name, in latin, in
* lowercase letters. Following abbreviation is allowed: ‘sp.’
*/
public static final String SPECIES = "species";
/**
* Corresponds to MCPD SPAUTHOR
*/
public static final String SPAUTHOR = "spauthor";
/**
* Corresponds to MCPD SUBTAXA
*/
public static final String SUBTAXA = "subtaxa";
/**
* Corresponds to MCPD SUBTAUTHOR
*/
public static final String SUBTAUTHOR = "subtauthor";
/**
* Universally Unique IDentifier for the accession, assigned by the
* first holding institute and immutable when accession is duplicated in
* another institute.
*/
public static final String UUID = "uuid";
/**
* ISO3 country code of country of origin.
*/
public static final String ORIGCTY = "orgCty";
/**
* Date on which the accession entered the collection as YYYYMMDD.
* Missing data (MM or DD) should be indicated with hyphens. Leading
* zeros are required.
*/
public static final String ACQDATE = "acqDate";
/**
* The status of an accession with regards to the Multilateral System
* (MLS) of the International Treaty on PlantGenetic Resources for Food
* and Agriculture.
*/
public static final String MLSSTAT = "mlsStat";
/**
* Is the accession “FAO In trust”
*/
public static final String INTRUST = "inTrust";
/**
* The general availability of the accession for distribution, but
* subject to current stock.
*/
public static final String AVAILABLE = "available";
/**
* MCPD Type of germplasm storage (Corresponds to MCPD STORAGE field).
*/
public static final String STORAGE = "storage";
/**
* MCPD Sample status
*/
public static final String SAMPSTAT = "sampStat";
/**
* FAO Institute Code (WIEWS code) of the institute where a safety
* duplicate of the accession is maintained.
*/
public static final String DUPLSITE = "duplSite";
/**
* Corresponds to BREDCODE.
*/
public static final String BREDCODE = "bredCode";
/**
* Corresponds to ANCEST.
*/
public static final String ANCEST = "ancest";
/**
* FAO WIEWS code of the donor institute
*/
public static final String DONORCODE = "donorCode";
/**
* Accession number at donor institute.
*/
public static final String DONORNUMB = "donorNumb";
/**
* Name of the donor institute (or person). Provide only when donorCode
* is not available.
*/
public static final String DONORNAME = "donorName";
/**
* Object containing the collecting data
*/
public static final String COLL = "coll";
/**
* Object containing georeference data
*/
public static final String GEO = "geo";
/**
* MCPD Remarks
*/
public static final String REMARKS = "remarks";
/**
* Marks if accession record is about a historic holding and the
* accession no longer exists.
*/
public static final String HISTORIC = "historic";
/**
* Accession name
*/
public static final String ACCENAME = "acceName";
/**
* Other numbers
*/
public static final String OTHERNUMB = "otherNumb";
}
public static interface Collecting {
/**
* Corresponds to COLLDATE
*/
public static final String COLLDATE = "collDate";
/**
* Corresponds to COLLSITE
*/
public static final String COLLSITE = "collSite";
/**
* Corresponds to MCPD COLLNUMB
*/
public static final String COLLNUMB = "collNumb";
/**
* Corresponds to MCPD COLLSRC
*/
public static final String COLLSRC = "collSrc";
/**
* FAO WIEWS code of collecting institute
*/
public static final String COLLCODE = "collCode";
/**
* The name of the collecting institute if collCode is not available.
*/
public static final String COLLNAME = "collName";
/**
* The address of the collecting institute if collCode is not available.
*/
public static final String COLLINSTADDRESS = "collInstAddress";
/**
* Corresponds to COLLMISSID
*/
public static final String COLLMISSID = "collMissId";
}
public static interface Geo {
/**
* Latitude
*/
public static final String LATITUDE = "latitude";
/**
* Longitude
*/
public static final String LONGITUDE = "longitude";
/**
* Elevation
*/
public static final String ELEVATION = "elevation";
/**
* COORDUNCERT (in meters)
*/
public static final String COORDUNCERT = "coordUncert";
/**
* Corresponds to COORDATUM
*/
public static final String COORDDATUM = "coordDatum";
/**
* Corresponds to GEOREFMETH
*/
public static final String GEOREFMETH = "georefMeth";
}
}
......@@ -16,14 +16,26 @@
package org.genesys2.server.model.json;
import org.genesys2.server.model.json.Api1Constants.Collecting;
import com.fasterxml.jackson.annotation.JsonProperty;
public class CollectingJson {
@JsonProperty(value = Collecting.COLLDATE)
private String collDate;
@JsonProperty(value = Collecting.COLLSITE)
private String collSite;
@JsonProperty(value = Collecting.COLLNUMB)
private String collNumb;
@JsonProperty(value = Collecting.COLLSRC)
private Integer collSrc;
@JsonProperty(value = Collecting.COLLCODE)
private String collCode;
@JsonProperty(value = Collecting.COLLNAME)
private String collName;
@JsonProperty(value = Collecting.COLLINSTADDRESS)
private String collInstAddress;
@JsonProperty(value = Collecting.COLLMISSID)
private String collMissId;
public String getCollDate() {
......
......@@ -16,12 +16,22 @@
package org.genesys2.server.model.json;
import org.genesys2.server.model.json.Api1Constants.Geo;
import com.fasterxml.jackson.annotation.JsonProperty;
public class GeoJson {
@JsonProperty(value = Geo.LATITUDE)
private Double latitude;
@JsonProperty(value = Geo.LONGITUDE)
private Double longitude;
@JsonProperty(value = Geo.ELEVATION)
private Double elevation;
@JsonProperty(value = Geo.COORDUNCERT)
private Double coordUncert;
@JsonProperty(value = Geo.COORDDATUM)
private String coordDatum;
@JsonProperty(value = Geo.GEOREFMETH)
private String georefMeth;
public Double getLatitude() {
......
......@@ -41,6 +41,7 @@ import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.server.persistence.domain.AccessionCustomRepository;
import org.genesys2.server.service.BatchRESTService;
import org.genesys2.server.service.GenesysService;
......@@ -95,13 +96,17 @@ public class BatchRESTServiceImpl implements BatchRESTService {
final Taxonomy2 current = new Taxonomy2();
// Load JSON values into "current"
current.setGenus(stringIfProvided(accnJson.get("genus"), current.getGenus()));
current.setGenus(stringIfProvided(accnJson.get("newGenus"), current.getGenus()));
current.setSpecies(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get("species"), current.getSpecies()), "sp."));
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(Api1Constants.Accession.GENUS), current.getGenus()));
current.setGenus(stringIfProvided(accnJson.get(Api1Constants.Accession.GENUS_NEW), current.getGenus()));
current.setSpecies(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SPECIES), current.getSpecies()), "sp."));
current.setSpAuthor(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SPAUTHOR), current.getSpAuthor()), ""));
current.setSubtaxa(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SUBTAXA), current.getSubtaxa()), ""));
current.setSubtAuthor(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SUBTAUTHOR), current.getSubtAuthor()), ""));
if (LOG.isDebugEnabled()) {
LOG.debug("Ensuring " + current);
}
Taxonomy2 ensuredTaxonomy = null;
try {
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
......@@ -200,7 +205,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
accession.setInstitute(institute);
accession.setAccessionName(dataJson.acceNumb);
if (accnJson.get("genus") == null && accnJson.get("newGenus") == null) {
if (accnJson.get(Api1Constants.Accession.GENUS) == null && accnJson.get(Api1Constants.Accession.GENUS_NEW) == null) {
throw new RESTApiException("Cannot create new accession without specifying genus");
}
......@@ -210,22 +215,23 @@ public class BatchRESTServiceImpl implements BatchRESTService {
LOG.trace("*** Updating accession " + dataJson);
}
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) {
if (accession.getId() == null || useUniqueAcceNumbs && accnJson.get(Api1Constants.Accession.GENUS) != null
|| accnJson.get(Api1Constants.Accession.GENUS_NEW) != null || accnJson.get(Api1Constants.Accession.SPECIES) != null
|| accnJson.get(Api1Constants.Accession.SPAUTHOR) != null || accnJson.get(Api1Constants.Accession.SUBTAXA) != null
|| accnJson.get(Api1Constants.Accession.SUBTAUTHOR) != null) {
updated |= updateTaxonomy(accession, accnJson);
}
updated |= updateAcceNumb(accession, accnJson.get("newAcceNumb"));
updated |= updateOrgCty(accession, accnJson.get("orgCty"));
updated |= updateUuid(accession, accnJson.get("uuid"));
updated |= updateRemarks(accession, accnJson.get("remarks"), toSaveRemarks, toRemoveRemarks);
updated |= updateAcceNumb(accession, accnJson.get(Api1Constants.Accession.ACCENUMB_NEW));
updated |= updateOrgCty(accession, accnJson.get(Api1Constants.Accession.ORIGCTY));
updated |= updateUuid(accession, accnJson.get(Api1Constants.Accession.UUID));
updated |= updateRemarks(accession, accnJson.get(Api1Constants.Accession.REMARKS), toSaveRemarks, toRemoveRemarks);
updated |= updateStorage(accession, accnJson);
// TODO Move other setters to methods
JsonNode value = accnJson.get("acqDate");
JsonNode value = accnJson.get(Api1Constants.Accession.ACQDATE);
if (value != null) {
final String acqDate = value.isNull() ? null : value.textValue();
if (!StringUtils.equals(acqDate, accession.getAcquisitionDate())) {
......@@ -233,7 +239,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated = true;
}
}
value = accnJson.get("mlsStat");
value = accnJson.get(Api1Constants.Accession.MLSSTAT);
if (value != null) {
if (!value.isNull() && !value.isBoolean()) {
throw new RESTApiDataTypeException("If provided, 'mlsStat' must be a boolean");
......@@ -245,7 +251,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated = true;
}
}
value = accnJson.get("inTrust");
value = accnJson.get(Api1Constants.Accession.INTRUST);
if (value != null) {
if (!value.isNull() && !value.isBoolean()) {
throw new RESTApiDataTypeException("If provided, 'inTrust' must be a boolean");
......@@ -257,7 +263,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated = true;
}
}
value = accnJson.get("available");
value = accnJson.get(Api1Constants.Accession.AVAILABLE);
if (value != null) {
if (!value.isNull() && !value.isBoolean()) {
throw new RESTApiDataTypeException("If provided, 'available' must be a boolean");
......@@ -269,7 +275,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated = true;
}
}
value = accnJson.get("historic");
value = accnJson.get(Api1Constants.Accession.HISTORIC);
if (value != null) {
if (value.isNull() || !value.isBoolean()) {
throw new RESTApiDataTypeException("If provided, 'historic' must be a boolean");
......@@ -281,17 +287,17 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
value = accnJson.get("acceName");
value = accnJson.get(Api1Constants.Accession.ACCENAME);
if (value != null) {
acceNames.put(accession, toMcpdArray(accnJson, "acceName"));
acceNames.put(accession, toMcpdArray(accnJson, Api1Constants.Accession.ACCENAME));
}
value = accnJson.get("otherNumb");
value = accnJson.get(Api1Constants.Accession.OTHERNUMB);
if (value != null) {
otherNumbs.put(accession, toMcpdArray(accnJson, "otherNumb"));
otherNumbs.put(accession, toMcpdArray(accnJson, Api1Constants.Accession.OTHERNUMB));
}
value = accnJson.get("sampStat");
value = accnJson.get(Api1Constants.Accession.SAMPSTAT);
if (value != null) {
if (!value.isNull() && !value.isNumber()) {
throw new RESTApiDataTypeException("If provided, 'sampStat' must be a number");
......@@ -303,55 +309,55 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
value = accnJson.get("duplSite");
value = accnJson.get(Api1Constants.Accession.DUPLSITE);
if (value != null) {
final String duplSite = arrayToString(toMcpdArray(accnJson, "duplSite"));
final String duplSite = arrayToString(toMcpdArray(accnJson, Api1Constants.Accession.DUPLSITE));
if (!StringUtils.equals(duplSite, accession.getDuplSite())) {
accession.setDuplSite(StringUtils.defaultIfBlank(duplSite, null));
updated = true;
}
}
if (accnJson.has("coll")) {
final ObjectNode collecting = (ObjectNode) accnJson.get("coll");
if (accnJson.has(Api1Constants.Accession.COLL)) {
final ObjectNode collecting = (ObjectNode) accnJson.get(Api1Constants.Accession.COLL);
AccessionCollect accnColl = genesysService.listAccessionCollect(accession);
if (accnColl == null) {
accnColl = new AccessionCollect();
accnColl.setAccession(accession);
}
value = collecting.get("collDate");
value = collecting.get(Api1Constants.Collecting.COLLDATE);
if (value != null) {
accnColl.setCollDate(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("collNumb");
value = collecting.get(Api1Constants.Collecting.COLLNUMB);
if (value != null) {
accnColl.setCollNumb(StringUtils.defaultIfBlank(value.textValue(), null));
collNumbs.put(accession, toMcpdArray(collecting, "collNumb"));
collNumbs.put(accession, toMcpdArray(collecting, Api1Constants.Collecting.COLLNUMB));
}
value = collecting.get("collSrc");
value = collecting.get(Api1Constants.Collecting.COLLSRC);
if (value != null) {
if (!value.isNull() && !value.isNumber()) {
throw new RESTApiDataTypeException("If provided, 'collSrc' must be a number");
}
accnColl.setCollSrc(value.isNumber() ? value.intValue() : null);
}
value = collecting.get("collCode");
value = collecting.get(Api1Constants.Collecting.COLLCODE);
if (value != null) {
accnColl.setCollCode(arrayToString(toMcpdArray(collecting, "collCode")));
accnColl.setCollCode(arrayToString(toMcpdArray(collecting, Api1Constants.Collecting.COLLCODE)));
}
value = collecting.get("collName");
value = collecting.get(Api1Constants.Collecting.COLLNAME);
if (value != null) {
accnColl.setCollName(arrayToString(toMcpdArray(collecting, "collName")));
accnColl.setCollName(arrayToString(toMcpdArray(collecting, Api1Constants.Collecting.COLLNAME)));
}
value = collecting.get("collInstAddress");
value = collecting.get(Api1Constants.Collecting.COLLINSTADDRESS);
if (value != null) {
accnColl.setCollInstAddress(arrayToString(toMcpdArray(collecting, "collInstAddress")));
accnColl.setCollInstAddress(arrayToString(toMcpdArray(collecting, Api1Constants.