Skip to content

Commit

Permalink
Merge pull request #91 from aodn/feature/citation-n-constraints#5667
Browse files Browse the repository at this point in the history
Feature/citation n constraints#5667
  • Loading branch information
HavierD authored Jul 12, 2024
2 parents 39f525f + 3d64dde commit 883d942
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static au.org.aodn.esindexer.utils.CommonUtils.safeGet;
Expand Down Expand Up @@ -55,6 +57,7 @@ public abstract class StacCollectionMapperService {
@Mapping(target="links", source = "source", qualifiedByName = "mapLinks")
@Mapping(target="license", source = "source", qualifiedByName = "mapLicense")
@Mapping(target="providers", source = "source", qualifiedByName = "mapProviders")
@Mapping(target="citation", source="source", qualifiedByName = "mapCitation")
public abstract StacCollectionModel mapToSTACCollection(MDMetadataType source);


Expand Down Expand Up @@ -174,6 +177,69 @@ String mapDescription(MDMetadataType source) {
return "";
}



@Named("mapCitation")
String mapCitation(MDMetadataType source) {

List<MDDataIdentificationType> items = MapperUtils.findMDDataIdentificationType(source);
var citationFactory = Citation.builder().build();
if(items.isEmpty()) {
return citationFactory.toJsonString();
}
for(MDDataIdentificationType item : items) {
var resourceConstraints = safeGet(item::getResourceConstraints);
if (resourceConstraints.isEmpty()) {
continue;
}
for (var resourceConstraint : resourceConstraints.get()) {
var abstractConstraints = safeGet(() -> resourceConstraint.getAbstractConstraints().getValue()).orElse(null);
if (abstractConstraints == null) {
continue;
}

if (abstractConstraints instanceof MDLegalConstraintsType legalConstraints) {
var otherConstraints = safeGet(legalConstraints::getOtherConstraints).orElse(null);
if (otherConstraints == null) {
continue;
}
otherConstraints.forEach(constraint -> safeGet(() -> constraint.getCharacterString().getValue().toString()).ifPresent(cons -> {
if(isSuggestedCitation(cons)){
citationFactory.setSuggestedCitation(cons);
}
else {
citationFactory.addOtherConstraint(cons);
}
}));
}
else if (abstractConstraints instanceof MDConstraintsType constraints) {
var useLimitations = safeGet(constraints::getUseLimitation).orElse(null);
if (useLimitations == null) {
continue;
}
useLimitations.forEach(limitation -> safeGet(() ->
limitation.getCharacterString().getValue().toString()).ifPresent(citationFactory::addUseLimitation));
}
}
}
return citationFactory.toJsonString();
}

/**
* Because suggested citation and other constraints are in the same block, we need to tell whether
* a constraint is a suggested citation or not. Current method is finding a pattern like [xxxx-xxxx-xxxx]
* It is not an accurate way. Still need TODO a better implementation
* Corresponding ticket has raised here: <a href="https://github.com/aodn/backlog/issues/5737">ticket 5737</a>
* @param cons the constraint
* @return true if the constraint is like a suggested citation
*/
private static boolean isSuggestedCitation(String cons) {
String regex = "\\[[^]]+]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(cons);
return matcher.find();
}

@Named("mapSummaries.temporal")
List<Map<String,String>> mapSummariesTemporal(MDMetadataType source) {
List<Map<String,String>> result = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample10_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@
"title": "IMOS - Australian National Mooring Network (ANMN) Facility - Current velocity time-series",
"description": null
},
"sci:citation": "{\"suggestedCitation\":\"The citation in a list of references is: \\\"IMOS [year-of-data-download], [Title], [data-access-URL], accessed [date-of-access].\\\"\",\"useLimitations\":[\"Data, products and services from IMOS are provided \\\"as is\\\" without any warranty as to fitness for a particular purpose.\"],\"otherConstraints\":[\"Any users of IMOS data are required to clearly acknowledge the source of the material derived from IMOS in the format: \\\"Data was sourced from Australia's Integrated Marine Observing System (IMOS) - IMOS is enabled by the National Collaborative Research Infrastructure strategy (NCRIS).\\\" If relevant, also credit other organisations involved in collection of this particular datastream (as listed in 'credit' in the metadata record).\",\"If using data from the Ningaloo (TAN100) mooring, please add to the citation - \\\"Department of Jobs, Tourism, Science and Innovation (DJTSI), Western Australian Government\\\".\",\"If using data from the Ocean Reference Station 65m (ORS065) mooring, please add to the citation - \\\"Sydney Water Corporation\\\".\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample4_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@
"record_suggest": {
"title": "Ocean acidification historical reconstruction"
},
"sci:citation": "{\"suggestedCitation\":null,\"useLimitations\":null,\"otherConstraints\":[\"The citation in a list of references is: citation name/s (year metadata published), metadata title. File identifier and Data accessed at (add http link).\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample5_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@
"record_suggest": {
"title": "IMOS - ACORN - Bonney Coast HF ocean radar site (South Australia, Australia)"
},
"sci:citation": "{\"suggestedCitation\":\"The citation in a list of references is: \\\"IMOS [year-of-data-download], [Title], [data-access-URL], accessed [date-of-access].\\\"\",\"useLimitations\":[\"Data, products and services from IMOS are provided \\\"as is\\\" without any warranty as to fitness for a particular purpose.\"],\"otherConstraints\":[\"Any users of IMOS data are required to clearly acknowledge the source of the material derived from IMOS in the format: \\\"Data was sourced from Australia’s Integrated Marine Observing System (IMOS) – IMOS is enabled by the National Collaborative Research Infrastructure strategy (NCRIS).\\\" If relevant, also credit other organisations involved in collection of this particular datastream (as listed in 'credit' in the metadata record).\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample6_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@
"record_suggest": {
"title": "RV Investigator Voyage IN2024_V01 End of Voyage (EOV) Archive"
},
"sci:citation": "{\"suggestedCitation\":null,\"useLimitations\":null,\"otherConstraints\":[\"Access to the raw (not quality-controlled) voyage data is intended for the collectors and processors of the data obtained in the MNF RV Investigator voyage. Quality-controlled data products will be made available under a CCBY licence.\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample7_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@
"record_suggest": {
"title": "RapidBenthos"
},
"sci:citation": "{\"suggestedCitation\":null,\"useLimitations\":null,\"otherConstraints\":[\"The data was collected under contract between AIMS and another party(s). Specific agreements for access and use of the data shall be negotiated separately. Contact the AIMS Data Centre (adc@aims.gov.au) for further information\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample8_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@
"title": "RV Investigator Voyage IN2019_V06 End of Voyage (EOV) Archive",
"description": null
},
"sci:citation": "{\"suggestedCitation\":null,\"useLimitations\":null,\"otherConstraints\":[\"Access to the raw (not quality-controlled) voyage data is intended for the collectors and processors of the data obtained in the MNF RV Investigator voyage. Quality-controlled data products will be made available under the MNF CCBY licence.\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
1 change: 1 addition & 0 deletions indexer/src/test/resources/canned/sample9_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
"title": "Heat-evolved microalgal symbionts increase thermal bleaching tolerance of coral juveniles without a trade-off against growth",
"description": null
},
"sci:citation": "{\"suggestedCitation\":\"Attribution: Format for citation of metadata sourced from Australian Institute of Marine Science (AIMS) in a list of reference is as follows: \\\"Australian Institute of Marine Science (AIMS). (2022). Heat-evolved microalgal symbionts increase thermal bleaching tolerance of coral juveniles without a trade-off against growth. https://apps.aims.gov.au/metadata/view/1e13ab6e-e546-44f2-a007-061c2815268a, accessed[date-of-access]\\\".\",\"useLimitations\":null,\"otherConstraints\":[\"Use Limitation: All AIMS data, products and services are provided \\\"as is\\\" and AIMS does not warrant their fitness for a particular purpose or non-infringement. While AIMS has made every reasonable effort to ensure high quality of the data, products and services, to the extent permitted by law the data, products and services are provided without any warranties of any kind, either expressed or implied, including without limitation any implied warranties of title, merchantability, and fitness for a particular purpose or non-infringement. AIMS make no representation or warranty that the data, products and services are accurate, complete, reliable or current. To the extent permitted by law, AIMS exclude all liability to any person arising directly or indirectly from the use of the data, products and services.\",\"\"]}",
"type": "Collection",
"stac_version": "1.0.0",
"stac_extensions": [
Expand Down
42 changes: 42 additions & 0 deletions stacmodel/src/main/java/au/org/aodn/stac/model/Citation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package au.org.aodn.stac.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Builder;
import lombok.Data;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;
import java.util.List;

@Data
@Builder
@SuppressWarnings("unused")
public class Citation {

private String suggestedCitation;
private List<String> useLimitations;
private List<String> otherConstraints ;

public void addUseLimitation(String useLimitation){
if (this.useLimitations == null) {
this.useLimitations = new ArrayList<>();
}
this.useLimitations.add(useLimitation);
}

public void addOtherConstraint(String otherConstraint){
if (this.otherConstraints == null) {
this.otherConstraints = new ArrayList<>();
}
this.otherConstraints.add(otherConstraint);
}

public String toJsonString() {
ObjectMapper mapper = new ObjectMapper();
try{
return mapper.writeValueAsString(this);
}catch (JsonProcessingException ignored){
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class StacCollectionModel {
protected List<LinkModel> links;
protected String license;
protected List<ProviderModel> providers;
@JsonProperty("sci:citation")
protected String citation;
/**
* Do not use keywords and use theme instead, read here
* protected List<String> keywords
Expand Down

0 comments on commit 883d942

Please sign in to comment.