From c2c829c8018cbedc479ba44bb6a2e3589ebe7c76 Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Mon, 12 Nov 2018 10:32:49 +0100 Subject: [PATCH 1/7] Adapt parsing Bagit Profile due to specification. (https://github.com/bagit-profiles/bagit-profiles) Inclusion of "Contact-Name," "Contact-Phone" and "Contact-Email," as defined in the BagIt spec, is not required but is encouraged. -> Add "Contact-Phone" -> "Contact-Name" and "Contact-Email" are now optional Add test for minimal profile Adapt other tests. Bag-Info: The parameters "required" is 'false' and "repeatable" is 'true' by default. Changed implementation accordingly. ("repeatable": Not used yet inside the library!?) --- .../profile/BagInfoRequirement.java | 10 +- .../conformance/profile/BagitProfile.java | 13 +- .../profile/BagitProfileDeserializer.java | 155 ++++++++------- src/main/resources/MessageBundle.properties | 1 + .../resources/MessageBundle_ar.properties | 1 + .../resources/MessageBundle_de_DE.properties | 1 + .../resources/MessageBundle_es_ES.properties | 1 + .../resources/MessageBundle_zh.properties | 1 + .../profile/AbstractBagitProfileTest.java | 49 +++-- .../profile/BagitProfileDeserializerTest.java | 26 +++ .../conformance/profile/BagitProfileTest.java | 5 + .../bagitProfiles/exampleProfile.json | 180 ++++++++++-------- .../exampleProfileOnlyRequiredFields.json | 91 +++++++++ 13 files changed, 367 insertions(+), 167 deletions(-) create mode 100644 src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java index 155c2ab03..e9656f9a8 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java @@ -8,9 +8,9 @@ * This class is used to define elements in a bag-info.txt file used by a bagit-profile. */ public class BagInfoRequirement { - private boolean required; + private boolean required = false; private List acceptableValues = new ArrayList<>(); - private boolean repeatable; + private boolean repeatable = true; @Override public boolean equals(final Object other) { @@ -37,6 +37,12 @@ public BagInfoRequirement(final boolean required, final List acceptableV this.acceptableValues = acceptableValues; } + public BagInfoRequirement(final boolean required, final List acceptableValues, boolean repeatable){ + this.required = required; + this.acceptableValues = acceptableValues; + this.repeatable = repeatable; + } + @Override public String toString() { return "[required=" + required + ", acceptableValues=" + acceptableValues + ", repeatable=" + repeatable + "]"; diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java index 1ed5158a9..2470a5cbb 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java @@ -16,6 +16,7 @@ public class BagitProfile { private String externalDescription = ""; private String contactName = ""; private String contactEmail = ""; + private String contactPhone = ""; private String version = ""; private Map bagInfoRequirements = new HashMap<>(); @@ -38,6 +39,7 @@ public boolean equals(final Object other) { && Objects.equals(sourceOrganization, castOther.sourceOrganization) && Objects.equals(externalDescription, castOther.externalDescription) && Objects.equals(contactName, castOther.contactName) && Objects.equals(contactEmail, castOther.contactEmail) + && Objects.equals(contactPhone, castOther.contactPhone) && Objects.equals(version, castOther.version) && Objects.equals(bagInfoRequirements, castOther.bagInfoRequirements) && Objects.equals(manifestTypesRequired, castOther.manifestTypesRequired) @@ -50,15 +52,14 @@ public boolean equals(final Object other) { } @Override public int hashCode() { - return Objects.hash(bagitProfileIdentifier, sourceOrganization, externalDescription, contactName, contactEmail, - version, bagInfoRequirements, manifestTypesRequired, fetchFileAllowed, serialization, + return Objects.hash(bagitProfileIdentifier, sourceOrganization, externalDescription, contactName, contactEmail, contactPhone, version, bagInfoRequirements, manifestTypesRequired, fetchFileAllowed, serialization, acceptableMIMESerializationTypes, acceptableBagitVersions, tagManifestTypesRequired, tagFilesRequired); } @Override public String toString() { return "BagitProfile [bagitProfileIdentifier=" + bagitProfileIdentifier + ", sourceOrganization=" + sourceOrganization + ", externalDescription=" + externalDescription + ", contactName=" + contactName - + ", contactEmail=" + contactEmail + ", version=" + version + ", bagInfoRequirements=" + bagInfoRequirements + + ", contactEmail=" + contactEmail + ", contactPhone=" + contactPhone + ", version=" + version + ", bagInfoRequirements=" + bagInfoRequirements + ", manifestTypesRequired=" + manifestTypesRequired + ", fetchFileAllowed=" + fetchFileAllowed + ", serialization=" + serialization + ", acceptableMIMESerializationTypes=" + acceptableMIMESerializationTypes + ", acceptableBagitVersions=" + acceptableBagitVersions + ", tagManifestTypesRequired=" @@ -143,6 +144,12 @@ public String getContactEmail() { public void setContactEmail(final String contactEmail) { this.contactEmail = contactEmail; } + public String getContactPhone() { + return contactPhone; + } + public void setContactPhone(String contactPhone) { + this.contactPhone = contactPhone; + } public String getVersion() { return version; } diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java index 4684d02bc..928d8e86c 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java @@ -19,9 +19,10 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer; /** - * Deserialize bagit profile json to a {@link BagitProfile} + * Deserialize bagit profile json to a {@link BagitProfile} */ public class BagitProfileDeserializer extends StdDeserializer { + private static final long serialVersionUID = 1L; private static final Logger logger = LoggerFactory.getLogger(BagitProfileDeserializer.class); private static final ResourceBundle messages = ResourceBundle.getBundle("MessageBundle"); @@ -36,149 +37,173 @@ public BagitProfileDeserializer(final Class vc) { @Override public BagitProfile deserialize(final JsonParser p, final DeserializationContext ctxt) - throws IOException, JsonProcessingException { + throws IOException, JsonProcessingException { final BagitProfile profile = new BagitProfile(); final JsonNode node = p.getCodec().readTree(p); - + parseBagitProfileInfo(node, profile); - + profile.setBagInfoRequirements(parseBagInfo(node)); - + profile.getManifestTypesRequired().addAll(parseManifestTypesRequired(node)); - + profile.setFetchFileAllowed(node.get("Allow-Fetch.txt").asBoolean()); logger.debug(messages.getString("fetch_allowed"), profile.isFetchFileAllowed()); - + profile.setSerialization(Serialization.valueOf(node.get("Serialization").asText())); - logger.debug(messages.getString("serialization_allowed"),profile.getSerialization()); - + logger.debug(messages.getString("serialization_allowed"), profile.getSerialization()); + profile.getAcceptableMIMESerializationTypes().addAll(parseAcceptableSerializationFormats(node)); - + profile.getTagManifestTypesRequired().addAll(parseRequiredTagmanifestTypes(node)); - + profile.getTagFilesRequired().addAll(parseRequiredTagFiles(node)); - + profile.getAcceptableBagitVersions().addAll(parseAcceptableVersions(node)); - + return profile; } - - private static void parseBagitProfileInfo(final JsonNode node, final BagitProfile profile){ + + private static void parseBagitProfileInfo(final JsonNode node, final BagitProfile profile) { final JsonNode bagitProfileInfoNode = node.get("BagIt-Profile-Info"); logger.debug(messages.getString("parsing_bagit_profile_info_section")); - + + // Read required tags first + // due to specification defined at https://github.com/bagit-profiles/bagit-profiles final String profileIdentifier = bagitProfileInfoNode.get("BagIt-Profile-Identifier").asText(); logger.debug(messages.getString("identifier"), profileIdentifier); profile.setBagitProfileIdentifier(profileIdentifier); - + final String sourceOrg = bagitProfileInfoNode.get("Source-Organization").asText(); logger.debug(messages.getString("source_organization"), sourceOrg); profile.setSourceOrganization(sourceOrg); - - final String contactName = bagitProfileInfoNode.get("Contact-Name").asText(); - logger.debug(messages.getString("contact_name"), contactName); - profile.setContactName(contactName); - - final String contactEmail = bagitProfileInfoNode.get("Contact-Email").asText(); - logger.debug(messages.getString("contact_email"), contactEmail); - profile.setContactEmail(contactEmail); - + final String extDescript = bagitProfileInfoNode.get("External-Description").asText(); logger.debug(messages.getString("external_description"), extDescript); profile.setExternalDescription(extDescript); - + final String version = bagitProfileInfoNode.get("Version").asText(); logger.debug(messages.getString("version"), version); profile.setVersion(version); + + final JsonNode contactNameNode = bagitProfileInfoNode.get("Contact-Name"); + if (contactNameNode != null) { + final String contactName = contactNameNode.asText(); + logger.debug(messages.getString("contact_name"), contactName); + profile.setContactName(contactName); + } + + final JsonNode contactEmailNode = bagitProfileInfoNode.get("Contact-Email"); + if (contactEmailNode != null) { + final String contactEmail = contactEmailNode.asText(); + logger.debug(messages.getString("contact_email"), contactEmail); + profile.setContactEmail(contactEmail); + } + + final JsonNode contactPhoneNode = bagitProfileInfoNode.get("Contact-Phone"); + if (contactPhoneNode != null) { + final String contactPhone = contactPhoneNode.asText(); + logger.debug(messages.getString("contact_phone"), contactPhone); + profile.setContactPhone(contactPhone); + } } - + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") - private static Map parseBagInfo(final JsonNode rootNode){ + private static Map parseBagInfo(final JsonNode rootNode) { final JsonNode bagInfoNode = rootNode.get("Bag-Info"); logger.debug(messages.getString("parsing_bag_info")); - final Map bagInfo = new HashMap<>(); - + final Map bagInfo = new HashMap<>(); + final Iterator> nodes = bagInfoNode.fields(); //stuck in java 6... - - while(nodes.hasNext()){ + + while (nodes.hasNext()) { final Entry node = nodes.next(); - + final BagInfoRequirement entry = new BagInfoRequirement(); - entry.setRequired(node.getValue().get("required").asBoolean()); - + // due to specification required is false by default. + final JsonNode requiredNode = node.getValue().get("required"); + if (requiredNode != null) { + entry.setRequired(requiredNode.asBoolean()); + } + final JsonNode valuesNode = node.getValue().get("values"); - if(valuesNode != null){ - for(final JsonNode value : valuesNode){ + if (valuesNode != null) { + for (final JsonNode value : valuesNode) { entry.getAcceptableValues().add(value.asText()); } } - + + final JsonNode repeatableNode = node.getValue().get("repeatable"); + if (repeatableNode != null) { + entry.setRepeatable(repeatableNode.asBoolean()); + } + logger.debug("{}: {}", node.getKey(), entry); bagInfo.put(node.getKey(), entry); } - + return bagInfo; } - - private static List parseManifestTypesRequired(final JsonNode node){ + + private static List parseManifestTypesRequired(final JsonNode node) { final JsonNode manifests = node.get("Manifests-Required"); - + final List manifestTypes = new ArrayList<>(); - + for (final JsonNode manifestName : manifests) { manifestTypes.add(manifestName.asText()); } - + logger.debug(messages.getString("required_manifest_types"), manifestTypes); - + return manifestTypes; } - - private static List parseAcceptableSerializationFormats(final JsonNode node){ + + private static List parseAcceptableSerializationFormats(final JsonNode node) { final JsonNode serialiationFormats = node.get("Accept-Serialization"); final List serialTypes = new ArrayList<>(); - + for (final JsonNode serialiationFormat : serialiationFormats) { serialTypes.add(serialiationFormat.asText()); } logger.debug(messages.getString("acceptable_serialization_mime_types"), serialTypes); - + return serialTypes; } - - private static List parseRequiredTagmanifestTypes(final JsonNode node){ + + private static List parseRequiredTagmanifestTypes(final JsonNode node) { final JsonNode tagManifestsRequiredNodes = node.get("Tag-Manifests-Required"); final List requiredTagmanifestTypes = new ArrayList<>(); - - for(final JsonNode tagManifestsRequiredNode : tagManifestsRequiredNodes){ + + for (final JsonNode tagManifestsRequiredNode : tagManifestsRequiredNodes) { requiredTagmanifestTypes.add(tagManifestsRequiredNode.asText()); } logger.debug(messages.getString("required_tagmanifest_types"), requiredTagmanifestTypes); - + return requiredTagmanifestTypes; } - - private static List parseRequiredTagFiles(final JsonNode node){ + + private static List parseRequiredTagFiles(final JsonNode node) { final JsonNode tagFilesRequiredNodes = node.get("Tag-Files-Required"); final List requiredTagFiles = new ArrayList<>(); - - for(final JsonNode tagFilesRequiredNode : tagFilesRequiredNodes){ + + for (final JsonNode tagFilesRequiredNode : tagFilesRequiredNodes) { requiredTagFiles.add(tagFilesRequiredNode.asText()); } logger.debug(messages.getString("tag_files_required"), requiredTagFiles); - + return requiredTagFiles; } - - private static List parseAcceptableVersions(final JsonNode node){ + + private static List parseAcceptableVersions(final JsonNode node) { final JsonNode acceptableVersionsNodes = node.get("Accept-BagIt-Version"); final List acceptableVersions = new ArrayList<>(); - - for(final JsonNode acceptableVersionsNode : acceptableVersionsNodes){ + + for (final JsonNode acceptableVersionsNode : acceptableVersionsNodes) { acceptableVersions.add(acceptableVersionsNode.asText()); } logger.debug(messages.getString("acceptable_bagit_versions"), acceptableVersions); - + return acceptableVersions; } } diff --git a/src/main/resources/MessageBundle.properties b/src/main/resources/MessageBundle.properties index 4973bd2e8..a77720d16 100644 --- a/src/main/resources/MessageBundle.properties +++ b/src/main/resources/MessageBundle.properties @@ -8,6 +8,7 @@ identifier=Identifier is [{}] source_organization=Source-Organization is [{}] contact_name=Contact-Name is [{}] contact_email=Contact-Email is [{}] +contact_phone=Contact-Phone is [{}] external_description=External-Description is [{}] version=Version is [{}] parsing_bag_info=Parsing the Bag-Info section diff --git a/src/main/resources/MessageBundle_ar.properties b/src/main/resources/MessageBundle_ar.properties index 34868ae7f..4bb857652 100644 --- a/src/main/resources/MessageBundle_ar.properties +++ b/src/main/resources/MessageBundle_ar.properties @@ -9,6 +9,7 @@ identifier=Identifier is [{}] source_organization=Source-Organization is [{}] contact_name=Contact-Name is [{}] contact_email=Contact-Email is [{}] +contact_phone=Contact-Phone is [{}] external_description=External-Description is [{}] version=Version is [{}] parsing_bag_info=Parsing the Bag-Info section diff --git a/src/main/resources/MessageBundle_de_DE.properties b/src/main/resources/MessageBundle_de_DE.properties index e7488a22d..a0a29095b 100644 --- a/src/main/resources/MessageBundle_de_DE.properties +++ b/src/main/resources/MessageBundle_de_DE.properties @@ -8,6 +8,7 @@ identifier=Identifier hat den Wert [{}] source_organization=Source-Organization hat den Wert [{}] contact_name=Contact-Name hat den Wert [{}] contact_email=Contact-Email hat den Wert [{}] +contact_phone=Contact-Phone hat den Wert [{}] external_description=External-Description hat den Wert [{}] version=Version hat den Wert [{}] parsing_bag_info=Lese Abschnitt Bag-Info diff --git a/src/main/resources/MessageBundle_es_ES.properties b/src/main/resources/MessageBundle_es_ES.properties index c63efd1d3..16f23fd86 100644 --- a/src/main/resources/MessageBundle_es_ES.properties +++ b/src/main/resources/MessageBundle_es_ES.properties @@ -9,6 +9,7 @@ identifier=Identificador es [{}] source_organization=Organizaci\u00f3n de la fuente es [{}] contact_name=Nombre del contacto es [{}] contact_email=Email del contacto es [{}] +contact_phone=Tel\u00e9fono de contacto es [{}] external_description=Descripci\u00f3n externa es [{}] version=La versi\u00f3n es [{}] parsing_bag_info=An\u00e1lisis de la secci\u00f3n de la bag-info diff --git a/src/main/resources/MessageBundle_zh.properties b/src/main/resources/MessageBundle_zh.properties index 34868ae7f..4bb857652 100644 --- a/src/main/resources/MessageBundle_zh.properties +++ b/src/main/resources/MessageBundle_zh.properties @@ -9,6 +9,7 @@ identifier=Identifier is [{}] source_organization=Source-Organization is [{}] contact_name=Contact-Name is [{}] contact_email=Contact-Email is [{}] +contact_phone=Contact-Phone is [{}] external_description=External-Description is [{}] version=Version is [{}] parsing_bag_info=Parsing the Bag-Info section diff --git a/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java b/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java index 3bba614eb..230751b30 100644 --- a/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java +++ b/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java @@ -26,6 +26,27 @@ protected BagitProfile createExpectedProfile(){ expectedProfile.setBagitProfileIdentifier("http://canadiana.org/standards/bagit/tdr_ingest.json"); expectedProfile.setContactEmail("tdr@canadiana.com"); expectedProfile.setContactName("William Wueppelmann"); + expectedProfile.setContactPhone("+1 613 907 7040"); + expectedProfile.setExternalDescription("BagIt profile for ingesting content into the C.O. TDR loading dock."); + expectedProfile.setSourceOrganization("Candiana.org"); + expectedProfile.setVersion("1.2"); + + expectedProfile.setBagInfoRequirements(createBagInfo()); + expectedProfile.setManifestTypesRequired(Arrays.asList("md5")); + expectedProfile.setFetchFileAllowed(false); + expectedProfile.setSerialization(Serialization.forbidden); + expectedProfile.setAcceptableMIMESerializationTypes(Arrays.asList("application/zip")); + expectedProfile.setAcceptableBagitVersions(Arrays.asList("0.96")); + expectedProfile.setTagManifestTypesRequired(Arrays.asList("md5")); + expectedProfile.setTagFilesRequired(Arrays.asList("DPN/dpnFirstNode.txt", "DPN/dpnRegistry")); + + return expectedProfile; + } + + protected BagitProfile createMinimalProfile(){ + BagitProfile expectedProfile = new BagitProfile(); + + expectedProfile.setBagitProfileIdentifier("http://canadiana.org/standards/bagit/tdr_ingest.json"); expectedProfile.setExternalDescription("BagIt profile for ingesting content into the C.O. TDR loading dock."); expectedProfile.setSourceOrganization("Candiana.org"); expectedProfile.setVersion("1.2"); @@ -45,21 +66,21 @@ protected BagitProfile createExpectedProfile(){ protected Map createBagInfo(){ Map info = new HashMap<>(); - info.put("Source-Organization", new BagInfoRequirement(true, Arrays.asList("Simon Fraser University", "York University"))); + info.put("Source-Organization", new BagInfoRequirement(true, Arrays.asList("Simon Fraser University", "York University"), false)); info.put("Organization-Address", new BagInfoRequirement(true, - Arrays.asList("8888 University Drive Burnaby, B.C. V5A 1S6 Canada", "4700 Keele Street Toronto, Ontario M3J 1P3 Canada"))); - info.put("Contact-Name", new BagInfoRequirement(true, Arrays.asList("Mark Jordan", "Nick Ruest"))); - info.put("Contact-Phone", new BagInfoRequirement(false, Arrays.asList())); - info.put("Contact-Email", new BagInfoRequirement(true, Arrays.asList())); - info.put("External-Description", new BagInfoRequirement(true, Arrays.asList())); - info.put("External-Identifier", new BagInfoRequirement(false, Arrays.asList())); - info.put("Bag-Size", new BagInfoRequirement(true, Arrays.asList())); - info.put("Bag-Group-Identifier", new BagInfoRequirement(false, Arrays.asList())); - info.put("Bag-Count", new BagInfoRequirement(true, Arrays.asList())); - info.put("Internal-Sender-Identifier", new BagInfoRequirement(false, Arrays.asList())); - info.put("Internal-Sender-Description", new BagInfoRequirement(false, Arrays.asList())); - info.put("Bagging-Date", new BagInfoRequirement(true, Arrays.asList())); - info.put("Payload-Oxum", new BagInfoRequirement(true, Arrays.asList())); + Arrays.asList("8888 University Drive Burnaby, B.C. V5A 1S6 Canada", "4700 Keele Street Toronto, Ontario M3J 1P3 Canada"), false)); + info.put("Contact-Name", new BagInfoRequirement(true, Arrays.asList("Mark Jordan", "Nick Ruest"), false)); + info.put("Contact-Phone", new BagInfoRequirement(false, Arrays.asList(), false)); + info.put("Contact-Email", new BagInfoRequirement(true, Arrays.asList(), false)); + info.put("External-Description", new BagInfoRequirement(true, Arrays.asList(), false)); + info.put("External-Identifier", new BagInfoRequirement(false, Arrays.asList(), false)); + info.put("Bag-Size", new BagInfoRequirement(true, Arrays.asList(), false)); + info.put("Bag-Group-Identifier", new BagInfoRequirement(false, Arrays.asList(), false)); + info.put("Bag-Count", new BagInfoRequirement(true, Arrays.asList(), false)); + info.put("Internal-Sender-Identifier", new BagInfoRequirement(false, Arrays.asList(), false)); + info.put("Internal-Sender-Description", new BagInfoRequirement(false, Arrays.asList(), false)); + info.put("Bagging-Date", new BagInfoRequirement(true, Arrays.asList(), false)); + info.put("Payload-Oxum", new BagInfoRequirement(true, Arrays.asList(), false)); return info; } diff --git a/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java b/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java index 1073a2f68..8ac1e2f9e 100644 --- a/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java +++ b/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java @@ -20,6 +20,7 @@ public void testDeserialize() throws Exception{ Assertions.assertEquals(expectedProfile.getBagitProfileIdentifier(), profile.getBagitProfileIdentifier()); Assertions.assertEquals(expectedProfile.getContactEmail(), profile.getContactEmail()); Assertions.assertEquals(expectedProfile.getContactName(), profile.getContactName()); + Assertions.assertEquals(expectedProfile.getContactPhone(), profile.getContactPhone()); Assertions.assertEquals(expectedProfile.getExternalDescription(), profile.getExternalDescription()); Assertions.assertEquals(expectedProfile.getManifestTypesRequired(), profile.getManifestTypesRequired()); Assertions.assertEquals(expectedProfile.getSerialization(), profile.getSerialization()); @@ -30,5 +31,30 @@ public void testDeserialize() throws Exception{ Assertions.assertEquals(expectedProfile.hashCode(), profile.hashCode()); } + @Test + public void testDeserializeWithoutOptionalTags() throws Exception{ + BagitProfile minimalProfile = createMinimalProfile(); + + BagitProfile profile = mapper.readValue(new File("src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json"), BagitProfile.class); + System.err.println(minimalProfile.toString()); + System.err.println(profile.toString()); + Assertions.assertEquals(minimalProfile, profile); + Assertions.assertEquals(minimalProfile.getAcceptableBagitVersions(), profile.getAcceptableBagitVersions()); + Assertions.assertEquals(minimalProfile.getAcceptableMIMESerializationTypes(), profile.getAcceptableMIMESerializationTypes()); + Assertions.assertEquals(minimalProfile.getBagInfoRequirements(), profile.getBagInfoRequirements()); + Assertions.assertEquals(minimalProfile.getBagitProfileIdentifier(), profile.getBagitProfileIdentifier()); + Assertions.assertEquals(minimalProfile.getContactEmail(), profile.getContactEmail()); + Assertions.assertEquals(minimalProfile.getContactName(), profile.getContactName()); + Assertions.assertEquals(minimalProfile.getContactPhone(), profile.getContactPhone()); + Assertions.assertEquals(minimalProfile.getExternalDescription(), profile.getExternalDescription()); + Assertions.assertEquals(minimalProfile.getManifestTypesRequired(), profile.getManifestTypesRequired()); + Assertions.assertEquals(minimalProfile.getSerialization(), profile.getSerialization()); + Assertions.assertEquals(minimalProfile.getSourceOrganization(), profile.getSourceOrganization()); + Assertions.assertEquals(minimalProfile.getTagFilesRequired(), profile.getTagFilesRequired()); + Assertions.assertEquals(minimalProfile.getTagManifestTypesRequired(), profile.getTagManifestTypesRequired()); + Assertions.assertEquals(minimalProfile.getVersion(), profile.getVersion()); + Assertions.assertEquals(minimalProfile.hashCode(), profile.hashCode()); + } + } diff --git a/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileTest.java b/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileTest.java index f9f844ce0..958da1fe3 100644 --- a/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileTest.java +++ b/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileTest.java @@ -16,6 +16,7 @@ public void testToString() throws Exception{ + "externalDescription=BagIt profile for ingesting content into the C.O. TDR loading dock., " + "contactName=William Wueppelmann, " + "contactEmail=tdr@canadiana.com, " + + "contactPhone=+1 613 907 7040, " + "version=1.2, " + "bagInfoRequirements={" + "Payload-Oxum=[required=true, acceptableValues=[], repeatable=false], " @@ -71,6 +72,10 @@ public void testEquals(){ differentContactEmail.setContactEmail("foo"); Assertions.assertFalse(profile.equals(differentContactEmail)); + BagitProfile differentContactPhone = createExpectedProfile(); + differentContactPhone.setContactPhone("foo"); + Assertions.assertFalse(profile.equals(differentContactPhone)); + BagitProfile differentVersion = createExpectedProfile(); differentVersion.setVersion("foo"); Assertions.assertFalse(profile.equals(differentVersion)); diff --git a/src/test/resources/bagitProfiles/exampleProfile.json b/src/test/resources/bagitProfiles/exampleProfile.json index a86d1a74e..6a7db5135 100644 --- a/src/test/resources/bagitProfiles/exampleProfile.json +++ b/src/test/resources/bagitProfiles/exampleProfile.json @@ -1,85 +1,99 @@ { - "BagIt-Profile-Info":{ - "BagIt-Profile-Identifier":"http://canadiana.org/standards/bagit/tdr_ingest.json", - "Source-Organization":"Candiana.org", - "Contact-Name":"William Wueppelmann", - "Contact-Email":"tdr@canadiana.com", - "External-Description":"BagIt profile for ingesting content into the C.O. TDR loading dock.", - "Version":"1.2" - }, - "Bag-Info":{ - "Source-Organization":{ - "required":true, - "values":[ - "Simon Fraser University", - "York University" - ] - }, - "Organization-Address":{ - "required":true, - "values":[ - "8888 University Drive Burnaby, B.C. V5A 1S6 Canada", - "4700 Keele Street Toronto, Ontario M3J 1P3 Canada" - ] - }, - "Contact-Name":{ - "required":true, - "values":[ - "Mark Jordan", - "Nick Ruest" - ] - }, - "Contact-Phone":{ - "required":false - }, - "Contact-Email":{ - "required":true - }, - "External-Description":{ - "required":true - }, - "External-Identifier":{ - "required":false - }, - "Bag-Size":{ - "required":true - }, - "Bag-Group-Identifier":{ - "required":false - }, - "Bag-Count":{ - "required":true - }, - "Internal-Sender-Identifier":{ - "required":false - }, - "Internal-Sender-Description":{ - "required":false - }, - "Bagging-Date":{ - "required":true, - "repeatable": false - }, - "Payload-Oxum":{ - "required":true - } - }, - "Manifests-Required":[ - "md5" - ], - "Allow-Fetch.txt":false, - "Serialization":"forbidden", - "Accept-Serialization":[ - "application/zip" - ], - "Tag-Manifests-Required":[ - "md5" - ], - "Tag-Files-Required":[ - "DPN/dpnFirstNode.txt", - "DPN/dpnRegistry" - ], - "Accept-BagIt-Version":[ - "0.96" - ] + "BagIt-Profile-Info": { + "BagIt-Profile-Identifier": "http://canadiana.org/standards/bagit/tdr_ingest.json", + "Source-Organization": "Candiana.org", + "Contact-Name": "William Wueppelmann", + "Contact-Email": "tdr@canadiana.com", + "Contact-Phone": "+1 613 907 7040", + "External-Description": "BagIt profile for ingesting content into the C.O. TDR loading dock.", + "Version": "1.2" + }, + "Bag-Info": { + "Source-Organization": { + "required": true, + "values": [ + "Simon Fraser University", + "York University" + ], + "repeatable": false + }, + "Organization-Address": { + "required": true, + "values": [ + "8888 University Drive Burnaby, B.C. V5A 1S6 Canada", + "4700 Keele Street Toronto, Ontario M3J 1P3 Canada" + ], + "repeatable": false + }, + "Contact-Name": { + "required": true, + "values": [ + "Mark Jordan", + "Nick Ruest" + ], + "repeatable": false + }, + "Contact-Phone": { + "required": false, + "repeatable": false + }, + "Contact-Email": { + "required": true, + "repeatable": false + }, + "External-Description": { + "required": true, + "repeatable": false + }, + "External-Identifier": { + "required": false, + "repeatable": false + }, + "Bag-Size": { + "required": true, + "repeatable": false + }, + "Bag-Group-Identifier": { + "required": false, + "repeatable": false + }, + "Bag-Count": { + "required": true, + "repeatable": false + }, + "Internal-Sender-Identifier": { + "required": false, + "repeatable": false + }, + "Internal-Sender-Description": { + "required": false, + "repeatable": false + }, + "Bagging-Date": { + "required": true, + "repeatable": false + }, + "Payload-Oxum": { + "required": true, + "repeatable": false + } + }, + "Manifests-Required": [ + "md5" + ], + "Allow-Fetch.txt": false, + "Serialization": "forbidden", + "Accept-Serialization": [ + "application/zip" + ], + "Tag-Manifests-Required": [ + "md5" + ], + "Tag-Files-Required": [ + "DPN/dpnFirstNode.txt", + "DPN/dpnRegistry" + ], + "Accept-BagIt-Version": [ + "0.96" + ] } \ No newline at end of file diff --git a/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json b/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json new file mode 100644 index 000000000..d7df949ed --- /dev/null +++ b/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json @@ -0,0 +1,91 @@ +{ + "BagIt-Profile-Info": { + "BagIt-Profile-Identifier": "http://canadiana.org/standards/bagit/tdr_ingest.json", + "Source-Organization": "Candiana.org", + "External-Description": "BagIt profile for ingesting content into the C.O. TDR loading dock.", + "Version": "1.2" + }, + "Bag-Info": { + "Source-Organization": { + "required": true, + "values": [ + "Simon Fraser University", + "York University" + ], + "repeatable": false + }, + "Organization-Address": { + "required": true, + "values": [ + "8888 University Drive Burnaby, B.C. V5A 1S6 Canada", + "4700 Keele Street Toronto, Ontario M3J 1P3 Canada" + ], + "repeatable": false + }, + "Contact-Name": { + "required": true, + "values": [ + "Mark Jordan", + "Nick Ruest" + ], + "repeatable": false + }, + "Contact-Phone": { + "repeatable": false + }, + "Contact-Email": { + "required": true, + "repeatable": false + }, + "External-Description": { + "required": true, + "repeatable": false + }, + "External-Identifier": { + "repeatable": false + }, + "Bag-Size": { + "required": true, + "repeatable": false + }, + "Bag-Group-Identifier": { + "repeatable": false + }, + "Bag-Count": { + "required": true, + "repeatable": false + }, + "Internal-Sender-Identifier": { + "repeatable": false + }, + "Internal-Sender-Description": { + "repeatable": false + }, + "Bagging-Date": { + "required": true, + "repeatable": false + }, + "Payload-Oxum": { + "required": true, + "repeatable": false + } + }, + "Manifests-Required": [ + "md5" + ], + "Allow-Fetch.txt": false, + "Serialization": "forbidden", + "Accept-Serialization": [ + "application/zip" + ], + "Tag-Manifests-Required": [ + "md5" + ], + "Tag-Files-Required": [ + "DPN/dpnFirstNode.txt", + "DPN/dpnRegistry" + ], + "Accept-BagIt-Version": [ + "0.96" + ] +} \ No newline at end of file From af27481317748f843fa7b3156021aa68eac32945 Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Mon, 12 Nov 2018 10:52:01 +0100 Subject: [PATCH 2/7] Fix due to PMD. --- .../bagit/conformance/profile/BagInfoRequirement.java | 4 ++-- .../repository/bagit/conformance/profile/BagitProfile.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java index e9656f9a8..559d19cbf 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java @@ -8,7 +8,7 @@ * This class is used to define elements in a bag-info.txt file used by a bagit-profile. */ public class BagInfoRequirement { - private boolean required = false; + private boolean required; private List acceptableValues = new ArrayList<>(); private boolean repeatable = true; @@ -37,7 +37,7 @@ public BagInfoRequirement(final boolean required, final List acceptableV this.acceptableValues = acceptableValues; } - public BagInfoRequirement(final boolean required, final List acceptableValues, boolean repeatable){ + public BagInfoRequirement(final boolean required, final List acceptableValues, final boolean repeatable){ this.required = required; this.acceptableValues = acceptableValues; this.repeatable = repeatable; diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java index 2470a5cbb..d7eb29933 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfile.java @@ -147,7 +147,7 @@ public void setContactEmail(final String contactEmail) { public String getContactPhone() { return contactPhone; } - public void setContactPhone(String contactPhone) { + public void setContactPhone(final String contactPhone) { this.contactPhone = contactPhone; } public String getVersion() { From db411d0088307f9f93bb1a845fe54ed08b2bd678 Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Mon, 12 Nov 2018 14:13:43 +0100 Subject: [PATCH 3/7] Bagit-Profile: Make field "Tag-Manifests-Required" optional --- .../conformance/profile/BagitProfileDeserializer.java | 7 ++++--- .../conformance/profile/AbstractBagitProfileTest.java | 1 - .../bagitProfiles/exampleProfileOnlyRequiredFields.json | 3 --- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java index 928d8e86c..c637e3d73 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java @@ -174,9 +174,10 @@ private static List parseAcceptableSerializationFormats(final JsonNode n private static List parseRequiredTagmanifestTypes(final JsonNode node) { final JsonNode tagManifestsRequiredNodes = node.get("Tag-Manifests-Required"); final List requiredTagmanifestTypes = new ArrayList<>(); - - for (final JsonNode tagManifestsRequiredNode : tagManifestsRequiredNodes) { - requiredTagmanifestTypes.add(tagManifestsRequiredNode.asText()); + if (tagManifestsRequiredNodes != null) { + for (final JsonNode tagManifestsRequiredNode : tagManifestsRequiredNodes) { + requiredTagmanifestTypes.add(tagManifestsRequiredNode.asText()); + } } logger.debug(messages.getString("required_tagmanifest_types"), requiredTagmanifestTypes); diff --git a/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java b/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java index 230751b30..d143ad4c9 100644 --- a/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java +++ b/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java @@ -57,7 +57,6 @@ protected BagitProfile createMinimalProfile(){ expectedProfile.setSerialization(Serialization.forbidden); expectedProfile.setAcceptableMIMESerializationTypes(Arrays.asList("application/zip")); expectedProfile.setAcceptableBagitVersions(Arrays.asList("0.96")); - expectedProfile.setTagManifestTypesRequired(Arrays.asList("md5")); expectedProfile.setTagFilesRequired(Arrays.asList("DPN/dpnFirstNode.txt", "DPN/dpnRegistry")); return expectedProfile; diff --git a/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json b/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json index d7df949ed..0de856c38 100644 --- a/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json +++ b/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json @@ -78,9 +78,6 @@ "Accept-Serialization": [ "application/zip" ], - "Tag-Manifests-Required": [ - "md5" - ], "Tag-Files-Required": [ "DPN/dpnFirstNode.txt", "DPN/dpnRegistry" From e8e0a77b2ba9a859cb53c31d439eea06dbbb675b Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Mon, 12 Nov 2018 14:23:28 +0100 Subject: [PATCH 4/7] Bagit-Profile: Make field "Tag-Files-Required" optional --- .../bagit/conformance/profile/BagitProfileDeserializer.java | 6 ++++-- .../bagit/conformance/profile/AbstractBagitProfileTest.java | 1 - .../bagitProfiles/exampleProfileOnlyRequiredFields.json | 4 ---- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java index c637e3d73..0da8c7f31 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java @@ -188,8 +188,10 @@ private static List parseRequiredTagFiles(final JsonNode node) { final JsonNode tagFilesRequiredNodes = node.get("Tag-Files-Required"); final List requiredTagFiles = new ArrayList<>(); - for (final JsonNode tagFilesRequiredNode : tagFilesRequiredNodes) { - requiredTagFiles.add(tagFilesRequiredNode.asText()); + if (tagFilesRequiredNodes != null) { + for (final JsonNode tagFilesRequiredNode : tagFilesRequiredNodes) { + requiredTagFiles.add(tagFilesRequiredNode.asText()); + } } logger.debug(messages.getString("tag_files_required"), requiredTagFiles); diff --git a/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java b/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java index d143ad4c9..59d91c460 100644 --- a/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java +++ b/src/test/java/gov/loc/repository/bagit/conformance/profile/AbstractBagitProfileTest.java @@ -57,7 +57,6 @@ protected BagitProfile createMinimalProfile(){ expectedProfile.setSerialization(Serialization.forbidden); expectedProfile.setAcceptableMIMESerializationTypes(Arrays.asList("application/zip")); expectedProfile.setAcceptableBagitVersions(Arrays.asList("0.96")); - expectedProfile.setTagFilesRequired(Arrays.asList("DPN/dpnFirstNode.txt", "DPN/dpnRegistry")); return expectedProfile; } diff --git a/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json b/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json index 0de856c38..dead840fb 100644 --- a/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json +++ b/src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json @@ -78,10 +78,6 @@ "Accept-Serialization": [ "application/zip" ], - "Tag-Files-Required": [ - "DPN/dpnFirstNode.txt", - "DPN/dpnRegistry" - ], "Accept-BagIt-Version": [ "0.96" ] From 856ee4ea9df994fae329c3a82f35bd83bdf1a7e6 Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Mon, 12 Nov 2018 14:28:41 +0100 Subject: [PATCH 5/7] Remove output to error console. --- .../bagit/conformance/profile/BagitProfileDeserializerTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java b/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java index 8ac1e2f9e..30a6b3031 100644 --- a/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java +++ b/src/test/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializerTest.java @@ -36,8 +36,6 @@ public void testDeserializeWithoutOptionalTags() throws Exception{ BagitProfile minimalProfile = createMinimalProfile(); BagitProfile profile = mapper.readValue(new File("src/test/resources/bagitProfiles/exampleProfileOnlyRequiredFields.json"), BagitProfile.class); - System.err.println(minimalProfile.toString()); - System.err.println(profile.toString()); Assertions.assertEquals(minimalProfile, profile); Assertions.assertEquals(minimalProfile.getAcceptableBagitVersions(), profile.getAcceptableBagitVersions()); Assertions.assertEquals(minimalProfile.getAcceptableMIMESerializationTypes(), profile.getAcceptableMIMESerializationTypes()); From f2e4ab1e515106e128fa2227f57e133a5db9ae1f Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Tue, 13 Nov 2018 14:48:59 +0100 Subject: [PATCH 6/7] Changes according to the comments. --- .../conformance/profile/BagInfoRequirement.java | 12 +++++++++++- .../profile/BagitProfileDeserializer.java | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java index 559d19cbf..25da68ca6 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagInfoRequirement.java @@ -31,12 +31,22 @@ public int hashCode() { public BagInfoRequirement(){ //intentionally left empty } - + /** + * Constructs a new BagInfoRequirement setting {@link #repeatable} to true (default). + * @param required Indicates whether or not the tag is required. + * @param acceptableValues List of acceptable values. + */ public BagInfoRequirement(final boolean required, final List acceptableValues){ this.required = required; this.acceptableValues = acceptableValues; } + /** + * Constructs a new BagInfoRequirement. + * @param required Indicates whether or not the tag is required. + * @param acceptableValues List of acceptable values. + * @param repeatable Indicates whether or not the tag is repeatable. + */ public BagInfoRequirement(final boolean required, final List acceptableValues, final boolean repeatable){ this.required = required; this.acceptableValues = acceptableValues; diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java index 0da8c7f31..6934be65b 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java @@ -68,7 +68,7 @@ private static void parseBagitProfileInfo(final JsonNode node, final BagitProfil final JsonNode bagitProfileInfoNode = node.get("BagIt-Profile-Info"); logger.debug(messages.getString("parsing_bagit_profile_info_section")); - // Read required tags first + // Read required tags // due to specification defined at https://github.com/bagit-profiles/bagit-profiles final String profileIdentifier = bagitProfileInfoNode.get("BagIt-Profile-Identifier").asText(); logger.debug(messages.getString("identifier"), profileIdentifier); @@ -86,6 +86,7 @@ private static void parseBagitProfileInfo(final JsonNode node, final BagitProfil logger.debug(messages.getString("version"), version); profile.setVersion(version); + // Read optional tags final JsonNode contactNameNode = bagitProfileInfoNode.get("Contact-Name"); if (contactNameNode != null) { final String contactName = contactNameNode.asText(); From e6ce9a79ec749004e0da6dc843fbfdbcc0a8c4db Mon Sep 17 00:00:00 2001 From: Volker Hartmann Date: Thu, 15 Nov 2018 08:34:04 +0100 Subject: [PATCH 7/7] Split the parsing of the BagIt-Profile-Info section into mandatory and optional tags. --- .../profile/BagitProfileDeserializer.java | 31 ++++++++++++++++--- src/main/resources/MessageBundle.properties | 2 ++ .../resources/MessageBundle_ar.properties | 2 ++ .../resources/MessageBundle_de_DE.properties | 2 ++ .../resources/MessageBundle_es_ES.properties | 2 ++ .../resources/MessageBundle_zh.properties | 2 ++ 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java index 6934be65b..3d48bec68 100644 --- a/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java +++ b/src/main/java/gov/loc/repository/bagit/conformance/profile/BagitProfileDeserializer.java @@ -65,11 +65,24 @@ public BagitProfile deserialize(final JsonParser p, final DeserializationContext } private static void parseBagitProfileInfo(final JsonNode node, final BagitProfile profile) { - final JsonNode bagitProfileInfoNode = node.get("BagIt-Profile-Info"); logger.debug(messages.getString("parsing_bagit_profile_info_section")); + + final JsonNode bagitProfileInfoNode = node.get("BagIt-Profile-Info"); + parseMandatoryTagsOfBagitProfileInfo(bagitProfileInfoNode, profile); + parseOptionalTagsOfBagitProfileInfo(bagitProfileInfoNode, profile); + } - // Read required tags - // due to specification defined at https://github.com/bagit-profiles/bagit-profiles + /** + * Parse required tags due to specification defined at + * {@link https://github.com/bagit-profiles/bagit-profiles} + * Note: If one of the tags is missing, a NullPointerException is thrown. + * + * @param bagitProfileInfoNode Root node of the bagit profile info section. + * @param profile Representation of bagit profile. + */ + private static void parseMandatoryTagsOfBagitProfileInfo(final JsonNode bagitProfileInfoNode, final BagitProfile profile) { + logger.debug(messages.getString("parsing_mandatory_tags_of_bagit_profile_info_section")); + final String profileIdentifier = bagitProfileInfoNode.get("BagIt-Profile-Identifier").asText(); logger.debug(messages.getString("identifier"), profileIdentifier); profile.setBagitProfileIdentifier(profileIdentifier); @@ -85,8 +98,18 @@ private static void parseBagitProfileInfo(final JsonNode node, final BagitProfil final String version = bagitProfileInfoNode.get("Version").asText(); logger.debug(messages.getString("version"), version); profile.setVersion(version); + } + + /** + * Parse optional tags due to specification defined at + * {@link https://github.com/bagit-profiles/bagit-profiles} + * + * @param bagitProfileInfoNode Root node of the bagit profile info section. + * @param profile Representation of bagit profile . + */ + private static void parseOptionalTagsOfBagitProfileInfo(final JsonNode bagitProfileInfoNode, final BagitProfile profile) { + logger.debug(messages.getString("parsing_optional_tags_of_bagit_profile_info_section")); - // Read optional tags final JsonNode contactNameNode = bagitProfileInfoNode.get("Contact-Name"); if (contactNameNode != null) { final String contactName = contactNameNode.asText(); diff --git a/src/main/resources/MessageBundle.properties b/src/main/resources/MessageBundle.properties index a77720d16..e8e1a3701 100644 --- a/src/main/resources/MessageBundle.properties +++ b/src/main/resources/MessageBundle.properties @@ -4,6 +4,8 @@ fetch_allowed=Are fetch files allowed? [{}] serialization_allowed=Serialization is: [{}] parsing_bagit_profile_info_section=Parsing the BagIt-Profile-Info section +parsing_mandatory_tags_of_bagit_profile_info_section=Parsing mandatory tags of the BagIt-Profile-Info section +parsing_optional_tags_of_bagit_profile_info_section=Parsing optional tags of the BagIt-Profile-Info section identifier=Identifier is [{}] source_organization=Source-Organization is [{}] contact_name=Contact-Name is [{}] diff --git a/src/main/resources/MessageBundle_ar.properties b/src/main/resources/MessageBundle_ar.properties index 4bb857652..81353903e 100644 --- a/src/main/resources/MessageBundle_ar.properties +++ b/src/main/resources/MessageBundle_ar.properties @@ -5,6 +5,8 @@ fetch_allowed=Are fetch files allowed? [{}] serialization_allowed=Serialization is\: [{}] parsing_bagit_profile_info_section=Parsing the BagIt-Profile-Info section +parsing_mandatory_tags_of_bagit_profile_info_section=Parsing mandatory tags of the BagIt-Profile-Info section +parsing_optional_tags_of_bagit_profile_info_section=Parsing optional tags of the BagIt-Profile-Info section identifier=Identifier is [{}] source_organization=Source-Organization is [{}] contact_name=Contact-Name is [{}] diff --git a/src/main/resources/MessageBundle_de_DE.properties b/src/main/resources/MessageBundle_de_DE.properties index a0a29095b..7386be7f6 100644 --- a/src/main/resources/MessageBundle_de_DE.properties +++ b/src/main/resources/MessageBundle_de_DE.properties @@ -4,6 +4,8 @@ fetch_allowed=Sind Fetch Dateien erlaubt? [{}] serialization_allowed=Serialisierung ist: [{}] parsing_bagit_profile_info_section=Lese Abschnitt BagIt-Profile-Info +parsing_mandatory_tags_of_bagit_profile_info_section=Parse die ben\u00f6tigten Tags im Abschnitt BagIt-Profile-Info +parsing_optional_tags_of_bagit_profile_info_section=Parse die optionalen Tags im Abschnitt BagIt-Profile-Info identifier=Identifier hat den Wert [{}] source_organization=Source-Organization hat den Wert [{}] contact_name=Contact-Name hat den Wert [{}] diff --git a/src/main/resources/MessageBundle_es_ES.properties b/src/main/resources/MessageBundle_es_ES.properties index 16f23fd86..38af9cee7 100644 --- a/src/main/resources/MessageBundle_es_ES.properties +++ b/src/main/resources/MessageBundle_es_ES.properties @@ -5,6 +5,8 @@ fetch_allowed=\u00bfSe permiten archivos de recuperaci\u00f3n? [{}] serialization_allowed=Serializaci\u00f3n es\: [{}] parsing_bagit_profile_info_section=An\u00e1lisis de la secci\u00f3n de informaci\u00f3n de perfil BagIt +parsing_mandatory_tags_of_bagit_profile_info_section=An\u00e1lisis de las etiquetas obligatorias de la secci\u00f3n de informaci\u00f3n de perfil BagIt +parsing_optional_tags_of_bagit_profile_info_section=An\u00e1lisis de las etiquetas opcionales de la secci\u00f3n de informaci\u00f3n de perfil BagIt identifier=Identificador es [{}] source_organization=Organizaci\u00f3n de la fuente es [{}] contact_name=Nombre del contacto es [{}] diff --git a/src/main/resources/MessageBundle_zh.properties b/src/main/resources/MessageBundle_zh.properties index 4bb857652..81353903e 100644 --- a/src/main/resources/MessageBundle_zh.properties +++ b/src/main/resources/MessageBundle_zh.properties @@ -5,6 +5,8 @@ fetch_allowed=Are fetch files allowed? [{}] serialization_allowed=Serialization is\: [{}] parsing_bagit_profile_info_section=Parsing the BagIt-Profile-Info section +parsing_mandatory_tags_of_bagit_profile_info_section=Parsing mandatory tags of the BagIt-Profile-Info section +parsing_optional_tags_of_bagit_profile_info_section=Parsing optional tags of the BagIt-Profile-Info section identifier=Identifier is [{}] source_organization=Source-Organization is [{}] contact_name=Contact-Name is [{}]