View Javadoc
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   import org.kuali.ole.select.bo.OleVendorAccountInfo;
8   import org.kuali.ole.service.OverlayRetrivalService;
9   import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
10  
11  import java.util.*;
12  
13  /**
14   * OleTxRecordBuilder is used to build the transaction information into a pojo which are extracted from the ingested marc and edi file.
15   */
16  public class OleTxRecordBuilder {
17      private static OleTxRecordBuilder oleTxRecordBuilder;
18      private OverlayRetrivalService overlayRetrivalService;
19  
20      /**
21       * default constructor of OleTxRecordBuilder.
22       */
23      private OleTxRecordBuilder() {
24  
25      }
26  
27      /**
28       *  Gets the instance of OleTxRecordBuilder.
29       *  If OleTxRecordBuilder is null it returns new instance else it returns existing instance.
30       * @return
31       */
32      public static OleTxRecordBuilder getInstance() {
33          if (null == oleTxRecordBuilder) {
34              oleTxRecordBuilder = new OleTxRecordBuilder();
35          }
36          return oleTxRecordBuilder;
37      }
38  
39      /**
40       * This method returns OleTxRecord.
41       * This method build the OleTxRecord based on lineItemOrder,list of profileAttribute,ediOrder
42       * @param lineItemOrder
43       * @param profileAttributeBos
44       * @param ediOrder
45       * @return  oleTxRecord
46       */
47      public OleTxRecord build(LineItemOrder lineItemOrder, EDIOrder ediOrder) throws Exception {
48          OleTxRecord oleTxRecord = new OleTxRecord();
49          oleTxRecord.setListPrice(getListPrice(lineItemOrder));
50          oleTxRecord.setQuantity(getQuantity(lineItemOrder));
51          oleTxRecord.setVendorItemIdentifier(getVendorItemIdentifier(lineItemOrder));
52          oleTxRecord.setVendorNumber(getVendorNumber(ediOrder));
53          /*oleTxRecord.setChartCode(getChartCode(profileAttributeBos));
54          oleTxRecord.setOrgCode(getAttributeValue(profileAttributeBos, OLEConstants.ORG_CODE));
55          oleTxRecord.setReceivingRequired(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.RECV_REQUIRED)));
56          oleTxRecord.setContractManager(getAttributeValue(profileAttributeBos, OLEConstants.CONTRACT_MANAGER));*/
57          //oleTxRecord.setAssignToUser(getAttributeValue(profileAttributeBos, OLEConstants.ASSIGN_TO_USER));
58          //oleTxRecord.setUseTaxIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.USE_TAXIND)));
59          //oleTxRecord.setOrderType(getAttributeValue(profileAttributeBos, OLEConstants.ORDER_TYPE));
60          /*oleTxRecord.setFundingSource(getAttributeValue(profileAttributeBos, OLEConstants.FUNDING_SOURCE));
61          oleTxRecord.setPayReqPositiveApprovalReq(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PAYREQ_POSITIVE_APPROVAL)));
62          oleTxRecord.setPurchaseOrderConfirmationIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PURCHASE_CONFIRMATION_INDICATOR)));
63          oleTxRecord.setRequisitionSource(getAttributeValue(profileAttributeBos, OLEConstants.REQUISITION_SOURCE));
64          oleTxRecord.setDeliveryCampusCode(getAttributeValue(profileAttributeBos, OLEConstants.DELIVERY_CAMPUS));
65          oleTxRecord.setBuildingCode(getAttributeValue(profileAttributeBos, OLEConstants.BUILDING));*/
66          //oleTxRecord.setVendorChoice(getAttributeValue(profileAttributeBos, OLEConstants.VENDOR_CHOICE));
67          /*oleTxRecord.setItemType(getAttributeValue(profileAttributeBos, OLEConstants.ITEM_TYPE));
68          oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.ROUTE_RQUESTER)));
69          oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PUBLIC_VIEW)));
70          oleTxRecord.setMethodOfPOTransmission(getAttributeValue(profileAttributeBos, OLEConstants.PO_TRAMISSION_METHOD));
71          oleTxRecord.setInternalPurchasingLimit(getAttributeValue(profileAttributeBos, OLEConstants.INTERNAL_PURCHASING_LIMIT));
72          oleTxRecord.setCostSource(getAttributeValue(profileAttributeBos, OLEConstants.COST_SOURCE));
73          oleTxRecord.setPercent(getAttributeValue(profileAttributeBos, OLEConstants.PERCENT));
74          oleTxRecord.setDefaultLocation(getAttributeValue(profileAttributeBos, OLEConstants.DEFAULT_LOCATION));*/
75          return oleTxRecord;
76      }
77  
78      public OleTxRecord build(List<ProfileAttributeBo> profileAttributeBos) throws Exception {
79          OleTxRecord oleTxRecord = new OleTxRecord();
80  /*        oleTxRecord.setListPrice(getListPrice(lineItemOrder));
81          oleTxRecord.setQuantity(getQuantity(lineItemOrder));
82          oleTxRecord.setVendorItemIdentifier(getVendorItemIdentifier(lineItemOrder));
83          oleTxRecord.setVendorNumber(getVendorNumber(ediOrder));       */
84          /*oleTxRecord.setChartCode(getChartCode(profileAttributeBos));
85          oleTxRecord.setOrgCode(getAttributeValue(profileAttributeBos, OLEConstants.ORG_CODE));
86          oleTxRecord.setReceivingRequired(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.RECV_REQUIRED)));
87          oleTxRecord.setContractManager(getAttributeValue(profileAttributeBos, OLEConstants.CONTRACT_MANAGER));*/
88          //oleTxRecord.setAssignToUser(getAttributeValue(profileAttributeBos, OLEConstants.ASSIGN_TO_USER));
89          //oleTxRecord.setUseTaxIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.USE_TAXIND)));
90          //oleTxRecord.setOrderType(getAttributeValue(profileAttributeBos, OLEConstants.ORDER_TYPE));
91          /*oleTxRecord.setFundingSource(getAttributeValue(profileAttributeBos, OLEConstants.FUNDING_SOURCE));
92          oleTxRecord.setPayReqPositiveApprovalReq(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PAYREQ_POSITIVE_APPROVAL)));
93          oleTxRecord.setPurchaseOrderConfirmationIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PURCHASE_CONFIRMATION_INDICATOR)));
94          oleTxRecord.setRequisitionSource(getAttributeValue(profileAttributeBos, OLEConstants.REQUISITION_SOURCE));
95          oleTxRecord.setDeliveryCampusCode(getAttributeValue(profileAttributeBos, OLEConstants.DELIVERY_CAMPUS));
96          oleTxRecord.setBuildingCode(getAttributeValue(profileAttributeBos, OLEConstants.BUILDING));*/
97          //oleTxRecord.setVendorChoice(getAttributeValue(profileAttributeBos, OLEConstants.VENDOR_CHOICE));
98          /*oleTxRecord.setItemType(getAttributeValue(profileAttributeBos, OLEConstants.ITEM_TYPE));
99          oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.ROUTE_RQUESTER)));
100         oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PUBLIC_VIEW)));
101         oleTxRecord.setMethodOfPOTransmission(getAttributeValue(profileAttributeBos, OLEConstants.PO_TRAMISSION_METHOD));
102         oleTxRecord.setInternalPurchasingLimit(getAttributeValue(profileAttributeBos, OLEConstants.INTERNAL_PURCHASING_LIMIT));
103         oleTxRecord.setCostSource(getAttributeValue(profileAttributeBos, OLEConstants.COST_SOURCE));
104         oleTxRecord.setPercent(getAttributeValue(profileAttributeBos, OLEConstants.PERCENT));
105         oleTxRecord.setDefaultLocation(getAttributeValue(profileAttributeBos, OLEConstants.DEFAULT_LOCATION));*/
106         return oleTxRecord;
107     }
108 
109 
110     /**
111      *  This method returns chartCode from the List of profileAttributeBos.
112      * @param profileAttributeBos
113      * @return   AttributeValue
114      */
115     private String getChartCode(List<ProfileAttributeBo> profileAttributeBos) {
116         return getAttributeValue(profileAttributeBos, OLEConstants.OLE_CHART_CODE);
117     }
118 
119     /**
120      *  This method gets the vendorNumber from ediOrder.
121      * @param ediOrder
122      * @return
123      */
124     private String getVendorNumber(EDIOrder ediOrder) {
125         return ediOrder.getMessage().getSupplierPartyQualifier().getSupplierInformation().getSupplierCodeIdentification();
126     }
127 
128     /**
129      * This method returns fundCode as AccountInfo, based on List of  supplierReferenceInformation got from lineItemOrder.
130      * @param lineItemOrder
131      * @return AccountInfo
132      */
133     public Map<String, String> getAccountInfo(LineItemOrder lineItemOrder) throws Exception {
134         List<SupplierReferenceInformation> supplierReferenceInformationList = lineItemOrder.getSupplierReferenceInformation();
135         if (!supplierReferenceInformationList.isEmpty()) {
136             SupplierReferenceInformation supplierReferenceInformation = supplierReferenceInformationList.get(0);
137             List<SupplierLineItemReference> supplierLineItemReferenceList = supplierReferenceInformation.getSupplierLineItemReference();
138             if (!supplierLineItemReferenceList.isEmpty()) {
139                 SupplierLineItemReference supplierLineItemReference = supplierLineItemReferenceList.get(0);
140                 if (supplierLineItemReference.getSuppliersOrderLine().equals("BFN")) {
141                     return translateRefNumberToOLEAccountInfo(supplierLineItemReference.getVendorReferenceNumber());
142                 }
143             }
144         }
145         return null;
146     }
147 
148 
149 
150     /**
151      * This method returns fundCode as AccountInfo, based on List of  supplierReferenceInformation got from lineItemOrder.
152      * @param vendorReferenceNumber
153      * @return AccountInfo
154      */
155     public Map<String, String> getAccountInfo(String vendorReferenceNumber) throws Exception {
156             return translateRefNumberToOLEAccountInfo(vendorReferenceNumber);
157     }
158 
159     /**
160      *  This method maps the vendorReferenceNumber and returns the  fundCode.
161      * @param vendorReferenceNumber
162      * @return  fundCodes
163      */
164     private Map<String, String> translateRefNumberToOLEAccountInfo(String vendorReferenceNumber)throws Exception{
165         //HashMap<String, String> fundCodes = new OLEAccountInfoExtractor().buildAccountInfoMap(vendorReferenceNumber);
166         HashMap<String, String> fundCodes = getVendorAccountObjectDetails(vendorReferenceNumber);
167         return fundCodes;
168     }
169 
170     private HashMap<String,String> getVendorAccountObjectDetails(String vendorReferenceNumber)throws Exception{
171         HashMap<String,String>  criteriaMap=new HashMap<String,String>();
172         criteriaMap.put("vendorRefNumber",vendorReferenceNumber);
173         OleVendorAccountInfo oleVendorAccountInfo = getOverlayRetrivalService().getAccountObjectForVendorRefNo(criteriaMap);
174         if(oleVendorAccountInfo==null)
175             return null;
176         HashMap<String,String> accountObjectMap=new HashMap<String, String>();
177         accountObjectMap.put(oleVendorAccountInfo.getAccountNumber(), oleVendorAccountInfo.getObjectCode());
178         return accountObjectMap;
179 
180     }
181 
182     /**
183      *  This method returns vendorItemReference number from the List of buyerReferenceInformation got from lineItemOrder.
184      * @param lineItemOrder
185      * @return vendorItemReference
186      */
187     public String getVendorItemIdentifier(LineItemOrder lineItemOrder) {
188         List<BuyerReferenceInformation> buyerReferenceInformationList = lineItemOrder.getBuyerReferenceInformation();
189         if (buyerReferenceInformationList.size() > 0) {
190             BuyerReferenceInformation buyerReferenceInformation = buyerReferenceInformationList.get(0);
191             List<BuyerLineItemReference> buyerLineItemReferenceList = buyerReferenceInformation.getBuyerLineItemReference();
192             if (buyerLineItemReferenceList.size() > 0) {
193                 BuyerLineItemReference buyerLineItemReferenceRef = buyerLineItemReferenceList.get(0);
194                 String buyersOrderLine = buyerLineItemReferenceRef.getBuyersOrderLine();
195                 String vendorItemReference = buyerLineItemReferenceRef.getOrderLineNumber();
196                 if (buyersOrderLine.equals("SLI")) {
197                     return vendorItemReference;
198                 }
199             }
200         }
201         return null;
202     }
203 
204     /**
205      * This method returns the Quantity from the list of QuantityInformation got from lineItemOrder.
206      * If there are no QuantityInformation then it return null.
207      * @param lineItemOrder
208      * @return Quantity
209      */
210     private String getQuantity(LineItemOrder lineItemOrder) {
211         List<QuantityInformation> quantityInformation = lineItemOrder.getQuantityInformation();
212         if (quantityInformation.size() > 0) {
213             List<Qunatity> qunatity = quantityInformation.get(0).getQunatity();
214             if (qunatity.size() > 0) {
215                 return qunatity.get(0).getQuantity();
216             }
217         }
218         return null;
219     }
220 
221     /**
222      *  This method returns ListPrice from the List of PriceInformation got from lineItemOrder.
223      *  If there are no PriceInformation then it return null.
224      * @param lineItemOrder
225      * @return  Price
226      */
227     private String getListPrice(LineItemOrder lineItemOrder) {
228         List<PriceInformation> priceInformation = lineItemOrder.getPriceInformation();
229         if (priceInformation.size() > 0) {
230             List<ItemPrice> itemPrice = priceInformation.get(0).getItemPrice();
231             if (itemPrice.size() > 0) {
232                 return itemPrice.get(0).getPrice();
233             }
234         }
235         return null;
236     }
237 
238     /**
239      * This method returns AttributeValue from List of profileAttribute with matching attributeName.
240      * If there are no profile attributes then it return null.
241      * @param profileAttributes
242      * @param attributeName
243      * @return  attributeValue
244      */
245     private String getAttributeValue(List<ProfileAttributeBo> profileAttributes, String attributeName) {
246         for (Iterator<ProfileAttributeBo> iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
247             ProfileAttributeBo attribute = iterator.next();
248             if (attribute.getAttributeName().equals(attributeName)) {
249                 return attribute.getAttributeValue();
250             }
251         }
252         return null;
253     }
254 
255     public OverlayRetrivalService getOverlayRetrivalService() {
256         if(overlayRetrivalService == null){
257             overlayRetrivalService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_RETRIVAL_SERVICE);
258         }
259         return overlayRetrivalService;
260     }
261 
262     public void setOverlayRetrivalService(OverlayRetrivalService overlayRetrivalService) {
263         this.overlayRetrivalService = overlayRetrivalService;
264     }
265 
266 }