














package au.com.<dummy>.jaxb.test02;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.stream.StreamSource;
import au.com.<dummy>.jaxb.test02.CRM_CustomerInformation_to_ERP_UserCollection;
import au.com.<dummy>.jaxb.test02.source.CustomerInformation;
import au.com.<dummy>.jaxb.test02.target.ExtraInfo;
import au.com.<dummy>.jaxb.test02.target.UserCollectionMessage;
import au.com.<dummy>.jaxb.test02.target.UserRecord;
import au.com.<dummy>.jaxb.test02.source.CustomerInformation.Customer;
import au.com.<dummy>.jaxb.test02.target.ObjectFactory;
public class CRM_CustomerInformation_to_ERP_UserCollection extends AbstractTransformation {
@Override
public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {
// TODO Auto-generated method stub
getTrace().addInfo("JAVA Mapping JAXB_Mapping is Initiated");
this.execute(in.getInputPayload().getInputStream(), out.getOutputPayload().getOutputStream());
}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
try {
InputStream is = in;
JAXBContext jaxbContext = JAXBContext.newInstance(CustomerInformation.class);
Unmarshaller unMarshaller = jaxbContext.createUnmarshaller();
JAXBElement<CustomerInformation> customerInforamtion = (JAXBElement<CustomerInformation>) unMarshaller.unmarshal(new StreamSource(is), CustomerInformation.class);
getTrace().addInfo("Unmarshall Successful");
/*————- Marshal the Target—————-*/
ObjectFactory objectFactory = new ObjectFactory();
UserCollectionMessage userCollectionMessage = objectFactory.createUserCollectionMessage();
JAXBElement<UserCollectionMessage> target = objectFactory.createUserCollection(userCollectionMessage);
for (int i = 0; i < customerInforamtion.getValue().getCustomer().size(); i++){
UserRecord user = objectFactory.createUserRecord();
Customer customer = customerInforamtion.getValue().getCustomer().get(i);
user.setFirstname(customer.getGivenname());
user.setLastname(customer.getSurname());
user.setFullname(customer.getGivenname()+" "+customer.getSurname());
user.setUsername(customer.getGivenname()+"_"+customer.getSurname());
ExtraInfo extraInfo = objectFactory.createExtraInfo();
extraInfo.setAddressLine1(customer.getAddress().getLine1());
extraInfo.setAddressLine2(customer.getAddress().getLine2());
extraInfo.setAddressLine3(customer.getAddress().getLine3());
extraInfo.setCity(customer.getAddress().getState());
extraInfo.setPostCode(customer.getAddress().getPostcode());
extraInfo.setDateOfBirth(customer.getDOB());
extraInfo.setEmailAddress(customer.getContact().getEmail());
extraInfo.setMobile(customer.getContact().getMobile());
user.setExtraInfo(extraInfo);
userCollectionMessage.getUser().add(user);
}
JAXBContext contextTarget = JAXBContext.newInstance(UserCollectionMessage.class);
Marshaller marshallerTarget = contextTarget.createMarshaller();
marshallerTarget.marshal(target, out);
}catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String srcMsgFileName = "src/source.xml";
String tgtMsgFileName = "src/target.xml";
try {
InputStream in = new FileInputStream(new File(srcMsgFileName));
OutputStream out = new FileOutputStream(new File(tgtMsgFileName));
CRM_CustomerInformation_to_ERP_UserCollection myMapping = new CRM_CustomerInformation_to_ERP_UserCollection();
myMapping.execute(in, out);
System.out.println("Mapping test completed successfully");
} catch (Exception e) {
System.err.println("Mapping test failed");
e.printStackTrace();
}
}
}





You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 26 | |
| 25 | |
| 21 | |
| 20 | |
| 19 | |
| 14 | |
| 14 | |
| 14 | |
| 14 | |
| 10 |