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);
}
}
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);
}
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());
}
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());
}
}
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();
}
Aggregations