From ff1ea51e30c949caea18ec7a475d92d3a96ea011 Mon Sep 17 00:00:00 2001 From: lucio Date: Tue, 10 Mar 2020 13:13:31 +0100 Subject: [PATCH] update to be compatible with the latest worms version --- .classpath | 40 +- .settings/org.eclipse.jdt.core.prefs | 9 +- pom.xml | 37 +- .../client/worms/AphiaAttributeSets.java | 41 + .../cs/fusion/client/worms/AphiaRecord.java | 188 +++++ .../cs/fusion/client/worms/Attribute.java | 90 +++ .../cs/fusion/client/worms/AttributeKey.java | 59 ++ .../fusion/client/worms/AttributeValue.java | 53 ++ .../fusion/client/worms/Classification.java | 47 ++ .../cs/fusion/client/worms/Distribution.java | 88 +++ .../worms/ExternalIdentifierSource.java | 64 ++ .../cs/fusion/client/worms/MatchType.java | 29 + .../cs/fusion/client/worms/Source.java | 64 ++ .../cs/fusion/client/worms/Vernacular.java | 34 + .../cs/fusion/client/worms/WormsClient.java | 726 ++++++++++++++++++ .../client/worms/WormsClientException.java | 45 ++ .../org/gcube/data/spd/wormsplugin/Utils.java | 52 +- .../data/spd/wormsplugin/WormsPlugin.java | 86 +-- .../ClassificationCapabilityImpl.java | 93 +-- .../capabilities/ExpansionCapabilityImpl.java | 22 +- .../capabilities/NamesMappingImpl.java | 21 +- .../org/gcube/data/spd/wormsplugin/Test.java | 4 +- .../wormsplugin/TestExpansionCapability.java | 7 +- .../data/spd/wormsplugin/TestMapping.java | 5 +- 24 files changed, 1722 insertions(+), 182 deletions(-) create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaAttributeSets.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaRecord.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/Attribute.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeKey.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeValue.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/Classification.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/Distribution.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/ExternalIdentifierSource.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/MatchType.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/Source.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/Vernacular.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClient.java create mode 100644 src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClientException.java diff --git a/.classpath b/.classpath index 6e26406..002ad57 100644 --- a/.classpath +++ b/.classpath @@ -1,10 +1,38 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index ec4300d..2f5cc74 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,8 @@ eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/pom.xml b/pom.xml index 8f7e7ee..ad9b202 100644 --- a/pom.xml +++ b/pom.xml @@ -5,13 +5,13 @@ maven-parent org.gcube.tools - 1.0.0 + 1.1.0 org.gcube.data.spd worms-spd-plugin - 1.8.0-SNAPSHOT + 1.8.1-SNAPSHOT worms-plugin worms plugin for species manager service @@ -41,35 +41,20 @@ org.gcube.resources.discovery ic-client - - + - org.apache.axis - axis - 1.4 + com.fasterxml.jackson.core + jackson-core - - - javax.xml - jaxrpc-api - 1.1 + com.fasterxml.jackson.core + jackson-annotations - - - commons-discovery - commons-discovery - 0.5 + com.fasterxml.jackson.core + jackson-databind - - - - wsdl4j - wsdl4j - 1.6.2 - - + org.gcube.data.spd spd-model @@ -121,7 +106,7 @@ org.apache.maven.plugins maven-assembly-plugin - 2.2 + ${distroDirectory}/descriptor.xml diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaAttributeSets.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaAttributeSets.java new file mode 100644 index 0000000..2942fdb --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaAttributeSets.java @@ -0,0 +1,41 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import java.util.Collection; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class AphiaAttributeSets { + + /** + * Unique and persistent identifier within WoRMS. Primary key in the + * database. + */ + @JsonProperty("AphiaID") + public int aphiaId; + + @JsonProperty("Attributes") + public Collection attributes; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaRecord.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaRecord.java new file mode 100644 index 0000000..d256c6e --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/AphiaRecord.java @@ -0,0 +1,188 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class AphiaRecord { + + /** + * Unique and persistent identifier within WoRMS. Primary key in the + * database. + */ + @JsonProperty("AphiaID") + public long aphiaId; + + /** + * HTTP URL to the AphiaRecord + */ + public String url; + + /** + * the full scientific name without authorship + */ + @JsonProperty("scientificname") + public String scientificName; + + /** + * the authorship information for the scientific name formatted according to + * the conventions of the applicable nomenclaturalCode + */ + public String authority; + + /** + * the taxonomic rank of the most specific name in the scientific name + */ + @JsonProperty("rank") + public String taxonomicRank; + + /** + * the status of the use of the scientific name (usually a taxonomic + * opinion). Additional technical statuses are (1) quarantined: hidden from + * public interface after decision from an editor and (2) deleted: AphiaID + * should NOT be used anymore, please replace it by the valid_AphiaID + */ + public String status; + + public String taxonRankID; + + public String parentNameUsageID; + + /** + * the reason why a scientific name is unaccepted + */ + @JsonProperty("unacceptreason") + public String unacceptReason; + + /** + * the AphiaID (for the scientific name) of the currently accepted taxon. + * NULL if there is no currently accepted taxon. + */ + @JsonProperty("valid_AphiaID") + public long validAphiaId; + + /** + * the scientific name of the currently accepted taxon + */ + @JsonProperty("valid_name") + public String validName; + + /** + * the authorship information for the scientific name of the currently + * accepted taxon + */ + @JsonProperty("valid_authority") + public String validAuthority; + + /** + * the full scientific name of the kingdom in which the taxon is classified + */ + @JsonProperty("kingdom") + public String taxonomicKingdom; + + /** + * the full scientific name of the phylum or division in which the taxon is + * classified + */ + @JsonProperty("phylum") + public String taxonomicPhylum; + + /** + * the full scientific name of the class in which the taxon is classified + */ + @JsonProperty("class") + public String taxonomicClass; + + /** + * the full scientific name of the order in which the taxon is classified + */ + @JsonProperty("order") + public String taxonomicOrder; + + /** + * the full scientific name of the family in which the taxon is classified + */ + @JsonProperty("family") + public String taxonomicFamily; + + /** + * the full scientific name of the genus in which the taxon is classified + */ + @JsonProperty("genus") + public String taxonomicGenus; + + /** + * a bibliographic reference for the resource as a statement indicating how + * this record should be cited (attributed) when used + */ + public String citation; + + /** + * LifeScience Identifier. Persistent GUID for an AphiaID + */ + public String lsid; + + /** + * a boolean flag indicating whether the taxon is a marine organism, i.e. + * can be found in/above sea water. Possible values: 0/1/NULL + */ + public Boolean isMarine; + + /** + * a boolean flag indicating whether the taxon occurrs in brackish habitats. + * Possible values: 0/1/NULL + */ + public Boolean isBrackish; + + /** + * a boolean flag indicating whether the taxon occurrs in freshwater + * habitats, i.e. can be found in/above rivers or lakes. Possible values: + * 0/1/NULL + */ + public Boolean isFreshwater; + + /** + * a boolean flag indicating the taxon is a terrestial organism, i.e. + * occurrs on land as opposed to the sea. Possible values: 0/1/NULL + */ + public Boolean isTerrestrial; + + /** + * a flag indicating an extinct organism. Possible values: 0/1/NULL + */ + public Boolean isExtinct; + + /** + * Type of match. + */ + @JsonProperty("match_type") + public MatchType matchType; + + /** + * The most recent date-time in GMT on which the resource was changed + */ + public String modified; + +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/Attribute.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/Attribute.java new file mode 100644 index 0000000..4030493 --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/Attribute.java @@ -0,0 +1,90 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import java.util.Collection; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class Attribute { + /** + * Unique and persistent identifier within WoRMS. Primary key in the + * database. + */ + @JsonProperty("AphiaID") + public int aphiaId; + + /** + * The corresponding AttributeKey its measurementTypeID + */ + @JsonProperty("measurementTypeID") + public int measurementTypeId; + + /** + * The corresponding AttributeKey its measurementType + */ + public String measurementType; + + /** + * The value of the measurement, fact, characteristic, or assertion + */ + public String measurementValue; + + /** + * The identifier for the AphiaSource for this attribute + */ + @JsonProperty("source_id") + public Integer sourceId; + + /** + * The AphiaSource reference for this attribute + */ + public String reference; + + /** + * Quality status of the record. Possible values: 'checked’, ‘trusted’ or + * 'unreviewed’. See http://www.marinespecies.org/aphia.php?p=manual#topic22 + */ + @JsonProperty("qualitystatus") + public String qualityStatus; + + /** + * The category identifier to list possible attribute values for this + * attribute definition + */ + @JsonProperty("CategoryID") + public Integer categoryID; + + /** + * The AphiaID from where this attribute is inherited + */ + @JsonProperty("AphiaID_Inherited") + public Integer aphiaIdInherited; + + /** + * The possible child attributes that help to describe to current attribute + */ + public Collection children; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeKey.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeKey.java new file mode 100644 index 0000000..3a439ed --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeKey.java @@ -0,0 +1,59 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import java.util.Collection; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class AttributeKey { + /** + * An internal identifier for the measurementType + */ + @JsonProperty("measurementTypeID") + public int measurementTypeId; + + /** + * The nature of the measurement, fact, characteristic, or assertion http://www.marinespecies.org/traits/wiki + */ + public String measurementType; + + /** + * The data type that is expected as value for this attribute definition + */ + @JsonProperty("input_id") + public int inputId; + + /** + * The category identifier to list possible attribute values for this attribute definition + */ + @JsonProperty("CategoryID") + public int categoryId; + + /** + * The possible child attribute keys that help to describe to current attribute + */ + public Collection children; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeValue.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeValue.java new file mode 100644 index 0000000..3f874ce --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/AttributeValue.java @@ -0,0 +1,53 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import java.util.Collection; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class AttributeValue { + /** + * An identifier for facts stored in the column measurementValue + */ + @JsonProperty("measurementValueID") + public int measurementValueId; + + /** + * The value of the measurement, fact, characteristic, or assertion + */ + public String measurementValue; + + /** + * Additional info/code that helps to the describe/define the + * measurementValue + */ + public String measurementValueCode; + + /** + * Child measurementValues that are more specific + */ + public Collection children; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/Classification.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/Classification.java new file mode 100644 index 0000000..6e5d8b4 --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/Classification.java @@ -0,0 +1,47 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class Classification { + /** + * Unique and persistent identifier within WoRMS. Primary key in the + * database. + */ + @JsonProperty("AphiaID") + public int aphiaId; + /** + * the taxonomic rank of the most specific name in the scientific name + */ + @JsonProperty("rank") + public String taxonomicRank; + /** + * the full scientific name without authorship + */ + @JsonProperty("scientificname") + public String scientificName; + public Classification child; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/Distribution.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/Distribution.java new file mode 100644 index 0000000..71f77e8 --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/Distribution.java @@ -0,0 +1,88 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class Distribution { + + /** + * The specific description of the place + */ + public String locality; + + /** + * An identifier for the locality. Using the Marine Regions Geographic + * IDentifier (MRGID), see http://www.marineregions.org/mrgid.php + */ + public String locationID; + + /** + * A geographic name less specific than the information captured in the + * locality term. Possible values: an IHO Sea Area or Nation, derived from + * the MarineRegions gazetteer + */ + public String higherGeography; + + /** + * An identifier for the geographic region within which the locality + * occurred, using MRGID + */ + public String higherGeographyID; + + /** + * The status of the distribution record. Possible values are ‘valid’ + * ,’doubtful’ or 'inaccurate’. See here for explanation of the statuses + */ + public String recordStatus; + + /** + * The type status of the distribution. Possible values: ‘holotype’ or + * empty. + */ + public String typeStatus; + + /** + * The process by which the biological individual(s) represented in the + * Occurrence became established at the location. Possible values: values + * listed as Origin in WRIMS + */ + public String establishmentMeans; + + /** + * The geographic latitude (in decimal degrees, WGS84) + */ + public double decimalLatitude; + + /** + * The geographic longitude (in decimal degrees, WGS84) + */ + public double decimalLongitude; + + /** + * Quality status of the record. Possible values: 'checked’, ‘trusted’ or + * 'unreviewed’. See http://www.marinespecies.org/aphia.php?p=manual#topic22 + */ + public String qualityStatus; + +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/ExternalIdentifierSource.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/ExternalIdentifierSource.java new file mode 100644 index 0000000..92ff7fe --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/ExternalIdentifierSource.java @@ -0,0 +1,64 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public enum ExternalIdentifierSource { + /** + * Barcode of Life Database (BOLD) TaxID + */ + bold, + /** + * Dyntaxa ID + */ + dyntaxa, + /** + * Encyclopedia of Life page identifier + */ + eol, + /** + * FishBase species ID + */ + fishbase, + /** + * IUCN Red List Identifier + */ + iucn, + /** + * Life Science Identifier + */ + lsid, + /** + * NCBI Taxonomy ID (Genbank) + */ + ncbi, + /** + * ITIS Taxonomic Serial Number + */ + tsn, + /** + * Global Invasive Species Database + */ + gisd +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/MatchType.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/MatchType.java new file mode 100644 index 0000000..3aeb73f --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/MatchType.java @@ -0,0 +1,29 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public enum MatchType { + exact, like, phonetic, near_1, near_2 +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/Source.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/Source.java new file mode 100644 index 0000000..c335e28 --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/Source.java @@ -0,0 +1,64 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class Source { + /** + * Unique identifier for the source within WoRMS. + */ + @JsonProperty("source_id") + public int sourceId; + /** + * Usage of the source for this taxon. See + * http://www.marinespecies.org/aphia.php?p=manual#topic6 for all values + */ + public String use; + /** + * Full citation string + */ + public String reference; + /** + * Page(s) where the taxon is mentioned + */ + public String page; + /** + * Direct link to the source record + */ + public String url; + /** + * External link (i.e. journal, data system, etc…) + */ + public String link; + /** + * Full text link (PDF) + */ + public String fulltext; + /** + * Digital Object Identifier + */ + public String doi; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/Vernacular.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/Vernacular.java new file mode 100644 index 0000000..9531a45 --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/Vernacular.java @@ -0,0 +1,34 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class Vernacular { + public String vernacular; + @JsonProperty("language_code") + public String languageCode; + public String language; +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClient.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClient.java new file mode 100644 index 0000000..eedfc9c --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClient.java @@ -0,0 +1,726 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.time.DateTimeException; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAccessor; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + *

+ * A client for the World Register + * of Marine Species REST API. Please refer to the terms of use. + *

+ *

+ * Acknowledgments: The development of the WoRMS Client was funded by DFG + * in the scope of the LakeBase project within the Scientific Library Services + * and Information Systems (LIS) program. + *

+ * + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class WormsClient { + + private final static int HTTP_MAX_URL_BYTES = 7806; + private final static String SERVICE_URL = "http://www.marinespecies.org/rest/"; + private final static ObjectMapper JSON = new ObjectMapper(); + + /** + * Constructs a {@link WormsClient} with a default {@link CloseableHttpClient} + * configured to a maximum number of 10 connections. + * + * @since 1.0.0 + */ + public WormsClient() {} + + + /** + * Get attribute definitions. To refer to root items specify ID = ‘0’. + * + * @param id + * The attribute definition id to search for + * @param includeChildren + * Include the tree of children. + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaAttributeKeysById(long id, boolean includeChildren) + throws WormsClientException { + return this.request( + SERVICE_URL + "AphiaAttributeKeysByID/" + id + ((includeChildren) ? "?include_inherited=true" : ""), + new TypeReference>() { + }); + } + + /** + * Get a list of attributes for a given AphiaID + * + * @param aphiaId + * The AphiaID to search for + * @param includeChildren + * Include attributes inherited from the taxon its parent(s). + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaAttributesByAphiaId(long aphiaId, boolean includeChildren) + throws WormsClientException { + return this.request( + SERVICE_URL + "AphiaAttributesByAphiaID/" + aphiaId + + ((includeChildren) ? "?include_inherited=true" : ""), + new TypeReference>() { + }); + } + + /** + * Get list values that are grouped by an CateogryID + * + * @param id + * The CateogryID to search for + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaAttributeValuesByCategoryId(long id) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaAttributeValuesByCategoryID/" + id, + new TypeReference>() { + }); + + } + + /** + *

+ * Get the direct children for a given AphiaID. + *

+ * + *

+ * Note: This methods might cause multiple calls of + * {@link #aphiaChildrenByAphiaId(long, boolean, long)} to receive all records + * in chunks of 50 records. + *

+ * + * @param aphiaId + * The AphiaID to search for + * @param marineOnly + * Limit to marine taxa. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaChildrenByAphiaId(long aphiaId, boolean marineOnly) + throws WormsClientException { + Collection totalResult = new ArrayList(); + Collection singleResult; + long offset = 1; + do { + singleResult = aphiaChildrenByAphiaId(aphiaId, marineOnly, offset); + totalResult.addAll(singleResult); + offset += 50; + } while (singleResult.size() == 50); + return totalResult; + } + + /** + * Get the direct children (max. 50) for a given AphiaID. + * + * @param aphiaId + * The AphiaID to search for + * @param marineOnly + * Limit to marine taxa. + * @param offset + * Starting recordnumber, when retrieving next chunk of 50 records. + * First record has number {@code 1}. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaChildrenByAphiaId(long aphiaId, boolean marineOnly, long offset) + throws WormsClientException { + return this.request( + SERVICE_URL + "AphiaChildrenByAphiaID/" + aphiaId + "?marine_only=" + marineOnly + "&offset=" + offset, + new TypeReference>() { + }); + } + + /** + * Get the complete classification for one taxon. This also includes any sub or + * super ranks. + * + * @param aphiaId + * The AphiaID to search for + * @return classification of the taxon + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Classification aphiaClassificationByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaClassificationByAphiaID/" + aphiaId, + new TypeReference() { + }); + } + + /** + * Get all distributions for a given AphiaID External Identifiers + * + * @param aphiaId + * The AphiaID to search for + * @return all distributions + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaDistributionsByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaDistributionsByAphiaID/" + aphiaId, + new TypeReference>() { + }); + } + + /** + * Get any external identifier(s) for a given AphiaID + * + * @param aphiaId + * The AphiaID to search for + * @param type + * Type of external identifier to return. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaExternalIdByAphiaId(long aphiaId, ExternalIdentifierSource type) + throws WormsClientException { + return this.request(SERVICE_URL + "AphiaExternalIDByAphiaID/" + aphiaId + "?type=" + type.name(), + new TypeReference>() { + }); + } + + /** + * Get the AphiaID for a given name + * + * @param scientificName + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Long aphiaIdByName(String scientificName) throws WormsClientException { + try { + return this.request( + SERVICE_URL + "AphiaIDByName/" + URLEncoder.encode(scientificName, "UTF-8").replace("+", "%20"), + new TypeReference() { + }); + } catch (UnsupportedEncodingException e) { + throw new WormsClientException(e); + } + } + + /** + *

+ * Get a list of AphiaIDs with attribute tree for a given attribute definition + * ID Distributions. + *

+ * + *

+ * Note: This methods might cause multiple calls of + * {@link #aphiaIdsByAttributeKeyId(long, long)} to receive all records in + * chunks of 50 records. + *

+ * + * @param id + * The attribute definition id to search for + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaIdsByAttributeKeyId(long id) throws WormsClientException { + Collection totalResult = new ArrayList(); + Collection singleResult; + long offset = 1; + do { + singleResult = aphiaIdsByAttributeKeyId(id, offset); + totalResult.addAll(singleResult); + offset += 50; + } while (singleResult.size() == 50); + return totalResult; + } + + /** + * Get a list of AphiaIDs (max 50) with attribute tree for a given attribute + * definition ID Distributions. + * + * @param id + * The attribute definition id to search for + * @param offset + * Starting record number, when retrieving next chunk of (50) + * records. First record has number {@code 1}. + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaIdsByAttributeKeyId(long id, long offset) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaIDsByAttributeKeyID/" + id, + new TypeReference>() { + }); + } + + /** + * Get the name for a given AphiaID + * + * @param aphiaId + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public String aphiaNameByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaNameByAphiaID/" + aphiaId, new TypeReference() { + }); + } + + /** + * Get the complete AphiaRecord for a given AphiaID + * + * @param aphiaId + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public AphiaRecord aphiaRecordByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaRecordByAphiaID/" + aphiaId, new TypeReference() { + }); + } + + /** + * Get the Aphia Record for a given external identifier Sources + * + * @param id + * @param type + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public AphiaRecord aphiaRecordByExternalId(String id, ExternalIdentifierSource type) throws WormsClientException { + try { + return this + .request( + SERVICE_URL + "AphiaRecordByExternalID/" + + URLEncoder.encode(id, "UTF-8").replace("+", "%20") + "?type=" + type.name(), + new TypeReference() { + }); + } catch (UnsupportedEncodingException e) { + throw new WormsClientException(e); + } + } + + /** + *

+ * Lists all AphiaRecords (max. 50) modified or added between a specific time + * interval + *

+ * + *

+ * Note: This methods might cause multiple request to receive all records + * in chunks of 50 records. + *

+ * + * @param statdate + * @param enddate + * @param marineOnly + * Limit to marine taxa. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaRecordsByDate(TemporalAccessor statdate, TemporalAccessor enddate, + boolean marineOnly) throws WormsClientException { + Collection totalResult = new ArrayList(); + Collection singleResult; + long offset = 1; + do { + singleResult = aphiaRecordsByDate(statdate, enddate, marineOnly, offset); + totalResult.addAll(singleResult); + offset += 50; + } while (singleResult.size() == 50); + return totalResult; + } + + /** + * Lists all AphiaRecords (max. 50) modified or added between a specific time + * interval + * + * @param statdate + * @param enddate + * @param marineOnly + * Limit to marine taxa. + * @param offset + * Starting record number, when retrieving next chunk of (50) + * records. First record has number {@code 1}. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaRecordsByDate(TemporalAccessor statdate, TemporalAccessor enddate, + boolean marineOnly, long offset) throws WormsClientException { + try { + return this.request(SERVICE_URL + "AphiaRecordsByDate?startdate=" + + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(statdate) + "&enddate=" + + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(enddate) + "&marine_only=" + marineOnly + "&offset=" + + offset, new TypeReference>() { + }); + } catch (DateTimeException e) { + throw new WormsClientException(e); + } + } + + /** + *

+ * For each given scientific name (may include authority), try to find one or + * more AphiaRecords, using the TAXAMATCH fuzzy matching algorithm by Tony Rees. + * This allows you to (fuzzy) match multiple names in one call. + *

+ * + *

+ * Note: This methods might cause multiple service request. + *

+ * + * @param scientificNames + * Names to search for + * @param marineOnly + * Limit to marine taxa. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public List> aphiaRecordsByMatchNames(List scientificNames, boolean marineOnly) + throws WormsClientException { + return requestPartitioned(SERVICE_URL + "AphiaRecordsByMatchNames?scientificnames[]=", scientificNames, + "&scientificnames[]=", 50, "&marine_only=" + marineOnly); + } + + /** + *

+ * Get one or more matching AphiaRecords for a given name. + *

+ * + *

+ * Note: This methods might cause multiple calls of + * {@link #aphiaRecordsByName(String, boolean, boolean, long)} to receive all + * records in chunks of 50 records. + *

+ * + * @param scientificName + * Name to search for + * @param like + * Add a "%"-sign added after the ScientificName (SQL LIKE function). + * @param marineOnly + * Limit to marine taxa. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaRecordsByName(String scientificName, boolean like, boolean marineOnly) + throws WormsClientException { + Collection totalResult = new ArrayList(); + Collection singleResult; + long offset = 1; + do { + singleResult = aphiaRecordsByName(scientificName, like, marineOnly, offset); + totalResult.addAll(singleResult); + offset += 50; + } while (singleResult.size() == 50); + return totalResult; + } + + /** + * Get one or more matching AphiaRecords (max. 50) for a given name. + * + * @param scientificName + * Name to search for + * @param like + * Add a "%"-sign added after the ScientificName (SQL LIKE function). + * @param marineOnly + * Limit to marine taxa. + * @param offset + * Starting record number, when retrieving next chunk of (50) + * records. First record has number {@code 1}. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaRecordsByName(String scientificName, boolean like, boolean marineOnly, + long offset) throws WormsClientException { + try { + return this.request( + SERVICE_URL + "AphiaRecordsByName/" + + URLEncoder.encode(Objects.requireNonNull(scientificName), "UTF-8").replace("+", "%20") + + "?like=" + like + "&marine_only=" + marineOnly + "&offset=" + offset, + new TypeReference>() { + }); + } catch (UnsupportedEncodingException e) { + throw new WormsClientException(e); + } + } + + /** + * For each given scientific name, try to find one or more AphiaRecords (max. + * 50). This allows you to match multiple names in one call. Limited to 500 + * names at once for performance reasons. + * + * @param scientificNames + * Collection of names to search for + * @param like + * Add a "%"-sign added after the ScientificName (SQL LIKE function). + * @param marineOnly + * Limit to marine taxa. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public List> aphiaRecordsByNames(List scientificNames, boolean like, + boolean marineOnly) throws WormsClientException { + return requestPartitioned(SERVICE_URL + "AphiaRecordsByNames?scientificnames[]=", scientificNames, + "&scientificnames[]=", 500, "&like=" + like + "&marine_only=" + marineOnly); + } + + /** + *

+ * Get one or more Aphia Records for a given vernacular. + *

+ * + *

+ * Note: This methods might cause multiple request to receive all records + * in chunks of 50 records. + *

+ * + * @param vernacular + * The vernacular to find records for + * @param like + * Add a "%"-sign before and after the input (SQL LIKE ‘%vernacular%’ + * function). + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaRecordsByVernacular(String vernacular, boolean like) + throws WormsClientException { + Collection totalResult = new ArrayList(); + Collection singleResult; + long offset = 1; + do { + singleResult = aphiaRecordsByVernacular(vernacular, like, offset); + totalResult.addAll(singleResult); + offset += 50; + } while (singleResult.size() == 50); + return totalResult; + } + + /** + * + * Get one or more Aphia Records (max. 50) for a given vernacular. + * + * @param vernacular + * The vernacular to find records for + * @param like + * Add a "%"-sign before and after the input (SQL LIKE ‘%vernacular%’ + * function). + * @param offset + * Starting record number, when retrieving next chunk of (50) + * records. First record has number {@code 1}. + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaRecordsByVernacular(String vernacular, boolean like, long offset) + throws WormsClientException { + try { + return this.request(SERVICE_URL + "AphiaRecordsByVernacular/" + + URLEncoder.encode(Objects.requireNonNull(vernacular), "UTF-8").replace("+", "%20") + "?like=" + + like + "&offset=" + offset, new TypeReference>() { + }); + } catch (UnsupportedEncodingException e) { + throw new WormsClientException(e); + } + } + + /** + * Get one or more sources/references including links, for one AphiaID + * + * @param aphiaId + * The AphiaID to search for + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaSourcesByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaSourcesByAphiaID/" + aphiaId, new TypeReference>() { + }); + } + + /** + * Get all synonyms for a given AphiaID. + * + * @param aphiaId + * The AphiaID to search for + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaSynonymsByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaSynonymsByAphiaID/" + aphiaId, + new TypeReference>() { + }); + } + + /** + * Get all vernaculars for a given AphiaID + * + * @param aphiaId + * The AphiaID to search for + * @return + * @throws WormsClientException + * + * @since 1.0.0 + */ + public Collection aphiaVernacularsByAphiaId(long aphiaId) throws WormsClientException { + return this.request(SERVICE_URL + "AphiaVernacularsByAphiaID/" + aphiaId, + new TypeReference>() { + }); + } + + @SuppressWarnings("unchecked") + private List> ensureEmptyCollections(List> list, long count) { + if (list.isEmpty()) { + // add omitted empty collections + return Stream.generate(() -> { + return (Collection) Collections.emptyList(); + }).limit(count).collect(Collectors.toList()); + } else { + return list; + } + } + + @SuppressWarnings("unchecked") + private T request(String url, TypeReference t) throws WormsClientException { + try { + URL urlConn = new URL(url); + HttpURLConnection connection = (HttpURLConnection)urlConn.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setRequestProperty("Content-type", "application/json"); + if (connection.getResponseCode() == 200) { + try (InputStream content = (InputStream)connection.getContent()) { + return JSON.readValue(content, t); + } catch (JsonParseException | JsonMappingException e) { + throw new WormsClientException("\"" + url + "\" returned invalid response.", e); + } + } else if (connection.getResponseCode() == 204) { + if (JSON.getTypeFactory().constructType(t).isContainerType()) { + try { + return (T) JSON.getTypeFactory().constructType(t).getRawClass().newInstance(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | SecurityException e) { + throw new WormsClientException("Failed to instantiate empty result for \"" + url + "\".", e); + } + } else { + return null; + } + } else { + throw new WormsClientException( + "\"" + url + "\" returned " + connection.getResponseCode() + "."); + } + } catch (IOException e) { + throw new WormsClientException("Request failed on \"" + url + "\".", e); + } + } + + private List> requestPartitioned(String requestPrefix, List names, + String requestNameDelimiter, int maxNamesPerRequest, String requestPostfix) throws WormsClientException { + List> totalResult = new ArrayList>(); + StringBuilder requestUrl = new StringBuilder(requestPrefix); + long requestNames = 0; + for (String scientificName : names) { + try { + String scientificNameEncoded = URLEncoder.encode(scientificName, "UTF-8").replace("+", "%20"); + if (requestNames == maxNamesPerRequest || requestUrl.length() + requestNameDelimiter.length() + + scientificNameEncoded.length() + requestPostfix.length() > HTTP_MAX_URL_BYTES) { + // reached max number of names per request or max length of URL + + // request partial result and add to total results + totalResult.addAll(ensureEmptyCollections(this.request(requestUrl.append(requestPostfix).toString(), + new TypeReference>>() { + }), requestNames)); + // reset request + requestUrl = new StringBuilder(requestPrefix); + requestNames = 0; + } + if (requestNames != 0) { + requestUrl.append(requestNameDelimiter); + } + requestUrl.append(scientificNameEncoded); + requestNames++; + } catch (UnsupportedEncodingException e) { + throw new WormsClientException(e); + } + } + // request last partial result and add to total results + totalResult.addAll(ensureEmptyCollections(this.request(requestUrl.append(requestPostfix).toString(), + new TypeReference>>() { + }), requestNames)); + + return totalResult; + } +} diff --git a/src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClientException.java b/src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClientException.java new file mode 100644 index 0000000..5d59de4 --- /dev/null +++ b/src/main/java/de/uni_jena/cs/fusion/client/worms/WormsClientException.java @@ -0,0 +1,45 @@ +package de.uni_jena.cs.fusion.client.worms; + +/*- + * #%L + * LakeBase Semantic Service + * %% + * Copyright (C) 2018 Heinz Nixdorf Chair for Distributed Information Systems, Friedrich Schiller University Jena + * %% + * 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. + * #L% + */ + +/** + * @author Jan Martin Keil + * @since 1.0.0 + */ +public class WormsClientException extends Exception { + private static final long serialVersionUID = -7269153574516662753L; + + public WormsClientException() { + } + + public WormsClientException(String message) { + super(message); + } + + public WormsClientException(Throwable cause) { + super(cause); + } + + public WormsClientException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/src/main/java/org/gcube/data/spd/wormsplugin/Utils.java b/src/main/java/org/gcube/data/spd/wormsplugin/Utils.java index b2d965e..720bf18 100644 --- a/src/main/java/org/gcube/data/spd/wormsplugin/Utils.java +++ b/src/main/java/org/gcube/data/spd/wormsplugin/Utils.java @@ -1,9 +1,9 @@ package org.gcube.data.spd.wormsplugin; -import java.rmi.RemoteException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; import java.util.List; import org.gcube.data.spd.model.CommonName; @@ -14,25 +14,27 @@ import org.gcube.data.spd.model.products.TaxonomyStatus.Status; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import aphia.v1_0.worms.AphiaRecord; -import aphia.v1_0.worms.Classification; -import aphia.v1_0.worms.Vernacular; +import de.uni_jena.cs.fusion.client.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.Classification; +import de.uni_jena.cs.fusion.client.worms.Vernacular; +import de.uni_jena.cs.fusion.client.worms.WormsClientException; + public class Utils { static Logger logger = LoggerFactory.getLogger(Utils.class); - public static Taxon retrieveTaxon(Classification classification, int aphiaID){ + public static Taxon retrieveTaxon(Classification classification, long aphiaID){ Taxon taxon = null; - while (classification.getAphiaID()!=aphiaID){ - Taxon newTaxon = new Taxon(classification.getAphiaID()+""); + while (classification.aphiaId!=aphiaID){ + Taxon newTaxon = new Taxon(classification.aphiaId+""); if (taxon!=null) newTaxon.setParent(taxon); - newTaxon.setRank(classification.getRank()); + newTaxon.setRank(classification.taxonomicRank); // logger.trace(classification.getRank()); // logger.trace(classification.getScientificname()); - newTaxon.setScientificName(classification.getScientificname()); - classification = classification.getChild(); + newTaxon.setScientificName(classification.scientificName); + classification = classification.child; taxon = newTaxon; } // logger.trace(taxon); @@ -40,52 +42,52 @@ public class Utils { } - public static TaxonomyItem retrieveTaxonomy(Classification classification, int aphiaID){ + public static TaxonomyItem retrieveTaxonomy(Classification classification, long aphiaID){ List listCommNames = new ArrayList (); TaxonomyItem taxon = null; - while (classification.getAphiaID()!=aphiaID){ + while (classification.aphiaId!=aphiaID){ - int id = classification.getAphiaID(); + int id = classification.aphiaId; TaxonomyItem newTaxon = new TaxonomyItem(id+""); if (taxon!=null) newTaxon.setParent(taxon); - newTaxon.setRank(classification.getRank()); - newTaxon.setScientificName(classification.getScientificname()); + newTaxon.setRank(classification.taxonomicRank); + newTaxon.setScientificName(classification.scientificName); newTaxon.setCredits(Utils.createCredits()); AphiaRecord record = null; try { - record = WormsPlugin.binding.getAphiaRecordByID(id); + record = WormsPlugin.wormsClient.aphiaRecordByAphiaId(id); }catch (Exception e) { logger.error("Error getAphiaRecordByID ", e); } if (record != null){ - newTaxon.setCitation(record.getCitation()); - newTaxon.setLsid(record.getLsid()); - newTaxon.setScientificNameAuthorship(record.getAuthority()); + newTaxon.setCitation(record.citation); + newTaxon.setLsid(record.lsid); + newTaxon.setScientificNameAuthorship(record.authority); } - Vernacular[] vernaculars; + Collection vernaculars; try { - vernaculars = WormsPlugin.binding.getAphiaVernacularsByID(classification.getAphiaID()); + vernaculars = WormsPlugin.wormsClient.aphiaVernacularsByAphiaId(classification.aphiaId); if (vernaculars!=null){ // logger.debug("found vernacular name"); for (Vernacular vernacular : vernaculars) { - if (vernacular.getLanguage_code()!=null){ - CommonName a = new CommonName(vernacular.getLanguage(),vernacular.getVernacular()); + if (vernacular.languageCode!=null){ + CommonName a = new CommonName(vernacular.language,vernacular.vernacular); listCommNames.add(a); } } } - } catch (RemoteException e) { + } catch (WormsClientException e) { logger.error("RemoteException", e); } newTaxon.setCommonNames(listCommNames); newTaxon.setStatus(new TaxonomyStatus("accepted", Status.ACCEPTED)); - classification = classification.getChild(); + classification = classification.child; taxon = newTaxon; } return taxon; diff --git a/src/main/java/org/gcube/data/spd/wormsplugin/WormsPlugin.java b/src/main/java/org/gcube/data/spd/wormsplugin/WormsPlugin.java index 3c1fbd8..156bc71 100644 --- a/src/main/java/org/gcube/data/spd/wormsplugin/WormsPlugin.java +++ b/src/main/java/org/gcube/data/spd/wormsplugin/WormsPlugin.java @@ -3,6 +3,7 @@ package org.gcube.data.spd.wormsplugin; import java.net.URL; import java.rmi.RemoteException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -31,36 +32,24 @@ import org.gcube.data.spd.wormsplugin.capabilities.NamesMappingImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import aphia.v1_0.worms.AphiaRecord; -import aphia.v1_0.worms.Source; -import aphia.v1_0.worms.Vernacular; +import de.uni_jena.cs.fusion.client.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.Source; +import de.uni_jena.cs.fusion.client.worms.Vernacular; +import de.uni_jena.cs.fusion.client.worms.WormsClient; +import de.uni_jena.cs.fusion.client.worms.WormsClientException; + public class WormsPlugin extends AbstractPlugin { private Logger logger = LoggerFactory.getLogger(WormsPlugin.class); public static String credits = "This information object has been generated via the Species Product Discovery service on XDATEX by interfacing with World Register of Marine Species (http://www.marinespecies.org/)"; - public static aphia.v1_0.worms.AphiaNameServiceBindingStub binding; - public static String baseurl; - + + public static WormsClient wormsClient; + @Override public void initialize(ServiceEndpoint res) throws Exception { setUseCache(true); - try { - for (AccessPoint ap:res.profile().accessPoints()) { - if (ap.name().equals("portType")){ - baseurl = ap.address(); - } - } - - binding = (aphia.v1_0.worms.AphiaNameServiceBindingStub) - new aphia.v1_0.worms.AphiaNameServiceLocator().getAphiaNameServicePort(new URL(baseurl)); - - } - catch (javax.xml.rpc.ServiceException jre) { - logger.error("error contacting worms service", jre); - throw jre; - } - super.initialize(res); + wormsClient = new WormsClient(); } @@ -103,73 +92,74 @@ public class WormsPlugin extends AbstractPlugin { DataProvider dp = new DataProvider("worms"); dp.setName("Worms"); - AphiaRecord[] records = null; + Collection records = null; List listCommNames = new ArrayList (); final int offsetlimit=50; int offset =1; do{ if (type.equals("vernacular")) - records = binding.getAphiaRecordsByVernacular(word, true, offset); + records = wormsClient.aphiaRecordsByVernacular(word, true, offset); else if (type.equals("scientific")) - records = binding.getAphiaRecords(word, true, false, false, offset); + records = wormsClient.aphiaRecordsByName(word, true, false, offset); + if (records!=null){ for (AphiaRecord record : records){ //logger.debug("found record in worms"); - Source[] sources = null; + Collection sources = null; - if (record==null || (sources= binding.getSourcesByAphiaID(record.getAphiaID()))==null || record.getScientificname()==null) + if (record==null || (sources= wormsClient.aphiaSourcesByAphiaId(record.aphiaId))==null || record.scientificName==null) continue; for (Source source : sources){ //logger.debug("found source in worms"); if (source==null) continue; - if (source.getReference()!=null){ + if (source.reference!=null){ // logger.debug("source has fulltext not null"); - DataSet ds = new DataSet(record.getAphiaID()+"||"+source.getReference().hashCode()); - ds.setName(source.getReference()); - if (source.getUrl()!=null) ds.setCitation(source.getUrl()); + DataSet ds = new DataSet(record.aphiaId+"||"+source.reference.hashCode()); + ds.setName(source.reference); + if (source.url!=null) ds.setCitation(source.url); ds.setDataProvider(dp); - ResultItem item = new ResultItem(record.getAphiaID()+"", record.getScientificname()); + ResultItem item = new ResultItem(record.aphiaId+"", record.scientificName); // Calendar now = Calendar.getInstance(); // SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // String credits ="Biodiversity data published by: "+ds.getName()+" (Accessed through WoRMS web service, "+format.format(now.getTime())+")"; - AphiaRecord[] synonyms = binding.getAphiaSynonymsByID(record.getAphiaID()); - if (synonyms!=null && synonyms.length>0){ + Collection synonyms = wormsClient.aphiaSynonymsByAphiaId(record.aphiaId); + if (synonyms!=null && synonyms.size()>0){ Product product = new Product(ProductType.Synonym, item.getId()); - product.setCount(synonyms.length); + product.setCount(synonyms.size()); item.setProducts(Collections.singletonList(product)); } - Vernacular[] vernaculars = binding.getAphiaVernacularsByID(record.getAphiaID()); + Collection vernaculars = wormsClient.aphiaVernacularsByAphiaId(record.aphiaId); + if (vernaculars!=null){ // logger.debug("found vernacular name"); for (Vernacular vernacular : vernaculars) { - if (vernacular.getLanguage_code()!=null){ - CommonName a = new CommonName(vernacular.getLanguage(),vernacular.getVernacular()); + if (vernacular.languageCode!=null){ + CommonName a = new CommonName(vernacular.language,vernacular.vernacular); listCommNames.add(a); } } } - item.setScientificNameAuthorship(record.getAuthority()); - item.setLsid(record.getLsid()); + item.setScientificNameAuthorship(record.authority); + item.setLsid(record.lsid); - item.setCitation(record.getCitation()); + item.setCitation(record.citation); item.setCredits(Utils.createCredits()); item.setCommonNames(listCommNames); - item.setDataSet(ds); - if (record.getRank()!=null) - item.setRank(record.getRank()); - else if (record.getScientificname().equals("Biota")) + if (record.taxonomicRank!=null) + item.setRank(record.taxonomicRank); + else if (record.scientificName.equals("Biota")) item.setRank("Superdomain"); - item.setParent(Utils.retrieveTaxon(binding.getAphiaClassificationByID(record.getAphiaID()), record.getAphiaID())); + item.setParent(Utils.retrieveTaxon(wormsClient.aphiaClassificationByAphiaId(record.aphiaId), record.aphiaId)); if (writer.isAlive()) writer.write(item); else @@ -180,9 +170,9 @@ public class WormsPlugin extends AbstractPlugin { } } offset+=offsetlimit; - } while (records!=null && records.length==offsetlimit); + } while (records!=null && records.size()==offsetlimit); - } catch (RemoteException e) { + } catch (WormsClientException e) { logger.error("error contacting WoRMS service", e); throw new ExternalRepositoryException(e); } catch (Throwable e) { diff --git a/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ClassificationCapabilityImpl.java b/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ClassificationCapabilityImpl.java index 2a51848..76dd744 100644 --- a/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ClassificationCapabilityImpl.java +++ b/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ClassificationCapabilityImpl.java @@ -2,6 +2,7 @@ package org.gcube.data.spd.wormsplugin.capabilities; import java.rmi.RemoteException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; @@ -26,9 +27,11 @@ import org.gcube.data.spd.wormsplugin.WormsPlugin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import aphia.v1_0.worms.AphiaRecord; -import aphia.v1_0.worms.Source; -import aphia.v1_0.worms.Vernacular; +import de.uni_jena.cs.fusion.client.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.Source; +import de.uni_jena.cs.fusion.client.worms.Vernacular; +import de.uni_jena.cs.fusion.client.worms.WormsClientException; + public class ClassificationCapabilityImpl extends ClassificationCapability { @@ -51,11 +54,11 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { // logger.trace(id); List list = new ArrayList(); try { - AphiaRecord[] records; + Collection records; final int offsetlimit=50; int offset =1; do{ - records = WormsPlugin.binding.getAphiaChildrenByID(Integer.parseInt(id), offset); + records = WormsPlugin.wormsClient.aphiaChildrenByAphiaId(Long.parseLong(id), false, offset); if (records!=null){ // logger.debug(records.length); @@ -66,7 +69,7 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { } } offset+=offsetlimit; - } while (records!=null && records.length==offsetlimit); + } while (records!=null && records.size()==offsetlimit); }catch (NumberFormatException e) { logger.error("id not valid",e); throw new IdNotValidException(e); @@ -81,20 +84,20 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { public void retrieveTaxa(ObjectWriter writer, String word, RecordType type) throws ExternalRepositoryException{ - Set hash = new HashSet(); + Set hash = new HashSet(); try { - AphiaRecord[] records = null; + Collection records = null; final int offsetlimit=50; int offset =1; do{ switch (type) { case SCIENTIFIC: - records = WormsPlugin.binding.getAphiaRecords(word, true, false, false, offset); + records = WormsPlugin.wormsClient.aphiaRecordsByName(word, true, false, offset); break; case VERNACULAR: - records = WormsPlugin.binding.getAphiaRecordsByVernacular(word, true, offset); + records = WormsPlugin.wormsClient.aphiaRecordsByVernacular(word, true, offset); break; default: logger.warn("invalid record type"); @@ -104,11 +107,11 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { if (records!=null){ for (AphiaRecord record : records){ - if (hash.contains(record.getAphiaID())){ + if (hash.contains(record.aphiaId)){ continue; } - hash.add(record.getAphiaID()); + hash.add(record.aphiaId); TaxonomyItem item = createItem(record, true); if ((item != null) && (writer.isAlive())) @@ -120,7 +123,7 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { offset+=offsetlimit; - } while (records!=null && records.length==offsetlimit); + } while (records!=null && records.size()==offsetlimit); } catch (Throwable e) { logger.error("error contacting worms service", e); @@ -130,33 +133,33 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { } //create TaxonomyItem - private TaxonomyItem createItem(AphiaRecord record, Boolean flag) throws RemoteException { + private TaxonomyItem createItem(AphiaRecord record, Boolean flag) throws WormsClientException { TaxonomyItem item = null; - String scientificname = record.getScientificname(); + String scientificname = record.scientificName; // logger.trace("scientificname " + scientificname); if (scientificname != null ){ - item = new TaxonomyItem(record.getAphiaID()+""); + item = new TaxonomyItem(record.aphiaId+""); - item.setScientificName(record.getScientificname()); - item.setScientificNameAuthorship(record.getAuthority()); - item.setLsid(record.getLsid()); + item.setScientificName(record.scientificName); + item.setScientificNameAuthorship(record.authority); + item.setLsid(record.lsid); item.setCredits(Utils.createCredits()); - item.setCitation(record.getCitation()); + item.setCitation(record.citation); - if (record.getRank()!=null) - item.setRank(record.getRank()); - else if (record.getScientificname().equals("Biota")) + if (record.taxonomicRank!=null) + item.setRank(record.taxonomicRank); + else if (record.scientificName.equals("Biota")) item.setRank("Superdomain"); List listCommNames = new ArrayList (); - Vernacular[] vernaculars = WormsPlugin.binding.getAphiaVernacularsByID(record.getAphiaID()); + Collection vernaculars = WormsPlugin.wormsClient.aphiaVernacularsByAphiaId(record.aphiaId); if (vernaculars!=null){ for (Vernacular vernacular : vernaculars) { - if (vernacular.getLanguage_code()!=null){ - CommonName a = new CommonName(vernacular.getLanguage(),vernacular.getVernacular()); + if (vernacular.languageCode!=null){ + CommonName a = new CommonName(vernacular.language,vernacular.vernacular); listCommNames.add(a); } } @@ -164,20 +167,20 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { item.setCommonNames(listCommNames); try{ - if (record.getStatus().equals("accepted")) + if (record.status.equals("accepted")) item.setStatus(new TaxonomyStatus("accepted", Status.ACCEPTED)); - else if (record.getStatus().equals("unaccepted") && WormsPlugin.binding.getAphiaRecordByID(record.getValid_AphiaID()).getStatus().equals("accepted")){ + else if (record.status.equals("unaccepted") && WormsPlugin.wormsClient.aphiaRecordByAphiaId(record.validAphiaId).status.equals("accepted")){ // logger.trace(WormsPlugin.binding.getAphiaSynonymsByID(record.getValid_AphiaID())); - item.setStatus(new TaxonomyStatus(Status.SYNONYM, record.getValid_AphiaID()+"", "synonym"));} + item.setStatus(new TaxonomyStatus(Status.SYNONYM, record.validAphiaId+"", "synonym"));} else - item.setStatus(new TaxonomyStatus(record.getStatus(), Status.UNKNOWN)); + item.setStatus(new TaxonomyStatus(record.status, Status.UNKNOWN)); }catch (Exception e) { - item.setStatus(new TaxonomyStatus(record.getStatus(), Status.UNKNOWN)); + item.setStatus(new TaxonomyStatus(record.status, Status.UNKNOWN)); } if (flag){ try{ - item.setParent(Utils.retrieveTaxonomy( WormsPlugin.binding.getAphiaClassificationByID(record.getAphiaID()), record.getAphiaID())); + item.setParent(Utils.retrieveTaxonomy( WormsPlugin.wormsClient.aphiaClassificationByAphiaId(record.aphiaId), record.aphiaId)); }catch (Exception e) { item.setParent(null); } @@ -185,25 +188,25 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { else item.setParent(null); - Source[] sources = null; - if ((sources= WormsPlugin.binding.getSourcesByAphiaID(record.getAphiaID()))!=null){ + Collection sources = null; + if ((sources= WormsPlugin.wormsClient.aphiaSourcesByAphiaId(record.aphiaId))!=null){ for (Source source : sources){ // logger.trace(source.getReference()); if (source==null) continue; - if (source.getReference()!=null){ + if (source.reference!=null){ StringBuilder p = new StringBuilder(); - p.append(source.getReference()); - if (source.getLink()!=null){ + p.append(source.reference); + if (source.link!=null){ p.append(", available online at "); - p.append(source.getLink()); + p.append(source.link); } - if (source.getUrl()!=null){ + if (source.url!=null){ p.append(", details: "); - p.append(source.getUrl()); + p.append(source.url); } - ElementProperty property = new ElementProperty(source.getUse(), p.toString()); + ElementProperty property = new ElementProperty(source.use, p.toString()); item.addProperty(property); } } @@ -250,14 +253,14 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { AphiaRecord record = null; try { - record = WormsPlugin.binding.getAphiaRecordByID(Integer.parseInt(id)); + record = WormsPlugin.wormsClient.aphiaRecordByAphiaId(Long.parseLong(id)); if (record!=null){ tax = createItem(record, true); } } catch (NumberFormatException e) { logger.error("NumberFormatException", e); throw new IdNotValidException(e); - } catch (RemoteException e) { + } catch (WormsClientException e) { logger.error("Remote Error", e); throw new ExternalRepositoryException(e); } @@ -272,8 +275,8 @@ public class ClassificationCapabilityImpl extends ClassificationCapability { throws IdNotValidException, MethodNotSupportedException, ExternalRepositoryException { try{ - AphiaRecord[] records = null; - if ((records = WormsPlugin.binding.getAphiaSynonymsByID(Integer.parseInt(id)))!=null){ + Collection records = null; + if ((records = WormsPlugin.wormsClient.aphiaSynonymsByAphiaId(Long.parseLong(id)))!=null){ for (AphiaRecord record : records){ TaxonomyItem tax = createItem(record, true); diff --git a/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ExpansionCapabilityImpl.java b/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ExpansionCapabilityImpl.java index 53fc93a..f8c9d4c 100644 --- a/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ExpansionCapabilityImpl.java +++ b/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/ExpansionCapabilityImpl.java @@ -1,6 +1,6 @@ package org.gcube.data.spd.wormsplugin.capabilities; -import java.rmi.RemoteException; +import java.util.Collection; import org.gcube.data.spd.model.exceptions.ExternalRepositoryException; import org.gcube.data.spd.model.exceptions.StreamNonBlockingException; @@ -10,7 +10,8 @@ import org.gcube.data.spd.wormsplugin.WormsPlugin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import aphia.v1_0.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.WormsClientException; public class ExpansionCapabilityImpl implements ExpansionCapability { @@ -22,32 +23,33 @@ public class ExpansionCapabilityImpl implements ExpansionCapability { logger.debug("searching synonyms for "+scientifcName); int offset =1; int elements =20; - AphiaRecord[] records = null; + Collection records = null; do{ try{ - records = WormsPlugin.binding.getAphiaRecords(scientifcName, true, false, false, offset); + records = WormsPlugin.wormsClient.aphiaRecordsByName(scientifcName, true, false, offset); if (records!=null){ for (AphiaRecord record : records){ try{ - AphiaRecord[] synonyms = WormsPlugin.binding.getAphiaSynonymsByID(record.getAphiaID()); + Collection synonyms = WormsPlugin.wormsClient.aphiaSynonymsByAphiaId(record.aphiaId); + if (synonyms!=null){ for (AphiaRecord synonym: synonyms){ if (!writer.isAlive()) return; - writer.write(synonym.getScientificname()); - logger.debug("found synonym "+synonym.getScientificname()); + writer.write(synonym.scientificName); + logger.debug("found synonym "+synonym.scientificName); } } }catch (Exception e) { writer.write(new StreamNonBlockingException("WoRMS",scientifcName)); - logger.error("error retrieving synonyms for aphia id "+record.getAphiaID(), e); + logger.error("error retrieving synonyms for aphia id "+record.aphiaId, e); } } } - } catch (RemoteException e) { + } catch (WormsClientException e) { throw new ExternalRepositoryException(e); } offset = elements+offset; - }while(records!=null && records.length == offset ); + }while(records!=null && records.size() == offset ); } } diff --git a/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/NamesMappingImpl.java b/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/NamesMappingImpl.java index f0f12a2..fc59644 100644 --- a/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/NamesMappingImpl.java +++ b/src/main/java/org/gcube/data/spd/wormsplugin/capabilities/NamesMappingImpl.java @@ -1,6 +1,6 @@ package org.gcube.data.spd.wormsplugin.capabilities; -import java.rmi.RemoteException; +import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -11,7 +11,8 @@ import org.gcube.data.spd.wormsplugin.WormsPlugin; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import aphia.v1_0.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.AphiaRecord; +import de.uni_jena.cs.fusion.client.worms.WormsClientException; public class NamesMappingImpl implements MappingCapability{ @@ -23,26 +24,26 @@ public class NamesMappingImpl implements MappingCapability{ String commonName) throws ExternalRepositoryException{ try { logger.debug("retrieving mapping for "+commonName); - AphiaRecord[] records; + Collection records; final int offsetlimit=50; int offset =1; Set snSet = new HashSet(); do{ - records = WormsPlugin.binding.getAphiaRecordsByVernacular(commonName, true, offset); + records = WormsPlugin.wormsClient.aphiaRecordsByVernacular(commonName, true, offset); if (records!=null){ for (AphiaRecord record : records){ if (!writer.isAlive()) return; - if (!snSet.contains(record.getScientificname())){ - logger.trace("writing (COMMONNAMESMAPPING) "+record.getScientificname() ); - writer.write(record.getScientificname()); - snSet.add(record.getScientificname()); + if (!snSet.contains(record.scientificName)){ + logger.trace("writing (COMMONNAMESMAPPING) "+record.scientificName ); + writer.write(record.scientificName); + snSet.add(record.scientificName); } } } offset+=offsetlimit; - } while (records!=null && records.length==offsetlimit); + } while (records!=null && records.size()==offsetlimit); - } catch (RemoteException e) { + } catch (WormsClientException e) { throw new ExternalRepositoryException(e); } } diff --git a/src/test/java/org/gcube/data/spd/wormsplugin/Test.java b/src/test/java/org/gcube/data/spd/wormsplugin/Test.java index 795da6d..39da6b5 100644 --- a/src/test/java/org/gcube/data/spd/wormsplugin/Test.java +++ b/src/test/java/org/gcube/data/spd/wormsplugin/Test.java @@ -1,9 +1,9 @@ package org.gcube.data.spd.wormsplugin; import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + import java.util.List; -import javax.xml.rpc.ServiceException; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.scope.api.ScopeProvider; @@ -22,7 +22,7 @@ public class Test { * @throws ServiceException * @throws ExternalRepositoryException */ - public static void main(String[] args) throws ServiceException, ExternalRepositoryException { + public static void main(String[] args) throws ExternalRepositoryException { SimpleQuery query = queryFor(ServiceEndpoint.class); diff --git a/src/test/java/org/gcube/data/spd/wormsplugin/TestExpansionCapability.java b/src/test/java/org/gcube/data/spd/wormsplugin/TestExpansionCapability.java index 6340f3f..cdd8018 100644 --- a/src/test/java/org/gcube/data/spd/wormsplugin/TestExpansionCapability.java +++ b/src/test/java/org/gcube/data/spd/wormsplugin/TestExpansionCapability.java @@ -5,7 +5,6 @@ import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; import java.util.List; -import javax.xml.rpc.ServiceException; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.scope.api.ScopeProvider; @@ -23,7 +22,7 @@ public class TestExpansionCapability { * @throws ServiceException * @throws ExternalRepositoryException */ - public static void main(String[] args) throws ServiceException, ExternalRepositoryException { + public static void main(String[] args) throws ExternalRepositoryException { SimpleQuery query = queryFor(ServiceEndpoint.class); query.addCondition("$resource/Profile/Category/text() eq 'BiodiversityRepository' and $resource/Profile/Name eq 'WoRMS' "); @@ -44,8 +43,8 @@ public class TestExpansionCapability { } } - WormsPlugin.binding = (aphia.v1_0.worms.AphiaNameServiceBindingStub) - new aphia.v1_0.worms.AphiaNameServiceLocator().getAphiaNameServicePort(); + /*WormsPlugin.binding = (aphia.v1_0.worms.AphiaNameServiceBindingStub) + new aphia.v1_0.worms.AphiaNameServiceLocator().getAphiaNameServicePort();*/ ExpansionCapabilityImpl b = new ExpansionCapabilityImpl(); b.getSynonyms(new ObjectWriter() { diff --git a/src/test/java/org/gcube/data/spd/wormsplugin/TestMapping.java b/src/test/java/org/gcube/data/spd/wormsplugin/TestMapping.java index 3e677d7..c0887d9 100644 --- a/src/test/java/org/gcube/data/spd/wormsplugin/TestMapping.java +++ b/src/test/java/org/gcube/data/spd/wormsplugin/TestMapping.java @@ -3,7 +3,6 @@ import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; import java.util.List; -import java.util.Set; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.scope.api.ScopeProvider; @@ -36,8 +35,8 @@ public class TestMapping { } } - WormsPlugin.binding = (aphia.v1_0.worms.AphiaNameServiceBindingStub) - new aphia.v1_0.worms.AphiaNameServiceLocator().getAphiaNameServicePort(); + /*WormsPlugin.binding = (aphia.v1_0.worms.AphiaNameServiceBindingStub) + new aphia.v1_0.worms.AphiaNameServiceLocator().getAphiaNameServicePort();*/ NamesMappingImpl b = new NamesMappingImpl();