Search in sources :

Example 6 with AtlasActionProcessor

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

the class StringComplexFieldActions method split.

/**
 * Splits the String with the specified delimiter.
 * @param split action model
 * @param input source
 * @return splitted
 */
@AtlasActionProcessor(sourceType = FieldType.ANY)
public static String[] split(Split split, String input) {
    if (split == null || split.getDelimiter() == null) {
        throw new IllegalArgumentException("Split must be specified with a delimiter");
    }
    String quotedDelimiter = Pattern.quote(split.getDelimiter());
    boolean collapseRepeatingDelimiter = split.getCollapseRepeatingDelimiters() == null ? false : split.getCollapseRepeatingDelimiters();
    if (collapseRepeatingDelimiter) {
        quotedDelimiter = "(" + quotedDelimiter + ")+";
    }
    return input == null ? null : input.toString().split(quotedDelimiter);
}
Also used : SubString(io.atlasmap.v2.SubString) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 7 with AtlasActionProcessor

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

the class StringComplexFieldActions method concatenate.

/**
 * Concatenates a list of String.
 * @param concat action model
 * @param inputs a list of source String
 * @return processed
 */
@AtlasActionProcessor(sourceType = FieldType.ANY)
public static String concatenate(Concatenate concat, List<String> inputs) {
    if (concat == null) {
        throw new IllegalArgumentException("Concatenate must be specified with a delimiter");
    }
    if (inputs == null) {
        return null;
    }
    String delim = concat.getDelimiter() == null ? "" : concat.getDelimiter();
    boolean delimitingEmptyValues = concat.getDelimitingEmptyValues() == null ? false : concat.getDelimitingEmptyValues();
    boolean isFirst = true;
    StringBuilder builder = new StringBuilder();
    for (String entry : inputs) {
        if (!isFirst && ((entry != null && !entry.isEmpty()) || delimitingEmptyValues)) {
            builder.append(delim);
        }
        if (entry != null) {
            builder.append(entry);
        }
        isFirst = false;
    }
    return builder.toString();
}
Also used : SubString(io.atlasmap.v2.SubString) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 8 with AtlasActionProcessor

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

the class NumberFieldActions method convertAreaUnit.

/**
 * Converts area unit.
 * @param convertAreaUnit action model
 * @param input source
 * @return converted
 */
@AtlasActionProcessor
public static Number convertAreaUnit(ConvertAreaUnit convertAreaUnit, Number input) {
    if (input == null) {
        return 0;
    }
    if (convertAreaUnit == null || convertAreaUnit.getFromUnit() == null || convertAreaUnit.getToUnit() == null) {
        throw new IllegalArgumentException("ConvertAreaUnit must be specified  with fromUnit and toUnit");
    }
    AreaUnitType fromUnit = convertAreaUnit.getFromUnit();
    AreaUnitType toUnit = convertAreaUnit.getToUnit();
    double rate = areaConvertionTable.get(fromUnit).get(toUnit);
    return doMultiply(input, rate);
}
Also used : AreaUnitType(io.atlasmap.v2.AreaUnitType) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 9 with AtlasActionProcessor

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

the class NumberFieldActions method convertDistanceUnit.

/**
 * Converts distance unit.
 * @param convertDistanceUnit action model
 * @param input source
 * @return converted
 */
@AtlasActionProcessor
public static Number convertDistanceUnit(ConvertDistanceUnit convertDistanceUnit, Number input) {
    if (input == null) {
        return 0;
    }
    if (convertDistanceUnit == null || convertDistanceUnit.getFromUnit() == null || convertDistanceUnit.getToUnit() == null) {
        throw new IllegalArgumentException("ConvertDistanceUnit must be specified  with fromUnit and toUnit");
    }
    DistanceUnitType fromUnit = convertDistanceUnit.getFromUnit();
    DistanceUnitType toUnit = convertDistanceUnit.getToUnit();
    double rate = distanceConvertionTable.get(fromUnit).get(toUnit);
    return doMultiply(input, rate);
}
Also used : DistanceUnitType(io.atlasmap.v2.DistanceUnitType) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 10 with AtlasActionProcessor

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

the class NumberFieldActions method convertVolumeUnit.

/**
 * Converts volume unit.
 * @param convertVolumeUnit action model
 * @param input source
 * @return converted
 */
@AtlasActionProcessor
public static Number convertVolumeUnit(ConvertVolumeUnit convertVolumeUnit, Number input) {
    if (input == null) {
        return 0;
    }
    if (convertVolumeUnit == null || convertVolumeUnit.getFromUnit() == null || convertVolumeUnit.getToUnit() == null) {
        throw new IllegalArgumentException("ConvertVolumeUnit must be specified  with fromUnit and toUnit");
    }
    VolumeUnitType fromUnit = convertVolumeUnit.getFromUnit();
    VolumeUnitType toUnit = convertVolumeUnit.getToUnit();
    double rate = volumeConvertionTable.get(fromUnit).get(toUnit);
    return doMultiply(input, rate);
}
Also used : VolumeUnitType(io.atlasmap.v2.VolumeUnitType) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Aggregations

AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)11 SubString (io.atlasmap.v2.SubString)4 ActionProcessor (io.atlasmap.spi.ActionProcessor)2 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 AtlasException (io.atlasmap.api.AtlasException)1 Expression (io.atlasmap.expression.Expression)1 ExpressionException (io.atlasmap.expression.ExpressionException)1 AtlasFieldAction (io.atlasmap.spi.AtlasFieldAction)1 Action (io.atlasmap.v2.Action)1 ActionDetail (io.atlasmap.v2.ActionDetail)1 AreaUnitType (io.atlasmap.v2.AreaUnitType)1 AtlasModelFactory.unwrapField (io.atlasmap.v2.AtlasModelFactory.unwrapField)1 AtlasModelFactory.wrapWithField (io.atlasmap.v2.AtlasModelFactory.wrapWithField)1 CollectionType (io.atlasmap.v2.CollectionType)1 CustomAction (io.atlasmap.v2.CustomAction)1 DistanceUnitType (io.atlasmap.v2.DistanceUnitType)1 Field (io.atlasmap.v2.Field)1 FieldType (io.atlasmap.v2.FieldType)1 MassUnitType (io.atlasmap.v2.MassUnitType)1 VolumeUnitType (io.atlasmap.v2.VolumeUnitType)1