Commit c402bfa3 authored by Matija Obreza's avatar Matija Obreza

Merge branch 'fix-uploading' into 'master'

Using Api0 and Api1Constants in conversion

See merge request genesys-pgr/genesys-server!291
parents f9d5681e b3042abb
...@@ -18,12 +18,7 @@ package org.genesys2.server.api.model; ...@@ -18,12 +18,7 @@ package org.genesys2.server.api.model;
import java.text.MessageFormat; import java.text.MessageFormat;
import com.fasterxml.jackson.databind.JsonNode;
import org.genesys2.server.model.impl.AccessionIdentifier3; import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.util.DOIUtils;
import org.genesys2.util.InvalidDOIException;
public class AccessionHeaderJson implements AccessionIdentifier3 { public class AccessionHeaderJson implements AccessionIdentifier3 {
public String doi; public String doi;
...@@ -31,22 +26,6 @@ public class AccessionHeaderJson implements AccessionIdentifier3 { ...@@ -31,22 +26,6 @@ public class AccessionHeaderJson implements AccessionIdentifier3 {
public String acceNumb; public String acceNumb;
public String genus; public String genus;
public static AccessionHeaderJson fromJson(JsonNode json) throws InvalidDOIException {
final AccessionHeaderJson dataJson = new AccessionHeaderJson();
dataJson.doi = json.has(Api1Constants.Accession.DOI) ? json.get(Api1Constants.Accession.DOI).textValue() : null;
if (dataJson.doi != null) {
DOIUtils.validateDoi(dataJson.doi);
}
dataJson.instCode = json.has(Api1Constants.Accession.INSTCODE) ? json.get(Api1Constants.Accession.INSTCODE).textValue() : null;
dataJson.acceNumb = json.has(Api1Constants.Accession.ACCENUMB) ? json.get(Api1Constants.Accession.ACCENUMB).textValue() : null;
dataJson.genus = json.has(Api1Constants.Accession.GENUS) ? json.get(Api1Constants.Accession.GENUS).textValue() : null;
return dataJson;
}
@Override @Override
public String getDoi() { public String getDoi() {
return doi; return doi;
......
...@@ -35,6 +35,8 @@ import org.genesys2.server.model.elastic.AccessionDetails; ...@@ -35,6 +35,8 @@ import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession; import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.json.AccessionJson; import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.model.json.Api0Constants;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.server.service.ElasticsearchService; import org.genesys2.server.service.ElasticsearchService;
import org.genesys2.server.service.GenesysFilterService; import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysRESTService; import org.genesys2.server.service.GenesysRESTService;
...@@ -415,31 +417,31 @@ public class AccessionController extends ApiBaseController { ...@@ -415,31 +417,31 @@ public class AccessionController extends ApiBaseController {
} }
private void upgradeToV2(ObjectNode update) { private void upgradeToV2(ObjectNode update) {
upgradeRename(update, "instCode", "instituteCode"); upgradeRename(update, Api0Constants.Accession.INSTCODE, Api1Constants.Accession.INSTCODE);
upgradeRename(update, "acceNumb", "accessionNumber"); upgradeRename(update, Api0Constants.Accession.ACCENUMB, Api1Constants.Accession.ACCENUMB);
upgradeRename(update, "spauthor", "spAuthor"); upgradeRename(update, Api0Constants.Accession.SPAUTHOR, Api1Constants.Accession.SPAUTHOR);
upgradeRename(update, "subtauthor", "subtAuthor"); upgradeRename(update, Api0Constants.Accession.SUBTAUTHOR, Api1Constants.Accession.SUBTAUTHOR);
upgradeRename(update, "acqDate", "acquisitionDate"); upgradeRename(update, Api0Constants.Accession.ACQDATE, Api1Constants.Accession.ACQDATE);
upgradeRename(update, "bredCode", "breederCode"); upgradeRename(update, Api0Constants.Accession.BREDCODE, Api1Constants.Accession.BREDCODE);
upgradeRename(update, "bredName", "breederName"); upgradeRename(update, Api0Constants.Accession.BREDNAME, Api1Constants.Accession.BREDNAME);
upgradeRename(update, "mlsStat", "mlsStatus"); upgradeRename(update, Api0Constants.Accession.MLSSTAT, Api1Constants.Accession.MLSSTAT);
upgradeRename(update, "orgCty", "origCty"); upgradeRename(update, Api0Constants.Accession.ORIGCTY, Api1Constants.Accession.ORIGCTY);
upgradeToArray(update, "breederCode"); // renamed above upgradeToArray(update, Api1Constants.Accession.BREDCODE); // renamed above
upgradeToArray(update, "breederName"); // renamed above upgradeToArray(update, Api1Constants.Accession.BREDNAME); // renamed above
if (update.has("geo")) { if (update.has("geo")) {
ObjectNode geo = (ObjectNode) update.get("geo"); ObjectNode geo = (ObjectNode) update.get("geo");
upgradeRename(geo, "coordUncert", "uncertainty"); upgradeRename(geo, Api0Constants.Geo.COORDUNCERT, Api1Constants.Geo.COORDUNCERT);
upgradeRename(geo, "coordDatum", "datum"); upgradeRename(geo, Api0Constants.Geo.COORDDATUM, Api1Constants.Geo.COORDDATUM);
upgradeRename(geo, "georefMeth", "method"); upgradeRename(geo, Api0Constants.Geo.GEOREFMETH, Api1Constants.Geo.GEOREFMETH);
} }
if (update.has("coll")) { if (update.has("coll")) {
ObjectNode coll = (ObjectNode) update.get("coll"); ObjectNode coll = (ObjectNode) update.get("coll");
upgradeToArray(coll, "collCode"); upgradeToArray(coll, Api1Constants.Collecting.COLLCODE);
upgradeToArray(coll, "collName"); upgradeToArray(coll, Api1Constants.Collecting.COLLNAME);
upgradeToArray(coll, "collInstAddress"); upgradeToArray(coll, Api1Constants.Collecting.COLLINSTADDRESS);
} }
ObjectNode taxonomy; ObjectNode taxonomy;
...@@ -449,11 +451,11 @@ public class AccessionController extends ApiBaseController { ...@@ -449,11 +451,11 @@ public class AccessionController extends ApiBaseController {
taxonomy = update.putObject("taxonomy"); taxonomy = update.putObject("taxonomy");
} }
upgradeTaxonomy(update, taxonomy, "genus"); upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.GENUS);
upgradeTaxonomy(update, taxonomy, "species"); upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SPECIES);
upgradeTaxonomy(update, taxonomy, "spAuthor"); upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SPAUTHOR);
upgradeTaxonomy(update, taxonomy, "subtaxa"); upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SUBTAXA);
upgradeTaxonomy(update, taxonomy, "subtAuthor"); upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SUBTAUTHOR);
} }
private void upgradeToArray(ObjectNode obj, String fieldName) { private void upgradeToArray(ObjectNode obj, String fieldName) {
......
...@@ -36,7 +36,7 @@ import org.genesys2.server.model.genesys.Metadata; ...@@ -36,7 +36,7 @@ import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method; import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.impl.AccessionIdentifier3; import org.genesys2.server.model.impl.AccessionIdentifier3;
import org.genesys2.server.model.impl.FaoInstitute; import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.json.Api1Constants; import org.genesys2.server.model.json.Api0Constants;
import org.genesys2.server.service.CropService; import org.genesys2.server.service.CropService;
import org.genesys2.server.service.DatasetService; import org.genesys2.server.service.DatasetService;
import org.genesys2.server.service.GenesysService; import org.genesys2.server.service.GenesysService;
...@@ -214,13 +214,13 @@ public class DatasetController extends ApiBaseController { ...@@ -214,13 +214,13 @@ public class DatasetController extends ApiBaseController {
final String key = field.getKey(); final String key = field.getKey();
final JsonNode value = field.getValue(); final JsonNode value = field.getValue();
if (Api1Constants.Accession.INSTCODE.equals(key)) { if (Api0Constants.Accession.INSTCODE.equals(key)) {
dataJson.instCode = value.asText(); dataJson.instCode = value.asText();
} else if (Api1Constants.Accession.DOI.equals(key)) { } else if (Api0Constants.Accession.DOI.equals(key)) {
dataJson.doi = value.asText(); dataJson.doi = value.asText();
} else if (Api1Constants.Accession.ACCENUMB.equals(key)) { } else if (Api0Constants.Accession.ACCENUMB.equals(key)) {
dataJson.acceNumb = value.asText(); dataJson.acceNumb = value.asText();
} else if (Api1Constants.Accession.GENUS.equals(key)) { } else if (Api0Constants.Accession.GENUS.equals(key)) {
dataJson.genus = value.asText(); dataJson.genus = value.asText();
} else if (key.startsWith("gm:")) { } else if (key.startsWith("gm:")) {
// Handle Genesys Method! // Handle Genesys Method!
......
...@@ -258,19 +258,19 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel { ...@@ -258,19 +258,19 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
if (other == null) { if (other == null) {
return false; return false;
} }
if (!genus.equalsIgnoreCase(other.genus)) { if (! StringUtils.equalsIgnoreCase(genus, other.genus)) {
return false; return false;
} }
if (!species.equalsIgnoreCase(other.species)) { if (! StringUtils.equalsIgnoreCase(species, other.species)) {
return false; return false;
} }
if (!spAuthor.equalsIgnoreCase(other.spAuthor)) { if (! StringUtils.equalsIgnoreCase(spAuthor, other.spAuthor)) {
return false; return false;
} }
if (!subtaxa.equalsIgnoreCase(other.subtaxa)) { if (! StringUtils.equalsIgnoreCase(subtaxa, other.subtaxa)) {
return false; return false;
} }
if (!subtAuthor.equalsIgnoreCase(other.subtAuthor)) { if (! StringUtils.equalsIgnoreCase(subtAuthor, other.subtAuthor)) {
return false; return false;
} }
......
/**
* 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 Api0Constants {
public static interface Accession {
public static final String CROP_NAMES = "crops";
/**
* 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";
/**
* URL linking to additional data about the accession either in the
* holding genebank or from another source.
*/
public static final String ACCEURL = "acceUrl";
/**
* Gene bank provided MCPD#CROPNAME
*/
public static final String CROPNAME = "cropName";
/**
* Accession DOI (Digital Object Identifier)
*/
public static final String DOI = "doi";
public static final String BREDNAME = "bredName";
}
public static interface Institute {
/**
* Corresponds to INSTCODE
*/
public static final String INSTCODE = "code";
public static final String INSTCODE_COUNTRY = "country.iso3";
}
public static interface Taxonomy {
public static final String SCIENTIFIC_NAME = "sciName";
/**
* 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";
}
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 {
public static final String LATITUDE_LONGITUDE = "latitudeAndLongitude";
/**
* 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";
}
public static interface Pdci {
/**
* PDCI Score
*/
public static final String SCORE = "score";
}
}
...@@ -27,12 +27,12 @@ public interface Api1Constants { ...@@ -27,12 +27,12 @@ public interface Api1Constants {
/** /**
* WIEWS code of accession holding institute. * WIEWS code of accession holding institute.
*/ */
public static final String INSTCODE = "instCode"; public static final String INSTCODE = "instituteCode";
/** /**
* Accession number. * Accession number.
*/ */
public static final String ACCENUMB = "acceNumb"; public static final String ACCENUMB = "accessionNumber";
/** /**
* Used to assign new ACCENUMB * Used to assign new ACCENUMB
...@@ -58,7 +58,7 @@ public interface Api1Constants { ...@@ -58,7 +58,7 @@ public interface Api1Constants {
/** /**
* Corresponds to MCPD SPAUTHOR * Corresponds to MCPD SPAUTHOR
*/ */
public static final String SPAUTHOR = "spauthor"; public static final String SPAUTHOR = "spAuthor";
/** /**
* Corresponds to MCPD SUBTAXA * Corresponds to MCPD SUBTAXA
...@@ -68,7 +68,7 @@ public interface Api1Constants { ...@@ -68,7 +68,7 @@ public interface Api1Constants {
/** /**
* Corresponds to MCPD SUBTAUTHOR * Corresponds to MCPD SUBTAUTHOR
*/ */
public static final String SUBTAUTHOR = "subtauthor"; public static final String SUBTAUTHOR = "subtAuthor";
/** /**
* Universally Unique IDentifier for the accession, assigned by the * Universally Unique IDentifier for the accession, assigned by the
...@@ -80,21 +80,21 @@ public interface Api1Constants { ...@@ -80,21 +80,21 @@ public interface Api1Constants {
/** /**
* ISO3 country code of country of origin. * ISO3 country code of country of origin.
*/ */
public static final String ORIGCTY = "orgCty"; public static final String ORIGCTY = "origCty";
/** /**
* Date on which the accession entered the collection as YYYYMMDD. * Date on which the accession entered the collection as YYYYMMDD.
* Missing data (MM or DD) should be indicated with hyphens. Leading * Missing data (MM or DD) should be indicated with hyphens. Leading
* zeros are required. * zeros are required.
*/ */
public static final String ACQDATE = "acqDate"; public static final String ACQDATE = "acquisitionDate";
/** /**
* The status of an accession with regards to the Multilateral System * The status of an accession with regards to the Multilateral System
* (MLS) of the International Treaty on PlantGenetic Resources for Food * (MLS) of the International Treaty on PlantGenetic Resources for Food
* and Agriculture. * and Agriculture.
*/ */
public static final String MLSSTAT = "mlsStat"; public static final String MLSSTAT = "mlsStatus";
/** /**
* Is the accession “FAO In trust” * Is the accession “FAO In trust”
...@@ -126,7 +126,7 @@ public interface Api1Constants { ...@@ -126,7 +126,7 @@ public interface Api1Constants {
/** /**
* Corresponds to BREDCODE. * Corresponds to BREDCODE.
*/ */
public static final String BREDCODE = "bredCode"; public static final String BREDCODE = "breederCode";
/** /**
* Corresponds to ANCEST. * Corresponds to ANCEST.
...@@ -196,6 +196,8 @@ public interface Api1Constants { ...@@ -196,6 +196,8 @@ public interface Api1Constants {
*/ */
public static final String DOI = "doi"; public static final String DOI = "doi";
public static final String BREDNAME = "breederName";
} }
public static interface Institute { public static interface Institute {
...@@ -304,17 +306,17 @@ public interface Api1Constants { ...@@ -304,17 +306,17 @@ public interface Api1Constants {
/** /**
* COORDUNCERT (in meters) * COORDUNCERT (in meters)
*/ */
public static final String COORDUNCERT = "coordUncert"; public static final String COORDUNCERT = "uncertainty";
/** /**
* Corresponds to COORDATUM * Corresponds to COORDATUM
*/ */
public static final String COORDDATUM = "coordDatum"; public static final String COORDDATUM = "datum";
/** /**
* Corresponds to GEOREFMETH * Corresponds to GEOREFMETH
*/ */
public static final String GEOREFMETH = "georefMeth"; public static final String GEOREFMETH = "method";
} }
public static interface Pdci { public static interface Pdci {
......
...@@ -18,7 +18,7 @@ package org.genesys2.server.model.json; ...@@ -18,7 +18,7 @@ package org.genesys2.server.model.json;
import java.util.Set; import java.util.Set;
import org.genesys2.server.model.json.Api1Constants.Collecting; import org.genesys2.server.model.json.Api0Constants.Collecting;