Skip to content

Commit

Permalink
Implementation of more supplementary and core tests, adding classes t…
Browse files Browse the repository at this point in the history
…o evaluate LSIDs and UUIDs, lookups from GBIF vocabulary for several terms and storage for access in a singleton. Completed all but one stub unit test, commented that one for build. Implementations include tdwg/bdq#75 tdwg/bdq#115 tdwg/bdq#277 tdwg/bdq#285.
  • Loading branch information
chicoreus committed Jul 27, 2024
1 parent f39d3e0 commit 5f96377
Show file tree
Hide file tree
Showing 9 changed files with 851 additions and 68 deletions.
249 changes: 215 additions & 34 deletions src/main/java/org/filteredpush/qc/metadata/DwCMetadataDQ.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,31 @@
*/
public enum EnumMetadataSourceAuthority {

/**
* GBIF LifeStage vocabulary
*/
GBIF_LIFESTAGE,
/**
* GBIF Pathway vocabulary
*/
GBIF_PATHWAY,
/**
* GBIF Type Status vocabulary
*/
GBIF_TYPESTATUS,
/**
* Darwin Core Class Names
*/
DWC_BASISOFRECORD,
/**
* Invalid Source Authority
*/
INVALID;

/**
* <p>getName.</p>
* getName get the name of the enumerated object.
*
* @return a {@link java.lang.String} object.
* @return the name of the object.
*/
public String getName() {
// return the exact name of the enum instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,22 @@ public MetadataSourceAuthority(String authorityString) throws SourceAuthorityExc
if (authorityString==null) { authorityString = ""; }
if (authorityString.toUpperCase().equals("DARWIN CORE BASISOFRECORD")) {
this.authority = EnumMetadataSourceAuthority.DWC_BASISOFRECORD;

} else if (authorityString.toUpperCase().equals("GBIF LIFESTAGE VOCABULARY")) {
this.authority = EnumMetadataSourceAuthority.GBIF_LIFESTAGE;
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/LifeStage")) {
this.authority = EnumMetadataSourceAuthority.GBIF_LIFESTAGE;
this.authority = EnumMetadataSourceAuthority.GBIF_LIFESTAGE;

} else if (authorityString.toUpperCase().equals("GBIF PATHWAY VOCABULARY")) {
this.authority = EnumMetadataSourceAuthority.GBIF_PATHWAY;
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/Pathway")) {
this.authority = EnumMetadataSourceAuthority.GBIF_PATHWAY;

} else if (authorityString.toUpperCase().equals("GBIF TYPESTATUS VOCABULARY")) {
this.authority = EnumMetadataSourceAuthority.GBIF_TYPESTATUS;
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/TypeStatus")) {
this.authority = EnumMetadataSourceAuthority.GBIF_TYPESTATUS;

} else if (authorityString.toUpperCase().startsWith("HTTPS://INVALID/")) {
this.authority = EnumMetadataSourceAuthority.INVALID;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,29 @@ public class GbifService {

private static final String gbifApiEndpoint = "https://api.gbif.org/v1/";

/**
* default constructor
*/
public GbifService() {
init();
}

/**
* set up class instance
*/
private void init() {
//ClientBuilder clientBuilder = new ClientBuilder().withUrl(gbifApiEndpoint);

//Vocabulary vocabularyClient = clientBuilder.build(Vocabulary.class);

}

/**
* Load a GBIF vocabulary
*
* @param vocabulary the name of the vocabulary to load
* @return a Map String, List String where the keys are vocabulary terms and the values are lists of
* possible alternative names for the term.
*/
public Map<String,List<String>> loadVocabulary(String vocabulary) {
HashMap<String,List<String>> result = new HashMap();

Expand Down Expand Up @@ -136,6 +148,10 @@ public Map<String,List<String>> loadVocabulary(String vocabulary) {
return result;
}

/**
* Main class for testing during development
* @param args arguments, none expected
*/
public static void main( String[] args ) {
GbifService test = new GbifService();
Map<String,List<String>> pathway = test.loadVocabulary("Pathway");
Expand Down
144 changes: 144 additions & 0 deletions src/main/java/org/filteredpush/qc/metadata/util/LSID.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/**
* LSID.java
*
* Copyright 2022 President and Fellows of Harvard College
*
* 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.filteredpush.qc.metadata.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* Utility class for testing strings that may be LSIDs.
*
* @author mole
* @version $Id: $Id
*/
public class LSID extends RFC8141URN {

private static final Log logger = LogFactory.getLog(LSID.class);

private String authority;
private String namespace;
private String objectID;
private String version;

/**
* <p>Constructor for LSID.</p>
*
* @param urn a {@link java.lang.String} object.
* @throws org.filteredpush.qc.metadata.util.URNFormatException if any.
*/
public LSID(String urn) throws URNFormatException {
super(urn);
// LSID specification https://www.omg.org/cgi-bin/doc?dtc/04-05-01.pdf
// has authority:namespace:objectidenfification with optional :revisionidentification
// where authority is usually an internet domain name or is a unique string and,
// namespace, objectidentification, and revisionidentification are
// specified as "alphanumeric sequence", but the examples therin include non-alphanumeric
// characters -., so using PCHAR without : for each._
String chars = PCHAR.replace(":", "");
logger.debug(chars);
logger.debug(nss);
String[] bits = nss.split(":");
if (bits.length<3 || bits.length > 4) {
throw new URNFormatException("Not a validly formatted LSID");
}
if (bits[0].length()<1 || bits[1].length()<1 || bits[2].length()<1) {
throw new URNFormatException("Not a validly formatted LSID");
}
authority = bits[0];
namespace = bits[1];
objectID = bits[2];
if (bits.length==4) {
version = bits[3];
} else {
version = null;
}
}

/**
* <p>Getter for the field <code>authority</code>.</p>
*
* @return the authority
*/
public String getAuthority() {
return authority;
}

/**
* <p>Setter for the field <code>authority</code>.</p>
*
* @param authority the authority to set
*/
public void setAuthority(String authority) {
this.authority = authority;
}

/**
* <p>Getter for the field <code>namespace</code>.</p>
*
* @return the namespace
*/
public String getNamespace() {
return namespace;
}

/**
* <p>Setter for the field <code>namespace</code>.</p>
*
* @param namespace the namespace to set
*/
public void setNamespace(String namespace) {
this.namespace = namespace;
}

/**
* <p>Getter for the field <code>objectID</code>.</p>
*
* @return the objectID
*/
public String getObjectID() {
return objectID;
}

/**
* <p>Setter for the field <code>objectID</code>.</p>
*
* @param objectID the objectID to set
*/
public void setObjectID(String objectID) {
this.objectID = objectID;
}

/**
* <p>Getter for the field <code>version</code>.</p>
*
* @return the version
*/
public String getVersion() {
return version;
}

/**
* <p>Setter for the field <code>version</code>.</p>
*
* @param version the version to set
*/
public void setVersion(String version) {
this.version = version;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class MetadataSingleton {
private Map<String,List<String>> pathwayTerms = new HashMap<String,List<String>>();
private Map<String,String> pathwayValues = new HashMap<String,String>();

private Map<String,List<String>> typeStatusTerms = new HashMap<String,List<String>>();
private Map<String,String> typeStatusValues = new HashMap<String,String>();

private MetadataSingleton() {
init();
}
Expand Down Expand Up @@ -90,24 +93,59 @@ private void init() {
}
}

typeStatusTerms = gbif.loadVocabulary("TypeStatus");
keys = typeStatusTerms.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
List<String> values = typeStatusTerms.get(key);
Iterator<String> i = values.iterator();
while (i.hasNext()) {
typeStatusValues.put(i.next(), key);
}
}

loaded = true;
loadError = "";
} catch (Exception e) {
loadError = e.getMessage();
}
}

/**
* get the lifeStage key:value pairs
*
* @return the map of lifeStage values from the vocabulary
*/
public Map<String,String> getLifeStageValues() {
return lifeStageValues;
}
/**
* get the pathway key:value pairs
*
* @return the map of pathway values from the vocabulary
*/
public Map<String,String> getPathwayValues() {
return pathwayValues;
}
/**
* get the typeStatus key:value pairs
*
* @return the map of typeStatus values from the vocabulary
*/
public Map<String,String> getTypeStatusValues() {
return typeStatusValues;
}

/**
* @return true if vocabularies have been loaded
*/
public Boolean isLoaded() {
return loaded;
}

/**
* @return any load error message
*/
public String getLoadError() {
return loadError;
}
Expand Down
Loading

0 comments on commit 5f96377

Please sign in to comment.