Example usage for com.amazonaws.util CollectionUtils isNullOrEmpty

List of usage examples for com.amazonaws.util CollectionUtils isNullOrEmpty

Introduction

In this page you can find the example usage for com.amazonaws.util CollectionUtils isNullOrEmpty.

Prototype

public static <T> boolean isNullOrEmpty(Collection<T> collection) 

Source Link

Usage

From source file:org.duracloud.chunk.util.ChunksManifestVerifier.java

License:Apache License

/**
 * Verifies the bytes and checksums of the chunks specified in the manifest
 * match what is in DuraCloud and returns a listing of the chunks with a flag
 * indicating whether the check was successful as well as an error message if it
 * was not. You can use the result.isSuccess() method as a shortcut for determining
 * whether all the items in the manifest matched on another.
 *
 * @param spaceId/*  w  w w.java 2  s  .  co m*/
 * @param manifest
 * @return a list of results - one for each chunk.
 * @throws ContentStoreException
 */
public Results verifyAllChunks(String spaceId, ChunksManifest manifest) {

    Results results = new Results();
    for (ManifestEntry entry : manifest.getEntries()) {
        String chunkId = entry.getChunkId();
        String checksum = entry.getChunkMD5();
        long byteSize = entry.getByteSize();

        try {
            Map<String, String> props = this.contentStore.getContentProperties(spaceId, entry.getChunkId());
            String remoteChecksum = props.get(ContentStore.CONTENT_CHECKSUM);
            long remoteByteSize = Long.valueOf(props.get(ContentStore.CONTENT_SIZE));

            if (!checksum.equals(remoteChecksum)) {
                results.add(chunkId, "manifest checksum (" + checksum + ") does not match DuraCloud checksum ("
                        + remoteChecksum + ")", false);
            } else if (byteSize != remoteByteSize) {
                results.add(chunkId, "manifest byte size (" + byteSize
                        + ") does not match DuraCloud byte size (" + remoteByteSize + ")", false);
            } else {
                results.add(chunkId, null, true);
            }

        } catch (Exception ex) {
            results.add(chunkId, ex.getMessage(), false);
        }
    }

    if (CollectionUtils.isNullOrEmpty(results.get())) {
        throw new DuraCloudRuntimeException("failed to retrieve any chunks at list in chunk manifest:  "
                + spaceId + "/" + manifest.getManifestId());
    } else {
        return results;
    }
}