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 #8 from fcrepo4-labs/legacy-fs-support
Added support for direct migration from legacy-fs.
- Loading branch information
Showing
16 changed files
with
484 additions
and
41 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/main/java/org/fcrepo/migration/foxml11/AkubraFSIDResolver.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,49 @@ | ||
package org.fcrepo.migration.foxml11; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.URLDecoder; | ||
|
||
/** | ||
* An extension of DirectoryScanningIDResolver for datastream directories of fedora | ||
* repositories using the akubra-fs storage implementation. | ||
* | ||
* @author mdurbin | ||
*/ | ||
public class AkubraFSIDResolver extends DirectoryScanningIDResolver { | ||
|
||
/** | ||
* Basic constructor. | ||
* @param indexDir A directory that will serve as a lucene index directory to cache ID resolution. | ||
* @param dsRoot the root directory of the AkubraFS datastream store. | ||
*/ | ||
public AkubraFSIDResolver(final File indexDir, final File dsRoot) throws IOException { | ||
super(indexDir, dsRoot); | ||
} | ||
|
||
/** | ||
* Basic constructor. | ||
* @param dsRoot the root directory of the AkubraFS datastream store. | ||
*/ | ||
public AkubraFSIDResolver(final File dsRoot) throws IOException { | ||
super(null, dsRoot); | ||
} | ||
|
||
@Override | ||
protected String getInternalIdForFile(final File f) { | ||
String id = f.getName(); | ||
try { | ||
id = URLDecoder.decode(id, "UTF-8"); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
if (!id.startsWith("info:fedora/")) { | ||
throw new IllegalArgumentException(f.getName() | ||
+ " does not appear to be a valid akubraFS datastream file!"); | ||
} | ||
id = id.substring("info:fedora/".length()); | ||
id = id.replace('/', '+'); | ||
return id; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/org/fcrepo/migration/foxml11/LegacyFSIDResolver.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,35 @@ | ||
package org.fcrepo.migration.foxml11; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* An extension of DirectoryScanningIDResolver for datastream directories of fedora | ||
* repositories using the legacy-fs storage implementation. | ||
* | ||
* @author mdurbin | ||
*/ | ||
public class LegacyFSIDResolver extends DirectoryScanningIDResolver { | ||
|
||
/** | ||
* Basic constructor. | ||
* @param indexDir A directory that will serve as a lucene index directory to cache ID resolution. | ||
* @param dsRoot the root directory of the AkubraFS datastream store. | ||
*/ | ||
public LegacyFSIDResolver(final File indexDir, final File dsRoot) throws IOException { | ||
super(indexDir, dsRoot); | ||
} | ||
|
||
/** | ||
* Basic constructor. | ||
* @param dsRoot the root directory of the AkubraFS datastream store. | ||
*/ | ||
public LegacyFSIDResolver(final File dsRoot) throws IOException { | ||
super(null, dsRoot); | ||
} | ||
|
||
@Override | ||
protected String getInternalIdForFile(final File f) { | ||
return f.getName().replaceFirst("_", ":"); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/test/java/org/fcrepo/migration/LegacyFoxmlStorageMigratorTest.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,41 @@ | ||
package org.fcrepo.migration; | ||
|
||
import org.junit.Before; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author mdurbin | ||
*/ | ||
public class LegacyFoxmlStorageMigratorTest extends Example1TestSuite { | ||
|
||
private static DummyHandler result; | ||
|
||
private static DummyURLFetcher fetcher; | ||
|
||
@Before | ||
public synchronized void processFoxml() throws XMLStreamException, IOException { | ||
if (getResult() == null) { | ||
final ConfigurableApplicationContext context = | ||
new ClassPathXmlApplicationContext("spring/stored-legacy-foxml.xml"); | ||
this.result = (DummyHandler) context.getBean("dummyHandler"); | ||
this.fetcher = (DummyURLFetcher) context.getBean("dummyFetcher"); | ||
final Migrator m = (Migrator) context.getBean("migrator"); | ||
m.run(); | ||
context.close(); | ||
} | ||
} | ||
|
||
@Override | ||
protected DummyHandler getResult() { | ||
return result; | ||
} | ||
|
||
@Override | ||
protected DummyURLFetcher getFetcher() { | ||
return fetcher; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/test/java/org/fcrepo/migration/foxml11/AkubraFSIDResolverTest.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,46 @@ | ||
package org.fcrepo.migration.foxml11; | ||
|
||
import junit.framework.Assert; | ||
import org.apache.commons.io.FileUtils; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
|
||
/** | ||
* @author mikedurbin | ||
*/ | ||
public class AkubraFSIDResolverTest { | ||
|
||
private AkubraFSIDResolver idResolver; | ||
|
||
private File tempDir; | ||
|
||
@Before | ||
public void setup() throws IOException { | ||
tempDir = File.createTempFile("tempfile", "basedir"); | ||
tempDir.delete(); | ||
tempDir.mkdir(); | ||
idResolver = new AkubraFSIDResolver(tempDir); | ||
} | ||
|
||
@Test | ||
public void testIDMapping() throws UnsupportedEncodingException { | ||
Assert.assertEquals("example:1+DS2+DS2.0", | ||
idResolver.getInternalIdForFile(new File("info%3Afedora%2Fexample%3A1%2FDS2%2FDS2.0"))); | ||
} | ||
|
||
@Test (expected = IllegalArgumentException.class) | ||
public void testBadFileIDMapping() throws UnsupportedEncodingException { | ||
idResolver.getInternalIdForFile(new File("example%3A1%2FDS2%2FDS2.0")); | ||
} | ||
|
||
|
||
@After | ||
public void cleanup() throws IOException { | ||
FileUtils.deleteDirectory(tempDir); | ||
} | ||
} |
Oops, something went wrong.