Skip to content

Commit

Permalink
Merge pull request #94 from aodn/feature/add-licence-with-url#5667
Browse files Browse the repository at this point in the history
Feature/add licence with url#5667
  • Loading branch information
utas-raymondng authored Jul 17, 2024
2 parents f320833 + bbaed62 commit 0611db5
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import au.org.aodn.stac.model.*;

import au.org.aodn.metadata.iso19115_3_2018.*;
import au.org.aodn.stac.util.JsonUtil;
import jakarta.xml.bind.JAXBElement;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -184,9 +185,9 @@ String mapDescription(MDMetadataType source) {
String mapCitation(MDMetadataType source) {

List<MDDataIdentificationType> items = MapperUtils.findMDDataIdentificationType(source);
var citationFactory = Citation.builder().build();
var citation = Citation.builder().build();
if(items.isEmpty()) {
return citationFactory.toJsonString();
return JsonUtil.toJsonString(citation);
}
for(MDDataIdentificationType item : items) {
var resourceConstraints = safeGet(item::getResourceConstraints);
Expand All @@ -206,10 +207,10 @@ String mapCitation(MDMetadataType source) {
}
otherConstraints.forEach(constraint -> safeGet(() -> constraint.getCharacterString().getValue().toString()).ifPresent(cons -> {
if(isSuggestedCitation(cons)){
citationFactory.setSuggestedCitation(cons);
citation.setSuggestedCitation(cons);
}
else {
citationFactory.addOtherConstraint(cons);
citation.addOtherConstraint(cons);
}
}));
}
Expand All @@ -219,11 +220,11 @@ else if (abstractConstraints instanceof MDConstraintsType constraints) {
continue;
}
useLimitations.forEach(limitation -> safeGet(() ->
limitation.getCharacterString().getValue().toString()).ifPresent(citationFactory::addUseLimitation));
limitation.getCharacterString().getValue().toString()).ifPresent(citation::addUseLimitation));
}
}
}
return citationFactory.toJsonString();
return JsonUtil.toJsonString(citation);
}

@Named("mapSummaries.statement")
Expand Down Expand Up @@ -610,16 +611,17 @@ List<ProviderModel> mapProviders(MDMetadataType source) {
@Named("mapLicense")
String mapLicense(MDMetadataType source) {
List<MDDataIdentificationType> items = MapperUtils.findMDDataIdentificationType(source);
List<String> potentialKeys = Arrays.asList("license", "creative commons");
List<String> licenses = new ArrayList<>();
List<String> potentialKeys = Arrays.asList("license", "creative commons");
if (!items.isEmpty()) {
for (MDDataIdentificationType i : items) {
i.getResourceConstraints().forEach(resourceConstraint -> {
if (resourceConstraint.getAbstractConstraints().getValue() instanceof MDLegalConstraintsType legalConstraintsType) {
legalConstraintsType.getOtherConstraints().forEach(otherConstraints -> {
for (String potentialKey : potentialKeys) {
if (otherConstraints.getCharacterString() != null && otherConstraints.getCharacterString().getValue().toString().toLowerCase().contains(potentialKey)) {
licenses.add(otherConstraints.getCharacterString().getValue().toString());
var license = License.builder().title(otherConstraints.getCharacterString().getValue().toString()).build();
licenses.add(JsonUtil.toJsonString(license));
}
}
});
Expand All @@ -629,7 +631,22 @@ String mapLicense(MDMetadataType source) {
legalConstraintsType.getReference().forEach(reference -> {
if (reference.getAbstractCitation().getValue() instanceof CICitationType2 ciCitationType2) {
if (ciCitationType2.getTitle() != null) {
licenses.add(ciCitationType2.getTitle().getCharacterString().getValue().toString());
var license = License.builder().title(ciCitationType2.getTitle().getCharacterString().getValue().toString()).build();

// set license url
safeGet(
() -> ciCitationType2.getOnlineResource().get(0).getCIOnlineResource().getLinkage().getCharacterString().getValue().toString()
).ifPresent(license::setUrl);

// set license graphic
safeGet(
() -> legalConstraintsType.getGraphic().get(0).getMDBrowseGraphic().getLinkage().get(0).getAbstractOnlineResource().getValue()
).ifPresent( abstractOnlineResource -> {
if (abstractOnlineResource instanceof CIOnlineResourceType2 ciOnlineResourceType2) {
safeGet(() -> ciOnlineResourceType2.getLinkage().getCharacterString().getValue().toString()).ifPresent(license::setLicenseGraphic);
}
});
licenses.add(JsonUtil.toJsonString(license));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/test/resources/canned/sample10_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@
"title": "ncUrlList help documentation"
}
],
"license": "Creative Commons Attribution 4.0 International License",
"license": "{\"title\":\"Creative Commons Attribution 4.0 International License\",\"url\":\"http://creativecommons.org/licenses/by/4.0/\",\"licenseGraphic\":\"https://licensebuttons.net/l/by/4.0/88x31.png\"}",
"providers": [
{
"name": "Integrated Marine Observing System (IMOS)",
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/test/resources/canned/sample4_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
"title": "GoGoDuck help documentation"
}
],
"license": "Creative Commons Attribution 4.0 International License",
"license": "{\"title\":\"Creative Commons Attribution 4.0 International License\",\"url\":\"http://creativecommons.org/licenses/by/4.0/\",\"licenseGraphic\":\"https://licensebuttons.net/l/by/4.0/88x31.png\"}",
"providers": [
{
"name": "Integrated Marine Observing System (IMOS)",
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/test/resources/canned/sample5_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
"title": "Suggest icon for dataset"
}
],
"license": "Creative Commons Attribution 4.0 International License",
"license": "{\"title\":\"Creative Commons Attribution 4.0 International License\",\"url\":\"http://creativecommons.org/licenses/by/4.0/\",\"licenseGraphic\":\"https://licensebuttons.net/l/by/4.0/88x31.png\"}",
"providers": [
{
"name": "Integrated Marine Observing System (IMOS)",
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/test/resources/canned/sample6_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
"type": "image"
}
],
"license": "Attribution 4.0",
"license": "{\"title\":\"Attribution 4.0\",\"url\":\"https://creativecommons.org/licenses/by/4.0/\",\"licenseGraphic\":\"https://i.creativecommons.org/l/by/4.0/88x31.png\"}",
"providers": [
{
"name": "CSIRO/Oceans and Atmosphere",
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/test/resources/canned/sample8_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
"title": "Marine National Facility"
}
],
"license": "Attribution 4.0",
"license": "{\"title\":\"Attribution 4.0\",\"url\":\"https://creativecommons.org/licenses/by/4.0/\",\"licenseGraphic\":\"https://i.creativecommons.org/l/by/4.0/88x31.png\"}",
"providers": [
{
"name": "CSIRO/Oceans and Atmosphere",
Expand Down
2 changes: 1 addition & 1 deletion indexer/src/test/resources/canned/sample9_stac.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
"title": "Harianto, J, Carey, N, Byrne, M. respR—An R package for the manipulation and analysis of respirometry data. Methods Ecol Evol. 2019; 10: 912– 920. https://doi.org/10.1111/2041-210X.13162"
}
],
"license": "Creative Commons Attribution 3.0 Australia License",
"license": "{\"title\":\"Creative Commons Attribution 3.0 Australia License\",\"url\":\"http://creativecommons.org/licenses/by/3.0/au/\",\"licenseGraphic\":\"http://i.creativecommons.org/l/by/3.0/au/88x31.png\"}",
"providers": [
{
"name": "Australian Institute of Marine Science (AIMS)",
Expand Down
9 changes: 0 additions & 9 deletions stacmodel/src/main/java/au/org/aodn/stac/model/Citation.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,4 @@ public void addOtherConstraint(String otherConstraint){
}
this.otherConstraints.add(otherConstraint);
}

public String toJsonString() {
ObjectMapper mapper = new ObjectMapper();
try{
return mapper.writeValueAsString(this);
}catch (JsonProcessingException ignored){
return null;
}
}
}
12 changes: 12 additions & 0 deletions stacmodel/src/main/java/au/org/aodn/stac/model/License.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package au.org.aodn.stac.model;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class License {
private String title;
private String url;
private String licenseGraphic;
}
15 changes: 15 additions & 0 deletions stacmodel/src/main/java/au/org/aodn/stac/util/JsonUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package au.org.aodn.stac.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtil {

public static <T> String toJsonString(T instance) {
ObjectMapper mapper = new ObjectMapper();
try{
return mapper.writeValueAsString(instance);
}catch (JsonProcessingException ignored){}
return null;
}
}

0 comments on commit 0611db5

Please sign in to comment.