View Javadoc

1   package org.kuali.ole;
2   
3   import com.thoughtworks.xstream.XStream;
4   import org.kuali.ole.pojo.edi.*;
5   
6   import java.util.Arrays;
7   
8   
9   /**
10   * Created by IntelliJ IDEA.
11   * User: palanivel
12   * Date: 3/2/12
13   * Time: 8:11 PM
14   * To change this template use File | Settings | File Templates.
15   */
16  public class OLETranscationalRecordGenerator {
17  
18      public String toXml(EDIOrder ediOrder) {
19          EDIOrders ediOrders = new EDIOrders();
20          ediOrders.setOrders(Arrays.asList(ediOrder));
21          String xml = toXml(ediOrders);
22          return xml;
23      }
24  
25      public String toXml(EDIOrders ediOrders) {
26          XStream xStream = intXStream();
27          String order = xStream.toXML(ediOrders);
28          return order;
29      }
30  
31      public EDIOrders fromXml(String requestXML) {
32          XStream xStream = intXStream();
33          return (EDIOrders) xStream.fromXML(requestXML);
34      }
35  
36      private XStream intXStream() {
37          XStream xStream = new XStream();
38          xStream.alias("orders", EDIOrders.class);
39          xStream.alias("order", EDIOrder.class);
40          xStream.addImplicitCollection(EDIOrders.class, "orders",EDIOrder.class);
41  
42          xStream.aliasField("sendersandreceiversidentification", EDIOrder.class, "senderAndReceiver");
43          xStream.aliasField("sendersandreceiversconstant", SenderAndReceiver.class, "sendersAndReceiversConstant");
44          xStream.aliasField("code", SendersAndReceiversConstant.class, "code");
45          xStream.aliasField("value", SendersAndReceiversConstant.class, "value");
46          xStream.aliasField("senderinformation", SenderAndReceiver.class, "senderInformation");
47          xStream.aliasField("senderid", SenderInformation.class, "senderId");
48          xStream.aliasField("senderidtype", SenderInformation.class, "senderIdType");
49          xStream.aliasField("receiverinformation", SenderAndReceiver.class, "receiverInformation");
50          xStream.aliasField("receiverid", ReceiverInformation.class, "receiverId");
51          xStream.aliasField("receiveridtype", ReceiverInformation.class, "receiverIdType");
52          xStream.aliasField("schedule", SenderAndReceiver.class, "schedule");
53          xStream.aliasField("preparationdate", Schedule.class, "preparationDate");
54          xStream.aliasField("preparationtime", Schedule.class, "preparationTime");
55          xStream.aliasField("interchangecontrolref", SenderAndReceiver.class, "interChangeControlReference");
56  
57          xStream.aliasField("messageheader", EDIOrder.class, "messageHeader");
58          xStream.aliasField("interchangecontrolref", MessageHeader.class, "interchangeControlReference");
59          xStream.aliasField("messagetypeinformation", MessageHeader.class, "messsageTypeInformation");
60          xStream.aliasField("messagetypeid", MesssageTypeInformation.class, "messageTypeId");
61          xStream.aliasField("constant1", MesssageTypeInformation.class, "constant1");
62          xStream.aliasField("constant2", MesssageTypeInformation.class, "constant2");
63          xStream.aliasField("constant3", MesssageTypeInformation.class, "constant3");
64          xStream.aliasField("constant4", MesssageTypeInformation.class, "constant4");
65  
66          xStream.aliasField("message", EDIOrder.class, "message");
67          xStream.aliasField("messagebeginning", Message.class, "messageBeginning");
68          xStream.aliasField("order", MessageBeginning.class, "messageBeginningOrder");
69          xStream.aliasField("interchangecontrolref", MessageBeginning.class, "messageBeginningInterchangeControlReference");
70          xStream.aliasField("codelistagency", MessageBeginning.class, "messageBeginningCodeListAgency");
71  
72          xStream.aliasField("messagecreationinfo", Message.class, "messageCreationInformation");
73          xStream.aliasField("details", MessageCreationInformation.class, "messageCreationInfoDetails");
74          xStream.aliasField("constant", MessageCreationInfoDetails.class, "messageCreationInfoConstant");
75          xStream.aliasField("date", MessageCreationInfoDetails.class, "messageCreationInfoDate");
76          xStream.aliasField("dateformat", MessageCreationInfoDetails.class, "messageCreationInfoDateFormat");
77  
78          xStream.aliasField("buyerpartyqualifier", Message.class, "buyerPartyQualifier");
79          xStream.aliasField("buyer", BuyerPartyQualifier.class, "buyer");
80          xStream.aliasField("buyerinfo", BuyerPartyQualifier.class, "buyerInformation");
81          xStream.aliasField("codedidentification", BuyerInformation.class, "buyerCodeIdentification");
82          xStream.aliasField("partyidentificationcode", BuyerInformation.class, "buyerPartyIdentificationCode");
83          xStream.aliasField("codelistagency", BuyerInformation.class, "buyerCodeListAgency");
84  
85          xStream.aliasField("reference", Message.class, "messageReference");
86          xStream.aliasField("partydetails", MessageReference.class, "partyDetails");
87          xStream.aliasField("additionalpartyidentification", PartyDetails.class, "additionalPartyIdentification");
88          xStream.aliasField("partyname", PartyDetails.class, "partyName");
89  
90          xStream.aliasField("supplierpartyqualifier", Message.class, "supplierPartyQualifier");
91          xStream.aliasField("supplier", SupplierPartyQualifier.class, "supplier");
92          xStream.aliasField("supplierinfo", SupplierPartyQualifier.class, "supplierInformation");
93          xStream.aliasField("codedidentification", SupplierInformation.class, "supplierCodeIdentification");
94          xStream.aliasField("partyidentificationcode", SupplierInformation.class, "supplierPartyIdentificationCode");
95          xStream.aliasField("codelistagency", SupplierInformation.class, "supplierCodeListAgency");
96  
97          xStream.aliasField("currencydetails", Message.class, "currencyDetails");
98          xStream.aliasField("supplierinfo", CurrencyDetails.class, "currencyDetailsSupplierInformation");
99          xStream.aliasField("defaultcurrency", CurrencyDetailsSupplierInformation.class, "defaultCurrency");
100         xStream.aliasField("currencytype", CurrencyDetailsSupplierInformation.class, "currencyType");
101         xStream.aliasField("ordercurrency", CurrencyDetailsSupplierInformation.class, "orderCurrency");
102 
103         xStream.alias("lineitemOrder", LineItemOrder.class);
104         xStream.alias("lineitem", LineItem.class);
105         xStream.alias("articlenumber", LineItemArticleNumber.class);
106         xStream.alias("productfunction", ProductFunction.class);
107         xStream.alias("articlenumber", ProductArticleNumber.class);
108         xStream.alias("itemdescription", ItemDescription.class);
109         xStream.alias("quantityinformation", QuantityInformation.class);
110         xStream.alias("quantity", Qunatity.class);
111         xStream.alias("priceinformation", PriceInformation.class);
112         xStream.alias("price", ItemPrice.class);
113         xStream.alias("referenceinformation", BuyerReferenceInformation.class);
114         xStream.alias("reference", BuyerLineItemReference.class);
115         xStream.alias("suppliersreferenceinformation", SupplierReferenceInformation.class);
116         xStream.alias("suppliersreference", SupplierLineItemReference.class);
117         xStream.alias("fundnumberreference", FundNumberReference.class);
118         xStream.alias("buyers", BuyersFundNumberReference.class);
119         xStream.alias("note",FreeTextNotes.class);
120         xStream.alias("transportstagequalifier", TransportStageQualifier.class);
121 
122         xStream.addImplicitCollection(EDIOrder.class, "lineItemOrder",LineItemOrder.class);
123         xStream.addImplicitCollection(LineItemOrder.class, "lineItem",LineItem.class);
124 
125         xStream.aliasField("sequencenumber",LineItem.class,"sequenceNumber");
126         xStream.aliasField("itemnumberid",LineItem.class,"itemNumberId");
127 
128         xStream.addImplicitCollection(LineItem.class, "lineItemArticleNumber",LineItemArticleNumber.class);
129 
130         xStream.aliasField("isbn",LineItemArticleNumber.class,"lineItemIsbn");
131         xStream.aliasField("itemnumbertype",LineItemArticleNumber.class,"lineItemNumberType");
132 
133         xStream.addImplicitCollection(LineItemOrder.class, "productFunction",ProductFunction.class);
134 
135         xStream.aliasField("productid",ProductFunction.class,"productId");
136 
137         xStream.addImplicitCollection(ProductFunction.class, "productArticleNumber",ProductArticleNumber.class);
138 
139         xStream.aliasField("isbn",ProductArticleNumber.class,"productIsbn");
140         xStream.aliasField("itemnumbertype",ProductArticleNumber.class,"productItemNumberType");
141 
142         xStream.addImplicitCollection(LineItemOrder.class, "itemDescriptionList",ItemDescription.class);
143 
144         xStream.aliasField("text",ItemDescription.class,"text");
145         xStream.aliasField("itemcharacteristiccode",ItemDescription.class,"itemCharacteristicCode");
146         xStream.aliasField("data",ItemDescription.class,"data");
147 
148         xStream.addImplicitCollection(LineItemOrder.class, "quantityInformation",QuantityInformation.class);
149         xStream.addImplicitCollection(QuantityInformation.class, "qunatity",Qunatity.class);
150 
151         xStream.aliasField("constant",Qunatity.class,"quantityConstant");
152         xStream.aliasField("quantity",Qunatity.class,"quantity");
153 
154         xStream.addImplicitCollection(LineItemOrder.class, "priceInformation",PriceInformation.class);
155         xStream.addImplicitCollection(PriceInformation.class, "itemPrice",ItemPrice.class);
156 
157         xStream.aliasField("grossprice",ItemPrice.class,"grossPrice");
158         xStream.aliasField("price",ItemPrice.class,"price");
159 
160         xStream.addImplicitCollection(LineItemOrder.class, "buyerReferenceInformation",BuyerReferenceInformation.class);
161         xStream.addImplicitCollection(BuyerReferenceInformation.class, "buyerLineItemReference",BuyerLineItemReference.class);
162 
163         xStream.aliasField("buyersorderline",BuyerLineItemReference.class,"buyersOrderLine");
164         xStream.aliasField("orderlinenumber",BuyerLineItemReference.class,"orderLineNumber");
165 
166 
167         xStream.addImplicitCollection(LineItemOrder.class, "supplierReferenceInformation",SupplierReferenceInformation.class);
168         xStream.addImplicitCollection(SupplierReferenceInformation.class, "supplierLineItemReference",SupplierLineItemReference.class);
169 
170         xStream.aliasField("suppliersorderline",SupplierLineItemReference.class,"suppliersOrderLine");
171         xStream.aliasField("vendorreferencenumber",SupplierLineItemReference.class,"vendorReferenceNumber");
172 
173 
174         xStream.addImplicitCollection(LineItemOrder.class, "fundNumberReference",FundNumberReference.class);
175         xStream.addImplicitCollection(FundNumberReference.class, "buyersFundNumberReference",BuyersFundNumberReference.class);
176 
177         xStream.aliasField("buyersfundnumber",BuyersFundNumberReference.class,"buyersFundNumber");
178         xStream.aliasField("budgetnumber",BuyersFundNumberReference.class,"budgetNumber");
179 
180         xStream.addImplicitCollection(LineItemOrder.class, "note",FreeTextNotes.class);
181 
182         xStream.aliasField("notelineitem",FreeTextNotes.class,"noteLineItem");
183         xStream.aliasField("noteempty1",FreeTextNotes.class,"noteempty1");
184         xStream.aliasField("noteempty2",FreeTextNotes.class,"noteempty2");
185         xStream.aliasField("noteempty3",FreeTextNotes.class,"noteempty3");
186 
187 
188         xStream.addImplicitCollection(LineItemOrder.class, "transportStageQualifier",TransportStageQualifier.class);
189 
190         xStream.aliasField("transportstagequalifierconstant",TransportStageQualifier.class,"transportStageConstant");
191         xStream.aliasField("surfacemail",TransportStageQualifier.class,"surfaceMail");
192 
193 
194         xStream.aliasField("summary", LineItemOrder.class, "supplierReferenceInformation");
195         xStream.aliasField("summarysection", Summary.class, "summarySection");
196         xStream.aliasField("separatorinfo", SummarySection.class, "separatorInformation");
197 
198         xStream.alias("controlinfomation", ControlInfomation.class);
199         xStream.alias("control", Control.class);
200 
201         xStream.addImplicitCollection(Summary.class, "controlInfomation",ControlInfomation.class);
202         xStream.addImplicitCollection(ControlInfomation.class, "control",Control.class);
203 
204         xStream.aliasField("controlqualifier", Control.class, "controlQualifier");
205         xStream.aliasField("totalqtysegments", Control.class, "totalQuantitySegments");
206 
207 
208         xStream.aliasField("unt", Summary.class, "untSummary");
209         xStream.aliasField("messagesegmentsnumber", UNTSummary.class, "segmentNumber");
210         xStream.aliasField("linsegmentstotal", UNTSummary.class, "linSegmentTotal");
211         xStream.addImplicitCollection(EDIOrders.class, "orders");
212         return xStream;
213     }
214 
215 }