Search in sources :

Example 6 with TargetOrderArray

use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.

the class JavaWriterUtilMock method setObjectOnParent.

/**
 * Set the given object within the parentObject.
 *
 * @param field
 *            - provided if we need it, I don't think we will since we already
 *            have the value in hand?
 * @param segmentContext
 *            - current segment for the field's path, this will be the last
 *            segment in the path.
 * @param parentObject
 *            - the object we're setting the value in
 * @param childObject
 *            - the childObject to set
 */
@SuppressWarnings({ "unchecked" })
@Override
public void setObjectOnParent(Field field, SegmentContext segmentContext, Object parentObject, Object childObject) throws AtlasException {
    String segment = segmentContext.getSegment();
    if (LOG.isDebugEnabled()) {
        LOG.debug("Setting object '" + segmentContext.getSegmentPath() + "'.\n\tchildObject: " + childObject + "\n\tparentObject: " + parentObject);
    }
    // now the cleanedSegment is a cleaned name such as "addressLine1"
    String cleanedSegment = AtlasPath.cleanPathSegment(segment);
    if ("addressLine1".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
        ((TargetAddress) parentObject).setAddressLine1((String) childObject);
    } else if ("addressLine1".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
        ((TargetAddress) parentObject).setAddressLine1((String) childObject);
    } else if ("addressLine2".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
        ((TargetAddress) parentObject).setAddressLine2((String) childObject);
    } else if ("city".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
        ((TargetAddress) parentObject).setCity((String) childObject);
    } else if ("state".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
        ((TargetAddress) parentObject).setState((String) childObject);
    } else if ("zipCode".equals(cleanedSegment) && parentObject instanceof TargetAddress) {
        ((TargetAddress) parentObject).setZipCode((String) childObject);
    } else if ("orders".equals(cleanedSegment) && parentObject instanceof TestListOrders) {
        ((TestListOrders) parentObject).setOrders((List<BaseOrder>) childObject);
    } else if ("orders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
        ((TargetOrderArray) parentObject).setOrders((TargetOrder[]) childObject);
    } else if ("address".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
        ((TargetOrder) parentObject).setAddress((TargetAddress) childObject);
    } else if ("name".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        ((TargetTestClass) parentObject).setName((String) childObject);
    } else if ("address".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        ((TargetTestClass) parentObject).setAddress((TargetAddress) childObject);
    } else if ("listOrders".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        ((TargetTestClass) parentObject).setListOrders((TestListOrders) childObject);
    } else if ("orderId".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
        ((TargetOrder) parentObject).setOrderId((Integer) childObject);
    } else if ("orderArray".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        ((TargetTestClass) parentObject).setOrderArray((TargetOrderArray) childObject);
    } else if ("numberOrders".equals(cleanedSegment) && parentObject instanceof TargetOrderArray) {
        ((TargetOrderArray) parentObject).setNumberOrders((Integer) childObject);
    } else if ("contact".equals(cleanedSegment) && parentObject instanceof TargetOrder) {
        ((TargetOrder) parentObject).setContact((TargetContact) childObject);
    } else if ("firstName".equals(cleanedSegment) && parentObject instanceof TargetContact) {
        ((TargetContact) parentObject).setFirstName((String) childObject);
    } else if ("lastName".equals(cleanedSegment) && parentObject instanceof TargetContact) {
        ((TargetContact) parentObject).setLastName((String) childObject);
    } else if ("primitives".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        ((TargetTestClass) parentObject).setPrimitives((TargetFlatPrimitiveClass) childObject);
    } else if ("intArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
        ((TargetFlatPrimitiveClass) parentObject).setIntArrayField((int[]) childObject);
    } else if ("boxedStringArrayField".equals(cleanedSegment) && parentObject instanceof TargetFlatPrimitiveClass) {
        ((TargetFlatPrimitiveClass) parentObject).setBoxedStringArrayField((String[]) childObject);
    } else if ("statesLong".equals(cleanedSegment) && parentObject instanceof TargetTestClass) {
        ((TargetTestClass) parentObject).setStatesLong((StateEnumClassLong) childObject);
    } else {
        String clz = parentObject.getClass().getSimpleName();
        String clz2 = childObject.getClass().getSimpleName();
        String setter = "set" + cleanedSegment.substring(0, 1).toUpperCase() + cleanedSegment.substring(1);
        String fix = "} else if (\"" + cleanedSegment + "\".equals(cleanedSegment) && parentObject instanceof " + clz + ") {\n " + "((" + clz + ") parentObject)." + setter + "((" + clz2 + ")childObject);";
        LOG.error(fix);
        throw new AtlasException("FIX: " + fix);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Object after value written: " + parentObject);
    }
}
Also used : StateEnumClassLong(io.atlasmap.java.test.StateEnumClassLong) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) TestListOrders(io.atlasmap.java.test.TestListOrders) BaseOrder(io.atlasmap.java.test.BaseOrder) TargetContact(io.atlasmap.java.test.TargetContact) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) AtlasException(io.atlasmap.api.AtlasException) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray)

Example 7 with TargetOrderArray

use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.

the class BaseDocumentWriterTest method reset.

@Before
public void reset() {
    classLoader = Thread.currentThread().getContextClassLoader();
    writer = new DocumentJavaFieldWriter(conversionService);
    writer.setTargetValueConverter(new TargetValueConverter(classLoader, conversionService) {

        public Object convert(AtlasInternalSession session, LookupTable lookupTable, Field sourceField, Object parentObject, Field targetField) throws AtlasException {
            return targetField.getValue();
        }
    });
    field = null;
    segmentContexts = new LinkedList<>();
    targetTestClassInstance = new TargetTestClass();
    targetTestClassInstance.setContact(new TargetContact());
    targetTestClassInstance.setAddress(new TargetAddress());
    targetOrderListInstance = new TestListOrders();
    targetOrderListInstance.setOrders(new LinkedList<>());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetTestClassInstance.setListOrders(targetOrderListInstance);
    targetOrderArrayInstance = new TargetOrderArray();
    targetOrderArrayInstance.setOrders(new BaseOrder[2]);
    targetOrderArrayInstance.getOrders()[0] = new TargetOrder();
    targetOrderArrayInstance.getOrders()[1] = new TargetOrder();
    targetTestClassInstance.setOrderArray(targetOrderArrayInstance);
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) TargetContact(io.atlasmap.java.test.TargetContact) TargetAddress(io.atlasmap.java.test.TargetAddress) AtlasException(io.atlasmap.api.AtlasException) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Field(io.atlasmap.v2.Field) JavaEnumField(io.atlasmap.java.v2.JavaEnumField) JavaField(io.atlasmap.java.v2.JavaField) TestListOrders(io.atlasmap.java.test.TestListOrders) LookupTable(io.atlasmap.v2.LookupTable) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) Before(org.junit.Before)

Example 8 with TargetOrderArray

use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.

the class DocumentJavaFieldWriterTest method testExpandCollectionArray.

@Test
public void testExpandCollectionArray() throws Exception {
    addClassForFieldPath("/", TargetOrderArray.class);
    addClassForFieldPath("/orders[5]", TargetOrder.class);
    addClassForFieldPath("/orders[5]/address", TargetAddress.class);
    write("/orders[4]/address/addressLine1", "hello world1.");
    write("/orders[14]/address/addressLine1", "hello world2.");
    write("/orders[2]/address/addressLine1", "hello world3.");
    TargetOrderArray o = (TargetOrderArray) writer.getRootObject();
    ensureNotNullAndClass(o, TargetOrderArray.class);
    ensureNotNullAndClass(o.getOrders(), TargetOrder[].class);
    assertEquals(15, o.getOrders().length);
    for (int i = 0; i < 15; i++) {
        System.out.println("Checking #" + i);
        if (i == 4 || i == 14 || i == 2) {
            ensureNotNullAndClass(o.getOrders()[i], TargetOrder.class);
            ensureNotNullAndClass(o.getOrders()[i].getAddress(), TargetAddress.class);
        } else {
            assertNull(o.getOrders()[i]);
        }
    }
    assertEquals("hello world1.", o.getOrders()[4].getAddress().getAddressLine1());
    assertEquals("hello world2.", o.getOrders()[14].getAddress().getAddressLine1());
    assertEquals("hello world3.", o.getOrders()[2].getAddress().getAddressLine1());
}
Also used : TargetOrder(io.atlasmap.java.test.TargetOrder) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Test(org.junit.Test)

Example 9 with TargetOrderArray

use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.

the class JavaConstructServiceComplexArrayTest method testConstructTargetOrderArrayFiltered.

@Test
public void testConstructTargetOrderArrayFiltered() throws Exception {
    Object targetObject = constructService.constructClass(generateOrderArray("Target"), Arrays.asList("orders", "orders/address"));
    assertNotNull(targetObject);
    assertTrue(targetObject instanceof TargetOrderArray);
    TargetOrderArray orderArray = (TargetOrderArray) targetObject;
    assertNotNull(orderArray.getOrders());
    assertTrue(orderArray.getOrders().length > 0);
    assertNull(orderArray.getNumberOrders());
    for (int i = 0; i < orderArray.getOrders().length; i++) {
        TargetOrder order = (TargetOrder) orderArray.getOrders()[i];
        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());
        assertNull(order.getContact());
    }
}
Also used : TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) Test(org.junit.Test)

Example 10 with TargetOrderArray

use of io.atlasmap.java.test.TargetOrderArray in project atlasmap by atlasmap.

the class BaseJavaFieldWriterTest method reset.

@BeforeEach
public void reset() {
    classLoader = Thread.currentThread().getContextClassLoader();
    writerUtil = new JavaFieldWriterUtil(conversionService);
    writer = new JavaFieldWriter(writerUtil);
    writer.setTargetValueConverter(new TargetValueConverter(classLoader, conversionService, writerUtil));
    field = null;
    segmentContexts = new LinkedList<>();
    targetTestClassInstance = new TargetTestClass();
    targetTestClassInstance.setContact(new TargetContact());
    targetTestClassInstance.setAddress(new TargetAddress());
    targetOrderListInstance = new TestListOrders();
    targetOrderListInstance.setOrders(new LinkedList<>());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetOrderListInstance.getOrders().add(new TargetOrder());
    targetTestClassInstance.setListOrders(targetOrderListInstance);
    targetOrderArrayInstance = new TargetOrderArray();
    targetOrderArrayInstance.setOrders(new BaseOrder[2]);
    targetOrderArrayInstance.getOrders()[0] = new TargetOrder();
    targetOrderArrayInstance.getOrders()[1] = new TargetOrder();
    targetTestClassInstance.setOrderArray(targetOrderArrayInstance);
    audits = new Audits();
}
Also used : Audits(io.atlasmap.v2.Audits) TargetContact(io.atlasmap.java.test.TargetContact) TestListOrders(io.atlasmap.java.test.TestListOrders) TargetAddress(io.atlasmap.java.test.TargetAddress) TargetOrder(io.atlasmap.java.test.TargetOrder) TargetTestClass(io.atlasmap.java.test.TargetTestClass) TargetOrderArray(io.atlasmap.java.test.TargetOrderArray) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)11 TargetAddress (io.atlasmap.java.test.TargetAddress)8 TargetContact (io.atlasmap.java.test.TargetContact)5 TargetTestClass (io.atlasmap.java.test.TargetTestClass)5 TestListOrders (io.atlasmap.java.test.TestListOrders)4 Test (org.junit.Test)4 AtlasException (io.atlasmap.api.AtlasException)3 BaseOrder (io.atlasmap.java.test.BaseOrder)3 Test (org.junit.jupiter.api.Test)3 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)2 JavaField (io.atlasmap.java.v2.JavaField)2 Field (io.atlasmap.v2.Field)2 StateEnumClassLong (io.atlasmap.java.test.StateEnumClassLong)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)1 Audits (io.atlasmap.v2.Audits)1 FieldGroup (io.atlasmap.v2.FieldGroup)1 LookupTable (io.atlasmap.v2.LookupTable)1 Before (org.junit.Before)1