Search in sources :

Example 36 with Field

use of org.talend.hl7.Field in project atlasmap by atlasmap.

the class BaseDefaultAtlasContextTest method prepareTargetField.

protected Field prepareTargetField(Mapping mapping, FieldType type, String path, int index) {
    Field field = prepareTargetField(mapping, path);
    field.setFieldType(type);
    field.setPath(path);
    field.setIndex(index);
    return field;
}
Also used : SimpleField(io.atlasmap.v2.SimpleField) Field(io.atlasmap.v2.Field)

Example 37 with Field

use of org.talend.hl7.Field in project atlasmap by atlasmap.

the class DefaultAtlasValidationServiceTest method testValidateAtlasMappingFileLookupFieldMappingRefNonExistentNames.

@Test
public void testValidateAtlasMappingFileLookupFieldMappingRefNonExistentNames() {
    AtlasMapping mapping = getAtlasMappingWithLookupTables("table1", "table2");
    // add one that does not exists
    Mapping lookupFieldMapping = AtlasModelFactory.createMapping(MappingType.LOOKUP);
    lookupFieldMapping.setLookupTableName("table3");
    Field inputField = createInputJavaField("inputName");
    Field outputField = createInputJavaField("outputName");
    lookupFieldMapping.getInputField().add(inputField);
    lookupFieldMapping.getOutputField().add(outputField);
    mapping.getMappings().getMapping().add(lookupFieldMapping);
    validations.addAll(validationService.validateMapping(mapping));
    assertTrue(validationHelper.hasErrors());
    assertFalse(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test) BaseValidatorTest(io.atlasmap.validators.BaseValidatorTest)

Example 38 with Field

use of org.talend.hl7.Field in project atlasmap by atlasmap.

the class DefaultAtlasValidationServiceTest method testValidateAtlasMappingFileLookupFieldMappingUnusedLookupTable.

@Test
public void testValidateAtlasMappingFileLookupFieldMappingUnusedLookupTable() {
    AtlasMapping mapping = getAtlasMappingFullValid();
    LookupTables lookupTables = new LookupTables();
    mapping.setLookupTables(lookupTables);
    LookupTable lookupTable = new LookupTable();
    lookupTable.setName("table1");
    lookupTable.setDescription("desc_table1");
    LookupTable lookupTable2 = new LookupTable();
    lookupTable2.setName("table2");
    lookupTable2.setDescription("desc_table2");
    lookupTables.getLookupTable().add(lookupTable);
    lookupTables.getLookupTable().add(lookupTable2);
    Mapping lookupFieldMapping = AtlasModelFactory.createMapping(MappingType.LOOKUP);
    lookupFieldMapping.setLookupTableName("table1");
    Field inputField = createInputJavaField("inputName");
    Field outputField = createInputJavaField("outputName");
    lookupFieldMapping.getInputField().add(inputField);
    lookupFieldMapping.getOutputField().add(outputField);
    mapping.getMappings().getMapping().add(lookupFieldMapping);
    validations.addAll(validationService.validateMapping(mapping));
    assertFalse(validationHelper.hasErrors());
    assertTrue(validationHelper.hasWarnings());
    assertFalse(validationHelper.hasInfos());
}
Also used : Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) LookupTables(io.atlasmap.v2.LookupTables) LookupTable(io.atlasmap.v2.LookupTable) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) Test(org.junit.Test) BaseValidatorTest(io.atlasmap.validators.BaseValidatorTest)

Example 39 with Field

use of org.talend.hl7.Field 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 40 with Field

use of org.talend.hl7.Field in project atlasmap by atlasmap.

the class AtlasServiceTest method testActionDeserialization.

@Test
public void testActionDeserialization() throws Exception {
    File file = new File("src/test/resources/atlasmapping-actions.json");
    AtlasMapping mapping = mapper.readValue(file, AtlasMapping.class);
    Mappings mappings = mapping.getMappings();
    for (BaseMapping baseMapping : mappings.getMapping()) {
        if (MappingType.MAP.equals(baseMapping.getMappingType())) {
            List<Field> fields = ((Mapping) baseMapping).getOutputField();
            for (Field f : fields) {
                if (f.getActions() != null && f.getActions().getActions() != null && !f.getActions().getActions().isEmpty()) {
                    System.out.println("Found actions: " + f.getActions().getActions().size());
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) AtlasMapping(io.atlasmap.v2.AtlasMapping) Mappings(io.atlasmap.v2.Mappings) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) BaseMapping(io.atlasmap.v2.BaseMapping) File(java.io.File) BaseMapping(io.atlasmap.v2.BaseMapping) Test(org.junit.Test)

Aggregations

Field (io.atlasmap.v2.Field)60 JavaField (io.atlasmap.java.v2.JavaField)15 Mapping (io.atlasmap.v2.Mapping)15 AtlasMapping (io.atlasmap.v2.AtlasMapping)14 SimpleField (io.atlasmap.v2.SimpleField)14 BaseMapping (io.atlasmap.v2.BaseMapping)12 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)11 Test (org.junit.Test)11 JsonField (io.atlasmap.json.v2.JsonField)8 LookupTable (io.atlasmap.v2.LookupTable)8 XmlField (io.atlasmap.xml.v2.XmlField)7 AtlasException (io.atlasmap.api.AtlasException)6 ConstantField (io.atlasmap.v2.ConstantField)6 AtlasConversionException (io.atlasmap.api.AtlasConversionException)5 JsonDocument (io.atlasmap.json.v2.JsonDocument)5 PropertyField (io.atlasmap.v2.PropertyField)5 ArrayList (java.util.ArrayList)5 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)4 AtlasModule (io.atlasmap.spi.AtlasModule)3 FieldType (io.atlasmap.v2.FieldType)3