Skip to content

Commit

Permalink
Updated a few javadoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkhi committed Mar 13, 2024
1 parent 16fd324 commit 3f479b4
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, ExportTemplateColumnDef> getColumnOrderMap() ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -76,5 +106,4 @@ enum DataModification {
this.label = label;
}
}
String getOperatedValue(String input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Boolean> columnsToWriteMap, ExportTemplate exportTemplate) {
if (exportTemplate != null) {
return new TemplateBasedDataWriter(exportTemplate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,10 @@ public abstract class FormattedDataWriter {

private String[] customisedHeaders;

public abstract void writeDataRowsForOneRowPerFile(List<? extends ProfileResourceNode> nodes, CsvWriter csvWriter);

public abstract void writeDataRowsForOneRowPerFormat(List<? extends ProfileResourceNode> nodes, CsvWriter csvWriter);

public abstract void writeHeadersForOneRowPerFile(List<? extends ProfileResourceNode> nodes, String[] headers, CsvWriter csvWriter);

public abstract void writeDataRowsForOneRowPerFile(List<? extends ProfileResourceNode> nodes, CsvWriter csvWriter);
public abstract void writeHeadersForOneRowPerFormat(List<? extends ProfileResourceNode> nodes, String[] headers, CsvWriter csvWriter);
public abstract void writeDataRowsForOneRowPerFormat(List<? extends ProfileResourceNode> nodes, CsvWriter csvWriter);

protected static String nullSafeName(Enum<?> value) {
return value == null ? CsvWriterConstants.EMPTY_STRING : value.toString();
Expand Down

0 comments on commit 3f479b4

Please sign in to comment.