diff --git a/droid-command-line/src/main/java/uk/gov/nationalarchives/droid/command/action/ExportCommand.java b/droid-command-line/src/main/java/uk/gov/nationalarchives/droid/command/action/ExportCommand.java index 9545b7069..15d385a1e 100644 --- a/droid-command-line/src/main/java/uk/gov/nationalarchives/droid/command/action/ExportCommand.java +++ b/droid-command-line/src/main/java/uk/gov/nationalarchives/droid/command/action/ExportCommand.java @@ -221,17 +221,19 @@ public String getColumnsToWrite() { /** * * @return the export details for this export command. + * For an export from CLI, + * OutputEncoding is always defaulted to UTF-8 + * exportTemplate is always null until we implement support for the template in CLI */ private ExportDetails getExportDetails() { ExportDetails.ExportDetailsBuilder builder = new ExportDetails.ExportDetailsBuilder(); - ExportDetails details = builder.withExportOptions(getExportOptions()) + + return builder.withExportOptions(getExportOptions()) .withOutpuEncoding("UTF-8") //default .withBomFlag(isBom()) .withQuotingAllFields(getQuoteAllFields()) .withColumnsToWrite(getColumnsToWrite()) .withExportTemplatePath(null) .build(); - - return details; } } diff --git a/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportDetails.java b/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportDetails.java index 094b8b6d5..ab6a1f907 100644 --- a/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportDetails.java +++ b/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportDetails.java @@ -51,7 +51,7 @@ public final class ExportDetails { private final String exportTemplatePath; /** - * Private constructor. The consumer can get the ExportDetails instance using the ExportDetailsBuilder. + * Private constructor. The consumer can get the ExportDetails instance using ExportDetailsBuilder. * @param exportOptions whether it is a "per row" export or "per format" export * @param outputEncoding encoding to be used * @param bomFlag whether to use BOM @@ -117,9 +117,9 @@ public String getExportTemplatePath() { */ public static class ExportDetailsBuilder { private ExportOptions exportOptions = ExportOptions.ONE_ROW_PER_FILE; - private String outputEncoding; + private String outputEncoding = "UTF-8"; private boolean bomFlag; - private boolean quoteAllFields; + private boolean quoteAllFields = true; private String columnsToWrite; private String exportTemplatePath; @@ -147,8 +147,8 @@ public ExportDetailsBuilder withColumnsToWrite(String columns) { return this; } - public ExportDetailsBuilder withExportTemplatePath(String templatePAth) { - this.exportTemplatePath = templatePAth; + public ExportDetailsBuilder withExportTemplatePath(String templatePath) { + this.exportTemplatePath = templatePath; return this; } diff --git a/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplate.java b/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplate.java index 07c429154..e8a052d92 100644 --- a/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplate.java +++ b/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplate.java @@ -33,7 +33,15 @@ import java.util.Map; +/** + * ExportTemplate interface. + * There is only one method which returns a map of integer -> ExportTemplateColumnDef + */ public interface ExportTemplate { + /** + * Get the map of Integer -> ExportTemplateColumnDef representing column order. + * @return Map with keys as column order and values as column definition + */ Map getColumnOrderMap() ; } diff --git a/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplateColumnDef.java b/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplateColumnDef.java index f09cd77f7..c5746e720 100644 --- a/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplateColumnDef.java +++ b/droid-export-interfaces/src/main/java/uk/gov/nationalarchives/droid/export/interfaces/ExportTemplateColumnDef.java @@ -31,13 +31,43 @@ */ package uk.gov.nationalarchives.droid.export.interfaces; +/** + * Export template column definition. + */ public interface ExportTemplateColumnDef { + /** + * Returns the header label to be used in the output for this column + * @return header + */ String getHeaderLabel(); + + /** + * Returns the well-known column names from one of the default headers + * Throws an exception if the definition represents a non-profile column + * @return origianl column name + */ String getOriginalColumnName(); + + /** + * Returns the data value, if any associated with this column definition. + * Throws an exception if the data is coming from profile results + * @return data value + */ String getDataValue(); + /** + * Returns the column type for this column definition + * @return column type + */ ColumnType getColumnType(); + /** + * Returns the result after performing the specific operation on the input + * @param input String representing input data + * @return String after performing operation associated with this column definition. + */ + String getOperatedValue(String input); + /** * Column type as defined in the ExportTemplate. There are 3 types of columns. */ @@ -76,5 +106,4 @@ enum DataModification { this.label = label; } } - String getOperatedValue(String input); } diff --git a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/ExportManagerImpl.java b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/ExportManagerImpl.java index 1e99b340f..c78b652db 100644 --- a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/ExportManagerImpl.java +++ b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/ExportManagerImpl.java @@ -31,21 +31,20 @@ */ package uk.gov.nationalarchives.droid.export; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.FutureTask; - import uk.gov.nationalarchives.droid.core.interfaces.filter.Filter; import uk.gov.nationalarchives.droid.export.interfaces.ExportDetails; import uk.gov.nationalarchives.droid.export.interfaces.ExportManager; import uk.gov.nationalarchives.droid.export.interfaces.ItemWriter; -//import uk.gov.nationalarchives.droid.export.template.ExportTemplateBuilder; import uk.gov.nationalarchives.droid.export.template.ExportTemplateBuilder; import uk.gov.nationalarchives.droid.profile.ProfileContextLocator; import uk.gov.nationalarchives.droid.profile.ProfileResourceNode; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; + /** * @author rflitcroft * diff --git a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ConstantStringColumnDef.java b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ConstantStringColumnDef.java index a1bccd0a7..325e7f04c 100644 --- a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ConstantStringColumnDef.java +++ b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ConstantStringColumnDef.java @@ -33,26 +33,44 @@ import uk.gov.nationalarchives.droid.export.interfaces.ExportTemplateColumnDef; +/** + * Class for a column definition representing constant string in the export template. + * e.g. foo: "bar" + * In such case, "foo" is the header for this column and "bar" is the value for it. + */ public class ConstantStringColumnDef implements ExportTemplateColumnDef { private final String headerLabel; - private String dataValue; + private final String dataValue; public ConstantStringColumnDef(String dataValue, String headerLabel) { this.dataValue = dataValue; this.headerLabel = headerLabel; } + /** + * Returns the header label associated with this column definition. + * @return header label + */ @Override public String getHeaderLabel() { return headerLabel; } + /** + * This type of column does not have a profile column associated with it. + * As a result, this method simply throws an exception if a consumer tries to get original column name + * @return nothing + */ @Override public String getOriginalColumnName() { throw new RuntimeException("Constant String Columns do not have an associated original column name"); } + /** + * Returns the data value associated with this column as defined in the export template. + * @return data value + */ @Override public String getDataValue() { return dataValue; @@ -63,6 +81,11 @@ public ColumnType getColumnType() { return ColumnType.ConstantString; } + /** + * This type of column does not have any associated operation, hence returns the input value as it is. + * @param input String representing input data + * @return the input value as it is + */ @Override public String getOperatedValue(String input) { return input; diff --git a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/DataModifierColumnDef.java b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/DataModifierColumnDef.java index 704637f20..c904411c3 100644 --- a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/DataModifierColumnDef.java +++ b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/DataModifierColumnDef.java @@ -33,26 +33,45 @@ import uk.gov.nationalarchives.droid.export.interfaces.ExportTemplateColumnDef; +/** + * Class for a column definition representing data modifier column in the export template. + * e.g. name: LCASE($FILE_PATH) + * In such case, "name" is the header for this column and the value is returned by performing + * an associated operation on the value retrieved from the underlying profile data. + * This type of column definition always has an underlying ProfileResourceNodeColumnDef + */ public class DataModifierColumnDef implements ExportTemplateColumnDef { private final DataModification operation; - private ProfileResourceNodeColumnDef innerDef; + private final ProfileResourceNodeColumnDef innerDef; public DataModifierColumnDef(ProfileResourceNodeColumnDef innerDef, DataModification operation) { this.innerDef = innerDef; this.operation = operation; } + /** + * Returns the header label associated with this column definition. + * @return header label + */ @Override public String getHeaderLabel() { return innerDef.getHeaderLabel(); } + /** + * Returns the original column name from an underlying definition. + * @return original name of underlying column. + */ @Override public String getOriginalColumnName() { return innerDef.getOriginalColumnName(); } + /** + * Return data value from the underlying definition + * @return data value from underlying definition + */ @Override public String getDataValue() { return innerDef.getDataValue(); @@ -63,6 +82,18 @@ public ColumnType getColumnType() { return ColumnType.DataModifier; } + /** + * Returns a value after performing an associated operation on the input value. + * e.g. If the operation is LCASE, it will convert the supplied value to lowercase + * @param input String representing input data + * @return String value after performing associated operation. + * Note: + * We only support LCASE and UCASE at the moment, if more operations need to be supported. + * they can be defined in the DataModification enum and appropriate conversion can be + * implemented here. We only support an operation returning String by taking in a single + * String parameter. + * + */ @Override public String getOperatedValue(String input) { switch(operation) { diff --git a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ProfileResourceNodeColumnDef.java b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ProfileResourceNodeColumnDef.java index 3ca84a761..0dfd060ec 100644 --- a/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ProfileResourceNodeColumnDef.java +++ b/droid-export/src/main/java/uk/gov/nationalarchives/droid/export/template/ProfileResourceNodeColumnDef.java @@ -33,6 +33,12 @@ import uk.gov.nationalarchives.droid.export.interfaces.ExportTemplateColumnDef; +/** + * Class for a column definition representing an underlying profile resource node column. + * e.g. identifier: $ID + * In such case, "identifier" is the header for this column and the data is retrieved from the + * ID column in the results . + */ public class ProfileResourceNodeColumnDef implements ExportTemplateColumnDef { private final String originalHeaderLabel; @@ -43,16 +49,29 @@ public ProfileResourceNodeColumnDef(String originalHeaderLabel, String headerLab this.headerLabel = headerLabel; } + /** + * Returns the header label associated with this column definition. + * @return header label + */ @Override public String getHeaderLabel() { return headerLabel; } + /** + * Returns the original column name + * @return The well-known name of column as it appears in the profile results + */ @Override public String getOriginalColumnName() { return originalHeaderLabel; } + /** + * This type of column does not have data associated with it. + * As a result, this method simply throws an exception if a consumer tries to get data from it + * @return nothing + */ @Override public String getDataValue() { throw new RuntimeException("Profile resource node column uses data from the profile results"); @@ -63,6 +82,11 @@ public ColumnType getColumnType() { return ColumnType.ProfileResourceNode; } + /** + * This type of column does not have any associated operation, hence returns the input value as it is. + * @param input String representing input data + * @return the input value as it is + */ @Override public String getOperatedValue(String input) { return input; diff --git a/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/DataWriterProvider.java b/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/DataWriterProvider.java index 69cc1aabf..31634e379 100644 --- a/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/DataWriterProvider.java +++ b/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/DataWriterProvider.java @@ -41,9 +41,15 @@ public final class DataWriterProvider { private DataWriterProvider() { - //private constructor to avoid anyone instantiating this class + //hidden constructor } + /** + * Instantiae and return specific data writer (either column based, or template based) + * @param columnsToWriteMap Map with a list of columns to write + * @param exportTemplate exportTemplate + * @return Specific data writer. + */ public static FormattedDataWriter getDataWriter(Map columnsToWriteMap, ExportTemplate exportTemplate) { if (exportTemplate != null) { return new TemplateBasedDataWriter(exportTemplate); diff --git a/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/FormattedDataWriter.java b/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/FormattedDataWriter.java index 7d93bbe5b..ddb33c4fd 100644 --- a/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/FormattedDataWriter.java +++ b/droid-results/src/main/java/uk/gov/nationalarchives/droid/profile/datawriter/FormattedDataWriter.java @@ -59,13 +59,10 @@ public abstract class FormattedDataWriter { private String[] customisedHeaders; - public abstract void writeDataRowsForOneRowPerFile(List nodes, CsvWriter csvWriter); - - public abstract void writeDataRowsForOneRowPerFormat(List nodes, CsvWriter csvWriter); - public abstract void writeHeadersForOneRowPerFile(List nodes, String[] headers, CsvWriter csvWriter); - + public abstract void writeDataRowsForOneRowPerFile(List nodes, CsvWriter csvWriter); public abstract void writeHeadersForOneRowPerFormat(List nodes, String[] headers, CsvWriter csvWriter); + public abstract void writeDataRowsForOneRowPerFormat(List nodes, CsvWriter csvWriter); protected static String nullSafeName(Enum value) { return value == null ? CsvWriterConstants.EMPTY_STRING : value.toString();