Search in sources :

Example 1 with AtlasFieldActionInfo

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);
}
Also used : SubString(io.atlasmap.v2.SubString) ReplaceAll(io.atlasmap.v2.ReplaceAll) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 2 with AtlasFieldActionInfo

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());
}
Also used : SubStringBefore(io.atlasmap.v2.SubStringBefore) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 3 with AtlasFieldActionInfo

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();
}
Also used : Concatenate(io.atlasmap.v2.Concatenate) SubString(io.atlasmap.v2.SubString) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 4 with AtlasFieldActionInfo

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);
}
Also used : ConvertVolumeUnit(io.atlasmap.v2.ConvertVolumeUnit) VolumeUnitType(io.atlasmap.v2.VolumeUnitType) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 5 with AtlasFieldActionInfo

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);
}
Also used : ConvertMassUnit(io.atlasmap.v2.ConvertMassUnit) MassUnitType(io.atlasmap.v2.MassUnitType) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Aggregations

AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)14 SubString (io.atlasmap.v2.SubString)4 ActionDetail (io.atlasmap.v2.ActionDetail)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasException (io.atlasmap.api.AtlasException)1 AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)1 ActionProcessor (io.atlasmap.spi.ActionProcessor)1 AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)1 AtlasFieldAction (io.atlasmap.spi.AtlasFieldAction)1 Action (io.atlasmap.v2.Action)1 Append (io.atlasmap.v2.Append)1 AreaUnitType (io.atlasmap.v2.AreaUnitType)1 CollectionType (io.atlasmap.v2.CollectionType)1 Concatenate (io.atlasmap.v2.Concatenate)1 ConvertAreaUnit (io.atlasmap.v2.ConvertAreaUnit)1 ConvertDistanceUnit (io.atlasmap.v2.ConvertDistanceUnit)1 ConvertMassUnit (io.atlasmap.v2.ConvertMassUnit)1 ConvertVolumeUnit (io.atlasmap.v2.ConvertVolumeUnit)1 CustomAction (io.atlasmap.v2.CustomAction)1 DistanceUnitType (io.atlasmap.v2.DistanceUnitType)1