use of io.atlasmap.v2.Action in project syndesis-qe by syndesisio.
the class AtlasMapperGenerator method getAtlasMappingStep.
public Step getAtlasMappingStep(StepDefinition mapping, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
processPrecedingSteps(precedingSteps);
processFolowingStep(followingStep);
List<DataMapperStepDefinition> mappings = mapping.getDataMapperDefinition().get().getDataMapperStepDefinition();
AtlasMapping atlasMapping = new AtlasMapping();
atlasMapping.setMappings(new Mappings());
for (DataSource s : processSources(precedingSteps)) {
atlasMapping.getDataSource().add(s);
}
atlasMapping.setName("REST." + UUID.randomUUID().toString());
atlasMapping.setLookupTables(new LookupTables());
atlasMapping.setProperties(new Properties());
atlasMapping.getDataSource().add(processTarget(followingStep));
atlasMapping.getMappings().getMapping().addAll(generateBaseMappings(mappings, precedingSteps, followingStep));
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
String mapperString = null;
try {
mapperString = mapper.writeValueAsString(atlasMapping);
log.debug(mapperString);
} catch (JsonProcessingException e) {
log.error("error: {}" + e);
}
final Step mapperStep = new Step.Builder().stepKind(StepKind.mapper).configuredProperties(TestUtils.map("atlasmapping", mapperString)).action(getMapperStepAction(followingStep.getConnectorDescriptor().get())).id(UUID.randomUUID().toString()).build();
return mapperStep;
}
use of io.atlasmap.v2.Action 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.Action in project atlasmap by atlasmap.
the class StringComplexFieldActions method replaceAll.
@AtlasFieldActionInfo(name = "ReplaceAll", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String replaceAll(Action action, String input) {
if (action == null || !(action instanceof ReplaceAll)) {
throw new IllegalArgumentException("Action must be a ReplaceAll action");
}
ReplaceAll replaceAll = (ReplaceAll) action;
String match = replaceAll.getMatch();
if (match == null || match.length() == 0) {
throw new IllegalArgumentException("ReplaceAll action must be specified with a non-empty old string");
}
String newString = replaceAll.getNewString();
return input == null ? null : input.replaceAll(match, newString == null ? "" : newString);
}
use of io.atlasmap.v2.Action in project atlasmap by atlasmap.
the class StringComplexFieldActions method subStringBefore.
@AtlasFieldActionInfo(name = "SubStringBefore", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String subStringBefore(Action action, String input) {
if (input == null || input.length() == 0) {
return input;
}
if (action == null || !(action instanceof SubStringBefore) || ((SubStringBefore) action).getStartIndex() == null || ((SubStringBefore) action).getStartIndex() < 0 || ((SubStringBefore) action).getMatch() == null || (((SubStringBefore) action).getEndIndex() != null && ((SubStringBefore) action).getEndIndex() < ((SubStringBefore) action).getStartIndex())) {
throw new IllegalArgumentException("SubStringBefore action must be specified with a positive startIndex and a string to match");
}
SubStringBefore subStringBefore = (SubStringBefore) action;
int idx = input.indexOf(subStringBefore.getMatch());
if (idx < 0) {
return input;
}
return doSubString(input.substring(0, idx), subStringBefore.getStartIndex(), subStringBefore.getEndIndex());
}
use of io.atlasmap.v2.Action in project atlasmap by atlasmap.
the class StringComplexFieldActions method concatenate.
@AtlasFieldActionInfo(name = "Concatenate", sourceType = FieldType.ANY, targetType = FieldType.STRING, sourceCollectionType = CollectionType.ALL, targetCollectionType = CollectionType.NONE)
public static String concatenate(Action action, Object input) {
if (action == null || !(action instanceof Concatenate)) {
throw new IllegalArgumentException("Action must be a Concatenate action");
}
if (input == null) {
return null;
}
Concatenate concat = (Concatenate) action;
String delim = concat.getDelimiter() == null ? "" : concat.getDelimiter();
Collection<?> inputs = collection(input);
StringBuilder builder = new StringBuilder();
for (Object entry : inputs) {
if (builder.length() > 0) {
builder.append(delim);
}
if (entry != null) {
builder.append(entry.toString());
}
}
return builder.toString();
}
Aggregations