Skip to content
Permalink
Browse files

Using properties file for namespace prefixes.

  • Loading branch information...
daniel-dgi authored and mikedurbin committed Jun 2, 2015
1 parent 7277e05 commit 202cff557ba5625f20781dcd69b9a341ad196ac9
@@ -20,19 +20,20 @@ Background work
* If so, you will need all of the export FOXML in a known directory.
* Will you be migrating from from a native fcrepo3 filesystem?
* If so, fcrepo3 should not be running, and you will need to determine if you're using legacy or akubra storage
* Determine your fcrepo4 url (ex: http://localhost:8080/rest/, http://yourHostName.ca:8080/fcrepo/rest/) ([line 140](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L140)
* There is currently only one implemented pid-mapping strategy, but you can configure it to put all of your migrated content under a given path ([line 93](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L93), sets that value to "migrated-fedora3").
* Determine your fcrepo4 url (ex: http://localhost:8080/rest/, http://yourHostName.ca:8080/fcrepo/rest/) ([line 143](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L143))
* There is currently only one implemented pid-mapping strategy, but you can configure it to put all of your migrated content under a given path ([line 94](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L94), sets that value to "migrated-fedora3").

Getting started:
* [Download](https://github.com/fcrepo4-labs/migration-utils/releases) the executable jar file
* Create a local copy of the example [configuration file](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml) and update as described below:
* If you are migrating from exported FOXML, you will leave [line 9](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L9).
* If you are migrating from a native fcrepo3 file system, you will need to change `exportedFoxmlDirectoryObjectSource` to `nativeFoxmlDirectoryObjectSource` in [line 9](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L9).
* If you are migrating from a native fcrepo3 file system, you will need to set the paths to the `objectStore` and `datastreamStore` ([Lines 143-139](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L143-L149)).
* If you are migrating from exported FOXML, you will need to set the path to the directory you have them stored in ([Lines 151-153](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L151-L153)).
* Set your fcrepo4 url ([Line 140](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L140)).
* If you are migrating from a native fcrepo3 file system, you will need to set the paths to the `objectStore` and `datastreamStore` ([Lines 146-152](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L146-L152)).
* If you are migrating from exported FOXML, you will need to set the path to the directory you have them stored in ([Lines 154-156](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L154-L156)).
* Set your fcrepo4 url ([Line 143](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L143)).
* If you would like to run the migration in test mode (console logging), you will leave [lines 11-16](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L11-L16) as is.
* If you would like to run the migration, you will need to comment out or remove [line 9](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L11), and uncomment [line 15](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L15).
* To set what namespace prefixes get declared, provide a properties file like [this](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/test/resources/namespaces.properties), and set the path to it at [line 163](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L163).


To run the migration scenario you have configured in the Spring XML configuration file:
@@ -16,7 +16,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.1.1.RELEASE</spring.version>
<jena.version>2.12.1</jena.version>
<checkstyle.plugin.version>2.14</checkstyle.plugin.version>
<checkstyle.plugin.version>2.15</checkstyle.plugin.version>
</properties>

<scm>
@@ -0,0 +1,40 @@
package org.fcrepo.migration.foxml11;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import com.hp.hpl.jena.update.UpdateRequest;

/**
* Utility bean to set namespace prefixes in a SPARQL update.
* @author danny
*
*/
public class NamespacePrefixMapper {

private Properties namespacePrefixes;

/**
* Constructor.
* @param namespaceFile Namespace properties file that gets injected in via Spring
* @throws IOException
*/
public NamespacePrefixMapper(final File namespaceFile) throws IOException {
namespacePrefixes = new Properties();
final FileInputStream namespaceInputStream = new FileInputStream(namespaceFile);
namespacePrefixes.load(namespaceInputStream);
namespaceInputStream.close();
}

/**
* Declares all the namespace prefixes provided in the properties file.
* @param updateRequest SPARQL update query that needs declared prefixes
*/
public void setPrefixes(final UpdateRequest updateRequest) {
namespacePrefixes.forEach((prefix,namespace) -> {
updateRequest.setPrefix((String) prefix, (String) namespace);
});
}
}
@@ -14,6 +14,7 @@
import com.hp.hpl.jena.sparql.modify.request.UpdateDeleteWhere;
import com.hp.hpl.jena.update.UpdateFactory;
import com.hp.hpl.jena.update.UpdateRequest;

import org.apache.jena.atlas.io.IndentedWriter;
import org.fcrepo.client.FedoraContent;
import org.fcrepo.client.FedoraDatastream;
@@ -30,13 +31,15 @@
import org.fcrepo.migration.ObjectReference;
import org.fcrepo.migration.ObjectVersionReference;
import org.fcrepo.migration.foxml11.DC;
import org.fcrepo.migration.foxml11.NamespacePrefixMapper;
import org.fcrepo.migration.urlmappers.SelfReferencingURLMapper;
import org.slf4j.Logger;

import javax.xml.bind.JAXBException;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -70,17 +73,22 @@

private ExternalContentURLMapper externalContentUrlMapper;

private NamespacePrefixMapper namespacePrefixMapper;

/**
* Basic object version handler.
* @param repo the fedora repository
* @param idMapper the id mapper
* @param localFedoraServer uri to fedora server
*/
public BasicObjectVersionHandler(final FedoraRepository repo, final MigrationIDMapper idMapper,
final String localFedoraServer) {
public BasicObjectVersionHandler(final FedoraRepository repo,
final MigrationIDMapper idMapper,
final String localFedoraServer,
final NamespacePrefixMapper namespacePrefixMapper) {
this.repo = repo;
this.idMapper = idMapper;
this.externalContentUrlMapper = new SelfReferencingURLMapper(localFedoraServer, idMapper);
this.namespacePrefixMapper = namespacePrefixMapper;
}

/**
@@ -509,7 +517,7 @@ protected void migrateDc(final DatastreamVersion v, final QuadAcc triplesToRemov
}

/**
* Utility function for udpating a FedoraResource's properties.
* Utility function for updating a FedoraResource's properties.
*
* @param resource FedoraResource to update.
* @param triplesToRemove List of triples to remove from resource.
@@ -522,9 +530,7 @@ protected void updateResourceProperties(final FedoraResource resource,
final QuadDataAcc triplesToInsert) throws RuntimeException {
try {
final UpdateRequest updateRequest = UpdateFactory.create();
updateRequest.setPrefix("dcterms", "http://purl.org/dc/terms/");
updateRequest.setPrefix("fedoraaccess", "http://fedora.info/definitions/1/0/access/");
updateRequest.setPrefix("fedora3model", "info:fedora/fedora-system:def/model#");
namespacePrefixMapper.setPrefixes(updateRequest);
updateRequest.add(new UpdateDeleteWhere(triplesToRemove));
updateRequest.add(new UpdateDataInsert(triplesToInsert));
final ByteArrayOutputStream sparqlUpdate = new ByteArrayOutputStream();
@@ -0,0 +1,8 @@
#The first time a property is added to the repository belonging to a particular namespace, that namespace
#prefix is registered and will be used from that point on (for all properties using that namespace). Setting values
#here before the first run will allow registration of preferred namespace prefixes, but will have no effect on
#subsequent runs.
dcterms = http://purl.org/dc/terms/
fedoraaccess = http://fedora.info/definitions/1/0/access/
fedora3model = info:fedora/fedora-system:def/model#
rels-ext = info:fedora/fedora-system:def/relations-external#
@@ -76,6 +76,7 @@
<constructor-arg name="repo" ref="fedora4Client" />
<constructor-arg name="idMapper" ref="idMapper" />
<constructor-arg name="localFedoraServer" ref="localFedoraServer" />
<constructor-arg name="namespacePrefixMapper" ref="namespacePrefixMapper"/>

<!-- set these to true if you want to copy the external content into your fedora 4
repository at the time of migration -->
@@ -128,11 +129,13 @@
<!--<constructor-arg name="indexDir" type="java.io.File" ref="indexRoot" />-->
</bean>


<!-- A bean that defines the codebase used to make HTTP requests to fetch content at URLs. -->
<bean id="httpClientURLFetcher" class="org.fcrepo.migration.foxml11.HttpClientURLFetcher" />


<!-- A utility bean to map namespace prefixes -->
<bean id="namespacePrefixMapper" class="org.fcrepo.migration.foxml11.NamespacePrefixMapper">
<constructor-arg name="namespaceFile" type="java.io.File" ref="namespaceFile"/>
</bean>

<!-- Local Environment Configuration -->

@@ -156,6 +159,10 @@
<constructor-arg type="java.lang.String" value="index" />
</bean>

<bean id="namespaceFile" class="java.io.File">
<constructor-arg type="java.lang.String" value="src/main/resources/namespaces.properties"/>
</bean>

<!--
The host and port for the fedora 3 server from which you're migrating content. This server
does not have to be running for all migration configurations, only if you have redirect or
@@ -16,7 +16,6 @@
<bean id="exportedFoxmlDirectoryObjectSource" class="org.fcrepo.migration.foxml11.ArchiveExportedFoxmlDirectoryObjectSource" >
<constructor-arg name="exportDir" ref="exportDir" />
<constructor-arg name="localFedoraServer" ref="localFedoraServer" />
<property name="fetcher" ref="httpClientURLFetcher"/>
</bean>

<bean id="objectAbstraction" class="org.fcrepo.migration.handlers.ObjectAbstractionStreamingFedoraObjectHandler">
@@ -31,6 +30,7 @@
<constructor-arg name="repo" ref="fedora4Client" />
<constructor-arg name="idMapper" ref="idMapper" />
<constructor-arg name="localFedoraServer" ref="localFedoraServer" />
<constructor-arg name="namespacePrefixMapper" ref="namespacePrefixMapper"/>
<property name="importExternal" value="false" />
<property name="importRedirect" value="false" />

@@ -42,6 +42,11 @@
<property name="charDepth" value="2" />
</bean>

<!-- A utility bean to map namespace prefixes -->
<bean id="namespacePrefixMapper" class="org.fcrepo.migration.foxml11.NamespacePrefixMapper">
<constructor-arg name="namespaceFile" type="java.io.File" ref="namespaceFile"/>
</bean>

<bean id="fedora4Client" class="org.fcrepo.client.impl.FedoraRepositoryImpl">
<constructor-arg name="repositoryURL" ref="fedora4Url" />
</bean>
@@ -60,4 +65,7 @@
<constructor-arg value="localhost:8080" />
</bean>

<bean id="namespaceFile" class="java.io.File">
<constructor-arg type="java.lang.String" value="src/main/resources/namespaces.properties"/>
</bean>
</beans>

0 comments on commit 202cff5

Please sign in to comment.
You can’t perform that action at this time.