From 034bbb7c74f3c32bcab770750fa6dceda63b9024 Mon Sep 17 00:00:00 2001 From: Maxym Borodenko Date: Mon, 8 Apr 2019 16:50:52 +0300 Subject: [PATCH] added taxonomy constants, fixed auth endpoint name --- .../genesys2/client/oauth/GenesysClient.java | 4 +- .../oauth/api/accession/AccessionJson.java | 133 +++------------ .../oauth/api/accession/Api1Constants.java | 61 ++++--- .../oauth/api/accession/TaxonomyJson.java | 157 ++++++++++++++++++ .../client/oauth/AccessionApiTest.java | 2 +- .../client/oauth/MockGenesysServer.java | 13 +- 6 files changed, 226 insertions(+), 144 deletions(-) create mode 100644 src/main/java/org/genesys2/client/oauth/api/accession/TaxonomyJson.java diff --git a/src/main/java/org/genesys2/client/oauth/GenesysClient.java b/src/main/java/org/genesys2/client/oauth/GenesysClient.java index 6c2ef54..ce6605a 100644 --- a/src/main/java/org/genesys2/client/oauth/GenesysClient.java +++ b/src/main/java/org/genesys2/client/oauth/GenesysClient.java @@ -401,7 +401,7 @@ public class GenesysClient { public String updateAccession(String instituteCode, String data) throws InterruptedException, GenesysApiException { for (int retry = 0; retry < 5; retry++) { try { - return query(Verb.PUT, "/acn/" + instituteCode + "/upsert", null, data); + return query(Verb.POST, "/acn/" + instituteCode + "/upsert", null, data); } catch (final PleaseRetryException e) { final long sleepTime = (long) (Math.pow(2, retry) * 100 + Math.pow(2, retry) * 2500 * Math.random()); LOG.warn("Retrying PUT after {} ms.", sleepTime); @@ -511,7 +511,7 @@ public class GenesysClient { * @throws GenesysApiException the Genesys API exception */ public String me() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException { - return query("/me"); + return query("/me/profile"); } /** diff --git a/src/main/java/org/genesys2/client/oauth/api/accession/AccessionJson.java b/src/main/java/org/genesys2/client/oauth/api/accession/AccessionJson.java index 7a3d1ef..da95632 100644 --- a/src/main/java/org/genesys2/client/oauth/api/accession/AccessionJson.java +++ b/src/main/java/org/genesys2/client/oauth/api/accession/AccessionJson.java @@ -51,26 +51,6 @@ public class AccessionJson { @JsonProperty(value = Accession.GENUS) private String genus; - /** The new genus. */ - @JsonProperty(value = Accession.GENUS_NEW) - private String newGenus; - - /** The species. */ - @JsonProperty(value = Accession.SPECIES) - private String species; - - /** The spauthor. */ - @JsonProperty(value = Accession.SPAUTHOR) - private String spauthor; - - /** The subtaxa. */ - @JsonProperty(value = Accession.SUBTAXA) - private String subtaxa; - - /** The subtauthor. */ - @JsonProperty(value = Accession.SUBTAUTHOR) - private String subtauthor; - /** The uuid. */ @JsonProperty(value = Accession.UUID) private String uuid; @@ -139,6 +119,10 @@ public class AccessionJson { @JsonProperty(value = Accession.GEO) private GeoJson geo; + /** The taxonomy. */ + @JsonProperty(value = Accession.TAXONOMY) + private TaxonomyJson taxonomy; + /** The remarks. */ @JsonProperty(value = Accession.REMARKS) private Remark[] remarks; @@ -166,6 +150,7 @@ public class AccessionJson { public AccessionJson() { this.geo = new GeoJson(); this.coll = new CollectingJson(); + this.taxonomy = new TaxonomyJson(); } /** @@ -284,96 +269,6 @@ public class AccessionJson { this.genus = genus; } - /** - * Gets the new genus. - * - * @return the new genus - */ - public String getNewGenus() { - return newGenus; - } - - /** - * Sets the new genus. - * - * @param newGenus the new new genus - */ - public void setNewGenus(final String newGenus) { - this.newGenus = newGenus; - } - - /** - * Gets the species. - * - * @return the species - */ - public String getSpecies() { - return species; - } - - /** - * Sets the species. - * - * @param species the new species - */ - public void setSpecies(final String species) { - this.species = species; - } - - /** - * Gets the spauthor. - * - * @return the spauthor - */ - public String getSpauthor() { - return spauthor; - } - - /** - * Sets the spauthor. - * - * @param spauthor the new spauthor - */ - public void setSpauthor(final String spauthor) { - this.spauthor = spauthor; - } - - /** - * Gets the subtaxa. - * - * @return the subtaxa - */ - public String getSubtaxa() { - return subtaxa; - } - - /** - * Sets the subtaxa. - * - * @param subtaxa the new subtaxa - */ - public void setSubtaxa(final String subtaxa) { - this.subtaxa = subtaxa; - } - - /** - * Gets the subtauthor. - * - * @return the subtauthor - */ - public String getSubtauthor() { - return subtauthor; - } - - /** - * Sets the subtauthor. - * - * @param subtauthor the new subtauthor - */ - public void setSubtauthor(final String subtauthor) { - this.subtauthor = subtauthor; - } - /** * Gets the uuid. * @@ -662,6 +557,24 @@ public class AccessionJson { this.geo = geo; } + /** + * Gets the taxonomy. + * + * @return the taxonomy + */ + public TaxonomyJson getTaxonomy() { + return taxonomy; + } + + /** + * Sets the taxonomy. + * + * @param taxonomy the new taxonomy + */ + public void setTaxonomy(final TaxonomyJson taxonomy) { + this.taxonomy = taxonomy; + } + /** * Gets the remarks. * diff --git a/src/main/java/org/genesys2/client/oauth/api/accession/Api1Constants.java b/src/main/java/org/genesys2/client/oauth/api/accession/Api1Constants.java index 4294526..1b783e0 100644 --- a/src/main/java/org/genesys2/client/oauth/api/accession/Api1Constants.java +++ b/src/main/java/org/genesys2/client/oauth/api/accession/Api1Constants.java @@ -55,26 +55,6 @@ public interface Api1Constants { */ 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. @@ -154,6 +134,9 @@ public interface Api1Constants { /** Object containing georeference data. */ public static final String GEO = "geo"; + /** Object containing taxonomy data. */ + public static final String TAXONOMY = "taxonomy"; + /** MCPD Remarks. */ public static final String REMARKS = "remarks"; @@ -235,4 +218,42 @@ public interface Api1Constants { /** Corresponds to GEOREFMETH. */ public static final String GEOREFMETH = "georefMeth"; } + + /** + * The Interface Taxonomy. + */ + public static interface Taxonomy { + + /** + * 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"; + + } } diff --git a/src/main/java/org/genesys2/client/oauth/api/accession/TaxonomyJson.java b/src/main/java/org/genesys2/client/oauth/api/accession/TaxonomyJson.java new file mode 100644 index 0000000..dce111c --- /dev/null +++ b/src/main/java/org/genesys2/client/oauth/api/accession/TaxonomyJson.java @@ -0,0 +1,157 @@ +/* + * Copyright 2019 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.client.oauth.api.accession; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The Class TaxonomyJson. + */ +public class TaxonomyJson { + + /** The genus. */ + @JsonProperty(value = Api1Constants.Taxonomy.GENUS) + private String genus; + + /** The new genus. */ + @JsonProperty(value = Api1Constants.Taxonomy.GENUS_NEW) + private String newGenus; + + /** The spAuthor. */ + @JsonProperty(value = Api1Constants.Taxonomy.SPAUTHOR) + private String spAuthor; + + /** The species. */ + @JsonProperty(value = Api1Constants.Taxonomy.SPECIES) + private String species; + + /** The subtAuthor. */ + @JsonProperty(value = Api1Constants.Taxonomy.SUBTAUTHOR) + private String subtAuthor; + + /** The subtaxa. */ + @JsonProperty(value = Api1Constants.Taxonomy.SUBTAXA) + private String subtaxa; + + /** + * Gets the genus. + * + * @return the genus + */ + public String getGenus() { + return genus; + } + + /** + * Sets the genus. + * + * @param genus the new genus + */ + public void setGenus(final String genus) { + this.genus = genus; + } + + /** + * Gets the new genus. + * + * @return the new genus + */ + public String getNewGenus() { + return newGenus; + } + + /** + * Sets the new genus. + * + * @param newGenus the new new genus + */ + public void setNewGenus(final String newGenus) { + this.newGenus = newGenus; + } + + /** + * Gets the spAuthor. + * + * @return the spAuthor + */ + public String getSpAuthor() { + return spAuthor; + } + + /** + * Sets the spAuthor. + * + * @param spAuthor the new spAuthor + */ + public void setSpAuthor(final String spAuthor) { + this.spAuthor = spAuthor; + } + + /** + * Gets the species. + * + * @return the species + */ + public String getSpecies() { + return species; + } + + /** + * Sets the species. + * + * @param species the new species + */ + public void setSpecies(final String species) { + this.species = species; + } + + /** + * Gets the subtAuthor. + * + * @return the subtAuthor + */ + public String getSubtAuthor() { + return subtAuthor; + } + + /** + * Sets the subtAuthor. + * + * @param subtAuthor the new subtAuthor + */ + public void setSubtAuthor(final String subtAuthor) { + this.subtAuthor = subtAuthor; + } + + /** + * Gets the subtaxa. + * + * @return the subtaxa + */ + public String getSubtaxa() { + return subtaxa; + } + + /** + * Sets the subtaxa. + * + * @param subtaxa the new subtaxa + */ + public void setSubtaxa(final String subtaxa) { + this.subtaxa = subtaxa; + } +} diff --git a/src/test/java/org/geneys2/client/oauth/AccessionApiTest.java b/src/test/java/org/geneys2/client/oauth/AccessionApiTest.java index 14ffebb..ce7339d 100644 --- a/src/test/java/org/geneys2/client/oauth/AccessionApiTest.java +++ b/src/test/java/org/geneys2/client/oauth/AccessionApiTest.java @@ -171,7 +171,7 @@ public class AccessionApiTest { assertThat("Expected matching INSTCODE", aj1.getInstituteCode(), is(instituteCode)); assertThat("Expected ACCENUMB starting with", aj1.getAccessionNumber(), CoreMatchers.startsWith("ACC-")); assertThat("Expected GENUS=Genus", aj1.getGenus(), is("Genus")); - assertThat("Expected SPECIES=null", aj1.getSpecies(), nullValue()); + assertThat("Expected SPECIES=null", aj1.getTaxonomy().getSpecies(), nullValue()); } } diff --git a/src/test/java/org/geneys2/client/oauth/MockGenesysServer.java b/src/test/java/org/geneys2/client/oauth/MockGenesysServer.java index f330dcf..f8a594d 100644 --- a/src/test/java/org/geneys2/client/oauth/MockGenesysServer.java +++ b/src/test/java/org/geneys2/client/oauth/MockGenesysServer.java @@ -188,17 +188,8 @@ public class MockGenesysServer { if (aj.getSampStat() != null) { existing.setSampStat(aj.getSampStat()); } - if (aj.getSpecies() != null) { - existing.setSpecies(aj.getSpecies()); - } - if (aj.getSpauthor() != null) { - existing.setSpauthor(aj.getSpauthor()); - } - if (aj.getSubtaxa() != null) { - existing.setSubtaxa(aj.getSubtaxa()); - } - if (aj.getSubtauthor() != null) { - existing.setSubtauthor(aj.getSubtauthor()); + if (aj.getTaxonomy() != null) { + } if (aj.getUuid() != null) { if (existing.getUuid() == null) { -- GitLab