Search in sources :

Example 36 with Field

use of io.atlasmap.v2.Field in project syndesis-qe by syndesisio.

the class AtlasMapperGenerator method generateCombineMapping.

private Mapping generateCombineMapping(DataMapperStepDefinition mappingDef, List<StepDefinition> precedingSteps, StepDefinition followingStep) {
    StepDefinition fromStep = precedingSteps.get(mappingDef.getFromStep() - 1);
    Mapping generatedMapping = new Mapping();
    generatedMapping.setId(UUID.randomUUID().toString());
    generatedMapping.setMappingType(MappingType.COMBINE);
    generatedMapping.setDelimiter(mappingDef.getStrategy().name());
    List<Field> in = new ArrayList<>();
    for (int i = 0; i < mappingDef.getInputFields().size(); i++) {
        String def = mappingDef.getInputFields().get(i);
        Field inField = fromStep.getInspectionResponseFields().get().stream().filter(f -> f.getPath().matches(def)).findFirst().get();
        inField.setIndex(i);
        in.add(inField);
    }
    Field out = followingStep.getInspectionResponseFields().get().stream().filter(f -> f.getPath().matches(mappingDef.getOutputFields().get(0))).findFirst().get();
    in.forEach(f -> f.setDocId(fromStep.getStep().getId().get()));
    out.setDocId(followingStep.getStep().getId().get());
    generatedMapping.getInputField().addAll(in);
    generatedMapping.getOutputField().add(out);
    return generatedMapping;
}
Also used : Field(io.atlasmap.v2.Field) JavaField(io.atlasmap.java.v2.JavaField) ArrayList(java.util.ArrayList) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasmapEndpoint(io.syndesis.qe.endpoints.AtlasmapEndpoint)

Example 37 with Field

use of io.atlasmap.v2.Field in project atlasmap by atlasmap.

the class JsonFieldReaderTest method read.

private AtlasInternalSession read(JsonField field) throws AtlasException {
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 38 with Field

use of io.atlasmap.v2.Field in project atlasmap by atlasmap.

the class JavaModule method processPreTargetExecution.

@Override
public void processPreTargetExecution(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null || atlasSession.getMapping().getMappings() == null || atlasSession.getMapping().getMappings().getMapping() == null) {
        throw new AtlasException("AtlasSession not properly intialized with a mapping that contains field mappings");
    }
    if (javaInspectionService == null) {
        javaInspectionService = new ClassInspectionService();
        javaInspectionService.setConversionService(getConversionService());
    }
    List<BaseMapping> mapping = atlasSession.getMapping().getMappings().getMapping();
    Object rootObject;
    String targetClassName = AtlasUtil.getUriParameterValue(getUri(), "className");
    JavaClass inspectClass = getJavaInspectionService().inspectClass(targetClassName);
    merge(inspectClass, mapping);
    List<String> targetPaths = AtlasModuleSupport.listTargetPaths(mapping);
    try {
        rootObject = getJavaConstructService().constructClass(inspectClass, targetPaths);
    } catch (Exception e) {
        throw new AtlasException(e);
    }
    DocumentJavaFieldWriter writer = new DocumentJavaFieldWriter(getConversionService());
    writer.setRootObject(rootObject);
    writer.setTargetValueConverter(targetValueConverter);
    atlasSession.setFieldWriter(getDocId(), writer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreTargetExcution completed", getDocId());
    }
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException)

Example 39 with Field

use of io.atlasmap.v2.Field in project atlasmap by atlasmap.

the class JavaModule method merge.

private void merge(JavaClass inspectionClass, List<BaseMapping> mappings) {
    if (inspectionClass == null || inspectionClass.getJavaFields() == null || inspectionClass.getJavaFields().getJavaField() == null) {
        return;
    }
    if (mappings == null || mappings.size() == 0) {
        return;
    }
    for (BaseMapping fm : mappings) {
        if (fm instanceof Mapping && (((Mapping) fm).getOutputField() != null)) {
            Field f = ((Mapping) fm).getOutputField().get(0);
            if (f.getPath() != null) {
                Field inspectField = findFieldByPath(inspectionClass, f.getPath());
                if (inspectField != null && f instanceof JavaField && inspectField instanceof JavaField) {
                    String overrideClassName = ((JavaField) f).getClassName();
                    JavaField javaInspectField = (JavaField) inspectField;
                    // Support mapping overrides className
                    if (overrideClassName != null && !overrideClassName.equals(javaInspectField.getClassName())) {
                        javaInspectField.setClassName(overrideClassName);
                    }
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 40 with Field

use of io.atlasmap.v2.Field in project atlasmap by atlasmap.

the class JavaModule method processSourceFieldMapping.

@Override
public void processSourceFieldMapping(AtlasInternalSession session) throws AtlasException {
    Field sourceField = session.head().getSourceField();
    DocumentJavaFieldReader reader = session.getFieldReader(getDocId(), DocumentJavaFieldReader.class);
    if (reader == null) {
        AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Source document '%s' doesn't exist", getDocId()), sourceField.getPath(), AuditStatus.ERROR, null);
        return;
    }
    reader.read(session);
    if (sourceField.getActions() != null && sourceField.getActions().getActions() != null) {
        getFieldActionService().processActions(sourceField.getActions(), sourceField);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processSourceFieldMapping completed: SourceField:[docId={}, path={}, type={}, value={}]", getDocId(), sourceField.getDocId(), sourceField.getPath(), sourceField.getFieldType(), sourceField.getValue());
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) DocumentJavaFieldReader(io.atlasmap.java.core.DocumentJavaFieldReader)

Aggregations

Field (io.atlasmap.v2.Field)60 Test (org.junit.Test)27 AtlasMapping (io.atlasmap.v2.AtlasMapping)24 Mapping (io.atlasmap.v2.Mapping)23 JavaField (io.atlasmap.java.v2.JavaField)20 SimpleField (io.atlasmap.v2.SimpleField)17 BaseMapping (io.atlasmap.v2.BaseMapping)15 Validation (io.atlasmap.v2.Validation)14 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)13 AtlasException (io.atlasmap.api.AtlasException)12 FieldType (io.atlasmap.v2.FieldType)12 JsonField (io.atlasmap.json.v2.JsonField)10 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 XmlField (io.atlasmap.xml.v2.XmlField)9 LookupTable (io.atlasmap.v2.LookupTable)8 AtlasConversionException (io.atlasmap.api.AtlasConversionException)7 ConstantField (io.atlasmap.v2.ConstantField)7 Head (io.atlasmap.spi.AtlasInternalSession.Head)6 PropertyField (io.atlasmap.v2.PropertyField)6 Method (java.lang.reflect.Method)6