Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* 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 lombok.SneakyThrows;
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;

import static java.lang.String.format;
import static nl.dtls.fairdatapoint.util.ResourceReader.loadClassResource;

/**
* This migration updates the default metadata schemas defining the `fdp`, `dataset`, and `distribution` shapes.
* This is done by copying the content from `resources/.../migration/production/0017_shape-*.ttl` files into the
* corresponding `definition` fields.
* Changes with respect to migration 0016:
* - changed `xsd:dateTime` to `xsd:date` for fdp `startDate` and `endDate` (to comply with the spec)
* - changed `dash:editor` for `issued` and `modified` from `DatePickerEditor` to `DateTimePickerEditor`,
* in `dataset` and `distribution`, for consistency with the `xsd:dateTime` datatype for those fields
*/
@ChangeUnit(
id = "Migration_0017_FixSchemaDateTimes",
order = "0017",
author = "migrationBot"
)
@Profile(Profiles.PRODUCTION)
public class Migration_0017_FixSchemaDateTimes {
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_0017_FixSchemaDateTimes(MongoTemplate template) {
this.database = template;
}

@Execution
public void run() {
updateSchema(KnownUUIDs.SCHEMA_V1_DATASET_UUID, "dataset");
updateSchema(KnownUUIDs.SCHEMA_V1_DISTRIBUTION_UUID, "distribution");
updateSchema(KnownUUIDs.SCHEMA_V1_FDP_UUID, "fdp");
}

@SneakyThrows
private void updateSchema(String versionUuid, String name) {
final MongoCollection<Document> schemasCol = database.getCollection(COL_SCHEMAS);
final String definition = loadClassResource(format("0017_shape-%s.ttl", name), getClass());
schemasCol.updateOne(
Filters.and(
Filters.eq(FIELD_VER_UUID, versionUuid),
Filters.eq(FIELD_LATEST, true)
),
Updates.set(FIELD_DEF, definition)
);
}

@RollbackExecution
public void rollback() {
// Rollback is not possible
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
sh:path dct:issued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 20 ;
], [
sh:path dct:modified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 21 ;
], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
sh:path dct:issued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 20 ;
], [
sh:path dct:modified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 21 ;
], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
sh:targetClass fdp:FAIRDataPoint ;
sh:property [
sh:path fdp:startDate ;
sh:datatype xsd:dateTime ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 40 ;
] , [
sh:path fdp:endDate ;
sh:datatype xsd:dateTime ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:viewer dash:LiteralViewer ;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
@prefix : <http://fairdatapoint.org/> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:DatasetShape a sh:NodeShape ;
sh:targetClass dcat:Dataset ;
sh:property [
sh:path dct:issued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 20 ;
], [
sh:path dct:modified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 21 ;
], [
sh:path dcat:theme ;
sh:nodeKind sh:IRI ;
sh:minCount 1 ;
dash:editor dash:URIEditor ;
dash:viewer dash:LabelViewer ;
sh:order 22 ;
], [
sh:path dcat:contactPoint ;
sh:nodeKind sh:IRI ;
sh:maxCount 1 ;
dash:editor dash:URIEditor ;
dash:viewer dash:LabelViewer ;
sh:order 23 ;
], [
sh:path dcat:keyword ;
sh:nodeKind sh:Literal ;
dash:editor dash:TextFieldEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 24 ;
], [
sh:path dcat:landingPage ;
sh:nodeKind sh:IRI ;
sh:maxCount 1 ;
dash:editor dash:URIEditor ;
dash:viewer dash:LabelViewer ;
sh:order 25 ;
] .
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@prefix : <http://fairdatapoint.org/> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:DistributionShape a sh:NodeShape ;
sh:targetClass dcat:Distribution ;
sh:property [
sh:path dct:issued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 20 ;
], [
sh:path dct:modified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 21 ;
], [
sh:path dcat:accessURL ;
sh:nodeKind sh:IRI ;
sh:maxCount 1 ;
dash:editor dash:URIEditor ;
sh:order 22 ;
], [
sh:path dcat:downloadURL ;
sh:nodeKind sh:IRI ;
sh:maxCount 1 ;
dash:editor dash:URIEditor ;
sh:order 23 ;
], [
sh:path dcat:mediaType ;
sh:nodeKind sh:Literal ;
sh:minCount 1 ;
sh:maxCount 1 ;
dash:editor dash:TextFieldEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 24 ;
], [
sh:path dcat:format ;
sh:nodeKind sh:Literal ;
sh:maxCount 1 ;
dash:editor dash:TextFieldEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 25 ;
], [
sh:path dcat:byteSize ;
sh:nodeKind sh:Literal ;
sh:maxCount 1 ;
dash:editor dash:TextFieldEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 26 ;
] .
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@prefix : <http://fairdatapoint.org/> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix fdp: <https://w3id.org/fdp/fdp-o#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:FDPShape a sh:NodeShape ;
sh:targetClass fdp:FAIRDataPoint ;
sh:property [
sh:path fdp:startDate ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 40 ;
] , [
sh:path fdp:endDate ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 41 ;
] , [
sh:path fdp:uiLanguage ;
sh:nodeKind sh:IRI ;
sh:maxCount 1 ;
sh:defaultValue <http://id.loc.gov/vocabulary/iso639-1/en>;
dash:editor dash:URIEditor ;
dash:viewer dash:LabelViewer ;
sh:order 42 ;
] , [
sh:path fdp:metadataIdentifier ;
sh:nodeKind sh:IRI ;
sh:maxCount 1 ;
dash:editor dash:URIEditor ;
dash:viewer dash:LabelViewer ;
sh:order 43 ;
] , [
sh:path fdp:metadataIssued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:viewer dash:LiteralViewer ;
] , [
sh:path fdp:metadataModified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:viewer dash:LiteralViewer ;
] .
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The content of these SHACL files is copied into the `metadataSchema.definition` field when mongodb migrations are executed (by mongock).
See corresponding migration classes in `src/main/java/nl/dtls/fairdatapoint/database/mongo/migration/production` for details.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
sh:path dct:issued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 20 ;
], [
sh:path dct:modified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 21 ;
], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
sh:path dct:issued ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 20 ;
], [
sh:path dct:modified ;
sh:datatype xsd:dateTime ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:editor dash:DateTimePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 21 ;
], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
sh:targetClass fdp:FAIRDataPoint ;
sh:property [
sh:path fdp:startDate ;
sh:datatype xsd:dateTime ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:viewer dash:LiteralViewer ;
sh:order 40 ;
] , [
sh:path fdp:endDate ;
sh:datatype xsd:dateTime ;
sh:datatype xsd:date ;
sh:maxCount 1 ;
dash:editor dash:DatePickerEditor ;
dash:viewer dash:LiteralViewer ;
Expand Down
Loading