Skip to content

Commit

Permalink
Using ebucore:hasMimeType and ebucore:filename instead of jcr/fedora:…
Browse files Browse the repository at this point in the history
…mimeType and premis:hasOriginalName
  • Loading branch information
escowles committed Jul 6, 2015
1 parent 738d442 commit 3b6464d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
Expand Up @@ -50,10 +50,11 @@
import java.util.Collection;

import static com.codahale.metrics.MetricRegistry.name;
import static org.fcrepo.kernel.FedoraJcrTypes.HAS_MIME_TYPE;
import static org.fcrepo.kernel.FedoraJcrTypes.FILENAME;
import static org.fcrepo.kernel.impl.utils.FedoraTypesUtils.isFedoraBinary;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.modeshape.jcr.api.JcrConstants.JCR_MIME_TYPE;
import static org.slf4j.LoggerFactory.getLogger;

/**
Expand Down Expand Up @@ -152,11 +153,11 @@ public void setContent(final InputStream content, final String contentType,
}

if (contentType != null) {
contentNode.setProperty(JCR_MIME_TYPE, contentType);
contentNode.setProperty(HAS_MIME_TYPE, contentType);
}

if (originalFileName != null) {
contentNode.setProperty(PREMIS_FILE_NAME, originalFileName);
contentNode.setProperty(FILENAME, originalFileName);
}

LOGGER.debug("Created content node at path: {}", contentNode.getPath());
Expand Down Expand Up @@ -244,8 +245,8 @@ public URI getContentDigest() {
@Override
public String getMimeType() {
try {
if (hasProperty(JCR_MIME_TYPE)) {
return getProperty(JCR_MIME_TYPE).getString();
if (hasProperty(HAS_MIME_TYPE)) {
return getProperty(HAS_MIME_TYPE).getString();
}
return "application/octet-stream";
} catch (final RepositoryException e) {
Expand All @@ -260,8 +261,8 @@ public String getMimeType() {
@Override
public String getFilename() {
try {
if (hasProperty(PREMIS_FILE_NAME)) {
return getProperty(PREMIS_FILE_NAME).getString();
if (hasProperty(FILENAME)) {
return getProperty(FILENAME).getString();
}
return node.getParent().getName();
} catch (final RepositoryException e) {
Expand Down
Expand Up @@ -26,6 +26,7 @@
<rdfs = 'http://www.w3.org/2000/01/rdf-schema#'>
<premis = 'http://www.loc.gov/premis/rdf/v1#'>
<ldp = 'http://www.w3.org/ns/ldp#'>
<ebucore = 'http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#'>

/*
* A fedora namespace for properties a user may set on a node that may
Expand Down
Expand Up @@ -284,9 +284,9 @@ public void testChecksumBlobs() throws RepositoryException, InvalidChecksumExcep

binaryService.findOrCreate(session, "/testLLObject/testRepositoryContent").setContent(
new ByteArrayInputStream("01234567890123456789012345678901234567890123456789".getBytes()),
"application/octet-stream",
null,
"text/plain",
null,
"numbers.txt",
null
);

Expand All @@ -303,6 +303,11 @@ public void testChecksumBlobs() throws RepositoryException, InvalidChecksumExcep
fixityResults.contains(null,
HAS_MESSAGE_DIGEST,
createResource("urn:sha1:9578f951955d37f20b601c26591e260c1e5389bf")));

assertEquals("Expected to find mime type",
ds.getNode().getProperty("ebucore:hasMimeType").getString(), "text/plain");
assertEquals("Expected to find file name",
ds.getNode().getProperty("ebucore:filename").getString(), "numbers.txt");
} finally {
session.logout();
}
Expand Down
Expand Up @@ -15,7 +15,7 @@
*/
package org.fcrepo.integration.kernel.impl.services;

import static org.fcrepo.kernel.FedoraJcrTypes.PREMIS_FILE_NAME;
import static org.fcrepo.kernel.FedoraJcrTypes.FILENAME;
import static org.jgroups.util.Util.assertEquals;
import static org.jgroups.util.Util.assertTrue;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
Expand Down Expand Up @@ -92,7 +92,7 @@ public void testCreateDatastreamNodeWithfilename() throws Exception {

assertTrue(session.getRootNode().hasNode("testDatastreamNode"));
assertEquals("xyz.jpg", session.getNode("/testDatastreamNode").getNode(JCR_CONTENT)
.getProperty(PREMIS_FILE_NAME).getString());
.getProperty(FILENAME).getString());
session.logout();
}

Expand Down
Expand Up @@ -50,7 +50,7 @@
import static org.mockito.MockitoAnnotations.initMocks;
import static org.modeshape.jcr.api.JcrConstants.JCR_CONTENT;
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;
import static org.modeshape.jcr.api.JcrConstants.JCR_MIME_TYPE;
import static org.fcrepo.kernel.FedoraJcrTypes.HAS_MIME_TYPE;

/**
* <p>DatastreamImplTest class.</p>
Expand Down Expand Up @@ -172,7 +172,7 @@ public void testSetContentWithFilename() throws RepositoryException,
when(mockContent.getProperty(JCR_DATA)).thenReturn(mockData);
when(mockData.getBinary()).thenReturn(mockBin);
testObj.setContent(mockStream, null, null, "xyz", null);
verify(mockContent).setProperty(PREMIS_FILE_NAME, "xyz");
verify(mockContent).setProperty(FILENAME, "xyz");
}

@Test(expected = InvalidChecksumException.class)
Expand Down Expand Up @@ -220,10 +220,10 @@ public void testGetMimeType() throws RepositoryException {
getContentNodeMock(mockContent, 8);
when(mockDsNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
when(mockDsNode.hasNode(JCR_CONTENT)).thenReturn(true);
when(mockContent.hasProperty(JCR_MIME_TYPE)).thenReturn(true);
when(mockContent.hasProperty(HAS_MIME_TYPE)).thenReturn(true);

final Property mockProperty = mock(Property.class);
when(mockContent.getProperty(JCR_MIME_TYPE)).thenReturn(mockProperty);
when(mockContent.getProperty(HAS_MIME_TYPE)).thenReturn(mockProperty);
when(mockProperty.getString()).thenReturn("application/x-mime-type");
assertEquals("application/x-mime-type", testObj.getMimeType());
}
Expand All @@ -239,7 +239,7 @@ public void testGetMimeTypeWithDefault() throws RepositoryException {
getContentNodeMock(mockContent, 8);
when(mockDsNode.getNode(JCR_CONTENT)).thenReturn(mockContent);
when(mockDsNode.hasNode(JCR_CONTENT)).thenReturn(true);
when(mockContent.hasProperty(JCR_MIME_TYPE)).thenReturn(false);
when(mockContent.hasProperty(HAS_MIME_TYPE)).thenReturn(false);

assertEquals("application/octet-stream", testObj.getMimeType());
}
Expand Down
Expand Up @@ -51,7 +51,9 @@ public interface FedoraJcrTypes {

String JCR_CREATEDBY = "jcr:createdBy";

String PREMIS_FILE_NAME = "premis:hasOriginalName";
String FILENAME = "ebucore:filename";

String HAS_MIME_TYPE = "ebucore:hasMimeType";

String CONTENT_SIZE = "premis:hasSize";

Expand Down

0 comments on commit 3b6464d

Please sign in to comment.