-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #446 from FAIRDataTeam/fix/version-metadata
Hotfix 1.17.1
- Loading branch information
Showing
14 changed files
with
261 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
.../fairdatapoint/database/mongo/migration/production/Migration_0015_FixMetadataVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...airdatapoint/database/rdf/migration/production/Rdf_Migration_0005_FixMetadataVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters