Skip to content

Commit

Permalink
Addressing code review
Browse files Browse the repository at this point in the history
  • Loading branch information
arp-0984 committed Oct 12, 2023
1 parent e439685 commit 7b7e6ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/main/java/emissary/core/constants/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ public class Parameters {
// Common parameters
public static final String DOCUMENT_TITLE = "DocumentTitle";
public static final String EVENT_DATE = "EventDate";
public static final String FILEXT = "FILEXT";
public static final String FILE_ABSOLUTEPATH = "FILE_ABSOLUTEPATH";
public static final String FILE_DATE = "FILE_DATE";
public static final String FILE_NAME = "FILE_NAME";
public static final String INPUT_FILEDATE = "INPUT_FILEDATE";
public static final String INPUT_FILENAME = "INPUT_FILENAME";
public static final String ORIGINAL_FILENAME = "Original-Filename";
public static final String SUMMARY = "SUMMARY";
public static final String FILE_ABSOLUTEPATH = "FILE_ABSOLUTEPATH";

// Common parameter prefixes

Expand Down
21 changes: 11 additions & 10 deletions src/main/java/emissary/output/DropOffUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static emissary.core.Form.PREFIXES_LANG;
import static emissary.core.Form.TEXT;
import static emissary.core.Form.UNKNOWN;
import static emissary.core.constants.Parameters.FILEXT;
import static emissary.core.constants.Parameters.FILE_ABSOLUTEPATH;
import static emissary.core.constants.Parameters.ORIGINAL_FILENAME;

Expand Down Expand Up @@ -84,7 +85,7 @@ public class DropOffUtil {
private static final String DEFAULT_EVENT_DATE_TO_NOW = "DEFAULT_EVENT_DATE_TO_NOW";
protected boolean defaultEventDateToNow = true;

private static List<String> DEFAULT_FILENAME_FIELDS;
private static List<String> defaultFilenameFields;

/**
* Create with the default configuration
Expand Down Expand Up @@ -150,13 +151,13 @@ protected void configure(final Configurator configG) {
this.maxFilextLen = Integer.MAX_VALUE;
}

DEFAULT_FILENAME_FIELDS = new ArrayList<>();
List<String> defaultFilenameFields = actualConfigG.findEntries("FILENAME_FIELDS");
if (!defaultFilenameFields.isEmpty()) {
DEFAULT_FILENAME_FIELDS.addAll(defaultFilenameFields);
defaultFilenameFields = new ArrayList<>();
List<String> configuredFilenameFields = actualConfigG.findEntries("FILENAME_FIELDS");
if (!configuredFilenameFields.isEmpty()) {
defaultFilenameFields.addAll(configuredFilenameFields);
} else {
DEFAULT_FILENAME_FIELDS.add(ORIGINAL_FILENAME);
DEFAULT_FILENAME_FIELDS.add(FILE_ABSOLUTEPATH);
defaultFilenameFields.add(ORIGINAL_FILENAME);
defaultFilenameFields.add(FILE_ABSOLUTEPATH);
}
} else {
logger.debug("Configuration is null for DropOffUtil, using defaults");
Expand Down Expand Up @@ -984,7 +985,7 @@ public Date extractEventDateFrom(final IBaseDataObject d, final boolean lastReso
/**
* Utilizes the static methods getFullFilepathsFromParams and getFileExtensions to extract the file extensions from all
* the filenames of the object of a given {@link IBaseDataObject}. If one or more file extensions are extracted, the
* IBaseDataObject's "FILEXT" parameter is set as the unique set of extracted file extensions, converted to lowercase.
* IBaseDataObject's FILEXT parameter is set as the unique set of extracted file extensions, converted to lowercase.
*
* @param p IBaseDataObject to process
*
Expand All @@ -993,7 +994,7 @@ void extractUniqueFileExtensions(IBaseDataObject p) {
List<String> filenames = getFullFilepathsFromParams(p);
Set<String> extensions = getFileExtensions(filenames, this.maxFilextLen);
if (!extensions.isEmpty()) {
p.setParameter("FILEXT", extensions);
p.setParameter(FILEXT, extensions);
}
}

Expand Down Expand Up @@ -1028,7 +1029,7 @@ public static List<String> getFullFilepathsFromParams(IBaseDataObject d) {

List<String> filenames = new ArrayList<>();

for (String ibdoField : DEFAULT_FILENAME_FIELDS) {
for (String ibdoField : defaultFilenameFields) {
if (d.hasParameter(ibdoField)) {
for (Object filename : d.getParameter(ibdoField)) {
String stringFileName = (String) filename;
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/emissary/output/DropOffUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static emissary.core.Form.TEXT;
import static emissary.core.Form.UNKNOWN;
import static emissary.core.constants.Parameters.EVENT_DATE;
import static emissary.core.constants.Parameters.FILEXT;
import static emissary.core.constants.Parameters.FILE_ABSOLUTEPATH;
import static emissary.core.constants.Parameters.FILE_DATE;
import static emissary.core.constants.Parameters.ORIGINAL_FILENAME;
Expand All @@ -39,7 +40,6 @@
class DropOffUtilTest extends UnitTest {
private DropOffUtil util = null;
private IBaseDataObject payload = null;
static final String FILEXT = "FILEXT";

@BeforeEach
public void createUtil() {
Expand Down Expand Up @@ -612,23 +612,24 @@ void testExtractFileExtensionsWithFullFilepaths() {
String[] originalFilenames = {"", "D:\\Users\\jdoe\\interesting.folder\\a.table", "flowers.456.123",
"/home/jdoe/SHARED_D.IR/cat", "taxes.thisfileextensionistoolong", ""};

String[][] extensions = {{"csv"}, {"table"}, {"zzz", "123"}, {"mov"}, {"bashrc"}, {""}};
String[][] extensions = {{"csv"}, {"table"}, {"zzz", "123"}, {"mov"}, {"bashrc"}, {}};

final IBaseDataObject ibdo = new BaseDataObject();

for (int i = 0; i < fileAbsolutepaths.length; i++) {
ibdo.setParameter(FILE_ABSOLUTEPATH, fileAbsolutepaths[i]);
ibdo.setParameter(ORIGINAL_FILENAME, originalFilenames[i]);
util.extractUniqueFileExtensions(ibdo);
if (extensions[i].length == 0) {
assertFalse(ibdo.hasParameter(FILEXT));
}
for (String extension : extensions[i]) {
assertEquals(extensions[i].length, ibdo.getParameter(FILEXT).size(), "Only "
+ extensions[i].length + " file extensions should have been extracted");
assertTrue(ibdo.getParameter(FILEXT).contains(extension), "FILEXT should be extracted");
}
// reset for the next test
ibdo.setParameter(FILEXT, "");
ibdo.setParameter(FILE_ABSOLUTEPATH, "");
ibdo.setParameter(ORIGINAL_FILENAME, "");
ibdo.clearParameters();
}
}

Expand All @@ -641,7 +642,7 @@ void testCleanSpecPath() {
}

@Test
void testGetBestFilename() {
void testGetFullFilepathsFromParams() {
IBaseDataObject ibdo = new BaseDataObject();
List<String> bestFilenames;

Expand Down

0 comments on commit 7b7e6ce

Please sign in to comment.