Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
boostrapping /federated node and adding property checks
  • Loading branch information
Vincent Nguyen committed Apr 22, 2013
1 parent 66659a3 commit c12ccde
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
65 changes: 53 additions & 12 deletions fcrepo-kernel/src/main/java/org/fcrepo/Datastream.java
Expand Up @@ -214,9 +214,16 @@ public void setContent(final InputStream content, final String mimeType,
* @return The size in bytes of content associated with this datastream.
* @throws RepositoryException
*/
public long getContentSize() throws RepositoryException {
return node.getNode(JCR_CONTENT).getProperty(CONTENT_SIZE).getLong();
}
public long getContentSize() {
try {
return node.getNode(JCR_CONTENT).getProperty(CONTENT_SIZE)
.getLong();
} catch (RepositoryException e) {
logger.error("Could not get contentSize() - " + e.getMessage());
}
// TODO Size is not stored, recalculate size?
return 0L;
}

/**
* Get the pre-calculated content digest for the binary payload
Expand All @@ -225,19 +232,37 @@ public long getContentSize() throws RepositoryException {
*/
public URI getContentDigest() throws RepositoryException {
final Node contentNode = node.getNode(JCR_CONTENT);
return ContentDigest
.asURI(contentNode.getProperty(DIGEST_ALGORITHM).getString(),
contentNode.getProperty(DIGEST_VALUE).getString());
try {
return ContentDigest
.asURI(contentNode.getProperty(DIGEST_ALGORITHM).getString(),
contentNode.getProperty(DIGEST_VALUE).getString());
} catch (RepositoryException e) {
logger.error("Could not get content digest - " + e.getMessage());
}
//TODO checksum not stored. recalculating checksum,
//however, this would defeat the purpose validating against the checksum
Binary binary = (Binary) contentNode.getProperty(JCR_DATA)
.getBinary();
String dsChecksum = binary.getHexHash();

return ContentDigest.asURI("SHA-1",dsChecksum);
}

/**
* Get the digest algorithm used to calculate the primary digest of the binary payload
* @return
* @throws RepositoryException
*/
public String getContentDigestType() throws RepositoryException {
return node.getNode(JCR_CONTENT).getProperty(DIGEST_ALGORITHM)
.getString();
public String getContentDigestType() {
try {
return node.getNode(JCR_CONTENT).getProperty(DIGEST_ALGORITHM)
.getString();
} catch (RepositoryException e) {
logger.error("Could not get content digest type - " + e.getMessage());
}
//only supporting sha-1
logger.debug("Using default digest type of SHA-1");
return "SHA-1";
}

/**
Expand Down Expand Up @@ -329,9 +354,25 @@ public Date getCreatedDate() throws RepositoryException {
* @return
* @throws RepositoryException
*/
public Date getLastModifiedDate() throws RepositoryException {
return new Date(node.getProperty(JCR_LASTMODIFIED).getDate()
.getTimeInMillis());
public Date getLastModifiedDate() {
//TODO no modified date stored
//attempt to set as created date?
try {
return new Date(node.getProperty(JCR_LASTMODIFIED).getDate()
.getTimeInMillis());
} catch (RepositoryException e) {
logger.error("Could not get last modified date");
}
logger.debug("Setting modified date");
try {
Date createdDate = getCreatedDate();
node.setProperty(JCR_LASTMODIFIED, createdDate.toString());
node.getSession().save();
return createdDate;
} catch(RepositoryException e) {
logger.error("Could not set new modified date - " + e.getMessage());
}
return null;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions fcrepo-kernel/src/main/java/org/fcrepo/services/PathService.java
Expand Up @@ -14,6 +14,8 @@
public abstract class PathService {

public static final String OBJECT_PATH = "/objects";

public static final String FEDERATED_PATH = "/federated";

private static final Logger logger = getLogger(PathService.class);

Expand All @@ -37,4 +39,24 @@ public static String getDatastreamJcrNodePath(final String pid,
" and dsId: " + dsId);
return getObjectJcrNodePath(pid) + "/" + dsId;
}

/**
* @param pid
* @return The federated JCR path to this object's backing node.
*/
public static String getFederatedNodePath(String pid) {
logger.trace("Executing getFederatedNodePath() with pid: " + pid);
return FEDERATED_PATH + "/" + pid;
}

/**
* @param pid
* @param dsId
* @return The federated JCR path to this datastream's backing node.
*/
public static String getFederatedDsNodePath(String pid, String dsId) {
logger.trace("Executing getFederatedDsNodePath() with pid: " + pid +
" and dsId: " + dsId);
return getFederatedNodePath(pid) + "/" + dsId;
}
}
Expand Up @@ -42,6 +42,8 @@ private void setupInitialNodes() throws RepositoryException {
final Session s = repository.login();
final Node objectStore =
new JcrTools(true).findOrCreateNode(s, "/objects");
final Node federatedStore =
new JcrTools(true).findOrCreateNode(s, "/federated");

if (objectStore.canAddMixin("fedora:objectStore")) {
objectStore.addMixin("fedora:objectStore");
Expand All @@ -50,6 +52,14 @@ private void setupInitialNodes() throws RepositoryException {
objectStore.setProperty("fedora:size", 0L);
}
}

if(federatedStore.canAddMixin("fedora:objectStore")) {
federatedStore.addMixin("fedora:objectStore");

if(!federatedStore.hasProperty("fedora:size")) {
federatedStore.setProperty("fedora:size", 0L);
}
}

s.save();
s.logout();
Expand Down
11 changes: 11 additions & 0 deletions pom.xml
Expand Up @@ -823,6 +823,17 @@
</roles>
<timezone>-4</timezone>
</developer>
<developer>
<id>vincentng</id>
<name>Vincent Nguyen</name>
<email>vng0 @ (domain of organization url)</email>
<organization>US Centers for Disease Control and Prevention</organization>
<organizationUrl>http://stacks.cdc.gov/</organizationUrl>
<roles>
<role>developer</role>
</roles>
<timezone>-5</timezone>
</developer>
<developer>
<id>nigelgbanks</id>
<name>Nigel Banks</name>
Expand Down

0 comments on commit c12ccde

Please sign in to comment.