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   
8   import java.util.HashMap;
9   import java.util.Iterator;
10  import java.util.List;
11  import java.util.Map;
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  
19      /**
20       * default constructor of OleTxRecordBuilder.
21       */
22      private OleTxRecordBuilder() {
23  
24      }
25  
26      /**
27       *  Gets the instance of OleTxRecordBuilder.
28       *  If OleTxRecordBuilder is null it returns new instance else it returns existing instance.
29       * @return
30       */
31      public static OleTxRecordBuilder getInstance() {
32          if (null == oleTxRecordBuilder) {
33              oleTxRecordBuilder = new OleTxRecordBuilder();
34          }
35          return oleTxRecordBuilder;
36      }
37  
38      /**
39       * This method returns OleTxRecord.
40       * This method build the OleTxRecord based on lineItemOrder,list of profileAttribute,ediOrder
41       * @param lineItemOrder
42       * @param profileAttributeBos
43       * @param ediOrder
44       * @return  oleTxRecord
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       *  This method returns chartCode from the List of profileAttributeBos.
83       * @param profileAttributeBos
84       * @return   AttributeValue
85       */
86      private String getChartCode(List<ProfileAttributeBo> profileAttributeBos) {
87          return getAttributeValue(profileAttributeBos, OLEConstants.OLE_CHART_CODE);
88      }
89  
90      /**
91       *  This method gets the vendorNumber from ediOrder.
92       * @param ediOrder
93       * @return
94       */
95      private String getVendorNumber(EDIOrder ediOrder) {
96          return ediOrder.getMessage().getSupplierPartyQualifier().getSupplierInformation().getSupplierCodeIdentification();
97      }
98  
99      /**
100      * This method returns fundCode as AccountInfo, based on List of  supplierReferenceInformation got from lineItemOrder.
101      * @param lineItemOrder
102      * @return AccountInfo
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      *  This method maps the vendorReferenceNumber and returns the  fundCode.
121      * @param vendorReferenceNumber
122      * @return  fundCodes
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      *  This method returns vendorItemReference number from the List of buyerReferenceInformation got from lineItemOrder.
131      * @param lineItemOrder
132      * @return vendorItemReference
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      * This method returns the Quantity from the list of QuantityInformation got from lineItemOrder.
153      * If there are no QuantityInformation then it return null.
154      * @param lineItemOrder
155      * @return Quantity
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      *  This method returns ListPrice from the List of PriceInformation got from lineItemOrder.
170      *  If there are no PriceInformation then it return null.
171      * @param lineItemOrder
172      * @return  Price
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      * This method returns AttributeValue from List of profileAttribute with matching attributeName.
187      * If there are no profile attributes then it return null.
188      * @param profileAttributes
189      * @param attributeName
190      * @return  attributeValue
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 }