Skip to content

Commit

Permalink
Change dcterms:hasVersion to dcat:version
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek committed Aug 8, 2023
1 parent 1c89dab commit 1a93ec2
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class SettingsFixtures {
.builder()
.type(SearchFilterType.LITERAL)
.label("Version")
.predicate("http://purl.org/dc/terms/hasVersion")
.predicate("http://www.w3.org/ns/dcat#version")
.queryFromRecords(true)
.presetValues(Collections.emptyList())
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* The MIT License
* Copyright © 2017 DTL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package nl.dtls.fairdatapoint.database.mongo.migration.production;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
import io.mongock.api.annotations.ChangeUnit;
import io.mongock.api.annotations.Execution;
import nl.dtls.fairdatapoint.Profiles;
import nl.dtls.fairdatapoint.util.KnownUUIDs;
import org.bson.Document;
import org.springframework.context.annotation.Profile;
import org.springframework.data.mongodb.core.MongoTemplate;

@ChangeUnit(
id = "Migration_0015_FixMetadataVersion",
order = "0015",
author = "migrationBot"
)
@Profile(Profiles.PRODUCTION)
public class Migration_0015_FixMetadataVersion {

private static final String FIELD_UUID = "uuid";
private static final String FIELD_VER_UUID = "versionUuid";
private static final String FIELD_LATEST = "latest";
private static final String FIELD_DEF = "definition";
private static final String COL_SCHEMAS = "metadataSchema";

private final MongoTemplate database;

public Migration_0015_FixMetadataVersion(MongoTemplate template) {
this.database = template;
}

@Execution
public void run() {
final MongoCollection<Document> schemasCol = database.getCollection(COL_SCHEMAS);
final Document latestResourcesSchema = schemasCol.find(
Filters.and(
Filters.eq(FIELD_UUID, KnownUUIDs.SCHEMA_RESOURCE_UUID),
Filters.eq(FIELD_LATEST, true)
)
).first();
if (latestResourcesSchema == null) {
return;
}
final String updatedDef = latestResourcesSchema.getString(FIELD_DEF)
.replace("dct:hasVersion", "dcat:version");
latestResourcesSchema.put(
FIELD_DEF, updatedDef
);
latestResourcesSchema.remove("_id");
latestResourcesSchema.put(FIELD_VER_UUID, KnownUUIDs.SCHEMA_V2_RESOURCE_UUID);
schemasCol.updateMany(
Filters.eq(FIELD_UUID, KnownUUIDs.SCHEMA_RESOURCE_UUID),
Updates.set(FIELD_LATEST, false)
);
schemasCol.insertOne(latestResourcesSchema);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* The MIT License
* Copyright © 2017 DTL
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package nl.dtls.fairdatapoint.database.rdf.migration.production;

import lombok.extern.slf4j.Slf4j;
import nl.dtls.fairdatapoint.vocabulary.DCAT3;
import nl.dtls.rdf.migration.entity.RdfMigrationAnnotation;
import nl.dtls.rdf.migration.runner.RdfProductionMigration;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.model.vocabulary.DCTERMS;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.RepositoryException;
import org.eclipse.rdf4j.repository.RepositoryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.i;
import static nl.dtls.fairdatapoint.util.ValueFactoryHelper.s;

@RdfMigrationAnnotation(
number = 5,
name = "Fix Metadata Version",
description = "Use dcat:version instead of dcterms:hasVersion")
@Slf4j
@Service
public class Rdf_Migration_0005_FixMetadataVersion implements RdfProductionMigration {

private static final String MSG_ADD = "Adding: {} {} {}";
private static final String MSG_REMOVE = "Removing: {} {} {}";

@Autowired
private Repository repository;

public void runMigration() {
updateVersionStatements();
}

private void updateVersionStatements() {
// change dcterms:hasVersion to dcat:version property (if object is literal)
try (RepositoryConnection conn = repository.getConnection()) {
final RepositoryResult<Statement> queryResult = conn.getStatements(null, DCTERMS.HAS_VERSION, null);
while (queryResult.hasNext()) {
final Statement st = queryResult.next();
if (st.getObject().isLiteral()) {
log.debug(MSG_ADD, st.getSubject(), DCAT3.VERSION, st.getObject());
conn.add(s(st.getSubject(), DCAT3.VERSION, st.getObject(), st.getSubject()));
log.debug(MSG_REMOVE, st.getSubject(), st.getPredicate(), st.getObject());
conn.remove(st);
}
}
}
catch (RepositoryException exception) {
log.error(exception.getMessage(), exception);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/
package nl.dtls.fairdatapoint.entity.metadata;

import nl.dtls.fairdatapoint.vocabulary.DCAT3;
import nl.dtls.fairdatapoint.vocabulary.FDP;
import nl.dtls.fairdatapoint.vocabulary.Sio;
import org.eclipse.rdf4j.model.IRI;
Expand Down Expand Up @@ -79,7 +80,7 @@ public static void setDescription(Model metadata, IRI uri, Literal description)
}

public static void setVersion(Model metadata, IRI uri, Literal version) {
update(metadata, uri, DCTERMS.HAS_VERSION, version);
update(metadata, uri, DCAT3.VERSION, version);
}

public static void setLanguage(Model metadata, IRI uri, IRI language) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import nl.dtls.fairdatapoint.entity.index.http.ExchangeDirection;
import nl.dtls.fairdatapoint.entity.index.http.ExchangeState;
import nl.dtls.fairdatapoint.service.index.entry.IndexEntryService;
import nl.dtls.fairdatapoint.vocabulary.DCAT3;
import nl.dtls.fairdatapoint.vocabulary.FDP;
import nl.dtls.fairdatapoint.vocabulary.R3D;
import org.eclipse.rdf4j.model.IRI;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class MetadataRetrievalUtils {
private static final Map<IRI, String> MAPPING = Map.of(
DCTERMS.TITLE, "title",
DCTERMS.DESCRIPTION, "description",
DCTERMS.HAS_VERSION, "version",
DCAT3.VERSION, "version",
DCTERMS.PUBLISHER, "publisher",
R3D.COUNTRY, "country"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import nl.dtls.fairdatapoint.service.schema.MetadataSchemaShaclUtils;
import nl.dtls.fairdatapoint.util.KnownUUIDs;
import nl.dtls.fairdatapoint.vocabulary.DATACITE;
import nl.dtls.fairdatapoint.vocabulary.DCAT3;
import nl.dtls.fairdatapoint.vocabulary.FDP;
import nl.dtls.fairdatapoint.vocabulary.R3D;
import org.bson.BasicBSONObject;
Expand Down Expand Up @@ -450,7 +451,7 @@ public static List<Statement> repositoryStatements(String persistentUrl, IRI lic
FactoryDefaults.add(s, RDF.TYPE, i("http://www.w3.org/ns/dcat#Resource"), baseUrl);
FactoryDefaults.add(s, DCTERMS.TITLE, l(DEFAULT_FDP_TITLE), baseUrl);
FactoryDefaults.add(s, RDFS.LABEL, l(DEFAULT_FDP_TITLE), baseUrl);
FactoryDefaults.add(s, DCTERMS.HAS_VERSION, l(1.0f), baseUrl);
FactoryDefaults.add(s, DCAT3.VERSION, l(1.0f), baseUrl);
FactoryDefaults.add(s, FDP.METADATAISSUED, l(OffsetDateTime.now()), baseUrl);
FactoryDefaults.add(s, FDP.METADATAMODIFIED, l(OffsetDateTime.now()), baseUrl);
FactoryDefaults.add(s, DCTERMS.LICENSE, license, baseUrl);
Expand Down Expand Up @@ -488,7 +489,7 @@ public static List<Statement> fdpStatements(String persistentUrl, IRI license,
FactoryDefaults.add(s, RDF.TYPE, DCAT.RESOURCE, baseUrl);
FactoryDefaults.add(s, DCTERMS.TITLE, l(DEFAULT_FDP_TITLE), baseUrl);
FactoryDefaults.add(s, RDFS.LABEL, l(DEFAULT_FDP_TITLE), baseUrl);
FactoryDefaults.add(s, DCTERMS.HAS_VERSION, l(1.0f), baseUrl);
FactoryDefaults.add(s, DCAT3.VERSION, l(1.0f), baseUrl);
FactoryDefaults.add(s, FDP.METADATAISSUED, l(OffsetDateTime.now()), baseUrl);
FactoryDefaults.add(s, FDP.METADATAMODIFIED, l(OffsetDateTime.now()), baseUrl);
FactoryDefaults.add(s, DCTERMS.LICENSE, license, baseUrl);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/nl/dtls/fairdatapoint/util/KnownUUIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public class KnownUUIDs {
public static final String SCHEMA_V1_RESOURCE_UUID =
"71d77460-f919-4f72-b265-ed26567fe361";

public static final String SCHEMA_V2_RESOURCE_UUID =
"4c65bdf7-bb56-4bca-ae22-74977b148b16";

public static final String SCHEMA_V1_FDP_UUID =
"4e64208d-f102-45a0-96e3-17b002e6213e";

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/nl/dtls/fairdatapoint/vocabulary/DCAT3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package nl.dtls.fairdatapoint.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;

public class DCAT3 {

public static final ValueFactory VF = SimpleValueFactory.getInstance();
public static final String PREFIX = "dcat";
public static final String NAMESPACE = "http://www.w3.org/ns/dcat#";

public static final IRI VERSION = VF.createIRI(NAMESPACE + "version");
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
sh:maxCount 1 ;
dash:editor dash:BlankNodeEditor ;
], [
sh:path dct:hasVersion ;
sh:path dcat:version ;
sh:name "version" ;
sh:nodeKind sh:Literal ;
sh:minCount 1 ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
sh:maxCount 1 ;
dash:editor dash:BlankNodeEditor ;
], [
sh:path dct:hasVersion ;
sh:path dcat:version ;
sh:name "version" ;
sh:nodeKind sh:Literal ;
sh:minCount 1 ;
Expand Down

0 comments on commit 1a93ec2

Please sign in to comment.