Search in sources :

Example 1 with RequiredManifestNotPresentException

use of gov.loc.repository.bagit.exceptions.conformance.RequiredManifestNotPresentException in project bagit-java by LibraryOfCongress.

the class BagProfileChecker method requiredManifestsExist.

@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
private static void requiredManifestsExist(final Set<Manifest> manifests, final List<String> requiredManifestTypes, final boolean isPayloadManifest) throws RequiredManifestNotPresentException {
    final Set<String> manifestTypesPresent = new HashSet<>();
    logger.debug(messages.getString("check_required_manifests_present"));
    for (final Manifest manifest : manifests) {
        manifestTypesPresent.add(manifest.getAlgorithm().getBagitName());
    }
    for (final String requiredManifestType : requiredManifestTypes) {
        if (!manifestTypesPresent.contains(requiredManifestType)) {
            final StringBuilder sb = new StringBuilder();
            if (isPayloadManifest) {
                sb.append("tag");
                sb.append(MessageFormatter.format(messages.getString("required_tag_manifest_type_not_present"), requiredManifestType).getMessage());
            } else {
                sb.append(MessageFormatter.format(messages.getString("required_manifest_type_not_present"), requiredManifestType).getMessage());
            }
            throw new RequiredManifestNotPresentException(sb.toString());
        }
    }
}
Also used : Manifest(gov.loc.repository.bagit.domain.Manifest) HashSet(java.util.HashSet) RequiredManifestNotPresentException(gov.loc.repository.bagit.exceptions.conformance.RequiredManifestNotPresentException)

Aggregations

Manifest (gov.loc.repository.bagit.domain.Manifest)1 RequiredManifestNotPresentException (gov.loc.repository.bagit.exceptions.conformance.RequiredManifestNotPresentException)1 HashSet (java.util.HashSet)1