Search in sources :

Example 1 with XmlFieldWriter

use of io.atlasmap.xml.core.XmlFieldWriter in project atlasmap by atlasmap.

the class XmlModule method processPostTargetExecution.

@Override
public void processPostTargetExecution(AtlasInternalSession session) throws AtlasException {
    XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
    if (writer != null && writer.getDocument() != null) {
        session.setTargetDocument(getDocId(), convertDocumentToString(writer.getDocument()));
    } else {
        AtlasUtil.addAudit(session, getDocId(), String.format("No target document created for DataSource:[id=%s, uri=%s]", getDocId(), this.getUri()), null, AuditStatus.WARN, null);
    }
    session.removeFieldWriter(getDocId());
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPostTargetExecution completed", getDocId());
    }
}
Also used : XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter)

Example 2 with XmlFieldWriter

use of io.atlasmap.xml.core.XmlFieldWriter in project atlasmap by atlasmap.

the class XmlModule method processPreTargetExecution.

@Override
public void processPreTargetExecution(AtlasInternalSession session) throws AtlasException {
    XmlNamespaces xmlNs = null;
    String template = null;
    for (DataSource ds : session.getMapping().getDataSource()) {
        if (DataSourceType.TARGET.equals(ds.getDataSourceType()) && ds instanceof XmlDataSource && (ds.getId() == null || ds.getId().equals(getDocId()))) {
            xmlNs = ((XmlDataSource) ds).getXmlNamespaces();
            template = ((XmlDataSource) ds).getTemplate();
        }
    }
    Map<String, String> nsMap = new HashMap<String, String>();
    if (xmlNs != null && xmlNs.getXmlNamespace() != null && !xmlNs.getXmlNamespace().isEmpty()) {
        for (XmlNamespace ns : xmlNs.getXmlNamespace()) {
            nsMap.put(ns.getAlias(), ns.getUri());
        }
    }
    XmlFieldWriter writer = new XmlFieldWriter(nsMap, template);
    session.setFieldWriter(getDocId(), writer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreTargetExcution completed", getDocId());
    }
}
Also used : HashMap(java.util.HashMap) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter) XmlNamespaces(io.atlasmap.xml.v2.XmlNamespaces) DataSource(io.atlasmap.v2.DataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource) XmlDataSource(io.atlasmap.xml.v2.XmlDataSource)

Example 3 with XmlFieldWriter

use of io.atlasmap.xml.core.XmlFieldWriter in project atlasmap by atlasmap.

the class XmlModule method processTargetFieldMapping.

@Override
public void processTargetFieldMapping(AtlasInternalSession session) throws AtlasException {
    Field sourceField = session.head().getSourceField();
    Field targetField = session.head().getTargetField();
    // Attempt to Auto-detect field type based on input value
    if (targetField.getFieldType() == null && sourceField.getValue() != null) {
        targetField.setFieldType(getConversionService().fieldTypeFromClass(sourceField.getValue().getClass()));
    }
    Object outputValue = null;
    // Do auto-conversion
    if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
        outputValue = sourceField.getValue();
    } else if (sourceField.getValue() != null) {
        try {
            outputValue = getConversionService().convertType(sourceField.getValue(), sourceField.getFormat(), targetField.getFieldType(), targetField.getFormat());
        } catch (AtlasConversionException e) {
            AtlasUtil.addAudit(session, targetField.getDocId(), String.format("Unable to auto-convert for sT=%s tT=%s tF=%s msg=%s", sourceField.getFieldType(), targetField.getFieldType(), targetField.getPath(), e.getMessage()), targetField.getPath(), AuditStatus.ERROR, null);
            return;
        }
    }
    targetField.setValue(outputValue);
    LookupTable lookupTable = session.head().getLookupTable();
    if (lookupTable != null) {
        processLookupField(session, lookupTable, targetField.getValue(), targetField);
    }
    if (isAutomaticallyProcessOutputFieldActions() && targetField.getActions() != null && targetField.getActions().getActions() != null) {
        getFieldActionService().processActions(targetField.getActions(), targetField);
    }
    XmlFieldWriter writer = session.getFieldWriter(getDocId(), XmlFieldWriter.class);
    writer.write(session);
    if (LOG.isDebugEnabled()) {
        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) XmlField(io.atlasmap.xml.v2.XmlField) AtlasConversionException(io.atlasmap.api.AtlasConversionException) LookupTable(io.atlasmap.v2.LookupTable) XmlFieldWriter(io.atlasmap.xml.core.XmlFieldWriter)

Aggregations

XmlFieldWriter (io.atlasmap.xml.core.XmlFieldWriter)3 AtlasConversionException (io.atlasmap.api.AtlasConversionException)1 DataSource (io.atlasmap.v2.DataSource)1 Field (io.atlasmap.v2.Field)1 LookupTable (io.atlasmap.v2.LookupTable)1 XmlDataSource (io.atlasmap.xml.v2.XmlDataSource)1 XmlField (io.atlasmap.xml.v2.XmlField)1 XmlNamespace (io.atlasmap.xml.v2.XmlNamespace)1 XmlNamespaces (io.atlasmap.xml.v2.XmlNamespaces)1 HashMap (java.util.HashMap)1