Skip to content

Commit

Permalink
fix up FedoraDatastreams to use new getFixity method
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 12, 2013
1 parent 7951f90 commit 9e7976c
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions fcrepo-http-api/src/main/java/org/fcrepo/api/FedoraDatastreams.java
Expand Up @@ -10,7 +10,7 @@
import static org.fcrepo.api.FedoraObjects.getObjectSize;
import static org.fcrepo.jaxb.responses.management.DatastreamProfile.DatastreamStates.A;
import static org.fcrepo.services.DatastreamService.createDatastreamNode;
import static org.fcrepo.services.LowLevelStorageService.getBlobs;
import static org.fcrepo.services.LowLevelStorageService.getFixity;
import static org.fcrepo.services.ObjectService.getObjectNode;
import static org.fcrepo.services.PathService.getDatastreamJcrNodePath;
import static org.fcrepo.services.PathService.getObjectJcrNodePath;
Expand Down Expand Up @@ -67,6 +67,7 @@
import org.fcrepo.services.DatastreamService;
import org.fcrepo.services.LowLevelStorageService;
import org.fcrepo.utils.ContentDigest;
import org.fcrepo.utils.FixityResult;
import org.fcrepo.utils.LowLevelCacheStore;
import org.modeshape.common.util.StringUtil;
import org.modeshape.jcr.api.Binary;
Expand Down Expand Up @@ -467,57 +468,44 @@ public DatastreamFixity getDatastreamFixity(@PathParam("pid")
*/
private DatastreamFixity validatedDatastreamFixity(Datastream ds) throws RepositoryException {
Node node = ds.getNode();
Map<LowLevelCacheStore, InputStream> blobs = getBlobs(node);
//compute size and checksum
//get properties for comparison
URI dsChecksum = ds.getContentDigest();
long dsSize = ds.getContentSize();
String dsChecksumStr = ContentDigest.asChecksumString(dsChecksum);

DatastreamFixity dsf = new DatastreamFixity();
dsf.statuses = new ArrayList<FixityStatus>(blobs.size());
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
logger.error("Could not locate a SHA1 provider: Everything is ruined.",e);
throw new RepositoryException(e.getMessage(),e);
}

Map<LowLevelCacheStore, FixityResult> blobs = getFixity(node, digest);
dsf.statuses = new ArrayList<FixityStatus>(blobs.size());

for (LowLevelCacheStore key: blobs.keySet()){
FixityStatus status = new FixityStatus();
status.validChecksum = false;
status.validSize = false;
status.dsChecksumType = ds.getContentDigestType();
status.dsChecksum = dsChecksum;
status.dsSize = dsSize;
InputStream in = blobs.get(key);
byte [] buf = new byte[1024];
int len = -1;
int read = 0;
digest.reset();
try {
while ((len = in.read(buf)) > -1){
digest.update(buf, 0, len);
read += len;
}
in.close();
} catch (IOException e) {
logger.error("Could not read blobs for datastream: Everything is ruined,", e);
throw new RepositoryException(e.getMessage(),e);
}

byte [] digestBytes = digest.digest();
String compChecksum = StringUtil.getHexString(digestBytes);
long compSize = read;
status.computedSize = compSize;
status.computedChecksum = compChecksum.toString();
logger.debug("Computed checksum: " + compChecksum);
logger.debug("Computed size is " + compSize);

if (compChecksum.toString().equals(dsChecksumStr)) {

FixityResult result = blobs.get(key);


status.computedSize = result.computedSize;
status.computedChecksum = result.computedChecksum;
logger.debug("Computed checksum: " + result.computedChecksum);
logger.debug("Computed size is " + result.computedSize);

if (result.computedChecksum.toString().equals(dsChecksumStr)) {
status.validChecksum = true;
}
if (compSize == dsSize) {
if (result.computedSize == dsSize) {
status.validSize = true;
}
dsf.statuses.add(status);
Expand Down

0 comments on commit 9e7976c

Please sign in to comment.