1 package org.kuali.ole.ingest;
2
3 import org.kuali.ole.OLEConstants;
4 import org.kuali.ole.ingest.pojo.ProfileAttributeBo;
5 import org.kuali.ole.pojo.OleTxRecord;
6 import org.kuali.ole.pojo.edi.*;
7
8 import java.util.HashMap;
9 import java.util.Iterator;
10 import java.util.List;
11 import java.util.Map;
12
13
14
15
16 public class OleTxRecordBuilder {
17 private static OleTxRecordBuilder oleTxRecordBuilder;
18
19
20
21
22 private OleTxRecordBuilder() {
23
24 }
25
26
27
28
29
30
31 public static OleTxRecordBuilder getInstance() {
32 if (null == oleTxRecordBuilder) {
33 oleTxRecordBuilder = new OleTxRecordBuilder();
34 }
35 return oleTxRecordBuilder;
36 }
37
38
39
40
41
42
43
44
45
46 public OleTxRecord build(LineItemOrder lineItemOrder, List<ProfileAttributeBo> profileAttributeBos, EDIOrder ediOrder) {
47 OleTxRecord oleTxRecord = new OleTxRecord();
48 oleTxRecord.setListPrice(getListPrice(lineItemOrder));
49 oleTxRecord.setQuantity(getQuantity(lineItemOrder));
50 oleTxRecord.setVendorItemIdentifier(getVendorItemIdentifier(lineItemOrder));
51 Map<String, String> accountInfo = getAccountInfo(lineItemOrder);
52 String accountNumber = accountInfo!=null?accountInfo.keySet().iterator().next():null;
53 oleTxRecord.setAccountNumber(accountNumber);
54 oleTxRecord.setObjectCode(accountInfo!=null?accountInfo.get(accountNumber):null);
55 oleTxRecord.setVendorNumber(getVendorNumber(ediOrder));
56 oleTxRecord.setChartCode(getChartCode(profileAttributeBos));
57 oleTxRecord.setItemChartCode(getAttributeValue(profileAttributeBos,OLEConstants.OLE_ITEM_CHART_CODE));
58 oleTxRecord.setOrgCode(getAttributeValue(profileAttributeBos, OLEConstants.ORG_CODE));
59 oleTxRecord.setReceivingRequired(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.RECV_REQUIRED)));
60 oleTxRecord.setContractManager(getAttributeValue(profileAttributeBos, OLEConstants.CONTRACT_MANAGER));
61 oleTxRecord.setAssignToUser(getAttributeValue(profileAttributeBos, OLEConstants.ASSIGN_TO_USER));
62 oleTxRecord.setUseTaxIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.USE_TAXIND)));
63 oleTxRecord.setOrderType(getAttributeValue(profileAttributeBos, OLEConstants.ORDER_TYPE));
64 oleTxRecord.setFundingSource(getAttributeValue(profileAttributeBos, OLEConstants.FUNDING_SOURCE));
65 oleTxRecord.setPayReqPositiveApprovalReq(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PAYREQ_POSITIVE_APPROVAL)));
66 oleTxRecord.setPurchaseOrderConfirmationIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PURCHASE_CONFIRMATION_INDICATOR)));
67 oleTxRecord.setRequisitionSource(getAttributeValue(profileAttributeBos, OLEConstants.REQUISITION_SOURCE));
68 oleTxRecord.setDeliveryCampusCode(getAttributeValue(profileAttributeBos, OLEConstants.DELIVERY_CAMPUS));
69 oleTxRecord.setBuildingCode(getAttributeValue(profileAttributeBos, OLEConstants.BUILDING));
70 oleTxRecord.setVendorChoice(getAttributeValue(profileAttributeBos, OLEConstants.VENDOR_CHOICE));
71 oleTxRecord.setItemType(getAttributeValue(profileAttributeBos, OLEConstants.ITEM_TYPE));
72 oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.ROUTE_RQUESTER)));
73 oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PUBLIC_VIEW)));
74 oleTxRecord.setMethodOfPOTransmission(getAttributeValue(profileAttributeBos, OLEConstants.PO_TRAMISSION_METHOD));
75 oleTxRecord.setInternalPurchasingLimit(getAttributeValue(profileAttributeBos, OLEConstants.INTERNAL_PURCHASING_LIMIT));
76 oleTxRecord.setCostSource(getAttributeValue(profileAttributeBos, OLEConstants.COST_SOURCE));
77 oleTxRecord.setPercent(getAttributeValue(profileAttributeBos, OLEConstants.PERCENT));
78 return oleTxRecord;
79 }
80
81
82
83
84
85
86 private String getChartCode(List<ProfileAttributeBo> profileAttributeBos) {
87 return getAttributeValue(profileAttributeBos, OLEConstants.OLE_CHART_CODE);
88 }
89
90
91
92
93
94
95 private String getVendorNumber(EDIOrder ediOrder) {
96 return ediOrder.getMessage().getSupplierPartyQualifier().getSupplierInformation().getSupplierCodeIdentification();
97 }
98
99
100
101
102
103
104 private Map<String, String> getAccountInfo(LineItemOrder lineItemOrder) {
105 List<SupplierReferenceInformation> supplierReferenceInformationList = lineItemOrder.getSupplierReferenceInformation();
106 if (!supplierReferenceInformationList.isEmpty()) {
107 SupplierReferenceInformation supplierReferenceInformation = supplierReferenceInformationList.get(0);
108 List<SupplierLineItemReference> supplierLineItemReferenceList = supplierReferenceInformation.getSupplierLineItemReference();
109 if (!supplierLineItemReferenceList.isEmpty()) {
110 SupplierLineItemReference supplierLineItemReference = supplierLineItemReferenceList.get(0);
111 if (supplierLineItemReference.getSuppliersOrderLine().equals("BFN")) {
112 return translateRefNumberToOLEAccountInfo(supplierLineItemReference.getVendorReferenceNumber());
113 }
114 }
115 }
116 return null;
117 }
118
119
120
121
122
123
124 private Map<String, String> translateRefNumberToOLEAccountInfo(String vendorReferenceNumber) {
125 HashMap<String, String> fundCodes = new OLEAccountInfoExtractor().buildAccountInfoMap(vendorReferenceNumber);
126 return fundCodes;
127 }
128
129
130
131
132
133
134 private String getVendorItemIdentifier(LineItemOrder lineItemOrder) {
135 List<BuyerReferenceInformation> buyerReferenceInformationList = lineItemOrder.getBuyerReferenceInformation();
136 if (buyerReferenceInformationList.size() > 0) {
137 BuyerReferenceInformation buyerReferenceInformation = buyerReferenceInformationList.get(0);
138 List<BuyerLineItemReference> buyerLineItemReferenceList = buyerReferenceInformation.getBuyerLineItemReference();
139 if (buyerLineItemReferenceList.size() > 0) {
140 BuyerLineItemReference buyerLineItemReferenceRef = buyerLineItemReferenceList.get(0);
141 String buyersOrderLine = buyerLineItemReferenceRef.getBuyersOrderLine();
142 String vendorItemReference = buyerLineItemReferenceRef.getOrderLineNumber();
143 if (buyersOrderLine.equals("SLI")) {
144 return vendorItemReference;
145 }
146 }
147 }
148 return null;
149 }
150
151
152
153
154
155
156
157 private String getQuantity(LineItemOrder lineItemOrder) {
158 List<QuantityInformation> quantityInformation = lineItemOrder.getQuantityInformation();
159 if (quantityInformation.size() > 0) {
160 List<Qunatity> qunatity = quantityInformation.get(0).getQunatity();
161 if (qunatity.size() > 0) {
162 return qunatity.get(0).getQuantity();
163 }
164 }
165 return null;
166 }
167
168
169
170
171
172
173
174 private String getListPrice(LineItemOrder lineItemOrder) {
175 List<PriceInformation> priceInformation = lineItemOrder.getPriceInformation();
176 if (priceInformation.size() > 0) {
177 List<ItemPrice> itemPrice = priceInformation.get(0).getItemPrice();
178 if (itemPrice.size() > 0) {
179 return itemPrice.get(0).getPrice();
180 }
181 }
182 return null;
183 }
184
185
186
187
188
189
190
191
192 private String getAttributeValue(List<ProfileAttributeBo> profileAttributes, String attributeName) {
193 for (Iterator<ProfileAttributeBo> iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
194 ProfileAttributeBo attribute = iterator.next();
195 if (attribute.getAttributeName().equals(attributeName)) {
196 return attribute.getAttributeValue();
197 }
198 }
199 return null;
200 }
201
202 }