Skip to content

Commit

Permalink
Corrected use of Terms and Values maps for validations and amendments…
Browse files Browse the repository at this point in the history
…, added to unit tests. Added implementations for core tests tdwg/bdq#284 tdwg/bdq#275 and tdwg/bdq#276 along with default methods and unit tests.
  • Loading branch information
chicoreus committed Jul 27, 2024
1 parent 815e2d7 commit 29be3f3
Show file tree
Hide file tree
Showing 7 changed files with 560 additions and 49 deletions.
212 changes: 167 additions & 45 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 @@ -164,4 +164,63 @@ public static DQResponse<ComplianceValue> validationSexStandard(
) {
return validationSexStandard(sex, null);
}

/**
* Propose amendment to the value of dwc:sex using bdq:sourceAuthority.
* Uses the default source authority
*
* Provides: 284 AMENDMENT_SEX_STANDARDIZED
* Version: 2024-03-25
*
* @param sex the provided dwc:sex to evaluate as ActedUpon.
* @return DQResponse the response of type AmendmentValue to return
*/
@Amendment(label="AMENDMENT_SEX_STANDARDIZED", description="Propose amendment to the value of dwc:sex using bdq:sourceAuthority.")
@Provides("33c45ae1-e2db-462a-a59e-7169bb01c5d6")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/33c45ae1-e2db-462a-a59e-7169bb01c5d6/2024-03-25")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL PREREQUISITES_NOT_MET if dwc:sex is EMPTY; AMENDED the value of dwc:sex if it can be unambiguously matched to a term in bdq:sourceAuthority; otherwise NOT_AMENDED")
public static DQResponse<AmendmentValue> amendmentSexStandardized(
@ActedUpon("dwc:sex") String sex
) {
return amendmentSexStandardized(sex, null);
}

/**
* Does the value of dwc:degreeOfEstablishment occur in bdq:sourceAuthority?
* Uses the default source authority
*
* Provides: 275 VALIDATION_DEGREEOFESTABLISHMENT_STANDARD
* Version: 2024-02-09
*
* @param degreeOfEstablishment the provided dwc:degreeOfEstablishment to evaluate as ActedUpon.
* @return DQResponse the response of type ComplianceValue to return
*/
@Validation(label="VALIDATION_DEGREEOFESTABLISHMENT_STANDARD", description="Does the value of dwc:degreeOfEstablishment occur in bdq:sourceAuthority?")
@Provides("060e7734-607d-4737-8b2c-bfa17788bf1a")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/060e7734-607d-4737-8b2c-bfa17788bf1a/2024-02-09")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL_PREREQUISITES_NOT_MET if dwc:degreeOfEstablishment is EMPTY; COMPLIANT if the value of dwc:degreeOfEstablishment is in the bdq:sourceAuthority; otherwise NOT_COMPLIANT.")
public static DQResponse<ComplianceValue> validationDegreeofestablishmentStandard(
@ActedUpon("dwc:degreeOfEstablishment") String degreeOfEstablishment
) {
return validationDegreeofestablishmentStandard(degreeOfEstablishment, null);
}

/**
* Propose amendment to the value of dwc:degreeOfEstablishment using the default bdq:sourceAuthority.
*
* Provides: 276 AMENDMENT_DEGREEOFESTABLISHMENT_STANDARDIZED
* Version: 2024-02-09
*
* @param degreeOfEstablishment the provided dwc:degreeOfEstablishment to evaluate as ActedUpon.
* @return DQResponse the response of type AmendmentValue to return
*/
@Amendment(label="AMENDMENT_DEGREEOFESTABLISHMENT_STANDARDIZED", description="Propose amendment to the value of dwc:degreeOfEstablishment using bdq:sourceAuthority.")
@Provides("74ef1034-e289-4596-b5b0-cde73796697d")
@ProvidesVersion("https://rs.tdwg.org/bdq/terms/74ef1034-e289-4596-b5b0-cde73796697d/2024-02-09")
@Specification("EXTERNAL_PREREQUISITES_NOT_MET if the bdq:sourceAuthority is not available; INTERNAL PREREQUISITES_NOT_MET if dwc:degreeOfEstablishment is EMPTY; AMENDED the value of dwc:degreeOfEstablishment if it can be unambiguously matched to a term in bdq:sourceAuthority; otherwise NOT_AMENDED bdq:sourceAuthority default = 'Darwin Core degreeOfEstablishment' {[https://dwc.tdwg.org/list/#dwc_degreeOfEstablishment]} {dwc:degreeOfEstablishment vocabulary API [https://api.gbif.org/v1/vocabularies/DegreeOfEstablishment/concepts]}")
public static DQResponse<AmendmentValue> amendmentDegreeofestablishmentStandardized(
@ActedUpon("dwc:degreeOfEstablishment") String degreeOfEstablishment
) {
return amendmentDegreeofestablishmentStandardized(degreeOfEstablishment, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public enum EnumMetadataSourceAuthority {
* GBIF Sex vocabulary
*/
GBIF_SEX,
/**
* GBIF Degree of Establishment Vocabulary
*/
GBIF_DEGREEOFESTABLISHMENT,
/**
* Darwin Core Class Names
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ public MetadataSourceAuthority(String authorityString) throws SourceAuthorityExc
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/Sex")) {
this.authority = EnumMetadataSourceAuthority.GBIF_SEX;

} else if (authorityString.toUpperCase().equals("GBIF DEGREEOFESTABLISHMENT VOCABULARY")) {
this.authority = EnumMetadataSourceAuthority.GBIF_DEGREEOFESTABLISHMENT;
} else if (authorityString.equals("https://api.gbif.org/v1/vocabularies/DegreeOfEstablishment")) {
this.authority = EnumMetadataSourceAuthority.GBIF_DEGREEOFESTABLISHMENT;
} else if (authorityString.toUpperCase().equals("DEGREE OF ESTABLISHMENT CONTROLLED VOCABULARY LIST OF TERMS")) {
// TODO: This should point at the TDWG vocabulary
this.authority = EnumMetadataSourceAuthority.GBIF_DEGREEOFESTABLISHMENT;

} 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 @@ -112,18 +112,33 @@ public Map<String,List<String>> loadVocabulary(String vocabulary) {
String name = item.get("name").toString();
ArrayList<String> list = new ArrayList<String>();
list.add(name);
if (!name.equals(name.toLowerCase())) {
list.add(name.toLowerCase());
}
logger.debug(name);
// label[0].value
JSONArray labels = (JSONArray) item.get("label");
for (int j=0; j<labels.size(); j++) {
String label = ((JSONObject)labels.get(j)).get("value").toString();
list.add(label);
if (!label.equals(label.toLowerCase())) {
list.add(label.toLowerCase());
}
if (!label.equals(label.toUpperCase())) {
list.add(label.toUpperCase());
}
}
// externalDefinitions[0]
JSONArray terms = (JSONArray) item.get("externalDefinitions");
for (int j=0; j<terms.size(); j++) {
String externalDefinition = terms.get(j).toString();
list.add(externalDefinition);
if (!externalDefinition.equals(externalDefinition.toLowerCase())) {
list.add(externalDefinition.toLowerCase());
}
if (!externalDefinition.equals(externalDefinition.toUpperCase())) {
list.add(externalDefinition.toUpperCase());
}
}
result.put(name,list);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class MetadataSingleton {
private Map<String,List<String>> sexTerms = new HashMap<String,List<String>>();
private Map<String,String> sexValues = new HashMap<String,String>();

private Map<String,List<String>> degreeOfEstablishmentTerms = new HashMap<String,List<String>>();
private Map<String,String> degreeOfEstablishmentValues = new HashMap<String,String>();

private MetadataSingleton() {
init();
}
Expand Down Expand Up @@ -118,6 +121,16 @@ private void init() {
}
}

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

loaded = true;
loadError = "";
Expand All @@ -127,39 +140,101 @@ private void init() {
}

/**
* get the lifeStage key:value pairs
* get the lifeStage value:key pairs
* for finding vocabulary values for alternative labels
*
* @return the map of lifeStage values from the vocabulary
*/
public Map<String,String> getLifeStageValues() {
return lifeStageValues;
}
/**
* get the pathway key:value pairs
* get the liifeStage key:list of value pairs
* for finding values in the vocabulary
*
* @return the map of lifeStage values from the vocabulary
*/
public Map<String, List<String>> getLifeStageTerms() {
return lifeStageTerms;
}

/**
* get the pathway value:key pairs
* for finding vocabulary values for alternative labels
*
* @return the map of pathway values from the vocabulary
*/
public Map<String,String> getPathwayValues() {
return pathwayValues;
}
/**
* get the typeStatus key:value pairs
* get the pathway key:list of value pairs
* for finding values in the vocabulary
*
* @return the map of pathway values from the vocabulary
*/
public Map<String, List<String>> getPathwayTerms() {
return pathwayTerms;
}

/**
* get the typeStatus value:key pairs
*
* @return the map of typeStatus values from the vocabulary
*/
public Map<String,String> getTypeStatusValues() {
return typeStatusValues;
}
/**
* get the typeStatus key:list of value pairs
* for finding values in the vocabulary
*
* @return the map of typeStatus values from the vocabulary
*/
public Map<String, List<String>> getTypeStatusTerms() {
return typeStatusTerms;
}

/**
* get the sex key:value pairs
* get the sex value:key pairs
* for finding vocabulary values for alternative labels
*
* @return the map of sex values from the vocabulary
*/
public Map<String,String> getSexValues() {
return sexValues;
}

/**
* get the sex key:list of value pairs
* for finding values in the vocabulary
*
* @return the map of sex values from the vocabulary
*/
public Map<String, List<String>> getSexTerms() {
return sexTerms;
}

/**
* get the degreeOfEstablishment value:key pairs
* for finding vocabulary values for alternative labels
*
* @return the map of degreeOfEstablishment values from the vocabulary
*/
public Map<String,String> getDegreeOfEstablishmentValues() {
return degreeOfEstablishmentValues;
}

/**
* get the degreeOfEstablishment key:list of value pairs
* for finding values in the vocabulary
*
* @return the map of degreeOfEstablishment values from the vocabulary
*/
public Map<String, List<String>> getDegreeOfEstablishmentTerms() {
return degreeOfEstablishmentTerms;
}

/**
* @return true if vocabularies have been loaded
*/
Expand Down
Loading

0 comments on commit 29be3f3

Please sign in to comment.