use of com.opensymphony.xwork2.Action 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 com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionService method buildAndProcessAction.
/**
* Instantiate the field action impl class from {@link ActionProcessor} and processes it.
* @param actionProcessor action processor
* @param actionParameters action parameters
* @param field field
* @return processed field
*/
public Field buildAndProcessAction(ActionProcessor actionProcessor, Map<String, Object> actionParameters, Field field) {
FieldType valueType = determineFieldType(field);
try {
Action action = actionProcessor.getActionClass().getDeclaredConstructor().newInstance();
for (Map.Entry<String, Object> property : actionParameters.entrySet()) {
String setter = "set" + property.getKey().substring(0, 1).toUpperCase() + property.getKey().substring(1);
action.getClass().getMethod(setter, property.getValue().getClass()).invoke(action, property.getValue());
}
return processAction(action, actionProcessor, valueType, field);
} catch (Exception e) {
throw new IllegalArgumentException(String.format("The action '%s' cannot be processed", actionProcessor.getActionDetail().getName()), e);
}
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class MappingFieldPairValidator method getActionOutputFieldType.
private FieldType getActionOutputFieldType(List<Validation> validations, String mappingId, Field f) {
if (f.getActions() == null || f.getActions().size() == 0) {
return null;
}
Action lastAction = f.getActions().get(f.getActions().size() - 1);
ActionDetail detail = null;
try {
detail = service.getFieldActionService().findActionDetail(lastAction, f.getFieldType());
} catch (AtlasException e) {
if (LOG.isDebugEnabled()) {
LOG.error("ActionDetail not found", e);
}
}
if (detail == null) {
Validation validation = new Validation();
validation.setScope(ValidationScope.MAPPING);
validation.setId(mappingId);
validation.setMessage(String.format("Couldn't find a metadata for transformation '%s'", lastAction.getDisplayName()));
validation.setStatus(ValidationStatus.ERROR);
validations.add(validation);
return null;
}
return detail.getTargetType();
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class AtlasBaseActionsTest method runActionTestList.
public Object runActionTestList(List<Action> actions, String sourceFirstName, Object targetExpected, Class<?> targetClassExpected) throws Exception {
System.out.println("Now running test for actions: " + actions);
System.out.println("Input: " + sourceFirstName);
System.out.println("Expected output: " + targetExpected);
Mapping m = new Mapping();
m.setMappingType(MappingType.MAP);
m.getInputField().add(this.sourceField);
m.getOutputField().add(this.targetField);
if (actions != null) {
m.getOutputField().get(0).setActions(new ArrayList<Action>());
m.getOutputField().get(0).getActions().addAll(actions);
}
DataSource src = new DataSource();
src.setDataSourceType(DataSourceType.SOURCE);
src.setUri(this.docURI);
DataSource tgt = new DataSource();
tgt.setDataSourceType(DataSourceType.TARGET);
tgt.setUri(this.docURI);
AtlasMapping atlasMapping = new AtlasMapping();
atlasMapping.setName("fieldactiontest");
atlasMapping.setMappings(new Mappings());
atlasMapping.getMappings().getMapping().add(m);
atlasMapping.getDataSource().add(src);
atlasMapping.getDataSource().add(tgt);
String tmpFile = "target/fieldactions-" + this.getClass().getSimpleName() + "-tmp.txt";
Json.mapper().writeValue(new File(tmpFile), atlasMapping);
AtlasContext context = atlasContextFactory.createContext(new File(tmpFile).toURI());
AtlasSession session = context.createSession();
session.setDefaultSourceDocument(createSource(sourceFirstName));
context.process(session);
Object targetActual = session.getDefaultTargetDocument();
assertNotNull(targetActual);
targetActual = getTargetValue(targetActual, targetClassExpected);
if (targetExpected != null) {
assertEquals(targetExpected, targetActual);
}
return targetActual;
}
use of com.opensymphony.xwork2.Action in project atlasmap by atlasmap.
the class DefaultAtlasPreviewContextTest method testProcessPreviewSourceFieldAction.
@Test
public void testProcessPreviewSourceFieldAction() throws AtlasException {
Mapping m = new Mapping();
m.setMappingType(MappingType.MAP);
Field source = new SimpleField();
source.setFieldType(FieldType.STRING);
source.setValue("abc");
ArrayList<Action> actions = new ArrayList<Action>();
actions.add(new Uppercase());
source.setActions(actions);
Field target = new SimpleField();
target.setFieldType(FieldType.STRING);
m.getInputField().add(source);
m.getOutputField().add(target);
previewContext.processPreview(m);
target = m.getOutputField().get(0);
assertEquals("ABC", target.getValue());
}
Aggregations