Search in sources :

Example 6 with AtlasFieldActionInfo

use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.

the class NumberFieldActions method convertDistanceUnit.

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

Example 7 with AtlasFieldActionInfo

use of io.atlasmap.spi.AtlasFieldActionInfo 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 8 with AtlasFieldActionInfo

use of io.atlasmap.spi.AtlasFieldActionInfo 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 9 with AtlasFieldActionInfo

use of io.atlasmap.spi.AtlasFieldActionInfo 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 10 with AtlasFieldActionInfo

use of io.atlasmap.spi.AtlasFieldActionInfo 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)

Aggregations

AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)13 SubString (io.atlasmap.v2.SubString)4 AtlasFieldAction (io.atlasmap.api.AtlasFieldAction)1 ActionDetail (io.atlasmap.v2.ActionDetail)1 Append (io.atlasmap.v2.Append)1 AreaUnitType (io.atlasmap.v2.AreaUnitType)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 DistanceUnitType (io.atlasmap.v2.DistanceUnitType)1 MassUnitType (io.atlasmap.v2.MassUnitType)1 PadStringLeft (io.atlasmap.v2.PadStringLeft)1 PadStringRight (io.atlasmap.v2.PadStringRight)1 ReplaceAll (io.atlasmap.v2.ReplaceAll)1 ReplaceFirst (io.atlasmap.v2.ReplaceFirst)1 SubStringAfter (io.atlasmap.v2.SubStringAfter)1 SubStringBefore (io.atlasmap.v2.SubStringBefore)1 VolumeUnitType (io.atlasmap.v2.VolumeUnitType)1