Search in sources :

Example 11 with AtlasFieldActionInfo

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

Example 12 with AtlasFieldActionInfo

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

the class StringComplexFieldActions method replaceFirst.

@AtlasFieldActionInfo(name = "ReplaceFirst", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceFirst(Action action, String input) {
    if (action == null || !(action instanceof ReplaceFirst)) {
        throw new IllegalArgumentException("Action must be a ReplaceFirst action");
    }
    ReplaceFirst replaceFirst = (ReplaceFirst) action;
    String match = replaceFirst.getMatch();
    if (match == null || match.length() == 0) {
        throw new IllegalArgumentException("ReplaceFirst action must be specified with a non-empty old string");
    }
    String newString = replaceFirst.getNewString();
    return input == null ? null : input.replaceFirst(match, newString == null ? "" : newString);
}
Also used : SubString(io.atlasmap.v2.SubString) ReplaceFirst(io.atlasmap.v2.ReplaceFirst) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 13 with AtlasFieldActionInfo

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

the class DefaultAtlasFieldActionService method loadFieldActions.

protected void loadFieldActions() {
    ClassLoader classLoader = this.getClass().getClassLoader();
    final ServiceLoader<AtlasFieldAction> fieldActionServiceLoader = ServiceLoader.load(AtlasFieldAction.class, classLoader);
    for (final AtlasFieldAction atlasFieldAction : fieldActionServiceLoader) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Loading FieldAction class: " + atlasFieldAction.getClass().getCanonicalName());
        }
        Class<?> clazz = atlasFieldAction.getClass();
        Method[] methods = clazz.getMethods();
        for (Method method : methods) {
            AtlasFieldActionInfo annotation = method.getAnnotation(AtlasFieldActionInfo.class);
            if (annotation != null) {
                ActionDetail det = new ActionDetail();
                det.setClassName(clazz.getName());
                det.setMethod(method.getName());
                det.setName(annotation.name());
                det.setSourceType(annotation.sourceType());
                det.setTargetType(annotation.targetType());
                det.setSourceCollectionType(annotation.sourceCollectionType());
                det.setTargetCollectionType(annotation.targetCollectionType());
                try {
                    det.setParameters(detectFieldActionParameters("io.atlasmap.v2." + annotation.name()));
                } catch (ClassNotFoundException e) {
                    LOG.error(String.format("Error detecting parameters for field action=%s msg=%s", annotation.name(), e.getMessage()), e);
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Loaded FieldAction: " + det.getName());
                }
                listActionDetails().add(det);
            }
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Loaded %s Field Actions", listActionDetails().size()));
    }
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) AtlasFieldAction(io.atlasmap.api.AtlasFieldAction) Method(java.lang.reflect.Method) 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