Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avalon overrides #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
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>org.fcrepo</groupId>
<version>6.4.0-SNAPSHOT</version>
<version>6.3.0-AVALON</version>
<artifactId>fcrepo-upgrade-utils</artifactId>
<name>Fedora Repository Utilities</name>
<description>The Fedora Commons repository upgrade utilities: Provides tools for maintaining the Fedora Commons
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/fcrepo/upgrade/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ public Lang getSrcRdfLang() {
return srcRdfLang;
}

/**
* @return the extension of the rdf lang of the export
*/
public String getSrcRdfExt() {
return srcRdfLang.getFileExtensions().get(0);
}

/**
* Sets the rdf lang of the export
* @param srcRdfLang the rdf lang of the export
Expand Down
49 changes: 24 additions & 25 deletions src/main/java/org/fcrepo/upgrade/utils/F47ToF5UpgradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class F47ToF5UpgradeManager extends UpgradeManagerBase implements UpgradeManager
private static final String FCR_VERSIONS_PATH_SEGMENT = "fcr%3Aversions";
private static final String FCR_ACL_PATH_SEGMENT = "fcr%3Aacl";
private static final String TYPE_RELATION = "type";
private static final String TURTLE_EXTENSION = ".ttl";
private static final String HEADERS_SUFFIX = ".headers";
public static final String APPLICATION_OCTET_STREAM_MIMETYPE = "application/octet-stream";
/**
Expand Down Expand Up @@ -120,7 +119,7 @@ private void processDirectory(final File dir) {
private void processFile(final Path path) {

//skip versions container
if (path.endsWith(FCR_VERSIONS_PATH_SEGMENT + TURTLE_EXTENSION)) {
if (path.endsWith(FCR_VERSIONS_PATH_SEGMENT + "." + config.getSrcRdfExt())) {
LOGGER.debug("version containers are not required for import. Skipping {}...", path);
return;
}
Expand All @@ -145,7 +144,7 @@ private void processFile(final Path path) {
Files.createDirectories(newLocation.getParent());
LOGGER.debug("copy file {} to {}", path, newLocation);
FileUtils.copyFile(path.toFile(), newLocation.toFile());
if (newLocation.toString().endsWith(TURTLE_EXTENSION)) {
if (newLocation.toString().endsWith(config.getSrcRdfExt())) {
upgradeRdfAndCreateHeaders(versionTimestamp, newLocation);
}
LOGGER.info("Resource upgraded: {}", path);
Expand All @@ -161,7 +160,7 @@ private void upgradeRdfAndCreateHeaders(final TemporalAccessor versionTimestamp,
//parse the file
final Model model = ModelFactory.createDefaultModel();
try (final InputStream is = new BufferedInputStream(new FileInputStream(newLocation.toFile()))) {
RDFDataMgr.read(model, is, Lang.TTL);
RDFDataMgr.read(model, is, config.getSrcRdfLang());
}

final Map<String, List<String>> metadataHeaders = new HashMap<>();
Expand All @@ -182,10 +181,10 @@ private void upgradeRdfAndCreateHeaders(final TemporalAccessor versionTimestamp,

//skip if ACL or Authorization: these files are upgraded through a separate code path
// see convertAcl() below.
if (rdfTypes.contains(ACL) || rdfTypes.contains(AUTHORIZATION)) {
newLocation.toFile().delete();
return;
}
//if (rdfTypes.contains(ACL) || rdfTypes.contains(AUTHORIZATION)) {
// newLocation.toFile().delete();
// return;
//}

rdfTypes.retainAll(LDP_CONTAINER_TYPES);
final var isConcreteContainerDefined = !rdfTypes.isEmpty();
Expand Down Expand Up @@ -251,17 +250,17 @@ private void upgradeRdfAndCreateHeaders(final TemporalAccessor versionTimestamp,
}
}
binaryHeaders.put(CONTENT_TYPE_HEADER, Collections.singletonList(mimetype));
} else if (statement.getPredicate().equals(ACCESS_CONTROL)) {
//} else if (statement.getPredicate().equals(ACCESS_CONTROL)) {
//remove the current statement across both past versions and latest version
model.remove(currentStatement);
rewriteModel.set(true);
//model.remove(currentStatement);
//rewriteModel.set(true);

//on the latest version
if(versionTimestamp == null) {
//convert the acl
convertAcl(newLocation, currentStatement.getSubject().getURI(),
currentStatement.getObject().asResource().getURI());
}
//if(versionTimestamp == null) {
// //convert the acl
// convertAcl(newLocation, currentStatement.getSubject().getURI(),
// currentStatement.getObject().asResource().getURI());
//}
}
});

Expand All @@ -284,7 +283,7 @@ private void upgradeRdfAndCreateHeaders(final TemporalAccessor versionTimestamp,
// rewrite only if the model has changed.
if (rewriteModel.get()) {
try {
RDFDataMgr.write(new BufferedOutputStream(new FileOutputStream(newLocation.toFile())), model, Lang.TTL);
RDFDataMgr.write(new BufferedOutputStream(new FileOutputStream(newLocation.toFile())), model, config.getSrcRdfLang());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -321,7 +320,7 @@ private void convertAcl(final Path convertedProtectedResourceLocation, String pr
//locate the exported acl rdf on disk based on aclURI
final var relativeAclPath = create(aclUri).getPath();
final var aclDirectory = Path.of(this.config.getInputDir().toPath().toString(), relativeAclPath);
final var aclRdfFilePath = aclDirectory + TURTLE_EXTENSION;
final var aclRdfFilePath = aclDirectory + "." + config.getSrcRdfExt();
final var newAclResource = ResourceFactory.createResource(protectedResource + "/fcr:acl");
final var aclModel = createModelFromFile(Path.of(aclRdfFilePath));
final var aclTriples = new ArrayList<Statement>();
Expand All @@ -338,7 +337,7 @@ private void convertAcl(final Path convertedProtectedResourceLocation, String pr

final var newAclFilePath = Path
.of(FilenameUtils.removeExtension(convertedProtectedResourceLocation.toString()),
FCR_ACL_PATH_SEGMENT + TURTLE_EXTENSION);
FCR_ACL_PATH_SEGMENT + "." + config.getSrcRdfExt());
newAclFilePath.getParent().toFile().mkdirs();

//determine the location of new acl
Expand Down Expand Up @@ -385,7 +384,7 @@ private void convertAcl(final Path convertedProtectedResourceLocation, String pr

//save to new acl to file
try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(newAclFilePath.toFile()))) {
RDFDataMgr.write(os, newModel, Lang.TTL);
RDFDataMgr.write(os, newModel, config.getSrcRdfLang());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -422,7 +421,7 @@ private Path resolveVersionsContainer(final Path path) {
while (currentPath != path.getRoot()) {
final var parent = currentPath.getParent();
if (parent.endsWith(FCR_VERSIONS_PATH_SEGMENT)) {
return Path.of(parent.toString() + TURTLE_EXTENSION);
return Path.of(parent.toString() + "." + config.getSrcRdfExt());
}

currentPath = parent;
Expand All @@ -432,10 +431,10 @@ private Path resolveVersionsContainer(final Path path) {

private TemporalAccessor resolveMementoTimestamp(final Path path) {
var metadataPath = path;
if (!path.toString().endsWith(TURTLE_EXTENSION)) {
if (!path.toString().endsWith(config.getSrcRdfExt())) {
final var metadataPathStr = metadataPath.toString();
final var newMetadataPathStr = FilenameUtils.removeExtension(metadataPathStr) + File.separator +
FCR_METADATA_PATH_SEGMENT + TURTLE_EXTENSION;
FCR_METADATA_PATH_SEGMENT + "." + config.getSrcRdfExt();
metadataPath = Path.of(newMetadataPathStr);
}

Expand All @@ -456,7 +455,7 @@ private TemporalAccessor resolveMementoTimestamp(final Path path) {
private Model createModelFromFile(final Path path) {
final Model model = ModelFactory.createDefaultModel();
try (final InputStream is = new BufferedInputStream(new FileInputStream(path.toFile()))) {
RDFDataMgr.read(model, is, Lang.TTL);
RDFDataMgr.read(model, is, config.getSrcRdfLang());
} catch (IOException ex) {
throw new RuntimeException(ex);
}
Expand All @@ -466,7 +465,7 @@ private Model createModelFromFile(final Path path) {
private Path resolveNewVersionedResourceLocation(final Path path, final TemporalAccessor mementoTimestamp) {
final var mementoId = MEMENTO_FORMATTER.format(mementoTimestamp);
//create a new location compatible with an F5 export.
final var isDescription = path.endsWith(FCR_METADATA_PATH_SEGMENT + TURTLE_EXTENSION);
final var isDescription = path.endsWith(FCR_METADATA_PATH_SEGMENT + "." + config.getSrcRdfExt());
final var inputPath = this.config.getInputDir().toPath();
final var relativePath = inputPath.relativize(path);
final var relativePathStr = relativePath.toString();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/fcrepo/upgrade/utils/RdfConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ private RdfConstants() {
private static final Set<Property> serverManagedProperties;
static {
final ImmutableSet.Builder<Property> b = ImmutableSet.builder();
b.addAll(fixityProperties).addAll(ldpManagedProperties).addAll(binaryProperties);
//b.addAll(fixityProperties).addAll(ldpManagedProperties).addAll(binaryProperties);
b.addAll(fixityProperties).addAll(ldpManagedProperties);
serverManagedProperties = b.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public ResourceMigrator(final Config config,

this.baseUri = stripTrailingSlash(config.getBaseUri());
this.srcRdfLang = config.getSrcRdfLang();
this.srcRdfExt = "." + srcRdfLang.getFileExtensions().get(0);
this.srcRdfExt = "." + config.getSrcRdfExt();

// Currently, this is all F6 supports
this.dstRdfLang = Lang.NT;
Expand Down