Search in sources :

Example 31 with Action

use of io.atlasmap.v2.Action in project atlasmap by atlasmap.

the class NumberFieldActions method convertAreaUnit.

@AtlasFieldActionInfo(name = "ConvertAreaUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertAreaUnit(Action action, Number input) {
    if (input == null) {
        return 0;
    }
    if (action == null || !(action instanceof ConvertAreaUnit) || ((ConvertAreaUnit) action).getFromUnit() == null || ((ConvertAreaUnit) action).getToUnit() == null) {
        throw new IllegalArgumentException("ConvertAreaUnit must be specfied  with fromUnit and toUnit");
    }
    AreaUnitType fromUnit = ((ConvertAreaUnit) action).getFromUnit();
    AreaUnitType toUnit = ((ConvertAreaUnit) action).getToUnit();
    double rate = areaConvertionTable.get(fromUnit).get(toUnit);
    return doMultiply(input, rate);
}
Also used : ConvertAreaUnit(io.atlasmap.v2.ConvertAreaUnit) AreaUnitType(io.atlasmap.v2.AreaUnitType) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 32 with Action

use of io.atlasmap.v2.Action in project atlasmap by atlasmap.

the class StringComplexFieldActions method append.

@AtlasFieldActionInfo(name = "Append", sourceType = FieldType.ANY, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String append(Action action, Object input) {
    if (!(action instanceof Append)) {
        throw new IllegalArgumentException("Action must be an Append action");
    }
    Append append = (Append) action;
    String string = append.getString();
    if (input == null && string == null) {
        return null;
    }
    if (string == null) {
        return input.toString();
    }
    return input == null ? string : input.toString().concat(string);
}
Also used : Append(io.atlasmap.v2.Append) SubString(io.atlasmap.v2.SubString) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 33 with Action

use of io.atlasmap.v2.Action in project atlasmap by atlasmap.

the class StringComplexFieldActions method subStringAfter.

@AtlasFieldActionInfo(name = "SubStringAfter", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String subStringAfter(Action action, String input) {
    if (input == null || input.length() == 0) {
        return input;
    }
    if (action == null || !(action instanceof SubStringAfter) || ((SubStringAfter) action).getStartIndex() == null || ((SubStringAfter) action).getStartIndex() < 0 || ((SubStringAfter) action).getMatch() == null || (((SubStringAfter) action).getEndIndex() != null && ((SubStringAfter) action).getEndIndex() < ((SubStringAfter) action).getStartIndex())) {
        throw new IllegalArgumentException("SubStringAfter action must be specified with a positive startIndex and a string to match");
    }
    SubStringAfter subStringAfter = (SubStringAfter) action;
    int idx = input.indexOf(subStringAfter.getMatch());
    if (idx < 0) {
        return input;
    }
    idx = idx + subStringAfter.getMatch().length();
    return doSubString(input.substring(idx), subStringAfter.getStartIndex(), subStringAfter.getEndIndex());
}
Also used : SubStringAfter(io.atlasmap.v2.SubStringAfter) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 34 with Action

use of io.atlasmap.v2.Action in project atlasmap by atlasmap.

the class StringComplexFieldActions method padStringRight.

@AtlasFieldActionInfo(name = "PadStringRight", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String padStringRight(Action action, String input) {
    if (action == null || !(action instanceof PadStringRight) || ((PadStringRight) action).getPadCharacter() == null || ((PadStringRight) action).getPadCount() == null) {
        throw new IllegalArgumentException("PadStringRight must be specfied with padCharacter and padCount");
    }
    PadStringRight padStringRight = (PadStringRight) action;
    StringBuilder builder = new StringBuilder();
    if (input != null) {
        builder.append(input);
    }
    for (int i = 0; i < padStringRight.getPadCount(); i++) {
        builder.append(padStringRight.getPadCharacter());
    }
    return builder.toString();
}
Also used : PadStringRight(io.atlasmap.v2.PadStringRight) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 35 with Action

use of io.atlasmap.v2.Action in project atlasmap by atlasmap.

the class StringComplexFieldActions method padStringLeft.

@AtlasFieldActionInfo(name = "PadStringLeft", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String padStringLeft(Action action, String input) {
    if (action == null || !(action instanceof PadStringLeft) || ((PadStringLeft) action).getPadCharacter() == null || ((PadStringLeft) action).getPadCount() == null) {
        throw new IllegalArgumentException("PadStringLeft must be specfied with padCharacter and padCount");
    }
    PadStringLeft padStringLeft = (PadStringLeft) action;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < padStringLeft.getPadCount(); i++) {
        builder.append(padStringLeft.getPadCharacter());
    }
    if (input != null) {
        builder.append(input);
    }
    return builder.toString();
}
Also used : PadStringLeft(io.atlasmap.v2.PadStringLeft) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Aggregations

Test (org.junit.Test)28 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)13 Action (io.atlasmap.v2.Action)6 ActionDetail (io.atlasmap.v2.ActionDetail)6 SubString (io.atlasmap.v2.SubString)6 ConvertMassUnit (io.atlasmap.v2.ConvertMassUnit)5 Action (com.opensymphony.xwork2.Action)3 AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)3 AtlasMapping (io.atlasmap.v2.AtlasMapping)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 AbsoluteValue (io.atlasmap.v2.AbsoluteValue)2 Actions (io.atlasmap.v2.Actions)2 Append (io.atlasmap.v2.Append)2 Concatenate (io.atlasmap.v2.Concatenate)2 ConvertAreaUnit (io.atlasmap.v2.ConvertAreaUnit)2 ConvertDistanceUnit (io.atlasmap.v2.ConvertDistanceUnit)2 ConvertVolumeUnit (io.atlasmap.v2.ConvertVolumeUnit)2 DataSource (io.atlasmap.v2.DataSource)2 LastIndexOf (io.atlasmap.v2.LastIndexOf)2