Skip to content

Commit

Permalink
Last changes to work with Jersey
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Apr 25, 2013
1 parent 5e688e7 commit 39e8bbd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
26 changes: 19 additions & 7 deletions src/main/java/org/fcrepo/serialization/bagit/BagItSerializer.java
@@ -1,6 +1,7 @@

package org.fcrepo.serialization.bagit;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Collections2.transform;
import static com.google.common.collect.ImmutableList.copyOf;
import static com.google.common.collect.ImmutableList.of;
Expand Down Expand Up @@ -44,7 +45,7 @@
import org.fcrepo.exception.InvalidChecksumException;
import org.fcrepo.serialization.BaseFedoraObjectSerializer;
import org.fcrepo.utils.NodeIterator;
import org.fcrepo.utils.FedoraPropertyIterator;
import org.fcrepo.utils.PropertyIterator;
import org.slf4j.Logger;

import com.google.common.base.Function;
Expand All @@ -53,7 +54,7 @@

public class BagItSerializer extends BaseFedoraObjectSerializer {

public Set<String> prefixes;
private Set<String> prefixes;

private BagFactory bagFactory = new BagFactory();

Expand All @@ -62,6 +63,7 @@ public class BagItSerializer extends BaseFedoraObjectSerializer {
@Override
public void serialize(final FedoraObject obj, final OutputStream out)
throws RepositoryException, IOException {
checkNotNull(obj, "Cannot serialize a null FedoraObject!");
logger.debug("Serializing object: " + obj.getName());
try (final InputStream is =
new FileInputStream(serializeToFile(obj.getNode()))) {
Expand All @@ -71,16 +73,26 @@ public void serialize(final FedoraObject obj, final OutputStream out)

public File serializeToFile(final Node node) throws RepositoryException,
IOException {

checkNotNull(node, "Cannot serialize a null Node!");
final File bagFile = createTempDir();
logger.debug("Bag assembly directory created at: {}", bagFile.getPath());
// create bag-info.txt
final File bagInfoTxtFile =
new File(bagFile, bagFactory.getBagConstants().getBagInfoTxt());
if (!bagInfoTxtFile.createNewFile()) {
throw new IllegalStateException(
"Could not create a bag-info-.txt file!");
}
logger.debug("bag-info.txt file created at: {}", bagInfoTxtFile
.getPath());
bagInfoTxtFile.deleteOnExit();
bagFile.deleteOnExit();
final Bag bag = bagFactory.createBag();

bag.addFileAsTag(bagInfoTxtFile);
// get recordable properties
logger.trace("Retrieving properties to serialize...");
final Iterator<Property> properties =
new FedoraPropertyIterator(node
.getProperties(prefixesInGlobForm()));
new PropertyIterator(node.getProperties(prefixesInGlobForm()));
// put 'em in a tag info file
logger.trace("Recording properties...");
final BagInfoTxt bagInfoTxt = bag.getBagInfoTxt();
Expand Down Expand Up @@ -208,7 +220,7 @@ public void deserialize(final Session session, final InputStream stream)

}

public Function<Property, List<NameValue>> property2BagItTags =
private Function<Property, List<NameValue>> property2BagItTags =
new Function<Property, List<NameValue>>() {

@Override
Expand Down
19 changes: 14 additions & 5 deletions src/test/resources/spring-test/rest.xml
Expand Up @@ -12,20 +12,29 @@

<context:property-placeholder/>
<context:annotation-config/>

<util:map id="serializers" key-type="java.lang.String"
value-type="org.fcrepo.serialization.FedoraObjectSerializer">
<description>Map from formats to serializers for Fedora objects</description>
<entry key="bagit">
<bean class="org.fcrepo.serialization.bagit.BagItSerializer"/>
<bean class="org.fcrepo.serialization.bagit.BagItSerializer">
<property name="prefixes">
<set value-type="java.lang.String">
<value>fedora</value>
<value>dc</value>
</set>
</property>
</bean>
</entry>
</util:map>

<bean class="org.fcrepo.serialization.FedoraObjectsSerialized"/>




<context:component-scan
base-package="org.fcrepo.api, org.fcrepo.serialization, org.fcrepo.exceptionhandlers"/>

<!-- Mints PIDs-->
<bean class="org.fcrepo.identifiers.UUIDPidMinter"/>
<bean class="org.fcrepo.session.SessionFactory"/>
Expand Down

0 comments on commit 39e8bbd

Please sign in to comment.