Search in sources :

Example 1 with Action

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;
}
Also used : DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) LookupTables(io.atlasmap.v2.LookupTables) Step(io.syndesis.common.model.integration.Step) Properties(io.atlasmap.v2.Properties) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataSource(io.atlasmap.v2.DataSource) JsonDataSource(io.atlasmap.json.v2.JsonDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 2 with Action

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;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) AtlasFieldAction(io.atlasmap.api.AtlasFieldAction) Action(io.atlasmap.v2.Action) ActionDetail(io.atlasmap.v2.ActionDetail) SimpleField(io.atlasmap.v2.SimpleField) FieldType(io.atlasmap.v2.FieldType)

Example 3 with Action

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);
}
Also used : SubString(io.atlasmap.v2.SubString) ReplaceAll(io.atlasmap.v2.ReplaceAll) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 4 with Action

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());
}
Also used : SubStringBefore(io.atlasmap.v2.SubStringBefore) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Example 5 with Action

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();
}
Also used : Concatenate(io.atlasmap.v2.Concatenate) SubString(io.atlasmap.v2.SubString) AtlasFieldActionInfo(io.atlasmap.spi.AtlasFieldActionInfo)

Aggregations

Test (org.junit.jupiter.api.Test)73 Action (io.atlasmap.v2.Action)35 Expression (io.atlasmap.v2.Expression)26 ArrayList (java.util.ArrayList)24 Field (io.atlasmap.v2.Field)23 SimpleField (io.atlasmap.v2.SimpleField)22 Mapping (io.atlasmap.v2.Mapping)19 FieldGroup (io.atlasmap.v2.FieldGroup)15 AtlasActionProcessor (io.atlasmap.spi.AtlasActionProcessor)14 AtlasMapping (io.atlasmap.v2.AtlasMapping)14 List (java.util.List)14 ActionDetail (io.atlasmap.v2.ActionDetail)13 AtlasFieldActionInfo (io.atlasmap.spi.AtlasFieldActionInfo)11 SubString (io.atlasmap.v2.SubString)11 ConstantField (io.atlasmap.v2.ConstantField)10 Collections (java.util.Collections)9 TimeUnit (java.util.concurrent.TimeUnit)9 SettableApiFuture (com.google.api.core.SettableApiFuture)8 ServiceOptions (com.google.cloud.ServiceOptions)8 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)8