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