use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method replaceAll.
@AtlasFieldActionInfo(name = "ReplaceAll", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceAll(Action action, String input) {
if (action == null || !(action instanceof ReplaceAll)) {
throw new IllegalArgumentException("Action must be a ReplaceAll action");
}
ReplaceAll replaceAll = (ReplaceAll) action;
String match = replaceAll.getMatch();
if (match == null || match.length() == 0) {
throw new IllegalArgumentException("ReplaceAll action must be specified with a non-empty old string");
}
String newString = replaceAll.getNewString();
return input == null ? null : input.replaceAll(match, newString == null ? "" : newString);
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method subStringBefore.
@AtlasFieldActionInfo(name = "SubStringBefore", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String subStringBefore(Action action, String input) {
if (input == null || input.length() == 0) {
return input;
}
if (action == null || !(action instanceof SubStringBefore) || ((SubStringBefore) action).getStartIndex() == null || ((SubStringBefore) action).getStartIndex() < 0 || ((SubStringBefore) action).getMatch() == null || (((SubStringBefore) action).getEndIndex() != null && ((SubStringBefore) action).getEndIndex() < ((SubStringBefore) action).getStartIndex())) {
throw new IllegalArgumentException("SubStringBefore action must be specified with a positive startIndex and a string to match");
}
SubStringBefore subStringBefore = (SubStringBefore) action;
int idx = input.indexOf(subStringBefore.getMatch());
if (idx < 0) {
return input;
}
return doSubString(input.substring(0, idx), subStringBefore.getStartIndex(), subStringBefore.getEndIndex());
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method concatenate.
@AtlasFieldActionInfo(name = "Concatenate", sourceType = FieldType.ANY, targetType = FieldType.STRING, sourceCollectionType = CollectionType.ALL, targetCollectionType = CollectionType.NONE)
public static String concatenate(Action action, Object input) {
if (action == null || !(action instanceof Concatenate)) {
throw new IllegalArgumentException("Action must be a Concatenate action");
}
if (input == null) {
return null;
}
Concatenate concat = (Concatenate) action;
String delim = concat.getDelimiter() == null ? "" : concat.getDelimiter();
Collection<?> inputs = collection(input);
StringBuilder builder = new StringBuilder();
for (Object entry : inputs) {
if (builder.length() > 0) {
builder.append(delim);
}
if (entry != null) {
builder.append(entry.toString());
}
}
return builder.toString();
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class NumberFieldActions method convertVolumeUnit.
@AtlasFieldActionInfo(name = "ConvertVolumeUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertVolumeUnit(Action action, Number input) {
if (input == null) {
return 0;
}
if (action == null || !(action instanceof ConvertVolumeUnit) || ((ConvertVolumeUnit) action).getFromUnit() == null || ((ConvertVolumeUnit) action).getToUnit() == null) {
throw new IllegalArgumentException("ConvertVolumeUnit must be specfied with fromUnit and toUnit");
}
VolumeUnitType fromUnit = ((ConvertVolumeUnit) action).getFromUnit();
VolumeUnitType toUnit = ((ConvertVolumeUnit) action).getToUnit();
double rate = volumeConvertionTable.get(fromUnit).get(toUnit);
return doMultiply(input, rate);
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class NumberFieldActions method convertMassUnit.
@AtlasFieldActionInfo(name = "ConvertMassUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertMassUnit(Action action, Number input) {
if (input == null) {
return 0;
}
if (action == null || !(action instanceof ConvertMassUnit) || ((ConvertMassUnit) action).getFromUnit() == null || ((ConvertMassUnit) action).getToUnit() == null) {
throw new IllegalArgumentException("ConvertMassUnit must be specfied with fromUnit and toUnit");
}
MassUnitType fromUnit = ((ConvertMassUnit) action).getFromUnit();
MassUnitType toUnit = ((ConvertMassUnit) action).getToUnit();
double rate = massConvertionTable.get(fromUnit).get(toUnit);
return doMultiply(input, rate);
}
Aggregations