Skip to content

Commit

Permalink
Added getCreatedDate() for Datastream
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Feb 28, 2013
1 parent 62ef98a commit 0c46d84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/Datastream.java
Expand Up @@ -9,6 +9,7 @@
import static org.modeshape.jcr.api.JcrConstants.JCR_DATA;

import java.io.InputStream;
import java.util.Date;

import javax.jcr.Node;
import javax.jcr.Property;
Expand Down Expand Up @@ -109,4 +110,9 @@ public void setLabel(String label) throws ValueFormatException,
node.setProperty(DC_TITLE, label);
}

public Date getCreatedDate() throws RepositoryException {
return new Date(node.getProperty("jcr:created").getDate()
.getTimeInMillis());
}

}
16 changes: 16 additions & 0 deletions fcrepo-kernel/src/test/java/org/fcrepo/DatastreamTest.java
Expand Up @@ -5,6 +5,7 @@
import static org.fcrepo.services.DatastreamService.getDatastream;
import static org.fcrepo.services.ObjectService.createObjectNode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -41,4 +42,19 @@ public void testLabel() throws RepositoryException, IOException {
final Datastream ds = getDatastream("testObject", "testDatastreamNode");
assertEquals("Wrong label!", "Best datastream ever!", ds.getLabel());
}

@Test
public void testCreatedDate() throws RepositoryException, IOException {
Session session = repo.login();
createObjectNode(session, "testObject");
createDatastreamNode(session,
"/objects/testObject/testDatastreamNode1",
"application/octet-stream", new ByteArrayInputStream(
"asdf".getBytes()));
session.save();
session.logout();
session = repo.login();
final Datastream ds = getDatastream("testObject", "testDatastreamNode1");
assertNotNull("Couldn't find created date on datastream!", ds.getCreatedDate());
}
}

0 comments on commit 0c46d84

Please sign in to comment.