Skip to content

Commit

Permalink
Merge pull request #442 from FAIRDataTeam/fix/version-metadata
Browse files Browse the repository at this point in the history
Hotfix 1.17.1 (develop)
  • Loading branch information
MarekSuchanek authored Aug 9, 2023
2 parents c877001 + 26e1b2a commit 73b7039
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 10 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]


## [1.17.1]

❗Manual check of custom and customized metadata schemas is required.

### Fixed

- Use `dcterms:hasVersion` has been changed to `dcat:version`

## [1.17.0]

### Added
Expand Down Expand Up @@ -368,3 +376,4 @@ The first release of reference FAIR Data Point implementation.
[1.16.1]: /../../tree/v1.16.1
[1.16.2]: /../../tree/v1.16.2
[1.17.0]: /../../tree/v1.17.0
[1.17.1]: /../../tree/v1.17.1
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ We support the latest major and minor version with patch versions that fix vulne

| Version | Supported |
|---------| ------------------ |
| 1.17.0 | :white_check_mark: |
| 1.17.1 | :white_check_mark: |
| < 1.17 | :x: |

## Current Recommendations
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>nl.dtls</groupId>
<artifactId>fairdatapoint</artifactId>
<version>1.17.0</version>
<version>1.17.1</version>
<packaging>jar</packaging>

<name>FairDataPoint</name>
Expand Down
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,123 @@
/**
* 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 io.mongock.api.annotations.RollbackExecution;
import nl.dtls.fairdatapoint.Profiles;
import nl.dtls.fairdatapoint.entity.schema.SemVer;
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_VERSION = "versionString";
private static final String FIELD_DEF = "definition";
private static final String COL_SCHEMAS = "metadataSchema";

private final MongoTemplate database;

private String previousVersionUuid;

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;
}
previousVersionUuid = latestResourcesSchema.getString(FIELD_VER_UUID);
latestResourcesSchema.put(
FIELD_DEF,
latestResourcesSchema
.getString(FIELD_DEF)
.replace(
"""
sh:path dct:hasVersion ;
sh:name "version" ;
sh:nodeKind sh:Literal ;
""",
"""
sh:path dcat:version ;
sh:nodeKind sh:Literal ;
"""
)
);
latestResourcesSchema.remove("_id");
latestResourcesSchema.put(FIELD_VER_UUID, KnownUUIDs.SCHEMA_V2_RESOURCE_UUID);
latestResourcesSchema.put(FIELD_LATEST, true);
final SemVer semVer = new SemVer(latestResourcesSchema.getString(FIELD_VERSION));
semVer.setPatch(semVer.getPatch() + 1);
latestResourcesSchema.put(FIELD_VERSION, semVer.toString());
schemasCol.updateMany(
Filters.and(
Filters.eq(FIELD_UUID, KnownUUIDs.SCHEMA_RESOURCE_UUID),
Filters.eq(FIELD_VER_UUID, previousVersionUuid)
),
Updates.set(FIELD_LATEST, false)
);
schemasCol.insertOne(latestResourcesSchema);
}

@RollbackExecution
public void rollback() {
final MongoCollection<Document> schemasCol = database.getCollection(COL_SCHEMAS);
schemasCol.deleteOne(
Filters.and(
Filters.eq(FIELD_UUID, KnownUUIDs.SCHEMA_RESOURCE_UUID),
Filters.eq(FIELD_VER_UUID, KnownUUIDs.SCHEMA_V2_RESOURCE_UUID)
)
);
schemasCol.updateOne(
Filters.and(
Filters.eq(FIELD_UUID, KnownUUIDs.SCHEMA_RESOURCE_UUID),
Filters.eq(FIELD_VER_UUID, previousVersionUuid)
),
Updates.set(FIELD_LATEST, true)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* 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.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 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
37 changes: 37 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,37 @@
/**
* 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.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.vocabulary.DCAT;

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

/**
* Temporary solution for DCAT3 which currently not supported in RDR4J vocabularies
*
* @TODO: remove once RDF4J supports DCAT3
*/
public class DCAT3 extends DCAT {
public static final IRI VERSION = i(NAMESPACE + "version");
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ metadataProperties:

openapi:
title: FAIR Data Point API
version: 1.17.0
version: 1.17.1
description: "The reference implementation of the metadata registration service: A service implementing the API specification. It contains an authentication system to allow maintainers to define and update metadata. Read-only access to the data is public."
contact:
name: Luiz Bonino
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
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 73b7039

Please sign in to comment.