Search in sources :

Example 1 with Equals

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

the class UiComplexSteps method processMapperSteps.

private void processMapperSteps() {
    List<StepDefinition> mappers = steps.getStepDefinitions().stream().filter(s -> s.getStep().getStepKind().equals(StepKind.mapper)).collect(Collectors.toList());
    if (mappers.isEmpty()) {
        log.debug("There are no mappers in this integration, proceeding...");
    } else {
        // mapping can be done on steps that preceed mapper step and the single step, which follows the mapper step.
        log.info("Found mapper step, creating new atlas mapping.");
        for (int i = 0; i < mappers.size(); i++) {
            List<StepDefinition> precedingSteps = steps.getStepDefinitions().subList(0, steps.getStepDefinitions().indexOf(mappers.get(i))).stream().filter(s -> s.getConnectorDescriptor().isPresent()).collect(Collectors.toList());
            StepDefinition followingStep = steps.getStepDefinitions().get(steps.getStepDefinitions().indexOf(mappers.get(i)) + 1);
            if (mappers.get(i).getStep().getConfiguredProperties().containsKey("atlasmapping")) {
                // TODO(tplevko): think of some way to substitute placeholders for the step ID's
                reflectStepIdsInAtlasMapping(mappers.get(i), precedingSteps, followingStep);
            } else {
                // TODO(tplevko): fix for more than one preceding step.
                mappers.get(i).setStep(atlasGenerator.getAtlasMappingStep(mappers.get(i), precedingSteps, followingStep));
            }
        }
    }
}
Also used : ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) Arrays(java.util.Arrays) Action(io.syndesis.common.model.action.Action) Step(io.syndesis.common.model.integration.Step) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingType(io.atlasmap.v2.MappingType) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) Connection(io.syndesis.common.model.connection.Connection) Map(java.util.Map) Given(cucumber.api.java.en.Given) Assertions(org.assertj.core.api.Assertions) StepKind(io.syndesis.common.model.integration.StepKind) Integration(io.syndesis.common.model.integration.Integration) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) Connector(io.syndesis.common.model.connection.Connector) AtlasMapperGenerator(io.syndesis.qe.bdd.datamapper.AtlasMapperGenerator) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IntegrationOverview(io.syndesis.qe.model.IntegrationOverview) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) TestUtils(io.syndesis.qe.utils.TestUtils) DataMapperDefinition(io.syndesis.qe.bdd.entities.DataMapperDefinition) StepsStorage(io.syndesis.qe.bdd.storage.StepsStorage) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint) DataMapperStepDefinition(io.syndesis.qe.bdd.entities.DataMapperStepDefinition) StepDefinition(io.syndesis.qe.bdd.entities.StepDefinition) ConnectorsEndpoint(io.syndesis.qe.endpoints.ConnectorsEndpoint) IntegrationsDeploymentEndpoint(io.syndesis.qe.endpoints.IntegrationsDeploymentEndpoint) ConnectionsEndpoint(io.syndesis.qe.endpoints.ConnectionsEndpoint) IntegrationsEndpoint(io.syndesis.qe.endpoints.IntegrationsEndpoint) IntegrationOverviewEndpoint(io.syndesis.qe.endpoints.IntegrationOverviewEndpoint)

Example 2 with Equals

use of io.atlasmap.v2.Equals 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 Equals

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

the class StringLengthValidatorTest method testValidateInvalid.

@Test
public void testValidateInvalid() {
    String pass = "";
    validator.validate(pass, validations, "testValidateInvalid");
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getAllValidations().size()));
    Validation validation = validations.get(0);
    assertNotNull(validation);
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertEquals("testValidateInvalid", validation.getId());
    assertTrue("Must be of this length".equals(validation.getMessage()));
}
Also used : Validation(io.atlasmap.v2.Validation) Test(org.junit.Test)

Example 4 with Equals

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

the class XmlFieldReader method read.

public void read(AtlasInternalSession session) throws AtlasException {
    if (document == null) {
        throw new AtlasException(new IllegalArgumentException("'document' cannot be null"));
    }
    Field field = session.head().getSourceField();
    if (field == null) {
        throw new AtlasException(new IllegalArgumentException("Argument 'field' cannot be null"));
    }
    seedDocumentNamespaces(document);
    XmlField xmlField = XmlField.class.cast(field);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Reading source value for field: " + xmlField.getPath());
    }
    if (document == null) {
        throw new AtlasException(new IllegalArgumentException("Argument 'document' cannot be null"));
    }
    if (xmlField == null) {
        throw new AtlasException(new IllegalArgumentException("Argument 'xmlField' cannot be null"));
    }
    Element parentNode = document.getDocumentElement();
    for (SegmentContext sc : new XmlPath(xmlField.getPath()).getSegmentContexts(false)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Now processing segment: " + sc.getSegment());
            LOG.debug("Parent element is currently: " + XmlIOHelper.writeDocumentToString(true, parentNode));
        }
        if (sc.getPrev() == null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Skipping root segment: " + sc);
            }
            // "/XOA/contact<>/firstName", skip.
            continue;
        }
        if (!XmlPath.isAttributeSegment(sc.getSegment())) {
            String childrenElementName = XmlPath.cleanPathSegment(sc.getSegment());
            String namespaceAlias = XmlPath.getNamespace(sc.getSegment());
            if (namespaceAlias != null && !"".equals(namespaceAlias)) {
                childrenElementName = namespaceAlias + ":" + childrenElementName;
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug("Looking for children elements with name: " + childrenElementName);
            }
            List<Element> children = XmlIOHelper.getChildrenWithName(childrenElementName, parentNode);
            if (children == null || children.isEmpty()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Skipping source value set, couldn't find children with name '" + childrenElementName + "', for segment: " + sc);
                }
                return;
            }
            parentNode = children.get(0);
            if (XmlPath.isCollectionSegment(sc.getSegment())) {
                int index = XmlPath.indexOfSegment(sc.getSegment());
                if (index >= children.size()) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Skipping source value set, children list can't fit index " + index + ", children list size: " + children.size());
                    }
                    return;
                }
                parentNode = children.get(index);
            }
        }
        if (sc.getNext() == null) {
            // last segment.
            String value = parentNode.getTextContent();
            if (XmlPath.isAttributeSegment(sc.getSegment())) {
                String attributeName = XmlPath.getAttribute(sc.getSegment());
                value = parentNode.getAttribute(attributeName);
            }
            if (value == null) {
                return;
            }
            if (xmlField.getFieldType() == null) {
                xmlField.setValue(value);
                xmlField.setFieldType(FieldType.STRING);
            } else {
                Object convertedValue;
                try {
                    convertedValue = conversionService.convertType(value, xmlField.getFormat(), xmlField.getFieldType(), null);
                    xmlField.setValue(convertedValue);
                } catch (AtlasConversionException e) {
                    AtlasUtil.addAudit(session, xmlField.getDocId(), String.format("Failed to convert field value '%s' into type '%s'", value, xmlField.getFieldType()), xmlField.getPath(), AuditStatus.ERROR, value);
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) SegmentContext(io.atlasmap.core.AtlasPath.SegmentContext) AtlasConversionException(io.atlasmap.api.AtlasConversionException) XmlField(io.atlasmap.xml.v2.XmlField) Element(org.w3c.dom.Element) AtlasException(io.atlasmap.api.AtlasException)

Example 5 with Equals

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

the class JsonModule 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 targetValue = null;
    // Do auto-conversion
    if (sourceField.getFieldType() != null && sourceField.getFieldType().equals(targetField.getFieldType())) {
        targetValue = sourceField.getValue();
    } else if (sourceField.getValue() != null) {
        try {
            targetValue = 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(targetValue);
    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);
    }
    JsonFieldWriter writer = session.getFieldWriter(getDocId(), JsonFieldWriter.class);
    writer.write(session);
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonFieldWriter(io.atlasmap.json.core.JsonFieldWriter) AtlasConversionException(io.atlasmap.api.AtlasConversionException) LookupTable(io.atlasmap.v2.LookupTable)

Aggregations

Field (io.atlasmap.v2.Field)7 Test (org.junit.Test)6 AtlasConversionException (io.atlasmap.api.AtlasConversionException)4 AtlasException (io.atlasmap.api.AtlasException)4 Validation (io.atlasmap.v2.Validation)4 FieldType (io.atlasmap.v2.FieldType)3 LookupTable (io.atlasmap.v2.LookupTable)3 Given (cucumber.api.java.en.Given)2 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)2 JavaField (io.atlasmap.java.v2.JavaField)2 ActionDetail (io.atlasmap.v2.ActionDetail)2 AtlasMapping (io.atlasmap.v2.AtlasMapping)2 BaseMapping (io.atlasmap.v2.BaseMapping)2 LookupEntry (io.atlasmap.v2.LookupEntry)2 Mapping (io.atlasmap.v2.Mapping)2 MappingType (io.atlasmap.v2.MappingType)2 SimpleField (io.atlasmap.v2.SimpleField)2 Validations (io.atlasmap.v2.Validations)2 AtlasMappingBaseTest (io.atlasmap.validation.AtlasMappingBaseTest)2 XmlFieldWriter (io.atlasmap.xml.core.XmlFieldWriter)2