Search in sources :

Example 1 with ActionProcessor

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

the class DefaultAtlasFieldActionsServiceTest method testProcessActionWithActionActionDetailObject.

@Test
public void testProcessActionWithActionActionDetailObject() throws AtlasException {
    ActionProcessor processor = null;
    Object sourceObject = "String";
    Action action = new Trim();
    processor = fieldActionsService.findActionProcessor(action, FieldType.STRING);
    assertEquals(sourceObject, processor.process(action, sourceObject));
    action = new GenerateUUID();
    processor = fieldActionsService.findActionProcessor(action, FieldType.NONE);
    assertNotNull(processor.process(action, sourceObject));
}
Also used : Action(io.atlasmap.v2.Action) Trim(io.atlasmap.v2.Trim) GenerateUUID(io.atlasmap.v2.GenerateUUID) ActionProcessor(io.atlasmap.spi.ActionProcessor) Test(org.junit.jupiter.api.Test)

Example 2 with ActionProcessor

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

the class DefaultAtlasFieldActionService method findActionProcessor.

/**
 * Finds the {@link ActionProcessor} that matches with the name and value type.
 * @param name name
 * @param value value
 * @return action processor
 */
public ActionProcessor findActionProcessor(String name, Object value) {
    FieldType valueType = (value != null ? getConversionService().fieldTypeFromClass(value.getClass()) : FieldType.NONE);
    String uppercaseName = name.toUpperCase();
    List<ActionProcessor> processors = new ArrayList<>();
    Lock readLock = actionProcessorsLock.readLock();
    try {
        readLock.lock();
        for (ActionProcessor processor : actionProcessors) {
            if (processor.getActionDetail().getName().toUpperCase().equals(uppercaseName)) {
                processors.add(processor);
            }
        }
    } finally {
        readLock.unlock();
    }
    return findBestActionProcessor(processors, valueType);
}
Also used : ArrayList(java.util.ArrayList) ActionProcessor(io.atlasmap.spi.ActionProcessor) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor) FieldType(io.atlasmap.v2.FieldType) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 3 with ActionProcessor

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

the class DefaultAtlasFieldActionService method createActionProcessor.

private void createActionProcessor(AtlasFieldAction atlasFieldAction, List<ActionProcessor> answer) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Loading FieldAction class: " + atlasFieldAction.getClass().getCanonicalName());
    }
    Class<?> clazz = atlasFieldAction.getClass();
    Method[] methods = clazz.getMethods();
    for (Method method : methods) {
        // Continue supporting creating details from @AtlasFieldActionInfo
        ActionProcessor det = createDetailFromFieldActionInfo(clazz, method);
        if (det != null) {
            answer.add(det);
        }
        // Also support using new simpler @AtlasActionProcessor
        det = createDetailFromProcessor(clazz, method);
        if (det != null) {
            answer.add(det);
        }
    }
}
Also used : Method(java.lang.reflect.Method) ActionProcessor(io.atlasmap.spi.ActionProcessor) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor)

Example 4 with ActionProcessor

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

the class DefaultAtlasFieldActionService method processActions.

@Override
public Field processActions(AtlasInternalSession session, Field field) throws AtlasException {
    ArrayList<Action> actions = field.getActions();
    if (actions == null || actions.isEmpty()) {
        return field;
    }
    Field tmpSourceField = field;
    FieldType currentType = determineFieldType(field);
    for (Action action : actions) {
        ActionProcessor processor = findActionProcessor(action, currentType);
        if (processor == null) {
            AtlasUtil.addAudit(session, field, String.format("Couldn't find metadata for a FieldAction '%s', please make sure it's in the classpath, and also have a service declaration under META-INF/services. Ignoring...", action.getDisplayName()), AuditStatus.WARN, null);
            continue;
        }
        ActionDetail detail = processor.getActionDetail();
        if (detail == null) {
            AtlasUtil.addAudit(session, field, String.format("Couldn't find metadata for a FieldAction '%s', ignoring...", action.getDisplayName()), AuditStatus.WARN, null);
            continue;
        }
        tmpSourceField = processAction(action, processor, currentType, tmpSourceField);
        currentType = determineFieldType(tmpSourceField);
    }
    return tmpSourceField;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) CustomAction(io.atlasmap.v2.CustomAction) AtlasFieldAction(io.atlasmap.spi.AtlasFieldAction) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) ActionProcessor(io.atlasmap.spi.ActionProcessor) AtlasActionProcessor(io.atlasmap.spi.AtlasActionProcessor) FieldType(io.atlasmap.v2.FieldType)

Example 5 with ActionProcessor

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

the class AtlasField method action.

/**
 * Apply the field action.
 * @param actionName action name
 * @param parameters action parameters
 * @return result field
 */
public AtlasField action(String actionName, List<Object> parameters) {
    Object value = parameters != null && parameters.size() > 1 ? parameters.get(parameters.size() - 1) : null;
    ActionProcessor ap = this.fieldActionService.findActionProcessor(actionName, value);
    return this;
}
Also used : ActionProcessor(io.atlasmap.spi.ActionProcessor)

Aggregations

ActionProcessor (io.atlasmap.spi.ActionProcessor)10 AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)6 Action (io.atlasmap.v2.Action)5 ActionDetail (io.atlasmap.v2.ActionDetail)4 CustomAction (io.atlasmap.v2.CustomAction)4 ArrayList (java.util.ArrayList)4 AtlasException (io.atlasmap.api.AtlasException)3 AtlasFieldAction (io.atlasmap.spi.AtlasFieldAction)3 FieldType (io.atlasmap.v2.FieldType)3 AtlasConversionException (io.atlasmap.api.AtlasConversionException)2 CollectionType (io.atlasmap.v2.CollectionType)2 Field (io.atlasmap.v2.Field)2 List (java.util.List)2 Map (java.util.Map)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 Test (org.junit.jupiter.api.Test)2 Expression (io.atlasmap.expression.Expression)1 FunctionResolver (io.atlasmap.expression.FunctionResolver)1