use of io.atlasmap.v2.SimpleField in project atlasmap by atlasmap.
the class DefaultAtlasFieldActionService method internalProcessActions.
protected Field internalProcessActions(Actions actions, Object sourceObject, FieldType targetType) throws AtlasException {
Field processedField = new SimpleField();
processedField.setValue(sourceObject);
processedField.setFieldType(targetType);
if (FieldType.COMPLEX.equals(targetType)) {
return processedField;
}
Object tmpSourceObject = sourceObject;
FieldType sourceType = (sourceObject != null ? getConversionService().fieldTypeFromClass(sourceObject.getClass()) : FieldType.NONE);
if (actions == null || actions.getActions() == null || actions.getActions().isEmpty()) {
if (sourceObject == null) {
return processedField;
}
processedField.setValue(getConversionService().convertType(sourceObject, sourceType, targetType));
processedField.setFieldType(targetType);
return processedField;
}
FieldType currentType = sourceType;
for (Action action : actions.getActions()) {
ActionDetail detail = findActionDetail(action.getDisplayName(), currentType);
if (!detail.getSourceType().equals(currentType) && !FieldType.ANY.equals(detail.getSourceType())) {
tmpSourceObject = getConversionService().convertType(sourceObject, currentType, detail.getSourceType());
}
processedField.setValue(processAction(action, detail, tmpSourceObject));
processedField.setFieldType(detail.getTargetType());
currentType = detail.getTargetType();
}
return processedField;
}
use of io.atlasmap.v2.SimpleField in project atlasmap by atlasmap.
the class DefaultAtlasContext method processSeparateField.
private List<Field> processSeparateField(DefaultAtlasSession session, Mapping mapping, Field sourceField) throws AtlasException {
List<Field> answer = new ArrayList<>();
String sourceValue;
try {
sourceValue = (String) factory.getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), FieldType.STRING, null);
} catch (AtlasConversionException e) {
AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Suitable converter for sourceField.path=%s hasn't been found", sourceField.getPath()), sourceField.getPath(), AuditStatus.WARN, null);
sourceValue = sourceField.getValue().toString();
}
List<String> separatedValues = null;
StringDelimiter delimiter = StringDelimiter.fromName(mapping.getDelimiter());
if (mapping.getDelimiter() != null) {
separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue, delimiter);
} else {
separatedValues = session.getAtlasContext().getContextFactory().getSeparateStrategy().separateValue(sourceValue);
}
if (separatedValues == null || separatedValues.isEmpty()) {
LOG.debug(String.format("Empty string for Separate mapping sourceField.path=%s", sourceField.getPath()));
} else {
for (String separatedValue : separatedValues) {
SimpleField simpleField = AtlasModelFactory.cloneFieldToSimpleField(sourceField);
simpleField.setValue(separatedValue);
simpleField.setFieldType(FieldType.STRING);
answer.add(simpleField);
}
}
return answer;
}
use of io.atlasmap.v2.SimpleField in project atlasmap by atlasmap.
the class BaseDefaultAtlasContextTest method populateSourceField.
protected Field populateSourceField(Mapping mapping, FieldType type, Object value) {
Field field = new SimpleField();
field.setFieldType(type);
field.setPath("/testPath" + value);
mapping.getInputField().add(field);
reader.sources.put(field.getPath(), value);
return field;
}
use of io.atlasmap.v2.SimpleField in project atlasmap by atlasmap.
the class BaseDefaultAtlasContextTest method prepareTargetField.
protected Field prepareTargetField(Mapping mapping, String path) {
Field field = new SimpleField();
field.setPath(path);
mapping.getOutputField().add(field);
return field;
}
use of io.atlasmap.v2.SimpleField 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);
}
Aggregations