Search in sources :

Example 1 with DocumentJavaFieldWriter

use of io.atlasmap.java.core.DocumentJavaFieldWriter 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 2 with DocumentJavaFieldWriter

use of io.atlasmap.java.core.DocumentJavaFieldWriter in project atlasmap by atlasmap.

the class JavaModule method processTargetFieldMapping.

@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
    DocumentJavaFieldWriter writer = session.getFieldWriter(getDocId(), DocumentJavaFieldWriter.class);
    writer.write(session);
    if (LOG.isDebugEnabled()) {
        Field sourceField = session.head().getSourceField();
        Field targetField = session.head().getTargetField();
        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());
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter)

Example 3 with DocumentJavaFieldWriter

use of io.atlasmap.java.core.DocumentJavaFieldWriter in project atlasmap by atlasmap.

the class JavaModule method processPostTargetExecution.

@Override
public void processPostTargetExecution(AtlasInternalSession session) throws AtlasException {
    DocumentJavaFieldWriter writer = session.getFieldWriter(getDocId(), DocumentJavaFieldWriter.class);
    if (writer != null && writer.getRootObject() != null) {
        session.setTargetDocument(getDocId(), writer.getRootObject());
    } else {
        AtlasUtil.addAudit(session, getDocId(), String.format("No target document created for DataSource '%s'", getDocId()), null, AuditStatus.WARN, null);
    }
    session.removeFieldWriter(getDocId());
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPostTargetExecution completed", getDocId());
    }
}
Also used : DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter)

Aggregations

DocumentJavaFieldWriter (io.atlasmap.java.core.DocumentJavaFieldWriter)3 AtlasException (io.atlasmap.api.AtlasException)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 ClassInspectionService (io.atlasmap.java.inspect.ClassInspectionService)1 JavaClass (io.atlasmap.java.v2.JavaClass)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1 JavaField (io.atlasmap.java.v2.JavaField)1 BaseMapping (io.atlasmap.v2.BaseMapping)1 Field (io.atlasmap.v2.Field)1