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
Pipeline #7929 passed with stages
in 6 minutes and 12 seconds
......@@ -18,12 +18,7 @@ package org.genesys2.server.api.model;
import java.text.MessageFormat;
import com.fasterxml.jackson.databind.JsonNode;
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 String doi;
......@@ -31,22 +26,6 @@ public class AccessionHeaderJson implements AccessionIdentifier3 {
public String acceNumb;
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
public String getDoi() {
return doi;
......
......@@ -35,6 +35,8 @@ import org.genesys2.server.model.elastic.AccessionDetails;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
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.GenesysFilterService;
import org.genesys2.server.service.GenesysRESTService;
......@@ -415,31 +417,31 @@ public class AccessionController extends ApiBaseController {
}
private void upgradeToV2(ObjectNode update) {
upgradeRename(update, "instCode", "instituteCode");
upgradeRename(update, "acceNumb", "accessionNumber");
upgradeRename(update, "spauthor", "spAuthor");
upgradeRename(update, "subtauthor", "subtAuthor");
upgradeRename(update, "acqDate", "acquisitionDate");
upgradeRename(update, "bredCode", "breederCode");
upgradeRename(update, "bredName", "breederName");
upgradeRename(update, "mlsStat", "mlsStatus");
upgradeRename(update, "orgCty", "origCty");
upgradeToArray(update, "breederCode"); // renamed above
upgradeToArray(update, "breederName"); // renamed above
upgradeRename(update, Api0Constants.Accession.INSTCODE, Api1Constants.Accession.INSTCODE);
upgradeRename(update, Api0Constants.Accession.ACCENUMB, Api1Constants.Accession.ACCENUMB);
upgradeRename(update, Api0Constants.Accession.SPAUTHOR, Api1Constants.Accession.SPAUTHOR);
upgradeRename(update, Api0Constants.Accession.SUBTAUTHOR, Api1Constants.Accession.SUBTAUTHOR);
upgradeRename(update, Api0Constants.Accession.ACQDATE, Api1Constants.Accession.ACQDATE);
upgradeRename(update, Api0Constants.Accession.BREDCODE, Api1Constants.Accession.BREDCODE);
upgradeRename(update, Api0Constants.Accession.BREDNAME, Api1Constants.Accession.BREDNAME);
upgradeRename(update, Api0Constants.Accession.MLSSTAT, Api1Constants.Accession.MLSSTAT);
upgradeRename(update, Api0Constants.Accession.ORIGCTY, Api1Constants.Accession.ORIGCTY);
upgradeToArray(update, Api1Constants.Accession.BREDCODE); // renamed above
upgradeToArray(update, Api1Constants.Accession.BREDNAME); // renamed above
if (update.has("geo")) {
ObjectNode geo = (ObjectNode) update.get("geo");
upgradeRename(geo, "coordUncert", "uncertainty");
upgradeRename(geo, "coordDatum", "datum");
upgradeRename(geo, "georefMeth", "method");
upgradeRename(geo, Api0Constants.Geo.COORDUNCERT, Api1Constants.Geo.COORDUNCERT);
upgradeRename(geo, Api0Constants.Geo.COORDDATUM, Api1Constants.Geo.COORDDATUM);
upgradeRename(geo, Api0Constants.Geo.GEOREFMETH, Api1Constants.Geo.GEOREFMETH);
}
if (update.has("coll")) {
ObjectNode coll = (ObjectNode) update.get("coll");
upgradeToArray(coll, "collCode");
upgradeToArray(coll, "collName");
upgradeToArray(coll, "collInstAddress");
upgradeToArray(coll, Api1Constants.Collecting.COLLCODE);
upgradeToArray(coll, Api1Constants.Collecting.COLLNAME);
upgradeToArray(coll, Api1Constants.Collecting.COLLINSTADDRESS);
}
ObjectNode taxonomy;
......@@ -449,11 +451,11 @@ public class AccessionController extends ApiBaseController {
taxonomy = update.putObject("taxonomy");
}
upgradeTaxonomy(update, taxonomy, "genus");
upgradeTaxonomy(update, taxonomy, "species");
upgradeTaxonomy(update, taxonomy, "spAuthor");
upgradeTaxonomy(update, taxonomy, "subtaxa");
upgradeTaxonomy(update, taxonomy, "subtAuthor");
upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.GENUS);
upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SPECIES);
upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SPAUTHOR);
upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SUBTAXA);
upgradeTaxonomy(update, taxonomy, Api1Constants.Accession.SUBTAUTHOR);
}
private void upgradeToArray(ObjectNode obj, String fieldName) {
......
......@@ -36,7 +36,7 @@ import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.impl.AccessionIdentifier3;
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.DatasetService;
import org.genesys2.server.service.GenesysService;
......@@ -214,13 +214,13 @@ public class DatasetController extends ApiBaseController {
final String key = field.getKey();
final JsonNode value = field.getValue();
if (Api1Constants.Accession.INSTCODE.equals(key)) {
if (Api0Constants.Accession.INSTCODE.equals(key)) {
dataJson.instCode = value.asText();
} else if (Api1Constants.Accession.DOI.equals(key)) {
} else if (Api0Constants.Accession.DOI.equals(key)) {
dataJson.doi = value.asText();
} else if (Api1Constants.Accession.ACCENUMB.equals(key)) {
} else if (Api0Constants.Accession.ACCENUMB.equals(key)) {
dataJson.acceNumb = value.asText();
} else if (Api1Constants.Accession.GENUS.equals(key)) {
} else if (Api0Constants.Accession.GENUS.equals(key)) {
dataJson.genus = value.asText();
} else if (key.startsWith("gm:")) {
// Handle Genesys Method!
......
......@@ -258,19 +258,19 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
if (other == null) {
return false;
}
if (!genus.equalsIgnoreCase(other.genus)) {
if (! StringUtils.equalsIgnoreCase(genus, other.genus)) {
return false;
}
if (!species.equalsIgnoreCase(other.species)) {
if (! StringUtils.equalsIgnoreCase(species, other.species)) {
return false;
}
if (!spAuthor.equalsIgnoreCase(other.spAuthor)) {
if (! StringUtils.equalsIgnoreCase(spAuthor, other.spAuthor)) {
return false;
}
if (!subtaxa.equalsIgnoreCase(other.subtaxa)) {
if (! StringUtils.equalsIgnoreCase(subtaxa, other.subtaxa)) {
return false;
}
if (!subtAuthor.equalsIgnoreCase(other.subtAuthor)) {
if (! StringUtils.equalsIgnoreCase(subtAuthor, other.subtAuthor)) {
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 {
/**
* WIEWS code of accession holding institute.
*/
public static final String INSTCODE = "instCode";
public static final String INSTCODE = "instituteCode";
/**
* Accession number.
*/
public static final String ACCENUMB = "acceNumb";
public static final String ACCENUMB = "accessionNumber";
/**
* Used to assign new ACCENUMB
......@@ -58,7 +58,7 @@ public interface Api1Constants {
/**
* Corresponds to MCPD SPAUTHOR
*/
public static final String SPAUTHOR = "spauthor";
public static final String SPAUTHOR = "spAuthor";
/**
* Corresponds to MCPD SUBTAXA
......@@ -68,7 +68,7 @@ public interface Api1Constants {
/**
* 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
......@@ -80,21 +80,21 @@ public interface Api1Constants {
/**
* 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.
* Missing data (MM or DD) should be indicated with hyphens. Leading
* 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
* (MLS) of the International Treaty on PlantGenetic Resources for Food
* and Agriculture.
*/
public static final String MLSSTAT = "mlsStat";
public static final String MLSSTAT = "mlsStatus";
/**
* Is the accession “FAO In trust”
......@@ -126,7 +126,7 @@ public interface Api1Constants {
/**
* Corresponds to BREDCODE.
*/
public static final String BREDCODE = "bredCode";
public static final String BREDCODE = "breederCode";
/**
* Corresponds to ANCEST.
......@@ -196,6 +196,8 @@ public interface Api1Constants {
*/
public static final String DOI = "doi";
public static final String BREDNAME = "breederName";
}
public static interface Institute {
......@@ -304,17 +306,17 @@ public interface Api1Constants {
/**
* COORDUNCERT (in meters)
*/
public static final String COORDUNCERT = "coordUncert";
public static final String COORDUNCERT = "uncertainty";
/**
* Corresponds to COORDATUM
*/
public static final String COORDDATUM = "coordDatum";
public static final String COORDDATUM = "datum";
/**
* Corresponds to GEOREFMETH
*/
public static final String GEOREFMETH = "georefMeth";
public static final String GEOREFMETH = "method";
}
public static interface Pdci {
......
......@@ -18,7 +18,7 @@ package org.genesys2.server.model.json;
import java.util.Set;
import org.genesys2.server.model.json.Api1Constants.Collecting;
import org.genesys2.server.model.json.Api0Constants.Collecting;
import com.fasterxml.jackson.annotation.JsonProperty;
......
......@@ -16,7 +16,7 @@
package org.genesys2.server.model.json;
import org.genesys2.server.model.json.Api1Constants.Geo;
import org.genesys2.server.model.json.Api0Constants.Geo;
import com.fasterxml.jackson.annotation.JsonProperty;
......
......@@ -68,7 +68,7 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.model.json.Api1Constants;
import org.genesys2.server.model.json.Api0Constants;
import org.genesys2.server.persistence.AccessionGeoRepository;
import org.genesys2.server.persistence.AccessionHistoricRepository;
import org.genesys2.server.persistence.AccessionIdRepository;
......@@ -193,30 +193,30 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public GenesysServiceImpl() {
List<String> columnList = new ArrayList<String>();
columnList.add(Api1Constants.Accession.DOI);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SCIENTIFIC_NAME);
columnList.add("taxonomy." + Api1Constants.Taxonomy.GENUS);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SPECIES);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SUBTAXA);
columnList.add(Api1Constants.Accession.ACCENAME);
columnList.add(Api1Constants.Accession.DONORNUMB);
columnList.add(Api1Constants.Accession.CROP_NAMES);
columnList.add(Api1Constants.Accession.CROPNAME);
columnList.add(Api1Constants.Accession.ORIGCTY);
columnList.add(Api1Constants.Accession.SAMPSTAT);
columnList.add("institute." + Api1Constants.Institute.INSTCODE);
columnList.add("geo." + Api1Constants.Geo.LATITUDE_LONGITUDE);
columnList.add("coll." + Api1Constants.Collecting.COLLMISSID);
columnList.add("pdci." + Api1Constants.Pdci.SCORE);
columnList.add(Api0Constants.Accession.DOI);
columnList.add("taxonomy." + Api0Constants.Taxonomy.SCIENTIFIC_NAME);
columnList.add("taxonomy." + Api0Constants.Taxonomy.GENUS);
columnList.add("taxonomy." + Api0Constants.Taxonomy.SPECIES);
columnList.add("taxonomy." + Api0Constants.Taxonomy.SUBTAXA);
columnList.add(Api0Constants.Accession.ACCENAME);
columnList.add(Api0Constants.Accession.DONORNUMB);
columnList.add(Api0Constants.Accession.CROP_NAMES);
columnList.add(Api0Constants.Accession.CROPNAME);
columnList.add(Api0Constants.Accession.ORIGCTY);
columnList.add(Api0Constants.Accession.SAMPSTAT);
columnList.add("institute." + Api0Constants.Institute.INSTCODE);
columnList.add("geo." + Api0Constants.Geo.LATITUDE_LONGITUDE);
columnList.add("coll." + Api0Constants.Collecting.COLLMISSID);
columnList.add("pdci." + Api0Constants.Pdci.SCORE);
availableDisplayColumns = Collections.unmodifiableList(columnList);
List<String> displayList = new ArrayList<String>();
displayList.add("taxonomy." + Api1Constants.Taxonomy.GENUS);
displayList.add("taxonomy." + Api1Constants.Taxonomy.SPECIES);
displayList.add(Api1Constants.Accession.ACCENAME);
displayList.add(Api1Constants.Accession.ORIGCTY);
displayList.add(Api1Constants.Accession.SAMPSTAT);
displayList.add("institute." + Api1Constants.Institute.INSTCODE);
displayList.add("taxonomy." + Api0Constants.Taxonomy.GENUS);
displayList.add("taxonomy." + Api0Constants.Taxonomy.SPECIES);
displayList.add(Api0Constants.Accession.ACCENAME);
displayList.add(Api0Constants.Accession.ORIGCTY);
displayList.add(Api0Constants.Accession.SAMPSTAT);
displayList.add("institute." + Api0Constants.Institute.INSTCODE);
defaultDisplayColumns = Collections.unmodifiableList(displayList);
}
......
......@@ -231,6 +231,7 @@ public class TaxonomyServiceImpl implements TaxonomyService {
newTaxa.setSpAuthor(example.getSpAuthor());
newTaxa.setSubtaxa(example.getSubtaxa());
newTaxa.setSubtAuthor(example.getSubtAuthor());
newTaxa.sanitize();
Taxonomy2 tsP = new Taxonomy2();
tsP.setGenus(newTaxa.getGenus());
......