Search in sources :

Example 11 with Equals

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

the class NonNullValidatorTest method testValidateInvalid.

@Test
public void testValidateInvalid() {
    validator.validate(null, validations, null);
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    Validation validation = validationHelper.getAllValidations().get(0);
    assertNotNull(validation);
    assertTrue("Cannot be null".equals(validation.getMessage()));
    assertEquals(ValidationScope.MAPPING, validation.getScope());
    assertNull(validation.getId());
    String empty = "";
    validationHelper.getAllValidations().clear();
    validator.validate(empty, validations, "testValidateInvalid-2");
    assertTrue(validationHelper.hasErrors());
    assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
    assertEquals(ValidationScope.MAPPING, validationHelper.getValidation().get(0).getScope());
    assertEquals("testValidateInvalid-2", validationHelper.getValidation().get(0).getId());
}
Also used : Validation(io.atlasmap.v2.Validation) Test(org.junit.Test)

Example 12 with Equals

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

the class OverloadedFieldActionsTest method testListActions.

@Test
public void testListActions() throws Exception {
    List<ActionDetail> actions = DefaultAtlasContextFactory.getInstance().getFieldActionService().listActionDetails();
    Integer found = 0;
    for (ActionDetail d : actions) {
        if (d.getName().equals("DayOfWeek")) {
            found++;
        }
    }
    assertEquals(Integer.valueOf(2), found);
}
Also used : ActionDetail(io.atlasmap.v2.ActionDetail) Test(org.junit.Test)

Example 13 with Equals

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

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

Example 15 with Equals

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

the class DefaultAtlasContext method extractCollectionMappings.

private List<Mapping> extractCollectionMappings(DefaultAtlasSession session, BaseMapping baseMapping) throws AtlasException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generating Source Mappings from mapping: {}", baseMapping);
    }
    if (!baseMapping.getMappingType().equals(MappingType.COLLECTION)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Mapping is not a collection mapping, not cloning: {}", baseMapping);
        }
        return Arrays.asList((Mapping) baseMapping);
    }
    List<Mapping> mappings = new LinkedList<>();
    for (BaseMapping m : ((Collection) baseMapping).getMappings().getMapping()) {
        Mapping mapping = (Mapping) m;
        Field sourceField = mapping.getInputField().get(0);
        boolean sourceIsCollection = AtlasPath.isCollection(sourceField.getPath());
        if (!sourceIsCollection) {
            // just copy it over
            if (LOG.isDebugEnabled()) {
                LOG.debug("Internal mapping's source field is not a collection, not cloning: {}", mapping);
            }
            // output object to be created for our copied firstName value
            for (Field f : mapping.getOutputField()) {
                f.setPath(AtlasPath.overwriteCollectionIndex(f.getPath(), 0));
            }
            mappings.add(mapping);
            continue;
        }
        AtlasModule module = resolveModule(FieldDirection.SOURCE, sourceField);
        int sourceCollectionSize = module.getCollectionSize(session, sourceField);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Internal mapping's source field is a collection. Cloning it for each item ({} clones): {}", sourceCollectionSize, mapping);
        }
        for (int i = 0; i < sourceCollectionSize; i++) {
            Mapping cloneMapping = (Mapping) AtlasModelFactory.cloneMapping(mapping, false);
            for (Field f : mapping.getInputField()) {
                Field clonedField = module.cloneField(f);
                clonedField.setPath(AtlasPath.overwriteCollectionIndex(clonedField.getPath(), i));
                cloneMapping.getInputField().add(clonedField);
            }
            for (Field f : mapping.getOutputField()) {
                Field clonedField = module.cloneField(f);
                if (AtlasPath.isCollection(clonedField.getPath())) {
                    clonedField.setPath(AtlasPath.overwriteCollectionIndex(clonedField.getPath(), i));
                }
                cloneMapping.getOutputField().add(clonedField);
            }
            mappings.add(cloneMapping);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Generated {} mappings from mapping: {}", mappings.size(), baseMapping);
    }
    ((Collection) baseMapping).getMappings().getMapping().clear();
    ((Collection) baseMapping).getMappings().getMapping().addAll(mappings);
    return mappings;
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) ConstantField(io.atlasmap.v2.ConstantField) AtlasModule(io.atlasmap.spi.AtlasModule) Collection(io.atlasmap.v2.Collection) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) LinkedList(java.util.LinkedList) BaseMapping(io.atlasmap.v2.BaseMapping)

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