Search in sources :

Example 41 with Field

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

the class XmlSchemaInspectionMultipleNamespacesTest method testMultipleNamespaces.

@Test
public void testMultipleNamespaces() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-schemaset.xml").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument answer = service.inspectSchema(schemaFile);
    Assert.assertEquals(3, answer.getXmlNamespaces().getXmlNamespace().size());
    for (XmlNamespace namespace : answer.getXmlNamespaces().getXmlNamespace()) {
        switch(namespace.getAlias()) {
            case "tns":
                Assert.assertEquals("io.atlasmap.xml.test:Root", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            case "first":
                Assert.assertEquals("io.atlasmap.xml.test:First", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            case "second":
                Assert.assertEquals("io.atlasmap.xml.test:Second", namespace.getUri());
                Assert.assertEquals(null, namespace.isTargetNamespace());
                break;
            default:
                Assert.fail(String.format("Unknown alias '%s'", namespace.getAlias()));
        }
    }
    List<Field> fields = answer.getFields().getField();
    Assert.assertEquals(1, fields.size());
    XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
    Assert.assertEquals("tns:RootDocument", complex.getName());
    List<XmlField> rootFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(4, rootFields.size());
    for (XmlField xmlField : rootFields) {
        switch(xmlField.getName()) {
            case "tns:Name":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/tns:Name", xmlField.getPath());
                break;
            case "tns:Value":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/tns:Value", xmlField.getPath());
                break;
            case "first:FirstElement":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/first:FirstElement", xmlField.getPath());
                List<XmlField> firstFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, firstFields.size());
                for (XmlField firstField : firstFields) {
                    switch(firstField.getName()) {
                        case "first:Name":
                            Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Name", firstField.getPath());
                            break;
                        case "first:Value":
                            Assert.assertEquals(FieldType.STRING, firstField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/first:FirstElement/first:Value", firstField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", firstField.getPath()));
                    }
                }
                break;
            case "second:SecondElement":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:RootDocument/second:SecondElement", xmlField.getPath());
                List<XmlField> secondFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, secondFields.size());
                for (XmlField secondField : secondFields) {
                    switch(secondField.getName()) {
                        case "second:Name":
                            Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Name", secondField.getPath());
                            break;
                        case "second:Value":
                            Assert.assertEquals(FieldType.STRING, secondField.getFieldType());
                            Assert.assertEquals("/tns:RootDocument/second:SecondElement/second:Value", secondField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", secondField.getPath()));
                    }
                }
                break;
            default:
                Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

Example 42 with Field

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

the class BaseXmlInspectionServiceTest method debugFields.

protected void debugFields(Fields xmlFields) {
    for (Field field : xmlFields.getField()) {
        Assert.assertTrue(field instanceof XmlField);
        XmlField xmlField = (XmlField) field;
        printXmlField(xmlField);
        if (xmlField instanceof XmlComplexType) {
            debugFields(((XmlComplexType) xmlField).getXmlFields());
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlField(io.atlasmap.xml.v2.XmlField)

Example 43 with Field

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

the class XmlSchemaInspectionMultipleNamespacesTest method testSyndesis.

@Test
public void testSyndesis() throws Exception {
    File schemaFile = Paths.get("src/test/resources/inspect/multiple-namespaces-syndesis.xml").toFile();
    XmlInspectionService service = new XmlInspectionService();
    XmlDocument answer = service.inspectSchema(schemaFile);
    Assert.assertEquals(1, answer.getXmlNamespaces().getXmlNamespace().size());
    XmlNamespace namespace = answer.getXmlNamespaces().getXmlNamespace().get(0);
    Assert.assertEquals("tns", namespace.getAlias());
    Assert.assertEquals("http://syndesis.io/v1/swagger-connector-template/request", namespace.getUri());
    Assert.assertEquals(null, namespace.isTargetNamespace());
    List<Field> fields = answer.getFields().getField();
    Assert.assertEquals(1, fields.size());
    XmlComplexType complex = XmlComplexType.class.cast(fields.get(0));
    Assert.assertEquals("tns:request", complex.getName());
    List<XmlField> rootFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(1, rootFields.size());
    complex = XmlComplexType.class.cast(rootFields.get(0));
    Assert.assertEquals("tns:body", complex.getName());
    List<XmlField> bodyFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(1, bodyFields.size());
    complex = XmlComplexType.class.cast(bodyFields.get(0));
    Assert.assertEquals("Pet", complex.getName());
    List<XmlField> petFields = complex.getXmlFields().getXmlField();
    Assert.assertEquals(6, petFields.size());
    for (XmlField xmlField : petFields) {
        switch(xmlField.getName()) {
            case "id":
                Assert.assertEquals(FieldType.DECIMAL, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/id", xmlField.getPath());
                break;
            case "Category":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/Category", xmlField.getPath());
                List<XmlField> categoryFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(2, categoryFields.size());
                for (XmlField categoryField : categoryFields) {
                    switch(categoryField.getName()) {
                        case "id":
                            Assert.assertEquals(FieldType.DECIMAL, categoryField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/Category/id", categoryField.getPath());
                            break;
                        case "name":
                            Assert.assertEquals(FieldType.STRING, categoryField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/Category/name", categoryField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", categoryField.getPath()));
                    }
                }
                break;
            case "name":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/name", xmlField.getPath());
                break;
            case "photoUrl":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/photoUrl", xmlField.getPath());
                List<XmlField> photoUrlFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(1, photoUrlFields.size());
                XmlField photoUrlField = photoUrlFields.get(0);
                Assert.assertEquals(FieldType.STRING, photoUrlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/photoUrl/photoUrl", photoUrlField.getPath());
                break;
            case "tag":
                Assert.assertEquals(FieldType.COMPLEX, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/tag", xmlField.getPath());
                List<XmlField> tagFields = XmlComplexType.class.cast(xmlField).getXmlFields().getXmlField();
                Assert.assertEquals(1, tagFields.size());
                XmlField tagField = tagFields.get(0);
                Assert.assertEquals(FieldType.COMPLEX, tagField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag", tagField.getPath());
                List<XmlField> tagTagFields = XmlComplexType.class.cast(tagField).getXmlFields().getXmlField();
                Assert.assertEquals(2, tagTagFields.size());
                for (XmlField tagTagField : tagTagFields) {
                    switch(tagTagField.getName()) {
                        case "id":
                            Assert.assertEquals(FieldType.DECIMAL, tagTagField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag/id", tagTagField.getPath());
                            break;
                        case "name":
                            Assert.assertEquals(FieldType.STRING, tagTagField.getFieldType());
                            Assert.assertEquals("/tns:request/tns:body/Pet/tag/Tag/name", tagTagField.getPath());
                            break;
                        default:
                            Assert.fail(String.format("Unknown field '%s'", tagTagField.getPath()));
                    }
                }
                break;
            case "status":
                Assert.assertEquals(FieldType.STRING, xmlField.getFieldType());
                Assert.assertEquals("/tns:request/tns:body/Pet/status", xmlField.getPath());
                break;
            default:
                Assert.fail(String.format("Unknown field '%s'", xmlField.getPath()));
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) XmlComplexType(io.atlasmap.xml.v2.XmlComplexType) XmlNamespace(io.atlasmap.xml.v2.XmlNamespace) XmlField(io.atlasmap.xml.v2.XmlField) XmlDocument(io.atlasmap.xml.v2.XmlDocument) File(java.io.File) Test(org.junit.Test)

Example 44 with Field

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

the class XmlFieldWriterTest method testThrowExceptionOnNullXmlField.

@Test(expected = AtlasException.class)
public void testThrowExceptionOnNullXmlField() throws Exception {
    createWriter();
    XmlField field = null;
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(mock(Field.class));
    when(session.head().getTargetField()).thenReturn(field);
    writer.write(session);
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 45 with Field

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

the class DefaultAtlasContext method processSourceFieldMappings.

private void processSourceFieldMappings(DefaultAtlasSession session, List<Field> sourceFields) throws AtlasException {
    for (Field sourceField : sourceFields) {
        session.head().setSourceField(sourceField);
        AtlasModule module = resolveModule(FieldDirection.SOURCE, sourceField);
        if (module == null) {
            AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Module not found for docId '%s'", sourceField.getDocId()), sourceField.getPath(), AuditStatus.ERROR, null);
            return;
        }
        if (!module.isSupportedField(sourceField)) {
            AtlasUtil.addAudit(session, sourceField.getDocId(), String.format("Unsupported source field type '%s' for DataSource '%s'", sourceField.getClass().getName(), module.getUri()), sourceField.getPath(), AuditStatus.ERROR, null);
            return;
        }
        module.processSourceFieldMapping(session);
    }
}
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)

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