From 7df959bcd9c710babd5c24e005d52e1f7f99d54a Mon Sep 17 00:00:00 2001 From: michael-conway Date: Thu, 30 Mar 2017 13:04:22 -0400 Subject: [PATCH] #21 remove formbased template distinction --- .../MetadataTemplateFormBotService.java | 387 +++++++----------- .../irods/jargon/formbot/package-info.java | 2 +- .../JargonMetadataExporter.java | 80 ++-- .../JargonMetadataResolver.java | 307 +++++++------- .../metadatatemplate/MetadataMergeResult.java | 12 +- .../MetadataTemplateConfiguration.java | 58 --- .../MetadataTemplateFileFilter.java | 9 +- .../JargonMetadataExporterTest.java | 333 ++++++--------- .../JargonMetadataResolverTest.java | 70 ++-- .../metadatatemplate/unittest/AllTests.java | 3 +- .../unittest/package-info.java | 1 + 11 files changed, 500 insertions(+), 762 deletions(-) delete mode 100644 metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateConfiguration.java diff --git a/metadata-templates/src/main/java/org/irods/jargon/formbot/MetadataTemplateFormBotService.java b/metadata-templates/src/main/java/org/irods/jargon/formbot/MetadataTemplateFormBotService.java index f3984ca..ec436f8 100644 --- a/metadata-templates/src/main/java/org/irods/jargon/formbot/MetadataTemplateFormBotService.java +++ b/metadata-templates/src/main/java/org/irods/jargon/formbot/MetadataTemplateFormBotService.java @@ -11,19 +11,10 @@ import org.irods.jargon.core.pub.IRODSAccessObjectFactory; import org.irods.jargon.core.pub.io.IRODSFileFactoryImpl; import org.irods.jargon.core.service.AbstractJargonService; -import org.irods.jargon.formbot.FormBotExecutionEnum; -import org.irods.jargon.formbot.FormBotExecutionResult; -import org.irods.jargon.formbot.FormBotField; -import org.irods.jargon.formbot.FormBotForm; -import org.irods.jargon.formbot.FormBotService; -import org.irods.jargon.formbot.FormBotValidationEnum; -import org.irods.jargon.formbot.FormBotValidationResult; -import org.irods.jargon.formbot.FormElementEnum; import org.irods.jargon.metadatatemplate.JargonMetadataExporter; import org.irods.jargon.metadatatemplate.JargonMetadataResolver; import org.irods.jargon.metadatatemplate.MetadataElement; import org.irods.jargon.metadatatemplate.MetadataTemplate; -import org.irods.jargon.metadatatemplate.FormBasedMetadataTemplate; import org.irods.jargon.metadatatemplate.MetadataTemplateParsingException; import org.irods.jargon.metadatatemplate.MetadataTemplateProcessingException; import org.irods.jargon.metadatatemplate.TemplateTypeEnum; @@ -38,15 +29,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; -public class MetadataTemplateFormBotService extends AbstractJargonService - implements FormBotService { - static private Logger log = LoggerFactory - .getLogger(IRODSFileFactoryImpl.class); +public class MetadataTemplateFormBotService extends AbstractJargonService implements FormBotService { + static private Logger log = LoggerFactory.getLogger(IRODSFileFactoryImpl.class); static private ObjectMapper objectMapper = new ObjectMapper(); @Override // public FormBotForm buildFormBotForm(String json) { - public String buildFormBotForm(String json) { + public String buildFormBotForm(final String json) { JsonNode node = null; @@ -56,9 +45,9 @@ public String buildFormBotForm(String json) { log.error("IOException: Failed to parse input JSON to JsonNode"); } - if (!(node.has("uuid") || node.has("fqName") || (node.has("name") && node - .has("activeDir")))) { - log.error("Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); + if (!(node.has("uuid") || node.has("fqName") || (node.has("name") && node.has("activeDir")))) { + log.error( + "Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); // return null; return ""; } @@ -70,12 +59,9 @@ public String buildFormBotForm(String json) { FormBotForm form = new FormBotForm(); try { - resolver = new JargonMetadataResolver(irodsAccount, - irodsAccessObjectFactory); + resolver = new JargonMetadataResolver(irodsAccount, irodsAccessObjectFactory); } catch (JargonException e) { - log.error( - "JargonException: JargonMetadataResolver could not be created", - e); + log.error("JargonException: JargonMetadataResolver could not be created", e); } if (resolver == null) { @@ -86,18 +72,16 @@ public String buildFormBotForm(String json) { try { if (node.has("uuid")) { - template = resolver.findTemplateByUUID(node.get("uuid") - .asText()); + template = resolver.findTemplateByUUID(node.get("uuid").asText()); } else if (node.has("fqName")) { - template = resolver.findTemplateByFqName(node.get("fqName") - .asText()); + template = resolver.findTemplateByFqName(node.get("fqName").asText()); } else if (node.has("name") && node.has("activeDir")) { - template = resolver.findTemplateByName(node.get("name") - .asText(), node.get("activeDir").asText()); + template = resolver.findTemplateByName(node.get("name").asText(), node.get("activeDir").asText()); } else { // This should already have been caught above, but // replicated here for completeness - log.error("Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); + log.error( + "Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); // return null; return ""; } @@ -126,7 +110,7 @@ public String buildFormBotForm(String json) { form.setUniqueId(uuidString); if (template.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate fbmt = (FormBasedMetadataTemplate) template; + MetadataTemplate fbmt = template; for (MetadataElement me : fbmt.getElements()) { FormBotField field = new FormBotField(); field.setName(me.getName()); @@ -247,7 +231,7 @@ public String buildFormBotForm(String json) { @Override // public FormBotValidationResult validateFormBotField(String json) { - public String validateFormBotField(String json) { + public String validateFormBotField(final String json) { JsonNode node = null; FormBotValidationResult validationResult = null; String returnJson = ""; @@ -258,8 +242,7 @@ public String validateFormBotField(String json) { log.error("IOException: Failed to parse input JSON to JsonNode"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Bad JSON"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, "Bad JSON"); + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Bad JSON"); try { returnJson = objectMapper.writeValueAsString(validationResult); } catch (JsonProcessingException e1) { @@ -267,13 +250,13 @@ public String validateFormBotField(String json) { } } - if (!(node.has("value") && (node.has("fieldUniqueName") || (node - .has("formUniqueName") && node.has("fieldName"))))) { - log.error("Insufficient information to find validate field: json must contain value and either fieldUniqueName, or formUniqueName AND fieldName"); + if (!(node.has("value") + && (node.has("fieldUniqueName") || (node.has("formUniqueName") && node.has("fieldName"))))) { + log.error( + "Insufficient information to find validate field: json must contain value and either fieldUniqueName, or formUniqueName AND fieldName"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Bad JSON"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, "Bad JSON"); + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Bad JSON"); try { returnJson = objectMapper.writeValueAsString(validationResult); } catch (JsonProcessingException e) { @@ -286,16 +269,12 @@ public String validateFormBotField(String json) { MetadataTemplate template = null; try { - resolver = new JargonMetadataResolver(irodsAccount, - irodsAccessObjectFactory); + resolver = new JargonMetadataResolver(irodsAccount, irodsAccessObjectFactory); } catch (JargonException e) { - log.error( - "JargonException: JargonMetadataResolver could not be created", - e); + log.error("JargonException: JargonMetadataResolver could not be created", e); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Could not create JargonMetadataResolver"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Could not create JargonMetadataResolver"); try { returnJson = objectMapper.writeValueAsString(validationResult); @@ -332,11 +311,11 @@ public String validateFormBotField(String json) { } else { // This should already have been caught above, but // replicated here for completeness - log.error("Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); + log.error( + "Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Insufficient information to find metadata template"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Insufficient information to find metadata template"); try { returnJson = objectMapper.writeValueAsString(validationResult); @@ -352,8 +331,7 @@ public String validateFormBotField(String json) { log.error("MetadataTemplateParsingException: Error parsing metadata template"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Error parsing metadata template"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Error parsing metadata template"); try { returnJson = objectMapper.writeValueAsString(validationResult); @@ -365,8 +343,7 @@ public String validateFormBotField(String json) { log.error("FileNotFoundException: Metadata template not found"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Metadata template not found"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, "Metadata template not found"); + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Metadata template not found"); try { returnJson = objectMapper.writeValueAsString(validationResult); } catch (JsonProcessingException e1) { @@ -377,8 +354,7 @@ public String validateFormBotField(String json) { log.error("MetadataTemplateProcessingException: Error processing metadata template"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Error processing metadata template"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Error processing metadata template"); try { returnJson = objectMapper.writeValueAsString(validationResult); @@ -390,8 +366,7 @@ public String validateFormBotField(String json) { log.error("IOException: Error reading metadata template from disk"); // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Error reading metadata template from disk"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Error reading metadata template from disk"); try { returnJson = objectMapper.writeValueAsString(validationResult); @@ -402,13 +377,12 @@ public String validateFormBotField(String json) { } if (template.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate fbmt = (FormBasedMetadataTemplate) template; + MetadataTemplate fbmt = template; for (MetadataElement me : fbmt.getElements()) { if (me.getName().equalsIgnoreCase(fieldName)) { me.setCurrentValue(value); - ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR - .validate(irodsAccount, irodsAccessObjectFactory, - me); + ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR.validate(irodsAccount, + irodsAccessObjectFactory, me); FormBotValidationEnum fbv; if (validationReturn == ValidationReturnEnum.SUCCESS) { @@ -422,11 +396,9 @@ public String validateFormBotField(String json) { // return new FormBotValidationResult(fbv, // validationReturn.toString()); - validationResult = new FormBotValidationResult(fbv, - validationReturn.toString()); + validationResult = new FormBotValidationResult(fbv, validationReturn.toString()); try { - returnJson = objectMapper - .writeValueAsString(validationResult); + returnJson = objectMapper.writeValueAsString(validationResult); } catch (JsonProcessingException e) { log.error("JsonProcessingException when writing FormBotValidationResult to json String"); } @@ -437,8 +409,7 @@ public String validateFormBotField(String json) { // return new FormBotValidationResult(FormBotValidationEnum.ERROR, // "Field not found"); - validationResult = new FormBotValidationResult( - FormBotValidationEnum.ERROR, "Field not found"); + validationResult = new FormBotValidationResult(FormBotValidationEnum.ERROR, "Field not found"); try { returnJson = objectMapper.writeValueAsString(validationResult); } catch (JsonProcessingException e) { @@ -449,7 +420,7 @@ public String validateFormBotField(String json) { @Override // public List validateFormBotForm(String json) { - public String validateFormBotForm(String json) { + public String validateFormBotForm(final String json) { JsonNode node = null; List fieldNames = null; List> fieldValues = null; @@ -461,8 +432,7 @@ public String validateFormBotForm(String json) { node = objectMapper.readValue(json, JsonNode.class); } catch (IOException e) { log.error("IOException: Failed to parse input JSON to JsonNode"); - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, "Bad JSON")); + returnList.add(new FormBotValidationResult(FormBotValidationEnum.ERROR, "Bad JSON")); // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); @@ -473,9 +443,9 @@ public String validateFormBotForm(String json) { } if (!(node.has("formUniqueName") && node.has("fields"))) { - log.error("Insufficient information to find metadata template and fields: json must contain formUniqueName and fields elements"); - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, "Bad JSON")); + log.error( + "Insufficient information to find metadata template and fields: json must contain formUniqueName and fields elements"); + returnList.add(new FormBotValidationResult(FormBotValidationEnum.ERROR, "Bad JSON")); // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); @@ -489,18 +459,14 @@ public String validateFormBotForm(String json) { MetadataTemplate template = null; try { - resolver = new JargonMetadataResolver(irodsAccount, - irodsAccessObjectFactory); + resolver = new JargonMetadataResolver(irodsAccount, irodsAccessObjectFactory); } catch (JargonException e) { - log.error( - "JargonException: JargonMetadataResolver could not be created", - e); + log.error("JargonException: JargonMetadataResolver could not be created", e); } if (resolver == null) { log.error("Unable to instantiate JargonMetadataResolver"); - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, + returnList.add(new FormBotValidationResult(FormBotValidationEnum.ERROR, "Unable to instantiate JargonMetadataResolver")); // return returnList; try { @@ -523,10 +489,8 @@ public String validateFormBotForm(String json) { fieldNames.add(fieldNode.get("fieldName").asText()); if (fieldNode.get("value").isArray()) { - ArrayNode valuesNode = (ArrayNode) fieldNode - .get("value"); - Iterator valuesIterator = valuesNode - .elements(); + ArrayNode valuesNode = (ArrayNode) fieldNode.get("value"); + Iterator valuesIterator = valuesNode.elements(); while (valuesIterator.hasNext()) { JsonNode valueNode = valuesIterator.next(); value.add(valueNode.asText()); @@ -541,13 +505,10 @@ public String validateFormBotForm(String json) { } try { - template = resolver.findTemplateByUUID(node.get("formUniqueName") - .asText()); + template = resolver.findTemplateByUUID(node.get("formUniqueName").asText()); } catch (MetadataTemplateParsingException e) { log.error("MetadataTemplateParsingException: Error parsing metadata template"); - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, - "Error parsing metadata template")); + returnList.add(new FormBotValidationResult(FormBotValidationEnum.ERROR, "Error parsing metadata template")); // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); @@ -557,10 +518,7 @@ public String validateFormBotForm(String json) { return returnJson; } catch (FileNotFoundException e) { log.error("FileNotFoundException: Metadata template not found"); - returnList - .add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, - "Metadata template not found")); + returnList.add(new FormBotValidationResult(FormBotValidationEnum.ERROR, "Metadata template not found")); // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); @@ -570,9 +528,8 @@ public String validateFormBotForm(String json) { return returnJson; } catch (MetadataTemplateProcessingException e) { log.error("MetadataTemplateProcessingException: Error processing metadata template"); - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, - "Error processing metadata template")); + returnList.add( + new FormBotValidationResult(FormBotValidationEnum.ERROR, "Error processing metadata template")); // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); @@ -582,8 +539,7 @@ public String validateFormBotForm(String json) { return returnJson; } catch (IOException e) { log.error("IOException: Error reading metadata template from disk"); - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.ERROR, + returnList.add(new FormBotValidationResult(FormBotValidationEnum.ERROR, "Error reading metadata template from disk")); // return returnList; try { @@ -597,26 +553,23 @@ public String validateFormBotForm(String json) { boolean validationFailed = false; if (template.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate fbmt = (FormBasedMetadataTemplate) template; + MetadataTemplate fbmt = template; for (int i = 0; i < fieldNames.size(); i++) { for (MetadataElement me : fbmt.getElements()) { String fieldName = fieldNames.get(i); List value = fieldValues.get(i); if (me.getName().equalsIgnoreCase(fieldName)) { me.setCurrentValue(value); - ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR - .validate(irodsAccount, - irodsAccessObjectFactory, me); + ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR.validate(irodsAccount, + irodsAccessObjectFactory, me); if ((validationReturn == ValidationReturnEnum.SUCCESS) || (validationReturn == ValidationReturnEnum.NOT_VALIDATED) || (validationReturn == ValidationReturnEnum.REGEX_SYNTAX_ERROR)) { - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.SUCCESS, + returnList.add(new FormBotValidationResult(FormBotValidationEnum.SUCCESS, validationReturn.toString())); break; } else { - returnList.add(new FormBotValidationResult( - FormBotValidationEnum.FAILURE, + returnList.add(new FormBotValidationResult(FormBotValidationEnum.FAILURE, validationReturn.toString())); validationFailed = true; break; @@ -627,13 +580,11 @@ public String validateFormBotForm(String json) { } // TODO else if (other type of MetadataTemplate) if (validationFailed) { - returnList.add(0, new FormBotValidationResult( - FormBotValidationEnum.FAILURE, - "At least one field failed validation")); + returnList.add(0, + new FormBotValidationResult(FormBotValidationEnum.FAILURE, "At least one field failed validation")); } else { - returnList.add(0, new FormBotValidationResult( - FormBotValidationEnum.SUCCESS, - "All fields passed validation")); + returnList.add(0, + new FormBotValidationResult(FormBotValidationEnum.SUCCESS, "All fields passed validation")); } // return returnList; @@ -647,7 +598,7 @@ public String validateFormBotForm(String json) { @Override // public FormBotExecutionResult executeFormBotField(String json) { - public String executeFormBotField(String json) { + public String executeFormBotField(final String json) { JsonNode node = null; FormBotExecutionResult executionResult = null; String returnJson = ""; @@ -656,8 +607,8 @@ public String executeFormBotField(String json) { node = objectMapper.readValue(json, JsonNode.class); } catch (IOException e) { log.error("IOException: Failed to parse input JSON to JsonNode"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Bad JSON"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Bad JSON"); executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Bad JSON"); try { returnJson = objectMapper.writeValueAsString(executionResult); @@ -667,12 +618,12 @@ public String executeFormBotField(String json) { return returnJson; } - if (!(node.has("value") && node.has("pathToObject") && (node - .has("fieldUniqueName") || (node.has("formUniqueName") && node - .has("fieldName"))))) { - log.error("Insufficient information to find validate field: json must contain value and either fieldUniqueName, or formUniqueName AND fieldName"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Bad JSON"); + if (!(node.has("value") && node.has("pathToObject") + && (node.has("fieldUniqueName") || (node.has("formUniqueName") && node.has("fieldName"))))) { + log.error( + "Insufficient information to find validate field: json must contain value and either fieldUniqueName, or formUniqueName AND fieldName"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Bad JSON"); executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Bad JSON"); try { returnJson = objectMapper.writeValueAsString(executionResult); @@ -687,15 +638,13 @@ public String executeFormBotField(String json) { MetadataTemplate template = null; try { - resolver = new JargonMetadataResolver(irodsAccount, - irodsAccessObjectFactory); + resolver = new JargonMetadataResolver(irodsAccount, irodsAccessObjectFactory); } catch (JargonException e) { - log.error( - "JargonException: JargonMetadataResolver could not be created", - e); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Could not create JargonMetadataResolver"); - executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Could not create JargonMetadataResolver"); + log.error("JargonException: JargonMetadataResolver could not be created", e); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Could not create JargonMetadataResolver"); + executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + "Could not create JargonMetadataResolver"); try { returnJson = objectMapper.writeValueAsString(executionResult); } catch (JsonProcessingException e1) { @@ -704,8 +653,7 @@ public String executeFormBotField(String json) { return returnJson; } - exporter = new JargonMetadataExporter(irodsAccessObjectFactory, - irodsAccount); + exporter = new JargonMetadataExporter(irodsAccessObjectFactory, irodsAccount); List value = new ArrayList(); @@ -735,10 +683,12 @@ public String executeFormBotField(String json) { } else { // This should already have been caught above, but // replicated here for completeness - log.error("Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Insufficient information to find metadata template"); - executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Insufficient information to find MetadataTemplate"); + log.error( + "Insufficient information to find metadata template: json must contain a field uuid, fqName, or both name and activeDir"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Insufficient information to find metadata template"); + executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + "Insufficient information to find MetadataTemplate"); try { returnJson = objectMapper.writeValueAsString(executionResult); } catch (JsonProcessingException e1) { @@ -751,8 +701,8 @@ public String executeFormBotField(String json) { template = resolver.findTemplateByUUID(formUuid); } catch (MetadataTemplateParsingException e) { log.error("MetadataTemplateParsingException: Error parsing metadata template"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Error parsing metadata template"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Error parsing metadata template"); executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Error parsing MetadataTemplate"); try { returnJson = objectMapper.writeValueAsString(executionResult); @@ -762,8 +712,8 @@ public String executeFormBotField(String json) { return returnJson; } catch (FileNotFoundException e) { log.error("FileNotFoundException: Metadata template not found"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Metadata template not found"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Metadata template not found"); executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "MetadataTemplate not found"); try { returnJson = objectMapper.writeValueAsString(executionResult); @@ -773,9 +723,10 @@ public String executeFormBotField(String json) { return returnJson; } catch (MetadataTemplateProcessingException e) { log.error("MetadataTemplateProcessingException: Error processing metadata template"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Error processing metadata template"); - executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Error processing MetadataTemplate"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Error processing metadata template"); + executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + "Error processing MetadataTemplate"); try { returnJson = objectMapper.writeValueAsString(executionResult); } catch (JsonProcessingException e1) { @@ -784,9 +735,10 @@ public String executeFormBotField(String json) { return returnJson; } catch (IOException e) { log.error("IOException: Error reading metadata template from disk"); -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Error reading metadata template from disk"); - executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Error reading MetadataTemplate from disk"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Error reading metadata template from disk"); + executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + "Error reading MetadataTemplate from disk"); try { returnJson = objectMapper.writeValueAsString(executionResult); } catch (JsonProcessingException e1) { @@ -796,39 +748,41 @@ public String executeFormBotField(String json) { } if (template.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate fbmt = (FormBasedMetadataTemplate) template; + MetadataTemplate fbmt = template; for (MetadataElement me : fbmt.getElements()) { if (me.getName().equalsIgnoreCase(fieldName)) { me.setCurrentValue(value); - ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR - .validate(irodsAccount, irodsAccessObjectFactory, - me); + ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR.validate(irodsAccount, + irodsAccessObjectFactory, me); if (validationReturn == ValidationReturnEnum.SUCCESS || validationReturn == ValidationReturnEnum.NOT_VALIDATED || validationReturn == ValidationReturnEnum.REGEX_SYNTAX_ERROR) { try { - exporter.saveElementToSystemMetadataOnObject(me, - pathToObject); + exporter.saveElementToSystemMetadataOnObject(me, pathToObject); } catch (JargonException e) { log.error("JargonException when trying to add metadata to data object"); -// return new FormBotExecutionResult( -// FormBotExecutionEnum.ERROR, -// "JargonException when trying to add metadata to data object"); - executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "JargonException when trying to save metadata to iRODS object"); + // return new FormBotExecutionResult( + // FormBotExecutionEnum.ERROR, + // "JargonException when trying to add metadata to + // data object"); + executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + "JargonException when trying to save metadata to iRODS object"); try { returnJson = objectMapper.writeValueAsString(executionResult); } catch (JsonProcessingException e1) { - log.error("JsonProcessingException when writing FormBotValidationResult to json String"); + log.error( + "JsonProcessingException when writing FormBotValidationResult to json String"); } return returnJson; } -// return new FormBotExecutionResult( -// FormBotExecutionEnum.SUCCESS, -// "Metadata added to data object"); - executionResult = new FormBotExecutionResult(FormBotExecutionEnum.SUCCESS, "Metadata added to iRODS object"); + // return new FormBotExecutionResult( + // FormBotExecutionEnum.SUCCESS, + // "Metadata added to data object"); + executionResult = new FormBotExecutionResult(FormBotExecutionEnum.SUCCESS, + "Metadata added to iRODS object"); try { returnJson = objectMapper.writeValueAsString(executionResult); } catch (JsonProcessingException e1) { @@ -836,11 +790,10 @@ public String executeFormBotField(String json) { } return returnJson; } else { - String retString = "Validation failed for field " - + fieldName + " with value " + value; -// return new FormBotExecutionResult( -// FormBotExecutionEnum.VALIDATION_FAILED, -// retString); + String retString = "Validation failed for field " + fieldName + " with value " + value; + // return new FormBotExecutionResult( + // FormBotExecutionEnum.VALIDATION_FAILED, + // retString); executionResult = new FormBotExecutionResult(FormBotExecutionEnum.VALIDATION_FAILED, retString); try { returnJson = objectMapper.writeValueAsString(executionResult); @@ -853,8 +806,8 @@ public String executeFormBotField(String json) { } } // TODO else if (other type of MetadataTemplate) -// return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, -// "Field not found"); + // return new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + // "Field not found"); executionResult = new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Field not found"); try { returnJson = objectMapper.writeValueAsString(executionResult); @@ -866,7 +819,7 @@ public String executeFormBotField(String json) { @Override // public List executeFormBotForm(String json) { - public String executeFormBotForm(String json) { + public String executeFormBotForm(final String json) { JsonNode node = null; List fieldNames = null; List> fieldValues = null; @@ -878,9 +831,8 @@ public String executeFormBotForm(String json) { node = objectMapper.readValue(json, JsonNode.class); } catch (IOException e) { log.error("IOException: Failed to parse input JSON to JsonNode"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, "Bad JSON")); -// return returnList; + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Bad JSON")); + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -889,12 +841,11 @@ public String executeFormBotForm(String json) { return returnJson; } - if (!(node.has("formUniqueName") && node.has("pathToObject") && node - .has("fields"))) { - log.error("Insufficient information to find metadata template and fields: json must contain formUniqueName and fields elements"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, "Bad JSON")); -// return returnList; + if (!(node.has("formUniqueName") && node.has("pathToObject") && node.has("fields"))) { + log.error( + "Insufficient information to find metadata template and fields: json must contain formUniqueName and fields elements"); + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Bad JSON")); + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -908,20 +859,16 @@ public String executeFormBotForm(String json) { MetadataTemplate template = null; try { - resolver = new JargonMetadataResolver(irodsAccount, - irodsAccessObjectFactory); + resolver = new JargonMetadataResolver(irodsAccount, irodsAccessObjectFactory); } catch (JargonException e) { - log.error( - "JargonException: JargonMetadataResolver could not be created", - e); + log.error("JargonException: JargonMetadataResolver could not be created", e); } if (resolver == null) { log.error("Unable to instantiate JargonMetadataResolver"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Unable to instantiate JargonMetadataResolver")); -// return returnList; + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -930,8 +877,7 @@ public String executeFormBotForm(String json) { return returnJson; } - exporter = new JargonMetadataExporter(irodsAccessObjectFactory, - irodsAccount); + exporter = new JargonMetadataExporter(irodsAccessObjectFactory, irodsAccount); String pathToObject = node.get("pathToObject").asText(); String formUuid = node.get("formUniqueName").asText(); @@ -948,10 +894,8 @@ public String executeFormBotForm(String json) { fieldNames.add(fieldNode.get("fieldName").asText()); if (fieldNode.get("value").isArray()) { - ArrayNode valuesNode = (ArrayNode) fieldNode - .get("value"); - Iterator valuesIterator = valuesNode - .elements(); + ArrayNode valuesNode = (ArrayNode) fieldNode.get("value"); + Iterator valuesIterator = valuesNode.elements(); while (valuesIterator.hasNext()) { JsonNode valueNode = valuesIterator.next(); value.add(valueNode.asText()); @@ -969,10 +913,8 @@ public String executeFormBotForm(String json) { template = resolver.findTemplateByUUID(formUuid); } catch (MetadataTemplateParsingException e) { log.error("MetadataTemplateParsingException: Error parsing metadata template"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, - "Error parsing metadata template")); -// return returnList; + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Error parsing metadata template")); + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -981,9 +923,8 @@ public String executeFormBotForm(String json) { return returnJson; } catch (FileNotFoundException e) { log.error("FileNotFoundException: Metadata template not found"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, "Metadata template not found")); -// return returnList; + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Metadata template not found")); + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -992,10 +933,9 @@ public String executeFormBotForm(String json) { return returnJson; } catch (MetadataTemplateProcessingException e) { log.error("MetadataTemplateProcessingException: Error processing metadata template"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, - "Error processing metadata template")); -// return returnList; + returnList + .add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Error processing metadata template")); + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -1004,10 +944,9 @@ public String executeFormBotForm(String json) { return returnJson; } catch (IOException e) { log.error("IOException: Error reading metadata template from disk"); - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "Error reading metadata template from disk")); -// return returnList; + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -1020,39 +959,33 @@ public String executeFormBotForm(String json) { boolean error = false; if (template.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate fbmt = (FormBasedMetadataTemplate) template; + MetadataTemplate fbmt = template; for (int i = 0; i < fieldNames.size(); i++) { for (MetadataElement me : fbmt.getElements()) { String fieldName = fieldNames.get(i); List value = fieldValues.get(i); if (me.getName().equalsIgnoreCase(fieldName)) { me.setCurrentValue(value); - ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR - .validate(irodsAccount, - irodsAccessObjectFactory, me); + ValidationReturnEnum validationReturn = ValidatorSingleton.VALIDATOR.validate(irodsAccount, + irodsAccessObjectFactory, me); if (validationReturn == ValidationReturnEnum.SUCCESS || validationReturn == ValidationReturnEnum.NOT_VALIDATED || validationReturn == ValidationReturnEnum.REGEX_SYNTAX_ERROR) { try { - exporter.saveElementToSystemMetadataOnObject( - me, pathToObject); + exporter.saveElementToSystemMetadataOnObject(me, pathToObject); } catch (JargonException e) { log.error("JargonException when trying to add metadata to data object"); - returnList - .add(new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, - "JargonException when adding metadata to data obj")); + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.ERROR, + "JargonException when adding metadata to data obj")); error = true; break; } - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.SUCCESS, + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.SUCCESS, validationReturn.toString())); break; } else { - returnList.add(new FormBotExecutionResult( - FormBotExecutionEnum.VALIDATION_FAILED, + returnList.add(new FormBotExecutionResult(FormBotExecutionEnum.VALIDATION_FAILED, validationReturn.toString())); validationFailed = true; break; @@ -1063,20 +996,17 @@ public String executeFormBotForm(String json) { } // TODO else if (other type of MetadataTemplate) if (error) { - returnList.add(0, new FormBotExecutionResult( - FormBotExecutionEnum.ERROR, - "At least one field generated an error")); + returnList.add(0, + new FormBotExecutionResult(FormBotExecutionEnum.ERROR, "At least one field generated an error")); } else if (validationFailed) { - returnList.add(0, new FormBotExecutionResult( - FormBotExecutionEnum.VALIDATION_FAILED, + returnList.add(0, new FormBotExecutionResult(FormBotExecutionEnum.VALIDATION_FAILED, "At least one field failed validation")); } else { - returnList.add(0, new FormBotExecutionResult( - FormBotExecutionEnum.SUCCESS, - "Metadata added to iRODS object")); + returnList.add(0, + new FormBotExecutionResult(FormBotExecutionEnum.SUCCESS, "Metadata added to iRODS object")); } -// return returnList; + // return returnList; try { returnJson = objectMapper.writeValueAsString(returnList); } catch (JsonProcessingException e1) { @@ -1089,8 +1019,7 @@ public MetadataTemplateFormBotService() { super(); } - public MetadataTemplateFormBotService( - final IRODSAccessObjectFactory irodsAccessObjectFactory, + public MetadataTemplateFormBotService(final IRODSAccessObjectFactory irodsAccessObjectFactory, final IRODSAccount irodsAccount) { super(irodsAccessObjectFactory, irodsAccount); } diff --git a/metadata-templates/src/main/java/org/irods/jargon/formbot/package-info.java b/metadata-templates/src/main/java/org/irods/jargon/formbot/package-info.java index 1c96e7b..7610248 100644 --- a/metadata-templates/src/main/java/org/irods/jargon/formbot/package-info.java +++ b/metadata-templates/src/main/java/org/irods/jargon/formbot/package-info.java @@ -1,5 +1,5 @@ /** - * + * */ /** * @author rskarbez diff --git a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataExporter.java b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataExporter.java index 7e0e10b..fc047d1 100644 --- a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataExporter.java +++ b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataExporter.java @@ -21,22 +21,20 @@ import org.slf4j.LoggerFactory; public class JargonMetadataExporter extends AbstractMetadataExporter { - static private Logger log = LoggerFactory - .getLogger(IRODSFileFactoryImpl.class); + static private Logger log = LoggerFactory.getLogger(IRODSFileFactoryImpl.class); public JargonMetadataExporter() { super(); } - public JargonMetadataExporter( - final IRODSAccessObjectFactory irodsAccessObjectFactory, + public JargonMetadataExporter(final IRODSAccessObjectFactory irodsAccessObjectFactory, final IRODSAccount irodsAccount) { super(irodsAccessObjectFactory, irodsAccount); } @Override - public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template, - String pathToObject) throws JargonException, FileNotFoundException { + public void saveTemplateToSystemMetadataOnObject(final MetadataTemplate template, final String pathToObject) + throws JargonException, FileNotFoundException { log.info("saveTemplateToSystemMetadataOnObject()"); if (pathToObject == null || pathToObject.isEmpty()) { @@ -47,16 +45,15 @@ public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template, throw new IllegalArgumentException("metadata template is null"); } - IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory( - irodsAccount).instanceIRODSFile(pathToObject); + IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount) + .instanceIRODSFile(pathToObject); if (!irodsObject.exists()) { - throw new FileNotFoundException( - "pathToObject does not resolve to an iRODS object"); + throw new FileNotFoundException("pathToObject does not resolve to an iRODS object"); } /* * FileCatalogObjectAO objectAO = null; - * + * * if (irodsObject.isFile()) { objectAO = * irodsAccessObjectFactory.getDataObjectAO(irodsAccount); } else if * (irodsObject.isDirectory()) { objectAO = @@ -66,9 +63,8 @@ public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template, * ); } */ if (template.getType() == TemplateTypeEnum.FORM_BASED) { - for (MetadataElement me : ((FormBasedMetadataTemplate) template) - .getElements()) { - this.saveElementToSystemMetadataOnObject(me, pathToObject); + for (MetadataElement me : template.getElements()) { + saveElementToSystemMetadataOnObject(me, pathToObject); /* * if (!me.getCurrentValue().isEmpty()) { for (String s : * me.getCurrentValue()) { AvuData avuData = AvuData .instance( @@ -85,8 +81,8 @@ public void saveTemplateToSystemMetadataOnObject(MetadataTemplate template, } @Override - public void saveElementToSystemMetadataOnObject(MetadataElement element, - String pathToObject) throws JargonException, FileNotFoundException { + public void saveElementToSystemMetadataOnObject(final MetadataElement element, final String pathToObject) + throws JargonException, FileNotFoundException { log.info("saveTemplateToSystemMetadataOnObject()"); if (pathToObject == null || pathToObject.isEmpty()) { @@ -97,12 +93,11 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, throw new IllegalArgumentException("metadata element is null"); } - IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory( - irodsAccount).instanceIRODSFile(pathToObject); + IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount) + .instanceIRODSFile(pathToObject); if (!irodsObject.exists()) { - throw new FileNotFoundException( - "pathToObject does not resolve to an iRODS object"); + throw new FileNotFoundException("pathToObject does not resolve to an iRODS object"); } FileCatalogObjectAO objectAO = null; @@ -112,10 +107,8 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, } else if (irodsObject.isDirectory()) { objectAO = irodsAccessObjectFactory.getCollectionAO(irodsAccount); } else { - throw new IllegalArgumentException( - "object at " - + pathToObject - + " is neither a data object nor a collection - the JargonMetadataResolver currently only supports these types of objects"); + throw new IllegalArgumentException("object at " + pathToObject + + " is neither a data object nor a collection - the JargonMetadataResolver currently only supports these types of objects"); } // // Clear out "stale" metadata before adding new metadata @@ -143,7 +136,7 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, /* * ((CollectionAO) objectAO).modifyAVUMetadata(absolutePath, * currentAvuData, newAvuData); - * + * * ((CollectionAO) * objectAO).findMetadataValuesByMetadataQueryForCollection(avuQuery, * collectionAbsolutePath) @@ -155,7 +148,7 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, /* * Check if the object already has an AVU with this attribute name If * not, add. If so, delete, then add. - * + * * Need to delete then add to account for list types. (For example, * replacing a list with a shorter list.) */ @@ -164,23 +157,18 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, List queryResult = null; try { - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, element.getName())); if (irodsObject.isFile()) { - queryResult = ((DataObjectAO) objectAO) - .findMetadataValuesForDataObjectUsingAVUQuery( - queryElements, pathToObject); + queryResult = ((DataObjectAO) objectAO).findMetadataValuesForDataObjectUsingAVUQuery(queryElements, + pathToObject); } else if (irodsObject.isDirectory()) { - queryResult = ((CollectionAO) objectAO) - .findMetadataValuesByMetadataQueryForCollection( - queryElements, pathToObject); + queryResult = ((CollectionAO) objectAO).findMetadataValuesByMetadataQueryForCollection(queryElements, + pathToObject); } } catch (JargonQueryException e) { - log.error( - "Jargon query exception looking up AVUs on iRODS object:{}", - pathToObject, e); + log.error("Jargon query exception looking up AVUs on iRODS object:{}", pathToObject, e); throw new JargonException(e); } @@ -189,18 +177,15 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, if (!queryResult.isEmpty()) { List oldAvuData = new ArrayList(); for (MetaDataAndDomainData mdd : queryResult) { - AvuData avuData = AvuData.instance(mdd.getAvuAttribute(), - mdd.getAvuValue(), mdd.getAvuUnit()); + AvuData avuData = AvuData.instance(mdd.getAvuAttribute(), mdd.getAvuValue(), mdd.getAvuUnit()); oldAvuData.add(avuData); } // Delete AVUs if (irodsObject.isFile()) { - ((DataObjectAO) objectAO).deleteBulkAVUMetadataFromDataObject( - pathToObject, oldAvuData); + ((DataObjectAO) objectAO).deleteBulkAVUMetadataFromDataObject(pathToObject, oldAvuData); } else if (irodsObject.isDirectory()) { - ((CollectionAO) objectAO).deleteBulkAVUMetadataFromCollection( - pathToObject, oldAvuData); + ((CollectionAO) objectAO).deleteBulkAVUMetadataFromCollection(pathToObject, oldAvuData); } } @@ -209,14 +194,11 @@ public void saveElementToSystemMetadataOnObject(MetadataElement element, if (!element.getCurrentValue().isEmpty()) { for (String s : element.getCurrentValue()) { AvuData avuData = AvuData.instance(element.getName(), s, - JargonMetadataTemplateConstants.AVU_UNIT_PREFIX - + element.getTemplateUuid().toString()); + JargonMetadataTemplateConstants.AVU_UNIT_PREFIX + element.getTemplateUuid().toString()); if (irodsObject.isFile()) { - ((DataObjectAO) objectAO).addAVUMetadata(pathToObject, - avuData); + ((DataObjectAO) objectAO).addAVUMetadata(pathToObject, avuData); } else if (irodsObject.isDirectory()) { - ((CollectionAO) objectAO).addAVUMetadata(pathToObject, - avuData); + ((CollectionAO) objectAO).addAVUMetadata(pathToObject, avuData); } } } diff --git a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataResolver.java b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataResolver.java index b6f20cf..6078360 100644 --- a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataResolver.java +++ b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/JargonMetadataResolver.java @@ -13,7 +13,6 @@ import org.irods.jargon.core.exception.JargonException; import org.irods.jargon.core.pub.IRODSAccessObjectFactory; import org.irods.jargon.core.pub.domain.AvuData; -import org.irods.jargon.core.pub.domain.Collection; import org.irods.jargon.core.pub.domain.ObjStat; import org.irods.jargon.core.pub.io.IRODSFile; import org.irods.jargon.core.pub.io.IRODSFileFactoryImpl; @@ -47,15 +46,15 @@ public class JargonMetadataResolver extends AbstractMetadataResolver { /** * Constructor for a JargonMetadataResolver. JargonMetadataResolver must be * initialized with an irodsAccount on the relevant server. - * + * * @param irodsAccount * {@link IRODSAccount} * @param irodsAccessObjectFactory * {@link IRODSAccessObjectFactory} * @throws JargonException */ - public JargonMetadataResolver(IRODSAccount irodsAccount, IRODSAccessObjectFactory irodsAccessObjectFactory) - throws JargonException { + public JargonMetadataResolver(final IRODSAccount irodsAccount, + final IRODSAccessObjectFactory irodsAccessObjectFactory) throws JargonException { this.irodsAccount = irodsAccount; this.irodsAccessObjectFactory = irodsAccessObjectFactory; @@ -83,14 +82,14 @@ public JargonMetadataResolver(IRODSAccount irodsAccount, IRODSAccessObjectFactor * WARNING: If the same template name appears in multiple public template * directories, only one is returned; determined by the list order of * publicTemplateLocations. - * + * * @return List of {@link MetadataTemplate} */ @Override public List listPublicTemplates() { List tempList = new ArrayList(); - for (String dir : this.getPublicTemplateLocations()) { + for (String dir : getPublicTemplateLocations()) { try { for (MetadataTemplate newMT : listTemplatesInCollection(dir)) { boolean isDuplicate = false; @@ -104,8 +103,9 @@ public List listPublicTemplates() { } } - if (!isDuplicate) + if (!isDuplicate) { tempList.add(newMT); + } } } catch (JargonException je) { log.error("JargonException when processing templates in {}", dir, je); @@ -129,13 +129,14 @@ public List listPublicTemplates() { * template "specialMetadata", the template that is returned will be the one * specified in the parent directory, and the template specified in the * grandparent directory will not appear in the list.) - * + * * @param absolutePath * {@link String} containing a fully-qualified iRODS path * @return List of {@link MetadataTemplate} */ @Override - public List listTemplatesInDirectoryHierarchyAbovePath(String absolutePath) throws IOException { + public List listTemplatesInDirectoryHierarchyAbovePath(final String absolutePath) + throws IOException { log.info("listTemplatesInDirectoryHierarchyAbovePath"); List templateList = null; File[] templateFiles = {}; @@ -176,18 +177,18 @@ public List listTemplatesInDirectoryHierarchyAbovePath(String * WARNING: If multiple public templates have the same name, results may be * unexpected. See the documentation for @link{listPublicTemplates} for more * information. - * + * * @param name * {@link String} containing the template name to be searched for * @param activeDir * {@link String} containing the active iRODS path - * + * * @return Nearest metadata template matching the name, or null * if no match */ @Override - public MetadataTemplate findTemplateByName(String name, String activeDir) throws FileNotFoundException, IOException, - MetadataTemplateProcessingException, MetadataTemplateParsingException { + public MetadataTemplate findTemplateByName(final String name, final String activeDir) throws FileNotFoundException, + IOException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("findTemplateByName()"); if (name == null || name.isEmpty()) { @@ -201,14 +202,14 @@ public MetadataTemplate findTemplateByName(String name, String activeDir) throws MetadataTemplate returnTemplate = null; // First look in directory hierarchy - returnTemplate = this.findTemplateByNameInDirectoryHierarchy(name, activeDir); + returnTemplate = findTemplateByNameInDirectoryHierarchy(name, activeDir); // If null, no template was found in directory hierarchy // Look in public locations if (returnTemplate == null) { log.info("No match in directory hierarchy, trying public locations"); - returnTemplate = this.findTemplateByNameInPublicTemplates(name); + returnTemplate = findTemplateByNameInPublicTemplates(name); } if (returnTemplate == null) { @@ -219,7 +220,7 @@ public MetadataTemplate findTemplateByName(String name, String activeDir) throws } @Override - public MetadataTemplate findTemplateByNameInDirectoryHierarchy(String name, String activeDir) + public MetadataTemplate findTemplateByNameInDirectoryHierarchy(final String name, final String activeDir) throws FileNotFoundException, IOException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("findTemplateByNameInDirectoryHierarchy()"); @@ -251,7 +252,7 @@ public MetadataTemplate findTemplateByNameInDirectoryHierarchy(String name, Stri log.info("Name matched: {}", f.getAbsolutePath()); try { - returnTemplate = this.processFileToMetadataTemplate(f); + returnTemplate = processFileToMetadataTemplate(f); } catch (JargonException je) { log.error("JargonException in processFileToMetadataTemplate", je); log.info("Matched {} with {}, but file could not be processed", name, f.getAbsolutePath()); @@ -266,8 +267,8 @@ public MetadataTemplate findTemplateByNameInDirectoryHierarchy(String name, Stri } @Override - public MetadataTemplate findTemplateByNameInPublicTemplates(String name) throws FileNotFoundException, IOException, - MetadataTemplateProcessingException, MetadataTemplateParsingException { + public MetadataTemplate findTemplateByNameInPublicTemplates(final String name) throws FileNotFoundException, + IOException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("findTemplateByNameInPublicTemplates()"); if (name == null || name.isEmpty()) { @@ -278,7 +279,7 @@ public MetadataTemplate findTemplateByNameInPublicTemplates(String name) throws IRODSFile collectionIrodsFile = null; boolean matched = false; - for (String publicDir : this.getPublicTemplateLocations()) { + for (String publicDir : getPublicTemplateLocations()) { try { collectionIrodsFile = irodsAccessObjectFactory.getIRODSFileFactory(irodsAccount) .instanceIRODSFile(publicDir); @@ -295,7 +296,7 @@ public MetadataTemplate findTemplateByNameInPublicTemplates(String name) throws log.info("Name matched: {}", f.getAbsolutePath()); try { - returnTemplate = this.processFileToMetadataTemplate(f); + returnTemplate = processFileToMetadataTemplate(f); matched = true; } catch (JargonException je) { log.error("JargonException in processFileToMetadataTemplate", je); @@ -306,8 +307,9 @@ public MetadataTemplate findTemplateByNameInPublicTemplates(String name) throws } } - if (matched) + if (matched) { break; + } } return returnTemplate; @@ -316,13 +318,13 @@ public MetadataTemplate findTemplateByNameInPublicTemplates(String name) throws /** * Return a MetadataTemplate given the fully-qualified path to the template * file. - * + * * @param fqName * {@link String} containing the iRODS path to a metadata * template file. */ @Override - public MetadataTemplate findTemplateByFqName(String fqName) throws FileNotFoundException, IOException, + public MetadataTemplate findTemplateByFqName(final String fqName) throws FileNotFoundException, IOException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("findTemplateByFqName()"); @@ -332,10 +334,10 @@ public MetadataTemplate findTemplateByFqName(String fqName) throws FileNotFoundE throw new IllegalArgumentException("fqName is null or empty"); } - IRODSFile templateFile = this.getPathAsIrodsFile(fqName); + IRODSFile templateFile = getPathAsIrodsFile(fqName); try { - returnTemplate = this.processFileToMetadataTemplate(templateFile.getAbsoluteFile()); + returnTemplate = processFileToMetadataTemplate(templateFile.getAbsoluteFile()); } catch (JargonException je) { log.error("JargonException in processFileToMetadataTemplate", je); returnTemplate = null; @@ -346,16 +348,16 @@ public MetadataTemplate findTemplateByFqName(String fqName) throws FileNotFoundE /** * Return the fully-qualified path to a metadata template file given a UUID. - * + * * @param uuid * {@link UUID} * @return String - * + * * XXX Should this make sure a template is in an "appropriate" * location? */ @Override - public String getFqNameForUUID(UUID uuid) { + public String getFqNameForUUID(final UUID uuid) { log.info("getFqNameForUUID()"); List queryElements = new ArrayList(); @@ -390,7 +392,7 @@ public String getFqNameForUUID(UUID uuid) { /** * Save this metadata template to a JSON file for use later. - * + * * Here, the second argument * irodsAbsolutePathToParentCollection, is assumed to be a path * to a .irods/metadataTemplates collection. If it is, the file will be @@ -399,18 +401,18 @@ public String getFqNameForUUID(UUID uuid) { * collection) or a /.irods/metadataTemplates collection underneath this * parent collection, and if successful, the template will be stored in that * newly created collection. - * + * * @param metadataTemplate * @param irodsAbsolutePathToParentCollection * a String containing an irods absolute path where a * .irods/metadataTemplates collection can be found or created. - * + * * @return a String containing the absolute path to the saved file, or null * if save failed */ @Override - public String saveFormBasedTemplateAsJSON(FormBasedMetadataTemplate metadataTemplate, - String irodsAbsolutePathToParentCollection) + public String saveFormBasedTemplateAsJSON(final MetadataTemplate metadataTemplate, + final String irodsAbsolutePathToParentCollection) throws FileNotFoundException, IOException, MetadataTemplateProcessingException { log.info("saveFormBasedTemplateAsJSON()"); @@ -425,8 +427,7 @@ public String saveFormBasedTemplateAsJSON(FormBasedMetadataTemplate metadataTemp } try { - metadataTemplatesLocation = this - .findOrCreateMetadataTemplatesCollection(irodsAbsolutePathToParentCollection); + metadataTemplatesLocation = findOrCreateMetadataTemplatesCollection(irodsAbsolutePathToParentCollection); } catch (JargonException je) { log.error("JargonException in findOrCreateMetadataTemplatesCollection", je); log.info("Save directory could not be found or created, file not saved."); @@ -443,7 +444,7 @@ public String saveFormBasedTemplateAsJSON(FormBasedMetadataTemplate metadataTemp log.info("Saving to: {}", absolutePath); try { - this.saveJSONStringToFile(jsonString, absolutePath); + saveJSONStringToFile(jsonString, absolutePath); } catch (JargonException je) { log.error("JargonException when trying to write String to file"); log.info("MetadataTemplate not saved to file"); @@ -451,14 +452,14 @@ public String saveFormBasedTemplateAsJSON(FormBasedMetadataTemplate metadataTemp } try { - this.addMdTemplateAVUToFile(metadataTemplate.getName(), absolutePath); + addMdTemplateAVUToFile(metadataTemplate.getName(), absolutePath); } catch (JargonException je) { log.info("Could not add template {} AVU to file", metadataTemplate.getName()); } for (MetadataElement me : metadataTemplate.getElements()) { try { - this.addMdElementAVUToFile(me.getName(), absolutePath); + addMdElementAVUToFile(me.getName(), absolutePath); } catch (JargonException je) { log.info("Could not add element {} AVU to file", me.getName()); } @@ -471,17 +472,17 @@ public String saveFormBasedTemplateAsJSON(FormBasedMetadataTemplate metadataTemp /** * Rename a metadata template file. - * + * * @param fqName * {@link String} * @param newFqName * {@link String} - * + * * XXX Change name property in template as well? - * + * */ @Override - public boolean renameTemplateByFqName(String fqName, String newFqName) { + public boolean renameTemplateByFqName(final String fqName, final String newFqName) { log.info("renameTemplateByFqName()"); if (fqName == null || fqName.isEmpty()) { @@ -492,8 +493,8 @@ public boolean renameTemplateByFqName(String fqName, String newFqName) { throw new IllegalArgumentException("newFqName is null or empty"); } - IRODSFile inFile = this.getPathAsIrodsFile(fqName); - IRODSFile irodsRenameFile = this.getPathAsIrodsFile(newFqName); + IRODSFile inFile = getPathAsIrodsFile(fqName); + IRODSFile irodsRenameFile = getPathAsIrodsFile(newFqName); if (!inFile.exists()) { log.info("{} does not exist, rename failed", inFile); @@ -519,10 +520,10 @@ public boolean renameTemplateByFqName(String fqName, String newFqName) { log.info("rename was successful, need to update mdTemplate: AVU"); List queryResult = new ArrayList(); - String newTemplateName = this.getLocalFileNameWithoutExtension(newFqName); + String newTemplateName = getLocalFileNameWithoutExtension(newFqName); try { - queryResult = this.queryTemplateAVUForFile(newFqName); + queryResult = queryTemplateAVUForFile(newFqName); } catch (JargonQueryException | JargonException je) { log.info("AvuQuery for UUID failed!", je); } @@ -530,7 +531,7 @@ public boolean renameTemplateByFqName(String fqName, String newFqName) { if (queryResult.isEmpty()) { log.info("MDTemplate AVU not found. Generating new one..."); try { - this.addMdTemplateAVUToFile(newTemplateName, newFqName); + addMdTemplateAVUToFile(newTemplateName, newFqName); } catch (JargonException je) { log.error("Adding AVU failed!", je); } @@ -547,7 +548,7 @@ public boolean renameTemplateByFqName(String fqName, String newFqName) { log.info("Generating new MDTemplate AVU..."); try { - this.addMdTemplateAVUToFile(newTemplateName, newFqName); + addMdTemplateAVUToFile(newTemplateName, newFqName); } catch (JargonException je) { log.error("Adding AVU failed!", je); } @@ -562,22 +563,22 @@ public boolean renameTemplateByFqName(String fqName, String newFqName) { * UUID. *

*

- * + * * @param fqName * {@link String} * @param newTemplateName * {@link String} * @param destDir * {@link String} - * + * * @return A {@link MetadataTemplate} instantiated from the cloned template * file. * @throws MetadataTemplateProcessingException * @throws MetadataTemplateParsingException */ @Override - public MetadataTemplate cloneTemplateByFqName(String fqName, String newTemplateName, String destDir) - throws FileNotFoundException, IOException, MetadataTemplateParsingException, + public MetadataTemplate cloneTemplateByFqName(final String fqName, final String newTemplateName, + final String destDir) throws FileNotFoundException, IOException, MetadataTemplateParsingException, MetadataTemplateProcessingException { log.info("cloneTemplateByFqName()"); @@ -599,8 +600,8 @@ public MetadataTemplate cloneTemplateByFqName(String fqName, String newTemplateN return null; } - IRODSFile inFile = this.getPathAsIrodsFile(fqName); - IRODSFile irodsDestDir = this.getPathAsIrodsFile(destDir); + IRODSFile inFile = getPathAsIrodsFile(fqName); + IRODSFile irodsDestDir = getPathAsIrodsFile(destDir); if (!inFile.exists()) { log.info("{} does not exist, clone failed", inFile); @@ -612,7 +613,7 @@ public MetadataTemplate cloneTemplateByFqName(String fqName, String newTemplateN return null; } - MetadataTemplate templateToBeCloned = this.findTemplateByFqName(fqName); + MetadataTemplate templateToBeCloned = findTemplateByFqName(fqName); if (templateToBeCloned == null) { log.info("{} could not be loaded by findTemplateByFqName, clone failed", inFile); @@ -625,11 +626,10 @@ public MetadataTemplate cloneTemplateByFqName(String fqName, String newTemplateN templateToBeCloned.setName(newTemplateName); // Save updated template (saveFormBasedTemplateAsJSON) - String pathToSavedTemplate = this.saveFormBasedTemplateAsJSON((FormBasedMetadataTemplate) templateToBeCloned, - destDir); + String pathToSavedTemplate = saveFormBasedTemplateAsJSON(templateToBeCloned, destDir); // Load template from file (findTemplateByFqName) - MetadataTemplate returnTemplate = this.findTemplateByFqName(pathToSavedTemplate); + MetadataTemplate returnTemplate = findTemplateByFqName(pathToSavedTemplate); // return loaded template return returnTemplate; @@ -642,17 +642,17 @@ public MetadataTemplate cloneTemplateByFqName(String fqName, String newTemplateN * This function contains a check to see if the UUID of the given file * matches the UUID of the new template to be saved. If not, the update * fails. - * + * * @param fqName * {@link String} * @param mdTemplate * {@link MetadataTemplate} - * + * * @return a boolean indicating whether the update succeeded (true) or * failed */ @Override - public boolean updateFormBasedTemplateByFqName(String fqName, FormBasedMetadataTemplate metadataTemplate) + public boolean updateFormBasedTemplateByFqName(final String fqName, final MetadataTemplate metadataTemplate) throws IOException { log.info("updateTemplateByFqName()"); @@ -670,7 +670,7 @@ public boolean updateFormBasedTemplateByFqName(String fqName, FormBasedMetadataT return false; } - IRODSFile inFile = this.getPathAsIrodsFile(fqName); + IRODSFile inFile = getPathAsIrodsFile(fqName); if (inFile == null) { log.info("{} could not be retrieved as IRODSFile; update failed", fqName); @@ -680,7 +680,7 @@ public boolean updateFormBasedTemplateByFqName(String fqName, FormBasedMetadataT List queryResult = null; try { - queryResult = this.queryTemplateAVUForFile(fqName); + queryResult = queryTemplateAVUForFile(fqName); } catch (JargonQueryException jqe) { log.error("AvuQuery for UUID failed!", jqe); log.info("Could not retrieve file UUID, not attempting to save file"); @@ -712,7 +712,7 @@ public boolean updateFormBasedTemplateByFqName(String fqName, FormBasedMetadataT log.info("Saving to: {}", fqName); try { - this.saveJSONStringToFile(jsonString, fqName); + saveJSONStringToFile(jsonString, fqName); } catch (JargonException je) { log.error("JargonException when trying to write String to file"); log.info("Template file not updated"); @@ -724,12 +724,12 @@ public boolean updateFormBasedTemplateByFqName(String fqName, FormBasedMetadataT /** * Delete a metadata template give its fully-qualified iRODS path. - * + * * @param fqName * {@link String} */ @Override - public boolean deleteTemplateByFqName(String fqName) { + public boolean deleteTemplateByFqName(final String fqName) { log.info("deleteTemplateByFqName()"); if (fqName == null || fqName.isEmpty()) { @@ -759,34 +759,34 @@ public boolean deleteTemplateByFqName(String fqName) { /** * Save the values in the MetadataTemplate onto the object in the system * metadata table. - * - * + * + * * @param metadataTemplate * @param pathToObject - * + * * @throws FileNotFoundException * @throws JargonException - * + * */ /* * public void saveTemplateToSystemMetadataOnObject( MetadataTemplate * metadataTemplate, String pathToObject) throws FileNotFoundException, * JargonException { log.info("saveTemplateToSystemMetadataOnObject()"); - * + * * if (pathToObject == null || pathToObject.isEmpty()) { throw new * IllegalArgumentException("pathToObject is null or empty"); } - * + * * if (metadataTemplate == null) { throw new * IllegalArgumentException("metadataTemplate is null"); } - * + * * IRODSFile irodsObject = irodsAccessObjectFactory.getIRODSFileFactory( * irodsAccount).instanceIRODSFile(pathToObject); - * + * * if (!irodsObject.exists()) { throw new FileNotFoundException( * "pathToObject does not resolve to an iRODS object"); } - * + * * FileCatalogObjectAO objectAO = null; - * + * * if (irodsObject.isFile()) { objectAO = * irodsAccessObjectFactory.getDataObjectAO(irodsAccount); } else if * (irodsObject.isDirectory()) { objectAO = @@ -794,7 +794,7 @@ public boolean deleteTemplateByFqName(String fqName) { * new IllegalArgumentException( "object at " + pathToObject + * " is neither a data object nor a collection - the JargonMetadataResolver currently only supports these types of objects" * ); } - * + * * if (metadataTemplate.getType() == TemplateTypeEnum.FORM_BASED) { for * (MetadataElement me : ((FormBasedMetadataTemplate) metadataTemplate) * .getElements()) { if (!me.getCurrentValue().isEmpty()) { for (String s : @@ -808,11 +808,11 @@ public boolean deleteTemplateByFqName(String fqName) { */ /** * Populate metadata templates from a list of AVUs - * + * * TODO Are unaffiliated AVUs and orphan AVUs properly two separate lists? - * + * * @param irodsAbsolutePathToCollection - * + * * @return {@link MetadataMergeResult}, containing a * {@link MetadataTemplate} that was initialized as a copy of * inTemplate whose elements' @@ -824,9 +824,9 @@ public boolean deleteTemplateByFqName(String fqName) { * @throws org.irods.jargon.core.exception.FileNotFoundException * @throws JargonException * @throws JargonQueryException - * + * */ - public MetadataMergeResult getAndMergeTemplateListForPath(String irodsAbsolutePath) + public MetadataMergeResult getAndMergeTemplateListForPath(final String irodsAbsolutePath) throws org.irods.jargon.core.exception.FileNotFoundException, JargonException, JargonQueryException, FileNotFoundException, IOException { log.info("getAndMergeTemplateListForPath()"); @@ -836,9 +836,9 @@ public MetadataMergeResult getAndMergeTemplateListForPath(String irodsAbsolutePa Map templateMap = new HashMap(); String templateSearchPath = pathObjStat.isSomeTypeOfCollection() ? irodsAbsolutePath - : this.getPathFromFqName(irodsAbsolutePath); + : getPathFromFqName(irodsAbsolutePath); - for (MetadataTemplate mt : this.listAllRequiredTemplates(templateSearchPath)) { + for (MetadataTemplate mt : listAllRequiredTemplates(templateSearchPath)) { log.info("Required template found: {}", mt.getName()); // TODO Right now, only supports searching by UUID // nameUUID would be more general @@ -859,8 +859,8 @@ public MetadataMergeResult getAndMergeTemplateListForPath(String irodsAbsolutePa return mergeTemplateListAndAVUs(templateMap, avuList, irodsAbsolutePath); } - MetadataMergeResult mergeTemplateListAndAVUs(Map templateMap, - List avuList, String irodsAbsolutePath) + MetadataMergeResult mergeTemplateListAndAVUs(final Map templateMap, + final List avuList, final String irodsAbsolutePath) throws FileNotFoundException, IOException, JargonException { log.info("mergeTemplateListAndAVUs()"); @@ -887,7 +887,7 @@ MetadataMergeResult mergeTemplateListAndAVUs(Map templ tempMt = templateMap.get(uuid); if (tempMt.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate tempFbmt = (FormBasedMetadataTemplate) tempMt; + MetadataTemplate tempFbmt = tempMt; for (MetadataElement me : tempFbmt.getElements()) { if (avu.getAvuAttribute().equalsIgnoreCase(me.getName())) { // Not a REF_IRODS_QUERY type, set current @@ -911,7 +911,7 @@ MetadataMergeResult mergeTemplateListAndAVUs(Map templ if (tempMt == null) { log.info("no template found for UUID {}", uuid); } else if (tempMt.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate tempFbmt = (FormBasedMetadataTemplate) tempMt; + MetadataTemplate tempFbmt = tempMt; for (MetadataElement me : tempFbmt.getElements()) { if (avu.getAvuAttribute().equalsIgnoreCase(me.getName())) { // Not a REF_IRODS_QUERY type, set current @@ -952,7 +952,7 @@ MetadataMergeResult mergeTemplateListAndAVUs(Map templ for (MetadataTemplate mt : returnList) { if (mt.getType() == TemplateTypeEnum.FORM_BASED) { - for (MetadataElement me : ((FormBasedMetadataTemplate) mt).getElements()) { + for (MetadataElement me : mt.getElements()) { if (me.getType() == ElementTypeEnum.REF_IRODS_QUERY) { me.getDisplayValue().add(getValueFromRefQuery(me.getCurrentValue().get(0), irodsAbsolutePath)); } @@ -963,7 +963,7 @@ MetadataMergeResult mergeTemplateListAndAVUs(Map templ return new MetadataMergeResult(returnList, orphans); } - String getValueFromRefQuery(String refQuery, String irodsAbsolutePath) { + String getValueFromRefQuery(final String refQuery, final String irodsAbsolutePath) { String returnString = ""; /* * try { // Check if need to reinitialize dataProfileAccessor if @@ -992,7 +992,7 @@ String getValueFromRefQuery(String refQuery, String irodsAbsolutePath) { * Parse an array of File objects to a list of MetadataTemplate objects. * Calls processFileToMetadataTemplate iteratively for each * File. - * + * * @param inFileArray * an array of File objects * @return returnList, an ArrayList of metadataTemplates, in the same order @@ -1000,7 +1000,7 @@ String getValueFromRefQuery(String refQuery, String irodsAbsolutePath) { * @throws JargonException * @throws IOException */ - List processFilesToMetadataTemplates(File[] inFileArray) + List processFilesToMetadataTemplates(final File[] inFileArray) throws JargonException, IOException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("processFilesToMetadataTemplates()"); @@ -1013,8 +1013,9 @@ List processFilesToMetadataTemplates(File[] inFileArray) // Handle "list order" for TemplatesInCollection and Public // Templates fileNameWithoutExtension = LocalFileUtils.getFileNameUpToExtension(f.getName()); - if (templateNames.contains(fileNameWithoutExtension)) + if (templateNames.contains(fileNameWithoutExtension)) { break; + } returnList.add(processFileToMetadataTemplate(f)); templateNames.add(returnList.get(returnList.size() - 1).getName()); @@ -1031,15 +1032,15 @@ List processFilesToMetadataTemplates(File[] inFileArray) * If the file does not already have a UUID associated with it, this * function will generate one and add an AVU containing it to the file as a * side effect.

MetadataTemplate - * + * * @throws JargonException * @throws IOException */ - MetadataTemplate processFileToMetadataTemplate(File inFile) + MetadataTemplate processFileToMetadataTemplate(final File inFile) throws JargonException, IOException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("processFileToMetadataTemplate()"); @@ -1064,7 +1065,7 @@ MetadataTemplate processFileToMetadataTemplate(File inFile) log.info("AvuQuery to see if file has UUID already"); try { - queryResult = this.queryTemplateAVUForFile(inFile.getAbsolutePath()); + queryResult = queryTemplateAVUForFile(inFile.getAbsolutePath()); } catch (JargonQueryException jqe) { log.error("AvuQuery for UUID failed!", jqe); } @@ -1074,7 +1075,7 @@ MetadataTemplate processFileToMetadataTemplate(File inFile) addMdTemplateAVUToFile(LocalFileUtils.getFileNameUpToExtension(inFile.getName()), inFile.getAbsolutePath()); try { - queryResult = this.queryTemplateAVUForFile(inFile.getAbsolutePath()); + queryResult = queryTemplateAVUForFile(inFile.getAbsolutePath()); } catch (JargonQueryException jqe) { log.error("AvuQuery for UUID failed!", jqe); } @@ -1105,7 +1106,7 @@ MetadataTemplate processFileToMetadataTemplate(File inFile) returnTemplate.setUuid(uuid); if (returnTemplate.getType() == TemplateTypeEnum.FORM_BASED) { - FormBasedMetadataTemplate fbmt = (FormBasedMetadataTemplate) returnTemplate; + MetadataTemplate fbmt = returnTemplate; for (MetadataElement me : fbmt.getElements()) { me.setTemplateUuid(uuid); } @@ -1122,9 +1123,9 @@ MetadataTemplate processFileToMetadataTemplate(File inFile) } /** - * + * */ - List listTemplatesInCollection(String irodsAbsolutePathToCollection) + List listTemplatesInCollection(final String irodsAbsolutePathToCollection) throws IOException, JargonException, MetadataTemplateProcessingException, MetadataTemplateParsingException { log.info("listTemplatesInCollection()"); @@ -1150,12 +1151,12 @@ List listTemplatesInCollection(String irodsAbsolutePathToColle *
  • Value: UUID associated with template
  • *
  • Unit: iRODS:mdTemplate
  • * - * + * * @param name * @param path * @throws JargonException */ - void addMdTemplateAVUToFile(String name, String path) throws JargonException { + void addMdTemplateAVUToFile(final String name, final String path) throws JargonException { log.info("addMdTemplateAVUToFile, name = {}", name); UUID uuid = UUID.randomUUID(); AvuData avuData = AvuData.instance(name, uuid.toString(), JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); @@ -1170,12 +1171,12 @@ void addMdTemplateAVUToFile(String name, String path) throws JargonException { *
  • Value: UUID associated with element
  • *
  • Unit: iRODS:mdElement
  • * - * + * * @param name * @param path * @throws JargonException */ - void addMdElementAVUToFile(String name, String path) throws JargonException { + void addMdElementAVUToFile(final String name, final String path) throws JargonException { log.info("addMdElementAVUToFile, name = {}", name); UUID uuid = UUID.randomUUID(); AvuData avuData = AvuData.instance(name, uuid.toString(), JargonMetadataTemplateConstants.MD_ELEMENT_UNIT); @@ -1193,27 +1194,26 @@ String findOrCreateMetadataTemplatesCollection(final String irodsAbsolutePathToP String irodsAbsolutePathToCollection = null; - if (this.isMetadataTemplatesCollection(irodsAbsolutePathToParent)) { + if (isMetadataTemplatesCollection(irodsAbsolutePathToParent)) { // Already a .irods/metadataTemplates collection, so we're good log.info("{} is a .irods/metadataTemplates collection", irodsAbsolutePathToParent); irodsAbsolutePathToCollection = irodsAbsolutePathToParent; - } else if (this.isDotIrodsCollection(irodsAbsolutePathToParent)) { + } else if (isDotIrodsCollection(irodsAbsolutePathToParent)) { // Parameter is a .irods collection, need to find or create a // metadataTemplates collection beneath it. log.info("{} is a .irods collection", irodsAbsolutePathToParent); - if (this.isMetadataTemplatesCollectionPresentUnderDotIrodsCollection(irodsAbsolutePathToParent)) { + if (isMetadataTemplatesCollectionPresentUnderDotIrodsCollection(irodsAbsolutePathToParent)) { log.info("{} contains a metadataTemplates collection", irodsAbsolutePathToParent); - irodsAbsolutePathToCollection = this - .computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToParent); + irodsAbsolutePathToCollection = computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToParent); } else { log.info("{} does not contain a metadataTemplates collection, attempting to create", irodsAbsolutePathToParent); - if (this.createMetadataTemplatesCollectionUnderDotIrods(irodsAbsolutePathToParent)) { + if (createMetadataTemplatesCollectionUnderDotIrods(irodsAbsolutePathToParent)) { log.info("metadataTemplates collection created"); - irodsAbsolutePathToCollection = this - .computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToParent); + irodsAbsolutePathToCollection = computeMetadataTemplatesPathUnderDotIrods( + irodsAbsolutePathToParent); } else { log.error("Error, collection not created"); throw new JargonException("Error in createMetadataTemplatesCollectionUnderDotIrods"); @@ -1225,11 +1225,7 @@ String findOrCreateMetadataTemplatesCollection(final String irodsAbsolutePathToP log.info("{} is neither a .irods collection nor a metadata templates collection", irodsAbsolutePathToParent); - // Is it a valid irods collection at all? - // This will throw a JargonException if not. - @SuppressWarnings("unused") - Collection collection = irodsAccessObjectFactory.getCollectionAO(irodsAccount) - .findByAbsolutePath(irodsAbsolutePathToParent); + irodsAccessObjectFactory.getCollectionAO(irodsAccount).findByAbsolutePath(irodsAbsolutePathToParent); log.info("{} exists", irodsAbsolutePathToParent); @@ -1237,19 +1233,19 @@ String findOrCreateMetadataTemplatesCollection(final String irodsAbsolutePathToP dotIrodsService.createDotIrodsUnderParent(irodsAbsolutePathToParent); // Make sure it was created - if (!this.isDotIrodsCollectionPresentInCollection(irodsAbsolutePathToParent)) { + if (!isDotIrodsCollectionPresentInCollection(irodsAbsolutePathToParent)) { log.error("Error, .irods collection was not created"); throw new JargonException("DotIrodsService.createDotIrodsUnderParent failed to create .irods"); } - String dotIrodsDir = this.computeDotIrodsPathUnderParent(irodsAbsolutePathToParent); + String dotIrodsDir = computeDotIrodsPathUnderParent(irodsAbsolutePathToParent); log.info(".irods created: {}", dotIrodsDir); // Create metadataTemplates subcollection - if (this.createMetadataTemplatesCollectionUnderDotIrods(dotIrodsDir)) { + if (createMetadataTemplatesCollectionUnderDotIrods(dotIrodsDir)) { log.info("metadataTemplates collection created"); - irodsAbsolutePathToCollection = this.computeMetadataTemplatesPathUnderDotIrods(dotIrodsDir); + irodsAbsolutePathToCollection = computeMetadataTemplatesPathUnderDotIrods(dotIrodsDir); } else { log.error("Error, collection not created"); throw new JargonException("Error in createMetadataTemplatesCollectionUnderDotIrods"); @@ -1271,10 +1267,10 @@ boolean createMetadataTemplatesCollectionUnderParent(final String irodsAbsoluteP log.info("irodsAbsolutePathToParent: {}", irodsAbsolutePathToParent); - String metadataTemplatesPath = this.computeMetadataTemplatesPathUnderParent(irodsAbsolutePathToParent); + String metadataTemplatesPath = computeMetadataTemplatesPathUnderParent(irodsAbsolutePathToParent); log.info("metadataTemplatesPath computed to be:{}", metadataTemplatesPath); - IRODSFile dotIrodsFile = this.getPathAsIrodsFile(metadataTemplatesPath); + IRODSFile dotIrodsFile = getPathAsIrodsFile(metadataTemplatesPath); if (dotIrodsFile == null) { // A JargonException was caught in getPathAsIrodsFile throw new JargonException("JargonException thrown by instanceIRODSFile in getPathAsIrodsFile"); @@ -1294,10 +1290,10 @@ boolean createMetadataTemplatesCollectionUnderDotIrods(final String irodsAbsolut log.info("irodsAbsolutePathToDotIrods: {}", irodsAbsolutePathToDotIrods); - String metadataTemplatesPath = this.computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToDotIrods); + String metadataTemplatesPath = computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToDotIrods); log.info("metadataTemplatesPath computed to be:{}", metadataTemplatesPath); - IRODSFile metadataTemplatesFile = this.getPathAsIrodsFile(metadataTemplatesPath); + IRODSFile metadataTemplatesFile = getPathAsIrodsFile(metadataTemplatesPath); if (metadataTemplatesFile == null) { // A JargonException was caught in getPathAsIrodsFile throw new JargonException("JargonException thrown by instanceIRODSFile in getPathAsIrodsFile"); @@ -1346,7 +1342,7 @@ String computeMetadataTemplatesPathUnderDotIrods(final String irodsAbsolutePathT return sb.toString(); } - boolean isMetadataTemplatesCollectionPresentUnderParentCollection(String irodsAbsolutePath) { + boolean isMetadataTemplatesCollectionPresentUnderParentCollection(final String irodsAbsolutePath) { log.info("isMetadataTemplatesCollectionPresentUnderParentCollection()"); if (irodsAbsolutePath == null || irodsAbsolutePath.isEmpty()) { @@ -1356,9 +1352,7 @@ boolean isMetadataTemplatesCollectionPresentUnderParentCollection(String irodsAb log.info("irodsAbsolutePath:{}", irodsAbsolutePath); try { - @SuppressWarnings("unused") - Collection collection = irodsAccessObjectFactory.getCollectionAO(irodsAccount) - .findByAbsolutePath(irodsAbsolutePath); + irodsAccessObjectFactory.getCollectionAO(irodsAccount).findByAbsolutePath(irodsAbsolutePath); } catch (JargonException je) { log.info( "JargonException thrown by findByAbsolutePath, {} does not exist or {} does not have sufficient permissions", @@ -1368,13 +1362,13 @@ boolean isMetadataTemplatesCollectionPresentUnderParentCollection(String irodsAb log.info("{} exists", irodsAbsolutePath); - IRODSFile metadataTemplatesCollectionAsFile = this - .getPathAsIrodsFile(this.computeMetadataTemplatesPathUnderParent(irodsAbsolutePath)); + IRODSFile metadataTemplatesCollectionAsFile = getPathAsIrodsFile( + computeMetadataTemplatesPathUnderParent(irodsAbsolutePath)); return (metadataTemplatesCollectionAsFile != null); } - boolean isMetadataTemplatesCollectionPresentUnderDotIrodsCollection(String irodsAbsolutePathToDotIrods) { + boolean isMetadataTemplatesCollectionPresentUnderDotIrodsCollection(final String irodsAbsolutePathToDotIrods) { log.info("isMetadataTemplatesCollectionPresentUnderParentCollection()"); if (irodsAbsolutePathToDotIrods == null || irodsAbsolutePathToDotIrods.isEmpty()) { @@ -1384,9 +1378,7 @@ boolean isMetadataTemplatesCollectionPresentUnderDotIrodsCollection(String irods log.info("irodsAbsolutePathToDotIrods:{}", irodsAbsolutePathToDotIrods); try { - @SuppressWarnings("unused") - Collection collection = irodsAccessObjectFactory.getCollectionAO(irodsAccount) - .findByAbsolutePath(irodsAbsolutePathToDotIrods); + irodsAccessObjectFactory.getCollectionAO(irodsAccount).findByAbsolutePath(irodsAbsolutePathToDotIrods); } catch (JargonException je) { log.info( "JargonException thrown by findByAbsolutePath, {} does not exist or {} does not have sufficient permissions", @@ -1396,13 +1388,13 @@ boolean isMetadataTemplatesCollectionPresentUnderDotIrodsCollection(String irods log.info("{} exists", irodsAbsolutePathToDotIrods); - IRODSFile metadataTemplatesCollectionAsFile = this - .getPathAsIrodsFile(this.computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToDotIrods)); + IRODSFile metadataTemplatesCollectionAsFile = getPathAsIrodsFile( + computeMetadataTemplatesPathUnderDotIrods(irodsAbsolutePathToDotIrods)); return (metadataTemplatesCollectionAsFile != null); } - boolean isDotIrodsCollectionPresentInCollection(String irodsAbsolutePath) { + boolean isDotIrodsCollectionPresentInCollection(final String irodsAbsolutePath) { log.info("isDotIrodsCollectionPresentInCollection()"); if (irodsAbsolutePath == null || irodsAbsolutePath.isEmpty()) { @@ -1412,9 +1404,7 @@ boolean isDotIrodsCollectionPresentInCollection(String irodsAbsolutePath) { log.info("irodsAbsolutePath:{}", irodsAbsolutePath); try { - @SuppressWarnings("unused") - Collection collection = irodsAccessObjectFactory.getCollectionAO(irodsAccount) - .findByAbsolutePath(irodsAbsolutePath); + irodsAccessObjectFactory.getCollectionAO(irodsAccount).findByAbsolutePath(irodsAbsolutePath); } catch (JargonException je) { log.info( "JargonException thrown by findByAbsolutePath, {} does not exist or {} does not have sufficient permissions", @@ -1424,13 +1414,12 @@ boolean isDotIrodsCollectionPresentInCollection(String irodsAbsolutePath) { log.info("{} exists", irodsAbsolutePath); - IRODSFile dotIrodsCollectionAsFile = this - .getPathAsIrodsFile(this.computeDotIrodsPathUnderParent(irodsAbsolutePath)); + IRODSFile dotIrodsCollectionAsFile = getPathAsIrodsFile(computeDotIrodsPathUnderParent(irodsAbsolutePath)); return (dotIrodsCollectionAsFile != null); } - boolean isMetadataTemplatesCollection(String irodsAbsolutePath) { + boolean isMetadataTemplatesCollection(final String irodsAbsolutePath) { log.info("isMetadataTemplatesCollection()"); if (irodsAbsolutePath == null || irodsAbsolutePath.isEmpty()) { @@ -1440,9 +1429,7 @@ boolean isMetadataTemplatesCollection(String irodsAbsolutePath) { log.info("irodsAbsolutePath:{}", irodsAbsolutePath); try { - @SuppressWarnings("unused") - Collection collection = irodsAccessObjectFactory.getCollectionAO(irodsAccount) - .findByAbsolutePath(irodsAbsolutePath); + irodsAccessObjectFactory.getCollectionAO(irodsAccount).findByAbsolutePath(irodsAbsolutePath); } catch (JargonException je) { log.info( "JargonException thrown by findByAbsolutePath, {} does not exist or {} does not have sufficient permissions", @@ -1457,7 +1444,7 @@ boolean isMetadataTemplatesCollection(String irodsAbsolutePath) { if (!irodsAbsolutePath.endsWith(DotIrodsConstants.METADATA_TEMPLATES_DIR)) { retVal = false; } else { - IRODSFile pathAsFile = this.getPathAsIrodsFile(irodsAbsolutePath); + IRODSFile pathAsFile = getPathAsIrodsFile(irodsAbsolutePath); if (pathAsFile == null) { retVal = false; @@ -1469,7 +1456,7 @@ boolean isMetadataTemplatesCollection(String irodsAbsolutePath) { return retVal; } - boolean isDotIrodsCollection(String irodsAbsolutePath) { + boolean isDotIrodsCollection(final String irodsAbsolutePath) { log.info("isDotIrodsCollection()"); if (irodsAbsolutePath == null || irodsAbsolutePath.isEmpty()) { @@ -1479,9 +1466,7 @@ boolean isDotIrodsCollection(String irodsAbsolutePath) { log.info("irodsAbsolutePath:{}", irodsAbsolutePath); try { - @SuppressWarnings("unused") - Collection collection = irodsAccessObjectFactory.getCollectionAO(irodsAccount) - .findByAbsolutePath(irodsAbsolutePath); + irodsAccessObjectFactory.getCollectionAO(irodsAccount).findByAbsolutePath(irodsAbsolutePath); } catch (JargonException je) { log.info( "JargonException thrown by findByAbsolutePath, {} does not exist or {} does not have sufficient permissions", @@ -1496,7 +1481,7 @@ boolean isDotIrodsCollection(String irodsAbsolutePath) { if (!irodsAbsolutePath.endsWith(DotIrodsConstants.DOT_IRODS_DIR)) { retVal = false; } else { - IRODSFile pathAsFile = this.getPathAsIrodsFile(irodsAbsolutePath); + IRODSFile pathAsFile = getPathAsIrodsFile(irodsAbsolutePath); if (pathAsFile == null) { retVal = false; @@ -1508,7 +1493,7 @@ boolean isDotIrodsCollection(String irodsAbsolutePath) { return retVal; } - IRODSFile getPathAsIrodsFile(String irodsAbsolutePath) { + IRODSFile getPathAsIrodsFile(final String irodsAbsolutePath) { log.info("getPathAsIrodsFile()"); IRODSFile retFile = null; @@ -1523,7 +1508,7 @@ IRODSFile getPathAsIrodsFile(String irodsAbsolutePath) { return retFile; } - void saveJSONStringToFile(String json, String irodsAbsolutePath) throws JargonException, IOException { + void saveJSONStringToFile(final String json, final String irodsAbsolutePath) throws JargonException, IOException { log.info("saveJSONStringToFile()"); if (json == null || json.isEmpty()) { @@ -1546,7 +1531,7 @@ void saveJSONStringToFile(String json, String irodsAbsolutePath) throws JargonEx templateIrodsFile.close(); } - List queryTemplateAVUForFile(String irodsAbsolutePathToFile) + List queryTemplateAVUForFile(final String irodsAbsolutePathToFile) throws JargonQueryException, JargonException { log.info("queryTemplateAVUForFile()"); @@ -1562,7 +1547,7 @@ List queryTemplateAVUForFile(String irodsAbsolutePathToFi return queryResult; } - List queryElementAVUForFile(String irodsAbsolutePathToFile) + List queryElementAVUForFile(final String irodsAbsolutePathToFile) throws JargonQueryException, JargonException { log.info("queryElementAVUForFile()"); @@ -1578,7 +1563,7 @@ List queryElementAVUForFile(String irodsAbsolutePathToFil return queryResult; } - String getLocalFileNameWithoutExtension(String inFileName) { + String getLocalFileNameWithoutExtension(final String inFileName) { String localFileName; int lastSlash = inFileName.lastIndexOf('/'); if (lastSlash == -1) { @@ -1589,7 +1574,7 @@ String getLocalFileNameWithoutExtension(String inFileName) { return LocalFileUtils.getFileNameUpToExtension(localFileName); } - String getPathFromFqName(String inFileName) { + String getPathFromFqName(final String inFileName) { String path; int lastSlash = inFileName.lastIndexOf('/'); if ((lastSlash == -1) || (lastSlash == (inFileName.length() - 1))) { diff --git a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataMergeResult.java b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataMergeResult.java index 4fcb2b6..d538766 100644 --- a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataMergeResult.java +++ b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataMergeResult.java @@ -4,14 +4,12 @@ import java.util.List; import org.irods.jargon.core.query.MetaDataAndDomainData; -import org.irods.jargon.metadatatemplate.MetadataTemplate; public class MetadataMergeResult { private List templates = new ArrayList(); private List unmatchedAvus = new ArrayList(); - public MetadataMergeResult(List inTemplates, - List inAvus) { + public MetadataMergeResult(final List inTemplates, final List inAvus) { setTemplates(inTemplates); setUnmatchedAvus(inAvus); } @@ -20,11 +18,11 @@ public List getTemplates() { return templates; } - public void setTemplates(List templateList) { - this.templates = new ArrayList(); + public void setTemplates(final List templateList) { + templates = new ArrayList(); for (MetadataTemplate mt : templateList) { - this.templates.add(mt.deepCopy()); + templates.add(mt); } } @@ -32,7 +30,7 @@ public List getUnmatchedAvus() { return unmatchedAvus; } - public void setUnmatchedAvus(List unmatchedAvus) { + public void setUnmatchedAvus(final List unmatchedAvus) { for (MetaDataAndDomainData avu : unmatchedAvus) { this.unmatchedAvus.add(avu); } diff --git a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateConfiguration.java b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateConfiguration.java deleted file mode 100644 index 20474c5..0000000 --- a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateConfiguration.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * - */ -package org.irods.jargon.metadatatemplate; - -import javax.annotation.PostConstruct; - -import org.irods.jargon.rest.configuration.RestConfiguration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -/** - * Metadata template specific configuration, augments {@link RestConfiguration} - * with settings for mdtemplates - * - * @author mconway - * - */ -@Component -@PropertySource("file:///etc/irods-ext/mdtemplate.properties") -public class MetadataTemplateConfiguration { - - private String publicTemplateRepositoryLocation = ""; - - @Autowired - Environment env; - - @PostConstruct - public void init() { - setPublicTemplateRepositoryLocation(env.getProperty("mdtemplate.public")); - - } - - public String getPublicTemplateRepositoryLocation() { - return publicTemplateRepositoryLocation; - } - - public void setPublicTemplateRepositoryLocation(String publicTemplateRepositoryLocation) { - this.publicTemplateRepositoryLocation = publicTemplateRepositoryLocation; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("MetadataTemplateConfiguration ["); - if (publicTemplateRepositoryLocation != null) { - builder.append("publicTemplateRepositoryLocation=").append(publicTemplateRepositoryLocation).append(", "); - } - if (env != null) { - builder.append("env=").append(env); - } - builder.append("]"); - return builder.toString(); - } - -} diff --git a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateFileFilter.java b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateFileFilter.java index 135567e..dca78b0 100644 --- a/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateFileFilter.java +++ b/metadata-templates/src/main/java/org/irods/jargon/metadatatemplate/MetadataTemplateFileFilter.java @@ -4,9 +4,9 @@ import java.io.FilenameFilter; /** - * + * * Filter to identify metadatatemplate ".mdtemplate" files - * + * * @author rskarbez * */ @@ -14,11 +14,10 @@ public class MetadataTemplateFileFilter implements FilenameFilter { @Override - public boolean accept(File file, String fileName) { + public boolean accept(final File file, final String fileName) { if (fileName.endsWith(MetadataTemplateConstants.TEMPLATE_FILE_EXT)) { return true; - } - else { + } else { return false; } } diff --git a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataExporterTest.java b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataExporterTest.java index ce1a23c..e61ba3a 100644 --- a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataExporterTest.java +++ b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataExporterTest.java @@ -45,8 +45,7 @@ public static void setUpBeforeClass() throws Exception { irodsTestSetupUtilities = new org.irods.jargon.testutils.IRODSTestSetupUtilities(); irodsTestSetupUtilities.clearIrodsScratchDirectory(); irodsTestSetupUtilities.initializeIrodsScratchDirectory(); - irodsTestSetupUtilities - .initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH); + irodsTestSetupUtilities.initializeDirectoryForTest(IRODS_TEST_SUBDIR_PATH); } @After @@ -58,60 +57,46 @@ public void tearDown() throws Exception { public void saveTemplateToSystemMetadataForDataObject() throws Exception { String testDirName1 = "saveTemplateToSystemMetadataForDataObjectDir"; - String targetIrodsCollection1 = testingPropertiesHelper - .buildIRODSCollectionAbsolutePathFromTestProperties( - testingProperties, IRODS_TEST_SUBDIR_PATH + '/' - + testDirName1); + String targetIrodsCollection1 = testingPropertiesHelper.buildIRODSCollectionAbsolutePathFromTestProperties( + testingProperties, IRODS_TEST_SUBDIR_PATH + '/' + testDirName1); - IRODSAccount irodsAccount = testingPropertiesHelper - .buildIRODSAccountFromTestProperties(testingProperties); + IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem - .getIRODSAccessObjectFactory(); + IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - IRODSFile targetCollectionAsFile1 = accessObjectFactory - .getIRODSFileFactory(irodsAccount).instanceIRODSFile( - targetIrodsCollection1); + IRODSFile targetCollectionAsFile1 = accessObjectFactory.getIRODSFileFactory(irodsAccount) + .instanceIRODSFile(targetIrodsCollection1); targetCollectionAsFile1.mkdirs(); - JargonMetadataResolver resolver = new JargonMetadataResolver( - irodsAccount, accessObjectFactory); + JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - JargonMetadataExporter exporter = new JargonMetadataExporter( - accessObjectFactory, irodsAccount); + JargonMetadataExporter exporter = new JargonMetadataExporter(accessObjectFactory, irodsAccount); - String mdTemplatePath1 = resolver - .findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); + String mdTemplatePath1 = resolver.findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); - DataTransferOperations dataTransferOperations = irodsFileSystem - .getIRODSAccessObjectFactory().getDataTransferOperations( - irodsAccount); + DataTransferOperations dataTransferOperations = irodsFileSystem.getIRODSAccessObjectFactory() + .getDataTransferOperations(irodsAccount); - dataTransferOperations.putOperation(TEMPLATE_FILE_NAME1, - mdTemplatePath1, irodsAccount.getDefaultStorageResource(), - null, null); + dataTransferOperations.putOperation(TEMPLATE_FILE_NAME1, mdTemplatePath1, + irodsAccount.getDefaultStorageResource(), null, null); String templateFqName1 = mdTemplatePath1 + '/' + TEMPLATE_NOPATH1; UUID uuid1 = UUID.randomUUID(); - AvuData avuData = AvuData.instance("test1", uuid1.toString(), - JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - templateFqName1, avuData); + AvuData avuData = AvuData.instance("test1", uuid1.toString(), JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(templateFqName1, avuData); // Create a file in targetIrodsCollection1 - dataTransferOperations.putOperation(TEST_FILE_NAME, - targetIrodsCollection1, + dataTransferOperations.putOperation(TEST_FILE_NAME, targetIrodsCollection1, irodsAccount.getDefaultStorageResource(), null, null); String testFileNameFQ = targetIrodsCollection1 + '/' + TEST_FILE_NOPATH; - MetadataTemplate metadataTemplate = resolver - .findTemplateByFqName(templateFqName1); - FormBasedMetadataTemplate fbmt = null; + MetadataTemplate metadataTemplate = resolver.findTemplateByFqName(templateFqName1); + MetadataTemplate fbmt = null; if (metadataTemplate.getType() == TemplateTypeEnum.FORM_BASED) { - fbmt = (FormBasedMetadataTemplate) metadataTemplate; + fbmt = metadataTemplate; } for (MetadataElement me : fbmt.getElements()) { @@ -129,59 +114,47 @@ public void saveTemplateToSystemMetadataForDataObject() throws Exception { List queryElements = new ArrayList(); List queryResult = new ArrayList(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "attribute1")); queryResult = accessObjectFactory.getDataObjectAO(irodsAccount) - .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, - testFileNameFQ); + .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, testFileNameFQ); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute attribute1", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute attribute1", !queryResult.isEmpty()); for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("attribute1 has wrong value", "value1", - mdd.getAvuValue()); + Assert.assertEquals("attribute1 has wrong value", "value1", mdd.getAvuValue()); } queryElements.clear(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "attribute2")); queryResult = accessObjectFactory.getDataObjectAO(irodsAccount) - .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, - testFileNameFQ); + .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, testFileNameFQ); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute attribute2", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute attribute2", !queryResult.isEmpty()); for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("attribute2 has wrong value", "42", - mdd.getAvuValue()); + Assert.assertEquals("attribute2 has wrong value", "42", mdd.getAvuValue()); } queryElements.clear(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "optional1")); queryResult = accessObjectFactory.getDataObjectAO(irodsAccount) - .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, - testFileNameFQ); + .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, testFileNameFQ); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute optional1", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute optional1", !queryResult.isEmpty()); for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("attribute2 has wrong value", - "optional_value1", mdd.getAvuValue()); + Assert.assertEquals("attribute2 has wrong value", "optional_value1", mdd.getAvuValue()); } } @@ -189,54 +162,41 @@ public void saveTemplateToSystemMetadataForDataObject() throws Exception { public void saveTemplateToSystemMetadataForCollection() throws Exception { String testDirName1 = "saveTemplateToSystemMetadataForCollectionDir"; - String targetIrodsCollection1 = testingPropertiesHelper - .buildIRODSCollectionAbsolutePathFromTestProperties( - testingProperties, IRODS_TEST_SUBDIR_PATH + '/' - + testDirName1); + String targetIrodsCollection1 = testingPropertiesHelper.buildIRODSCollectionAbsolutePathFromTestProperties( + testingProperties, IRODS_TEST_SUBDIR_PATH + '/' + testDirName1); - IRODSAccount irodsAccount = testingPropertiesHelper - .buildIRODSAccountFromTestProperties(testingProperties); + IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem - .getIRODSAccessObjectFactory(); + IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - IRODSFile targetCollectionAsFile1 = accessObjectFactory - .getIRODSFileFactory(irodsAccount).instanceIRODSFile( - targetIrodsCollection1); + IRODSFile targetCollectionAsFile1 = accessObjectFactory.getIRODSFileFactory(irodsAccount) + .instanceIRODSFile(targetIrodsCollection1); targetCollectionAsFile1.mkdirs(); - JargonMetadataResolver resolver = new JargonMetadataResolver( - irodsAccount, accessObjectFactory); + JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - JargonMetadataExporter exporter = new JargonMetadataExporter( - accessObjectFactory, irodsAccount); + JargonMetadataExporter exporter = new JargonMetadataExporter(accessObjectFactory, irodsAccount); - String mdTemplatePath1 = resolver - .findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); + String mdTemplatePath1 = resolver.findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); - DataTransferOperations dataTransferOperations = irodsFileSystem - .getIRODSAccessObjectFactory().getDataTransferOperations( - irodsAccount); + DataTransferOperations dataTransferOperations = irodsFileSystem.getIRODSAccessObjectFactory() + .getDataTransferOperations(irodsAccount); - dataTransferOperations.putOperation(TEMPLATE_FILE_NAME1, - mdTemplatePath1, irodsAccount.getDefaultStorageResource(), - null, null); + dataTransferOperations.putOperation(TEMPLATE_FILE_NAME1, mdTemplatePath1, + irodsAccount.getDefaultStorageResource(), null, null); String templateFqName1 = mdTemplatePath1 + '/' + TEMPLATE_NOPATH1; UUID uuid1 = UUID.randomUUID(); - AvuData avuData = AvuData.instance("test1", uuid1.toString(), - JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - templateFqName1, avuData); + AvuData avuData = AvuData.instance("test1", uuid1.toString(), JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(templateFqName1, avuData); - MetadataTemplate metadataTemplate = resolver - .findTemplateByFqName(templateFqName1); - FormBasedMetadataTemplate fbmt = null; + MetadataTemplate metadataTemplate = resolver.findTemplateByFqName(templateFqName1); + MetadataTemplate fbmt = null; if (metadataTemplate.getType() == TemplateTypeEnum.FORM_BASED) { - fbmt = (FormBasedMetadataTemplate) metadataTemplate; + fbmt = metadataTemplate; } for (MetadataElement me : fbmt.getElements()) { @@ -249,65 +209,52 @@ public void saveTemplateToSystemMetadataForCollection() throws Exception { } } - exporter.saveTemplateToSystemMetadataOnObject(fbmt, - targetIrodsCollection1); + exporter.saveTemplateToSystemMetadataOnObject(fbmt, targetIrodsCollection1); List queryElements = new ArrayList(); List queryResult = new ArrayList(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "attribute1")); queryResult = accessObjectFactory.getCollectionAO(irodsAccount) - .findMetadataValuesByMetadataQueryForCollection(queryElements, - targetIrodsCollection1); + .findMetadataValuesByMetadataQueryForCollection(queryElements, targetIrodsCollection1); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute attribute1", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute attribute1", !queryResult.isEmpty()); for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("attribute1 has wrong value", "value1", - mdd.getAvuValue()); + Assert.assertEquals("attribute1 has wrong value", "value1", mdd.getAvuValue()); } queryElements.clear(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "attribute2")); queryResult = accessObjectFactory.getCollectionAO(irodsAccount) - .findMetadataValuesByMetadataQueryForCollection(queryElements, - targetIrodsCollection1); + .findMetadataValuesByMetadataQueryForCollection(queryElements, targetIrodsCollection1); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute attribute2", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute attribute2", !queryResult.isEmpty()); for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("attribute2 has wrong value", "42", - mdd.getAvuValue()); + Assert.assertEquals("attribute2 has wrong value", "42", mdd.getAvuValue()); } queryElements.clear(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "optional1")); queryResult = accessObjectFactory.getCollectionAO(irodsAccount) - .findMetadataValuesByMetadataQueryForCollection(queryElements, - targetIrodsCollection1); + .findMetadataValuesByMetadataQueryForCollection(queryElements, targetIrodsCollection1); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute optional1", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute optional1", !queryResult.isEmpty()); for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("attribute2 has wrong value", - "optional_value1", mdd.getAvuValue()); + Assert.assertEquals("attribute2 has wrong value", "optional_value1", mdd.getAvuValue()); } } @@ -315,60 +262,46 @@ public void saveTemplateToSystemMetadataForCollection() throws Exception { public void saveTemplateToSystemMetadataWithListInput() throws Exception { String testDirName1 = "saveTemplateToSystemMetadataWithListInputDir"; - String targetIrodsCollection1 = testingPropertiesHelper - .buildIRODSCollectionAbsolutePathFromTestProperties( - testingProperties, IRODS_TEST_SUBDIR_PATH + '/' - + testDirName1); + String targetIrodsCollection1 = testingPropertiesHelper.buildIRODSCollectionAbsolutePathFromTestProperties( + testingProperties, IRODS_TEST_SUBDIR_PATH + '/' + testDirName1); - IRODSAccount irodsAccount = testingPropertiesHelper - .buildIRODSAccountFromTestProperties(testingProperties); + IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem - .getIRODSAccessObjectFactory(); + IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - IRODSFile targetCollectionAsFile1 = accessObjectFactory - .getIRODSFileFactory(irodsAccount).instanceIRODSFile( - targetIrodsCollection1); + IRODSFile targetCollectionAsFile1 = accessObjectFactory.getIRODSFileFactory(irodsAccount) + .instanceIRODSFile(targetIrodsCollection1); targetCollectionAsFile1.mkdirs(); - JargonMetadataResolver resolver = new JargonMetadataResolver( - irodsAccount, accessObjectFactory); + JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - JargonMetadataExporter exporter = new JargonMetadataExporter( - accessObjectFactory, irodsAccount); + JargonMetadataExporter exporter = new JargonMetadataExporter(accessObjectFactory, irodsAccount); - String mdTemplatePath1 = resolver - .findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); + String mdTemplatePath1 = resolver.findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); - DataTransferOperations dataTransferOperations = irodsFileSystem - .getIRODSAccessObjectFactory().getDataTransferOperations( - irodsAccount); + DataTransferOperations dataTransferOperations = irodsFileSystem.getIRODSAccessObjectFactory() + .getDataTransferOperations(irodsAccount); - dataTransferOperations.putOperation(TEMPLATE_FILE_NAME6, - mdTemplatePath1, irodsAccount.getDefaultStorageResource(), - null, null); + dataTransferOperations.putOperation(TEMPLATE_FILE_NAME6, mdTemplatePath1, + irodsAccount.getDefaultStorageResource(), null, null); String templateFqName1 = mdTemplatePath1 + '/' + TEMPLATE_NOPATH6; UUID uuid1 = UUID.randomUUID(); - AvuData avuData = AvuData.instance("test6", uuid1.toString(), - JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - templateFqName1, avuData); + AvuData avuData = AvuData.instance("test6", uuid1.toString(), JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(templateFqName1, avuData); // Create a file in targetIrodsCollection1 - dataTransferOperations.putOperation(TEST_FILE_NAME, - targetIrodsCollection1, + dataTransferOperations.putOperation(TEST_FILE_NAME, targetIrodsCollection1, irodsAccount.getDefaultStorageResource(), null, null); String testFileNameFQ = targetIrodsCollection1 + '/' + TEST_FILE_NOPATH; - MetadataTemplate metadataTemplate = resolver - .findTemplateByFqName(templateFqName1); - FormBasedMetadataTemplate fbmt = null; + MetadataTemplate metadataTemplate = resolver.findTemplateByFqName(templateFqName1); + MetadataTemplate fbmt = null; if (metadataTemplate.getType() == TemplateTypeEnum.FORM_BASED) { - fbmt = (FormBasedMetadataTemplate) metadataTemplate; + fbmt = metadataTemplate; } for (MetadataElement me : fbmt.getElements()) { @@ -385,92 +318,73 @@ public void saveTemplateToSystemMetadataWithListInput() throws Exception { List queryElements = new ArrayList(); List queryResult = new ArrayList(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "string_list")); queryResult = accessObjectFactory.getDataObjectAO(irodsAccount) - .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, - testFileNameFQ); + .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, testFileNameFQ); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute string_list", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute string_list", !queryResult.isEmpty()); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create 4 instances of Attribute string_list", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create 4 instances of Attribute string_list", queryResult.size() == 4); } @Test - public void saveTemplateToSystemMetadataDeleteListAVUsOnFile() - throws Exception { + public void saveTemplateToSystemMetadataDeleteListAVUsOnFile() throws Exception { String testDirName1 = "saveTemplateToSystemMetadataDeleteListAVUsOnFileDir"; - String targetIrodsCollection1 = testingPropertiesHelper - .buildIRODSCollectionAbsolutePathFromTestProperties( - testingProperties, IRODS_TEST_SUBDIR_PATH + '/' - + testDirName1); + String targetIrodsCollection1 = testingPropertiesHelper.buildIRODSCollectionAbsolutePathFromTestProperties( + testingProperties, IRODS_TEST_SUBDIR_PATH + '/' + testDirName1); - IRODSAccount irodsAccount = testingPropertiesHelper - .buildIRODSAccountFromTestProperties(testingProperties); + IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); - IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem - .getIRODSAccessObjectFactory(); + IRODSAccessObjectFactory accessObjectFactory = irodsFileSystem.getIRODSAccessObjectFactory(); - IRODSFile targetCollectionAsFile1 = accessObjectFactory - .getIRODSFileFactory(irodsAccount).instanceIRODSFile( - targetIrodsCollection1); + IRODSFile targetCollectionAsFile1 = accessObjectFactory.getIRODSFileFactory(irodsAccount) + .instanceIRODSFile(targetIrodsCollection1); targetCollectionAsFile1.mkdirs(); - JargonMetadataResolver resolver = new JargonMetadataResolver( - irodsAccount, accessObjectFactory); + JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - JargonMetadataExporter exporter = new JargonMetadataExporter( - accessObjectFactory, irodsAccount); + JargonMetadataExporter exporter = new JargonMetadataExporter(accessObjectFactory, irodsAccount); - String mdTemplatePath1 = resolver - .findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); + String mdTemplatePath1 = resolver.findOrCreateMetadataTemplatesCollection(targetIrodsCollection1); - DataTransferOperations dataTransferOperations = irodsFileSystem - .getIRODSAccessObjectFactory().getDataTransferOperations( - irodsAccount); + DataTransferOperations dataTransferOperations = irodsFileSystem.getIRODSAccessObjectFactory() + .getDataTransferOperations(irodsAccount); - dataTransferOperations.putOperation(TEMPLATE_FILE_NAME6, - mdTemplatePath1, irodsAccount.getDefaultStorageResource(), - null, null); + dataTransferOperations.putOperation(TEMPLATE_FILE_NAME6, mdTemplatePath1, + irodsAccount.getDefaultStorageResource(), null, null); String templateFqName1 = mdTemplatePath1 + '/' + TEMPLATE_NOPATH6; UUID uuid1 = UUID.randomUUID(); - AvuData avuData = AvuData.instance("test6", uuid1.toString(), - JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - templateFqName1, avuData); + AvuData avuData = AvuData.instance("test6", uuid1.toString(), JargonMetadataTemplateConstants.MD_TEMPLATE_UNIT); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(templateFqName1, avuData); // Create a file in targetIrodsCollection1 - dataTransferOperations.putOperation(TEST_FILE_NAME, - targetIrodsCollection1, + dataTransferOperations.putOperation(TEST_FILE_NAME, targetIrodsCollection1, irodsAccount.getDefaultStorageResource(), null, null); String testFileNameFQ = targetIrodsCollection1 + '/' + TEST_FILE_NOPATH; // Create a list AVU on the test file - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - testFileNameFQ, AvuData.instance("string_list", "value1", "")); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - testFileNameFQ, AvuData.instance("string_list", "value2", "")); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - testFileNameFQ, AvuData.instance("string_list", "value3", "")); - accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata( - testFileNameFQ, AvuData.instance("string_list", "value4", "")); - - MetadataTemplate metadataTemplate = resolver - .findTemplateByFqName(templateFqName1); - FormBasedMetadataTemplate fbmt = null; + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(testFileNameFQ, + AvuData.instance("string_list", "value1", "")); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(testFileNameFQ, + AvuData.instance("string_list", "value2", "")); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(testFileNameFQ, + AvuData.instance("string_list", "value3", "")); + accessObjectFactory.getDataObjectAO(irodsAccount).addAVUMetadata(testFileNameFQ, + AvuData.instance("string_list", "value4", "")); + + MetadataTemplate metadataTemplate = resolver.findTemplateByFqName(templateFqName1); + MetadataTemplate fbmt = null; if (metadataTemplate.getType() == TemplateTypeEnum.FORM_BASED) { - fbmt = (FormBasedMetadataTemplate) metadataTemplate; + fbmt = metadataTemplate; } for (MetadataElement me : fbmt.getElements()) { @@ -484,25 +398,20 @@ public void saveTemplateToSystemMetadataDeleteListAVUsOnFile() List queryElements = new ArrayList(); List queryResult = new ArrayList(); - queryElements.add(AVUQueryElement.instanceForValueQuery( - AVUQueryElement.AVUQueryPart.ATTRIBUTE, + queryElements.add(AVUQueryElement.instanceForValueQuery(AVUQueryElement.AVUQueryPart.ATTRIBUTE, QueryConditionOperators.EQUAL, "string_list")); queryResult = accessObjectFactory.getDataObjectAO(irodsAccount) - .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, - testFileNameFQ); + .findMetadataValuesForDataObjectUsingAVUQuery(queryElements, testFileNameFQ); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject did not create Attribute string_list", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject did not create Attribute string_list", !queryResult.isEmpty()); - Assert.assertTrue( - "saveTemplateToSystemMetadataOnObject removed original instances of Attribute string_list", + Assert.assertTrue("saveTemplateToSystemMetadataOnObject removed original instances of Attribute string_list", queryResult.size() == 1); - + for (MetaDataAndDomainData mdd : queryResult) { - Assert.assertEquals("string_list has wrong value", - "new_value", mdd.getAvuValue()); + Assert.assertEquals("string_list has wrong value", "new_value", mdd.getAvuValue()); } } } diff --git a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataResolverTest.java b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataResolverTest.java index 22c440e..86dc1fb 100644 --- a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataResolverTest.java +++ b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/JargonMetadataResolverTest.java @@ -73,7 +73,7 @@ public void testSaveMetadataTemplateAsJsonNoDotIrodsSpecifiedDir() throws Except IRODSFile targetCollectionAsFile = accessObjectFactory.getIRODSFileFactory(irodsAccount) .instanceIRODSFile(targetIrodsCollection); targetCollectionAsFile.mkdirs(); - FormBasedMetadataTemplate template = new FormBasedMetadataTemplate(); + MetadataTemplate template = new MetadataTemplate(); template.setAuthor("me"); template.setDescription("descr"); template.setName(testDirName); @@ -431,7 +431,7 @@ public void findTemplateByNameSingleMatch() throws Exception { String templateFqName = mdTemplatePath2 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); resolver.setPublicTemplateLocations(Arrays.asList(targetIrodsCollection3)); metadataTemplate = resolver.findTemplateByName("test1", targetIrodsCollection2); @@ -485,7 +485,7 @@ public void findTemplateByNameDuplicateMatch() throws Exception { String templateFqName = mdTemplatePath2 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); resolver.setPublicTemplateLocations(Arrays.asList(targetIrodsCollection3)); metadataTemplate = resolver.findTemplateByName("test1", mdTemplatePath2); @@ -537,7 +537,7 @@ public void findTemplateByNameNoMatch() throws Exception { dataTransferOperations.putOperation(TEMPLATE_FILE_NAME3, targetIrodsCollection3, irodsAccount.getDefaultStorageResource(), null, null); - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); resolver.setPublicTemplateLocations(Arrays.asList(targetIrodsCollection3)); metadataTemplate = resolver.findTemplateByName("notGoingToMatch", mdTemplatePath2); @@ -597,7 +597,7 @@ public void findTemplateByNameInDirectoryHierarchyFilePresent() throws Exception String templateFqName = mdTemplatePath3 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByNameInDirectoryHierarchy("test1", targetIrodsCollection3); @@ -655,7 +655,7 @@ public void findTemplateByNameInDirectoryHierarchyFileAbsent() throws Exception dataTransferOperations.putOperation(TEMPLATE_FILE_NAME3, mdTemplatePath1, irodsAccount.getDefaultStorageResource(), null, null); - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByNameInDirectoryHierarchy("notGoingToBeFound", targetIrodsCollection3); @@ -705,7 +705,7 @@ public void findTemplateByNameInPublicTemplatesFilePresent() throws Exception { String templateFqName = targetIrodsCollection1 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); @@ -755,7 +755,7 @@ public void findTemplateByNameInPublicTemplatesFileAbsent() throws Exception { dataTransferOperations.putOperation(TEMPLATE_FILE_NAME2, targetIrodsCollection2, irodsAccount.getDefaultStorageResource(), null, null); - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); @@ -800,7 +800,7 @@ public void findTemplateByFqNameValid() throws Exception { String templateFqName = mdTemplatePath1 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByFqName(templateFqName); @@ -839,7 +839,7 @@ public void findTemplateByFqNameInvalid() throws Exception { String badTemplateFqName = mdTemplatePath1 + "/notReallyATemplateFile"; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByFqName(badTemplateFqName); @@ -962,12 +962,11 @@ public void saveFormBasedTemplateAsJsonGivenMdTemplateDir() throws Exception { String templateFqName = mdTemplatePath1 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByFqName(templateFqName); - String pathToSavedFile = resolver.saveFormBasedTemplateAsJSON((FormBasedMetadataTemplate) metadataTemplate, - mdTemplatePath2); + String pathToSavedFile = resolver.saveFormBasedTemplateAsJSON(metadataTemplate, mdTemplatePath2); MetadataTemplate template = resolver.findTemplateByFqName(pathToSavedFile); @@ -1015,12 +1014,11 @@ public void saveFormBasedTemplateAsJsonGivenParentDir() throws Exception { String templateFqName = mdTemplatePath1 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByFqName(templateFqName); - String pathToSavedFile = resolver.saveFormBasedTemplateAsJSON((FormBasedMetadataTemplate) metadataTemplate, - targetIrodsCollection2); + String pathToSavedFile = resolver.saveFormBasedTemplateAsJSON(metadataTemplate, targetIrodsCollection2); MetadataTemplate template = resolver.findTemplateByFqName(pathToSavedFile); @@ -1070,12 +1068,11 @@ public void saveFormBasedTemplateAsJsonCheckAVUs() throws Exception { String templateFqName = mdTemplatePath1 + '/' + TEMPLATE_NOPATH1; - MetadataTemplate metadataTemplate = new FormBasedMetadataTemplate(); + MetadataTemplate metadataTemplate = new MetadataTemplate(); metadataTemplate = resolver.findTemplateByFqName(templateFqName); - String pathToSavedFile = resolver.saveFormBasedTemplateAsJSON((FormBasedMetadataTemplate) metadataTemplate, - mdTemplatePath2); + String pathToSavedFile = resolver.saveFormBasedTemplateAsJSON(metadataTemplate, mdTemplatePath2); List templateAVUs = resolver.queryTemplateAVUForFile(pathToSavedFile); List elementAVUs = resolver.queryElementAVUForFile(pathToSavedFile); @@ -1223,12 +1220,11 @@ public void updateFormBasedTemplateValid() throws Exception { JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - FormBasedMetadataTemplate template = (FormBasedMetadataTemplate) resolver - .findTemplateByFqName(mdTemplateFqName1); + MetadataTemplate template = resolver.findTemplateByFqName(mdTemplateFqName1); String mdTemplateFqName2 = resolver.saveFormBasedTemplateAsJSON(template, targetIrodsCollection2); - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName2); + template = resolver.findTemplateByFqName(mdTemplateFqName2); MetadataElement me = new MetadataElement(); me.setElementName("addedElement"); @@ -1242,7 +1238,7 @@ public void updateFormBasedTemplateValid() throws Exception { Assert.assertTrue("updateFormBasedTemplateByFqName returned false", retVal); - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName2); + template = resolver.findTemplateByFqName(mdTemplateFqName2); Assert.assertEquals("template description not changed by updateFormBasedTemplateByFqName", template.getDescription(), "TemplateModified"); @@ -1290,12 +1286,11 @@ public void updateFormBasedTemplateUuidMismatch() throws Exception { JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - FormBasedMetadataTemplate template = (FormBasedMetadataTemplate) resolver - .findTemplateByFqName(mdTemplateFqName1); + MetadataTemplate template = resolver.findTemplateByFqName(mdTemplateFqName1); String mdTemplateFqName2 = resolver.saveFormBasedTemplateAsJSON(template, targetIrodsCollection2); - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName2); + template = resolver.findTemplateByFqName(mdTemplateFqName2); MetadataElement me = new MetadataElement(); me.setElementName("addedElement"); @@ -1308,7 +1303,7 @@ public void updateFormBasedTemplateUuidMismatch() throws Exception { boolean retVal = resolver.updateFormBasedTemplateByFqName(mdTemplateFqName2, template); - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName2); + template = resolver.findTemplateByFqName(mdTemplateFqName2); Assert.assertFalse("updateFormBasedTemplateByFqName returned true", retVal); Assert.assertEquals("template description inappropriately changed by updateFormBasedTemplateByFqName", @@ -1366,19 +1361,18 @@ public void updateFormBasedTemplateFqNameInvalid() throws Exception { JargonMetadataResolver resolver = new JargonMetadataResolver(irodsAccount, accessObjectFactory); - FormBasedMetadataTemplate template = (FormBasedMetadataTemplate) resolver - .findTemplateByFqName(mdTemplateFqName1); + MetadataTemplate template = resolver.findTemplateByFqName(mdTemplateFqName1); String mdTemplateFqName3 = resolver.saveFormBasedTemplateAsJSON(template, targetIrodsCollection1); - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName2); + template = resolver.findTemplateByFqName(mdTemplateFqName2); String mdTemplateFqName4 = resolver.saveFormBasedTemplateAsJSON(template, targetIrodsCollection2); String mdTemplateFqName5 = resolver.computeMetadataTemplatesPathUnderParent(targetIrodsCollection2) + '/' + TEMPLATE_NOPATH1; - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName3); + template = resolver.findTemplateByFqName(mdTemplateFqName3); MetadataElement me = new MetadataElement(); me.setElementName("addedElement"); @@ -1393,7 +1387,7 @@ public void updateFormBasedTemplateFqNameInvalid() throws Exception { Assert.assertFalse("updateFormBasedTemplateByFqName returned true", retVal); MetadataTemplate template2 = resolver.findTemplateByFqName(mdTemplateFqName5); - template = (FormBasedMetadataTemplate) resolver.findTemplateByFqName(mdTemplateFqName4); + template = resolver.findTemplateByFqName(mdTemplateFqName4); Assert.assertNull("updateFormBasedTemplateByFqName inappropriately saved a file", template2); @@ -1553,10 +1547,10 @@ public void getAndMergeTemplateListForFile() throws Exception { // Because templates are assigned random UUIDs, they come out in random // order. Need to find the right one to test. - FormBasedMetadataTemplate template = null; + MetadataTemplate template = null; for (MetadataTemplate mt : result.getTemplates()) { if (mt.getName().compareTo("test2") == 0) { - template = (FormBasedMetadataTemplate) mt; + template = mt; break; } } @@ -1645,10 +1639,10 @@ public void getAndMergeTemplateListForCollection() throws Exception { // Because templates are assigned random UUIDs, they come out in random // order. Need to find the right one to test. - FormBasedMetadataTemplate template = null; + MetadataTemplate template = null; for (MetadataTemplate mt : result.getTemplates()) { if (mt.getName().compareTo("test2") == 0) { - template = (FormBasedMetadataTemplate) mt; + template = mt; break; } } @@ -1696,7 +1690,7 @@ public void getAndMergeTemplateWithRefIrodsQueryForFile() throws Exception { MetadataMergeResult result = resolver.getAndMergeTemplateListForPath(testFileNameFQ); - FormBasedMetadataTemplate template = (FormBasedMetadataTemplate) result.getTemplates().get(0); + MetadataTemplate template = result.getTemplates().get(0); for (MetadataElement me : template.getElements()) { if (me.getName().equalsIgnoreCase("data_name")) { @@ -1755,7 +1749,7 @@ public void getAndMergeTemplateWithRefIrodsQueryForCollection() throws Exception MetadataMergeResult result = resolver.getAndMergeTemplateListForPath(targetIrodsCollection1); - FormBasedMetadataTemplate template = (FormBasedMetadataTemplate) result.getTemplates().get(0); + MetadataTemplate template = result.getTemplates().get(0); for (MetadataElement me : template.getElements()) { if (me.getName().equalsIgnoreCase("coll_owner")) { diff --git a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/AllTests.java b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/AllTests.java index 2848846..5dba5e5 100644 --- a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/AllTests.java +++ b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/AllTests.java @@ -8,8 +8,7 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({ JargonMetadataResolverTest.class, - JargonMetadataExporterTest.class, +@SuiteClasses({ JargonMetadataResolverTest.class, JargonMetadataExporterTest.class, MetadataTemplateFormBotServiceTest.class }) public class AllTests { diff --git a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/package-info.java b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/package-info.java index 513ee94..33e2cb8 100644 --- a/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/package-info.java +++ b/metadata-templates/src/test/java/org/irods/jargon/metadatatemplate/unittest/package-info.java @@ -1,5 +1,6 @@ /** * Unit test suites and support + * * @author Mike Conway - DICe * */