Skip to content

Commit

Permalink
remove deprecated datautil methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Sep 8, 2023
1 parent 2d36dd7 commit 551d431
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 206 deletions.
180 changes: 0 additions & 180 deletions src/main/java/emissary/util/DataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.format.DateTimeParseException;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.TreeSet;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

import static emissary.core.constants.Parameters.EVENT_DATE;
import static emissary.core.constants.Parameters.FILE_DATE;

public class DataUtil {
private static final Logger logger = LoggerFactory.getLogger(DataUtil.class);
private static final Pattern NL_REPL = Pattern.compile("[\n\r]+");
Expand Down Expand Up @@ -114,174 +102,6 @@ public static String csvescape(final String field) {
return s;
}

/**
* Get the event or collection date from a data object by checking the EventDate and FILE_DATE parameters. If both are
* missing default to today.
*
* @param payload data object to examine
* @return event date
*/
@Deprecated
public static Calendar getEventDate(final IBaseDataObject payload) {
String evDate = payload.getStringParameter(EVENT_DATE);
if (evDate == null) {
evDate = payload.getStringParameter(FILE_DATE);
}
Date eventDate = null;
if (evDate != null) {
try {
eventDate = emissary.util.TimeUtil.getDateFromISO8601(evDate);
} catch (DateTimeParseException e) {
logger.debug("Could not parse event date from payload, default to curren time", e);
eventDate = new Date();
}
} else {
eventDate = new Date();
}
return getCal(eventDate);
}

/**
* Get a Calendar object from a Date Object with the TZ set to UTC
*
* @param eventDate the date object to convert
* @return specified time UTC calendar
*/
@Deprecated
public static Calendar getCal(final Date eventDate) {
final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTime(eventDate);
return cal;
}

/**
* Merge two maps with semicolon delimited lists as values
*/
@Deprecated
public static void merge(final Map<String, String> info, final Map<String, String> recordInfo) {
for (final Map.Entry<String, String> entry : recordInfo.entrySet()) {
addInfo(info, entry.getKey(), entry.getValue());
}
}

/**
* Merge a key-value pair into a map, where the values are semicolon delimited lists
*
* @param info the map to merge into
* @param key the newly arriving key
* @param value the newly arriving value
*/
@Deprecated
public static void addInfo(final Map<String, String> info, final String key, final String value) {
if (info.containsKey(key)) {
final Set<String> existingValues = split(info.get(key));
existingValues.addAll(split(value));
info.put(key, join(existingValues));
} else {
info.put(key, value);
}
}

private static final Pattern SEMICOLON_SPLIT = Pattern.compile(IBaseDataObject.DEFAULT_PARAM_SEPARATOR);

/**
* Convert a semicolon delmited list as a set of strings
*
* @param values semicolon delimited list
* @return strings in list
*/
@Deprecated
public static Set<String> split(final String values) {
final Set<String> valuesSet = new HashSet<>();
final String[] items = SEMICOLON_SPLIT.split(values);
valuesSet.addAll(Arrays.asList(items));
return valuesSet;
}

/**
* Join a collection with a delimiter
*
* @param values the collection to join
* @param delim the string delimiter to use
* @param sort true if the output should be sorted
*/
@Deprecated
public static String join(final Collection<String> values, final String delim, final boolean sort) {
final Collection<String> tojoin;
if (sort) {
tojoin = new TreeSet<>();
tojoin.addAll(values);
} else {
tojoin = values;
}

final StringBuilder sb = new StringBuilder();
for (final String v : tojoin) {
if (sb.length() > 0) {
sb.append(delim);
}
sb.append(v);
}
return sb.toString();
}

/**
* Join a collection with a delimiter, output in sorted order
*
* @param values the collection to join
* @param delim the string delimiter to use
*/
@Deprecated
public static String join(final Collection<String> values, final String delim) {
return join(values, delim, true);
}

/**
* Join a collection with a semi-colon delimiter, output in sorted order
*
* @param values the collection to join
*/
@Deprecated
public static String join(final Collection<String> values) {
return join(values, IBaseDataObject.DEFAULT_PARAM_SEPARATOR, true);
}

/**
* Given a map of key-values, merge each into {@link IBaseDataObject} checking for duplication
*
* @param parent IBaseDataObject to merge String parameter with
* @param map key-value pairs to merge
*/
@Deprecated
public static void mergeMap(final IBaseDataObject parent, final Map<String, String> map) {
for (final Map.Entry<String, String> e : map.entrySet()) {
mergeParameter(parent, e.getKey(), e.getValue());
}
}

/**
* Assume key is name of String value parameter. Check wither parent already has string value in a delim-separated
* string. If so do nothing, otherwise, add delim + value
*
* @param parent IBaseDataObject to mere String parameter with
* @param key name of String parameter
* @param val String to append if not already in parents values
*/
@Deprecated
public static void mergeParameter(final IBaseDataObject parent, final String key, final String val) {
String param;
if (parent.hasParameter(key)) {
param = parent.getStringParameter(key);
final Set<String> oldvals = split(param);
final Set<String> newvals = split(val);
newvals.addAll(oldvals);
param = join(newvals);
} else {
param = val;
}
parent.setParameter(key, param);
}

/**
* Copy an array of metadata parameters from one data object to another
*
Expand Down
26 changes: 0 additions & 26 deletions src/test/java/emissary/util/DataUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;

import static emissary.core.constants.Parameters.EVENT_DATE;
import static emissary.core.constants.Parameters.FILE_DATE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -91,28 +87,6 @@ void testCsvEscape() {
assertEquals("\"foo\"\"bar\"", DataUtil.csvescape("foo\"bar"), "DQ escaping");
}

@SuppressWarnings("deprecation")
@Test
void testGetEventDate() {
// TODO: fix up deprecated methods
final IBaseDataObject d = DataObjectFactory.getInstance();
final Calendar now = DataUtil.getCal(new Date());
Calendar dcal = DataUtil.getEventDate(d);
assertEquals(TimeUtil.getDateAsPath(now.getTime()), TimeUtil.getDateAsPath(dcal.getTime()), "Default eventDate is now");

d.putParameter(FILE_DATE, "2013-01-01 12:34:56");
dcal = DataUtil.getEventDate(d);
assertEquals("2013-01-01/12/30", TimeUtil.getDateAsPath(dcal.getTime()), "FILE_DATE is used when present");

d.putParameter(EVENT_DATE, "2012-01-01 12:34:56");
dcal = DataUtil.getEventDate(d);
assertEquals("2012-01-01/12/30", TimeUtil.getDateAsPath(dcal.getTime()), "EventDate is used when present");

d.setParameter(EVENT_DATE, "ArmyBoots");
dcal = DataUtil.getEventDate(d);
assertEquals(TimeUtil.getDateAsPath(now.getTime()), TimeUtil.getDateAsPath(dcal.getTime()), "Now is used when field is invalid");
}

@Test
void testSetCurrentFormAndFiletype() {
final IBaseDataObject d = DataObjectFactory.getInstance(null, "foo", "UNKNOWN");
Expand Down

0 comments on commit 551d431

Please sign in to comment.