diff --git a/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/development/settings/data/SettingsFixtures.java b/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/development/settings/data/SettingsFixtures.java index 2af1f1ca9..883105b3f 100644 --- a/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/development/settings/data/SettingsFixtures.java +++ b/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/development/settings/data/SettingsFixtures.java @@ -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(); diff --git a/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/production/Migration_0015_FixMetadataVersion.java b/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/production/Migration_0015_FixMetadataVersion.java new file mode 100644 index 000000000..128829d04 --- /dev/null +++ b/src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/production/Migration_0015_FixMetadataVersion.java @@ -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 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); + } +} diff --git a/src/main/java/nl/dtls/fairdatapoint/database/rdf/migration/production/Rdf_Migration_0005_FixMetadataVersion.java b/src/main/java/nl/dtls/fairdatapoint/database/rdf/migration/production/Rdf_Migration_0005_FixMetadataVersion.java new file mode 100644 index 000000000..c7f2504b5 --- /dev/null +++ b/src/main/java/nl/dtls/fairdatapoint/database/rdf/migration/production/Rdf_Migration_0005_FixMetadataVersion.java @@ -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 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); + } + } +} diff --git a/src/main/java/nl/dtls/fairdatapoint/entity/metadata/MetadataSetter.java b/src/main/java/nl/dtls/fairdatapoint/entity/metadata/MetadataSetter.java index a25f83997..9795efbd4 100644 --- a/src/main/java/nl/dtls/fairdatapoint/entity/metadata/MetadataSetter.java +++ b/src/main/java/nl/dtls/fairdatapoint/entity/metadata/MetadataSetter.java @@ -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; @@ -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) { diff --git a/src/main/java/nl/dtls/fairdatapoint/service/index/event/MetadataRetrievalUtils.java b/src/main/java/nl/dtls/fairdatapoint/service/index/event/MetadataRetrievalUtils.java index efcf95d61..5fce7c74d 100644 --- a/src/main/java/nl/dtls/fairdatapoint/service/index/event/MetadataRetrievalUtils.java +++ b/src/main/java/nl/dtls/fairdatapoint/service/index/event/MetadataRetrievalUtils.java @@ -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; @@ -73,7 +74,7 @@ public class MetadataRetrievalUtils { private static final Map MAPPING = Map.of( DCTERMS.TITLE, "title", DCTERMS.DESCRIPTION, "description", - DCTERMS.HAS_VERSION, "version", + DCAT3.VERSION, "version", DCTERMS.PUBLISHER, "publisher", R3D.COUNTRY, "country" ); diff --git a/src/main/java/nl/dtls/fairdatapoint/service/reset/FactoryDefaults.java b/src/main/java/nl/dtls/fairdatapoint/service/reset/FactoryDefaults.java index b1e055f88..a44b39791 100644 --- a/src/main/java/nl/dtls/fairdatapoint/service/reset/FactoryDefaults.java +++ b/src/main/java/nl/dtls/fairdatapoint/service/reset/FactoryDefaults.java @@ -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; @@ -450,7 +451,7 @@ public static List 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); @@ -488,7 +489,7 @@ public static List 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); diff --git a/src/main/java/nl/dtls/fairdatapoint/util/KnownUUIDs.java b/src/main/java/nl/dtls/fairdatapoint/util/KnownUUIDs.java index 4a527b7be..9824653e7 100644 --- a/src/main/java/nl/dtls/fairdatapoint/util/KnownUUIDs.java +++ b/src/main/java/nl/dtls/fairdatapoint/util/KnownUUIDs.java @@ -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"; diff --git a/src/main/java/nl/dtls/fairdatapoint/vocabulary/DCAT3.java b/src/main/java/nl/dtls/fairdatapoint/vocabulary/DCAT3.java new file mode 100644 index 000000000..009ae581c --- /dev/null +++ b/src/main/java/nl/dtls/fairdatapoint/vocabulary/DCAT3.java @@ -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"); +} diff --git a/src/main/resources/nl/dtls/fairdatapoint/database/mongo/migration/development/schema/data/shape-resource.ttl b/src/main/resources/nl/dtls/fairdatapoint/database/mongo/migration/development/schema/data/shape-resource.ttl index 2587f288d..bc54d66af 100644 --- a/src/main/resources/nl/dtls/fairdatapoint/database/mongo/migration/development/schema/data/shape-resource.ttl +++ b/src/main/resources/nl/dtls/fairdatapoint/database/mongo/migration/development/schema/data/shape-resource.ttl @@ -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 ; diff --git a/src/main/resources/nl/dtls/fairdatapoint/service/reset/shape-resource.ttl b/src/main/resources/nl/dtls/fairdatapoint/service/reset/shape-resource.ttl index 7e8c3cc74..e5f5df490 100644 --- a/src/main/resources/nl/dtls/fairdatapoint/service/reset/shape-resource.ttl +++ b/src/main/resources/nl/dtls/fairdatapoint/service/reset/shape-resource.ttl @@ -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 ;