use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessActionsActionsField.
@Test
public void testProcessActionsActionsField() throws AtlasException {
Actions actions = null;
SimpleField field = new SimpleField();
field.setFieldType(FieldType.COMPLEX);
fieldActionsService.processActions(actions, field);
field.setValue(null);
field.setFieldType(FieldType.INTEGER);
fieldActionsService.processActions(actions, field);
field.setValue(new Integer(0));
field.setFieldType(FieldType.INTEGER);
fieldActionsService.processActions(actions, field);
@SuppressWarnings("serial")
class MockActions extends Actions {
@Override
public List<Action> getActions() {
return null;
}
}
fieldActionsService.processActions(new MockActions(), field);
actions = new Actions();
fieldActionsService.processActions(actions, field);
actions.getActions().add(new Trim());
field.setValue("testString");
field.setFieldType(FieldType.STRING);
fieldActionsService.processActions(actions, field);
field.setValue(new Integer(8));
field.setFieldType(FieldType.NUMBER);
fieldActionsService.processActions(actions, field);
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testProcessActionsActionsFieldAtlasConversionException.
@Test(expected = AtlasConversionException.class)
public void testProcessActionsActionsFieldAtlasConversionException() throws AtlasException {
Actions actions = null;
SimpleField field = new SimpleField();
Object value = new Object();
field.setValue(value);
field.setFieldType(FieldType.INTEGER);
fieldActionsService.processActions(actions, field);
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionsServiceTest method testprocessActionsActionsObjectFieldTypeAtlasConversionException.
@Test(expected = AtlasConversionException.class)
public void testprocessActionsActionsObjectFieldTypeAtlasConversionException() throws AtlasException {
Actions actions = null;
SimpleField field = new SimpleField();
Object value = new Object();
field.setValue(value);
field.setFieldType(FieldType.INTEGER);
fieldActionsService.processActions(actions, field);
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class XmlModule method processTargetFieldMapping.
@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
Field sourceField = session.head().getSourceField();
Field targetField = session.head().getTargetField();
// Attempt to Auto-detect field type based on input value
if (targetField.getFieldType() == null && sourceField.getValue() != null) {
targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
}
Object outputValue = null;
// Do auto-conversion
if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
outputValue = sourceField.getValue();
} else if (sourceField.getValue() != null) {
try {
outputValue = getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), targetField.getFieldType(), targetField.getFormat());
} catch (AtlasConversionException e) {
AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Unable to auto-convert for sT=%s tT=%s tF=%s msg=%s", sourceField.getFieldType(), targetField.getFieldType(), targetField.getPath(), e.getMessage()), targetField.getPath(), AuditStatus.ERROR, null);
return;
}
}
targetField.setValue(outputValue);
LookupTable lookupTable = session.head().getLookupTable();
if (lookupTable != null) {
processLookupField(session, lookupTable, targetField.getValue(), targetField);
}
if (isAutomaticallyProcessOutputFieldActions() && targetField.getActions() != null && targetField.getActions().getActions() != null) {
getFieldActionService().processActions(targetField.getActions(), targetField);
}
XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
writer.write(session);
if (LOG.isDebugEnabled()) {
LOG.debug("{}: processTargetFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}], TargetField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue(), targetField.getDocId(), targetField.getPath(), targetField.getFieldType(), targetField.getValue());
}
}
use of io.atlasmap.v2.Field in project atlasmap by atlasmap.
the class AtlasServiceTest method testActionDeserialization.
@Test
public void testActionDeserialization() throws Exception {
File file = new File("src/test/resources/atlasmapping-actions.json");
AtlasMapping mapping = mapper.readValue(file, AtlasMapping.class);
Mappings mappings = mapping.getMappings();
for (BaseMapping baseMapping : mappings.getMapping()) {
if (MappingType.MAP.equals(baseMapping.getMappingType())) {
List<Field> fields = ((Mapping) baseMapping).getOutputField();
for (Field f : fields) {
if (f.getActions() != null && f.getActions().getActions() != null && !f.getActions().getActions().isEmpty()) {
System.out.println("Found actions: " + f.getActions().getActions().size());
}
}
}
}
}
Aggregations