Search in sources :

Example 31 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaModule method processPreTargetExecution.

@Override
public void processPreTargetExecution(AtlasInternalSession atlasSession) throws AtlasException {
    if (atlasSession == null || atlasSession.getMapping() == null || atlasSession.getMapping().getMappings() == null || atlasSession.getMapping().getMappings().getMapping() == null) {
        throw new AtlasException("AtlasSession not properly intialized with a mapping that contains field mappings");
    }
    if (javaInspectionService == null) {
        javaInspectionService = new ClassInspectionService();
        javaInspectionService.setConversionService(getConversionService());
    }
    List<BaseMapping> mapping = atlasSession.getMapping().getMappings().getMapping();
    Object rootObject;
    String targetClassName = AtlasUtil.getUriParameterValue(getUri(), "className");
    JavaClass inspectClass = getJavaInspectionService().inspectClass(targetClassName);
    merge(inspectClass, mapping);
    List<String> targetPaths = AtlasModuleSupport.listTargetPaths(mapping);
    try {
        rootObject = getJavaConstructService().constructClass(inspectClass, targetPaths);
    } catch (Exception e) {
        throw new AtlasException(e);
    }
    DocumentJavaFieldWriter writer = new DocumentJavaFieldWriter(getConversionService());
    writer.setRootObject(rootObject);
    writer.setTargetValueConverter(targetValueConverter);
    atlasSession.setFieldWriter(getDocId(), writer);
    if (LOG.isDebugEnabled()) {
        LOG.debug("{}: processPreTargetExcution completed", getDocId());
    }
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) DocumentJavaFieldWriter(io.atlasmap.java.core.DocumentJavaFieldWriter) ClassInspectionService(io.atlasmap.java.inspect.ClassInspectionService) AtlasException(io.atlasmap.api.AtlasException) BaseMapping(io.atlasmap.v2.BaseMapping) AtlasValidationException(io.atlasmap.api.AtlasValidationException) AtlasException(io.atlasmap.api.AtlasException)

Example 32 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaModule method merge.

private void merge(JavaClass inspectionClass, List<BaseMapping> mappings) {
    if (inspectionClass == null || inspectionClass.getJavaFields() == null || inspectionClass.getJavaFields().getJavaField() == null) {
        return;
    }
    if (mappings == null || mappings.size() == 0) {
        return;
    }
    for (BaseMapping fm : mappings) {
        if (fm instanceof Mapping && (((Mapping) fm).getOutputField() != null)) {
            Field f = ((Mapping) fm).getOutputField().get(0);
            if (f.getPath() != null) {
                Field inspectField = findFieldByPath(inspectionClass, f.getPath());
                if (inspectField != null && f instanceof JavaField && inspectField instanceof JavaField) {
                    String overrideClassName = ((JavaField) f).getClassName();
                    JavaField javaInspectField = (JavaField) inspectField;
                    // Support mapping overrides className
                    if (overrideClassName != null && !overrideClassName.equals(javaInspectField.getClassName())) {
                        javaInspectField.setClassName(overrideClassName);
                    }
                }
            }
        }
    }
}
Also used : Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) JavaField(io.atlasmap.java.v2.JavaField) BaseMapping(io.atlasmap.v2.BaseMapping) Mapping(io.atlasmap.v2.Mapping) BaseMapping(io.atlasmap.v2.BaseMapping)

Example 33 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaConstructServiceComplexArrayTest method generateOrderArray.

protected JavaClass generateOrderArray(String prefix) {
    JavaClass j = classInspectionService.inspectClass("io.atlasmap.java.test." + prefix + "OrderArray");
    for (JavaField jf : j.getJavaFields().getJavaField()) {
        if (jf.getPath().equals("orders")) {
            jf.setClassName("io.atlasmap.java.test." + prefix + "Order");
            jf.setArraySize(new Integer(3));
        }
        if (jf instanceof JavaClass) {
            for (JavaField cjf : ((JavaClass) jf).getJavaFields().getJavaField()) {
                if (cjf.getPath().equals("orders/contact")) {
                    cjf.setClassName("io.atlasmap.java.test." + prefix + "Contact");
                }
                if (cjf.getPath().equals("orders/address")) {
                    cjf.setClassName("io.atlasmap.java.test." + prefix + "Address");
                }
            }
        }
    }
    return j;
}
Also used : JavaField(io.atlasmap.java.v2.JavaField) JavaClass(io.atlasmap.java.v2.JavaClass)

Example 34 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaConstructServiceComplexTest method testConstructSourceParentOrder.

@Test
public void testConstructSourceParentOrder() throws Exception {
    JavaClass javaClass = generateParentOrder("Source");
    Object targetObject = constructService.constructClass(javaClass, null);
    assertNotNull(targetObject);
    assertTrue(targetObject instanceof SourceParentOrder);
    SourceParentOrder parentOrder = (SourceParentOrder) targetObject;
    assertNotNull(parentOrder.getOrder());
    SourceOrder order = (SourceOrder) parentOrder.getOrder();
    assertNotNull(order.getAddress());
    assertTrue(order.getAddress() instanceof SourceAddress);
    SourceAddress address = (SourceAddress) order.getAddress();
    assertNull(address.getAddressLine1());
    assertNull(address.getAddressLine2());
    assertNull(address.getCity());
    assertNull(address.getState());
    assertNull(address.getZipCode());
    assertNotNull(order.getContact());
    assertTrue(order.getContact() instanceof SourceContact);
    SourceContact contact = (SourceContact) order.getContact();
    assertNull(contact.getFirstName());
    assertNull(contact.getLastName());
    assertNull(contact.getPhoneNumber());
    assertNull(contact.getZipCode());
}
Also used : SourceParentOrder(io.atlasmap.java.test.SourceParentOrder) SourceAddress(io.atlasmap.java.test.SourceAddress) JavaClass(io.atlasmap.java.v2.JavaClass) SourceOrder(io.atlasmap.java.test.SourceOrder) SourceContact(io.atlasmap.java.test.SourceContact) Test(org.junit.Test)

Example 35 with JavaClass

use of io.atlasmap.java.v2.JavaClass in project atlasmap by atlasmap.

the class JavaConstructServiceComplexTest method testConstructTargetParentOrder.

@Test
public void testConstructTargetParentOrder() throws Exception {
    JavaClass javaClass = generateParentOrder("Target");
    Object targetObject = constructService.constructClass(javaClass, null);
    assertNotNull(targetObject);
    assertTrue(targetObject instanceof TargetParentOrder);
    TargetParentOrder parentOrder = (TargetParentOrder) targetObject;
    assertNotNull(parentOrder.getOrder());
    TargetOrder order = (TargetOrder) parentOrder.getOrder();
    assertNotNull(order.getAddress());
    assertTrue(order.getAddress() instanceof TargetAddress);
    TargetAddress address = (TargetAddress) order.getAddress();
    assertNull(address.getAddressLine1());
    assertNull(address.getAddressLine2());
    assertNull(address.getCity());
    assertNull(address.getState());
    assertNull(address.getZipCode());
    assertNotNull(order.getContact());
    assertTrue(order.getContact() instanceof TargetContact);
    TargetContact contact = (TargetContact) order.getContact();
    assertNull(contact.getFirstName());
    assertNull(contact.getLastName());
    assertNull(contact.getPhoneNumber());
    assertNull(contact.getZipCode());
}
Also used : JavaClass(io.atlasmap.java.v2.JavaClass) TargetContact(io.atlasmap.java.test.TargetContact) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetParentOrder(io.atlasmap.java.test.TargetParentOrder) Test(org.junit.Test)

Aggregations

JavaClass (io.atlasmap.java.v2.JavaClass)47 JavaField (io.atlasmap.java.v2.JavaField)21 Test (org.junit.Test)18 ClassInspectionService (io.atlasmap.java.inspect.ClassInspectionService)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 TargetAddress (io.atlasmap.java.test.TargetAddress)2 TargetOrder (io.atlasmap.java.test.TargetOrder)2 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)2 ModifierList (io.atlasmap.java.v2.ModifierList)2 BaseMapping (io.atlasmap.v2.BaseMapping)2 Field (io.atlasmap.v2.Field)2 Method (java.lang.reflect.Method)2 ApplicationPath (javax.ws.rs.ApplicationPath)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 AtlasException (io.atlasmap.api.AtlasException)1 AtlasValidationException (io.atlasmap.api.AtlasValidationException)1 DocumentJavaFieldWriter (io.atlasmap.java.core.DocumentJavaFieldWriter)1