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));
}
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);
}
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);
}
}
}
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;
}
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;
}
Aggregations