Skip to content
Snippets Groups Projects
Commit 14c577ae authored by Jesper Zedlitz's avatar Jesper Zedlitz
Browse files

Merge branch '22-beim-modifikationsdatum-gekoppelte-dienste-beruecksichtigen' into 'main'

Resolve "beim Modifikationsdatum gekoppelte Dienste berücksichtigen"

Closes #22

See merge request !19
parents 71a4b76a ba1ece7a
No related branches found
No related tags found
1 merge request!19Resolve "beim Modifikationsdatum gekoppelte Dienste berücksichtigen"
Pipeline #495 passed
...@@ -8,10 +8,7 @@ import org.apache.jena.datatypes.RDFDatatype; ...@@ -8,10 +8,7 @@ import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.xsd.XSDDatatype; import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.iri.IRI; import org.apache.jena.iri.IRI;
import org.apache.jena.iri.IRIFactory; import org.apache.jena.iri.IRIFactory;
import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.*;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.DCAT; import org.apache.jena.vocabulary.DCAT;
import org.apache.jena.vocabulary.DCTerms; import org.apache.jena.vocabulary.DCTerms;
import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.RDF;
...@@ -29,6 +26,7 @@ import org.slf4j.LoggerFactory; ...@@ -29,6 +26,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.time.LocalDate;
import java.util.*; import java.util.*;
/** /**
...@@ -703,7 +701,9 @@ public class MDMetadata2Dataset { ...@@ -703,7 +701,9 @@ public class MDMetadata2Dataset {
dataset.addProperty(DCATAPde.contributorID, model.createResource(settings.contributorId)); dataset.addProperty(DCATAPde.contributorID, model.createResource(settings.contributorId));
final Element mdIdentifier = (Element) metadata.selectSingleNode("gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString"); final Element mdIdentifier = (Element) metadata.selectSingleNode("gmd:identificationInfo/gmd:MD_DataIdentification/gmd:citation/gmd:CI_Citation/gmd:identifier/gmd:MD_Identifier/gmd:code/gco:CharacterString");
String searchId = mdIdentifier != null ? mdIdentifier.getTextTrim() : id; final String searchId = mdIdentifier != null ? mdIdentifier.getTextTrim() : id;
LocalDate datasetModificationDate = RDFUtils.literalToDate(dataset.getProperty(DCTerms.modified).getLiteral());
// add coupled services // add coupled services
if (cswInterface != null && searchId != null) { if (cswInterface != null && searchId != null) {
...@@ -712,6 +712,16 @@ public class MDMetadata2Dataset { ...@@ -712,6 +712,16 @@ public class MDMetadata2Dataset {
try { try {
for (Resource dist : convertServiceToDistributions(service)) { for (Resource dist : convertServiceToDistributions(service)) {
dataset.addProperty(DCAT.distribution, dist); dataset.addProperty(DCAT.distribution, dist);
// Is the modification date of the service more recent?
final Literal distributionModified = dist.getProperty(DCTerms.modified).getLiteral();
final LocalDate distributionModificationDate = RDFUtils.literalToDate(distributionModified);
if (distributionModificationDate.isAfter(datasetModificationDate)) {
// update dct:modified value of the dataset
dataset.removeAll(DCTerms.modified);
dataset.addProperty(DCTerms.modified, distributionModified);
datasetModificationDate = distributionModificationDate;
}
} }
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
log.warn("Skipping distribution for dataset {}: {}", searchId, ex.getMessage()); log.warn("Skipping distribution for dataset {}: {}", searchId, ex.getMessage());
......
package de.landsh.opendata.csw2dcat;
import org.apache.commons.lang3.StringUtils;
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.rdf.model.Literal;
import java.time.LocalDate;
public class RDFUtils {
/**
* Convert a literal of type XSDdate or XSDdateTime into a LocalDate.
*/
public static LocalDate literalToDate(Literal literal) {
if (literal == null) {
return null;
}
String dateString;
if (XSDDatatype.XSDdate.equals(literal.getDatatype()) || XSDDatatype.XSDdateTime.equals(literal.getDatatype())) {
dateString = StringUtils.substring(literal.getString(), 0,10);
} else {
throw new IllegalArgumentException("Unknown datatype for a date: " + literal.getDatatypeURI());
}
return LocalDate.parse(dateString);
}
}
\ No newline at end of file
...@@ -363,6 +363,10 @@ public class MDMetadata2DatasetTests { ...@@ -363,6 +363,10 @@ public class MDMetadata2DatasetTests {
service.convert(inputDocument); service.convert(inputDocument);
} }
/**
* <pre>e95c2bed-84c0-4e7c-a194-1568887fc355</pre> is a dataset.
* <pre>5a9a19d0-f24b-427e-9bdd-c1c7da2e84e7</pre> is a coupled service of this dataset.
*/
@Test @Test
public void convert_coupledServices_Seehunde() throws DocumentException, IOException { public void convert_coupledServices_Seehunde() throws DocumentException, IOException {
...@@ -376,6 +380,10 @@ public class MDMetadata2DatasetTests { ...@@ -376,6 +380,10 @@ public class MDMetadata2DatasetTests {
assertTrue(result.hasLiteral(DCTerms.identifier, "e95c2bed-84c0-4e7c-a194-1568887fc355")); assertTrue(result.hasLiteral(DCTerms.identifier, "e95c2bed-84c0-4e7c-a194-1568887fc355"));
// The modification date of the dataset itself is 2022-05-05. The modification date of the service is 2023-06-01.
// The resulting modification date of the dataset is the latest modification date of one of its coupled services.
assertEquals("2023-06-01^^http://www.w3.org/2001/XMLSchema#date", result.getProperty(DCTerms.modified).getLiteral().toString());
final Map<String, Resource> distributionMap = collectDistributions(result); final Map<String, Resource> distributionMap = collectDistributions(result);
checkSeehundeDistributions(distributionMap); checkSeehundeDistributions(distributionMap);
......
package de.landsh.opendata.csw2dcat;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
class RDFUtilsTest {
final Model model = ModelFactory.createDefaultModel();
@Test
void literalToDate_null() {
assertNull(RDFUtils.literalToDate(null));
}
@Test
void literalToDate_date() {
assertEquals(
LocalDate.of(2023, 7, 22),
RDFUtils.literalToDate(model.createTypedLiteral("2023-07-22", "http://www.w3.org/2001/XMLSchema#date")));
}
@Test
void literalToDate_dateTime() {
assertEquals(
LocalDate.of(2020, 7, 14),
RDFUtils.literalToDate(model.createTypedLiteral("2020-07-14T12:17:01.654617", "http://www.w3.org/2001/XMLSchema#dateTime")));
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment