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.HashMap;
12  import java.util.Iterator;
13  import java.util.List;
14  import java.util.Map;
15  
16  /**
17   * OleTxRecordBuilder is used to build the transaction information into a pojo which are extracted from the ingested marc and edi file.
18   */
19  public class OleTxRecordBuilder {
20      private static OleTxRecordBuilder oleTxRecordBuilder;
21      private OverlayRetrivalService overlayRetrivalService;
22  
23      /**
24       * default constructor of OleTxRecordBuilder.
25       */
26      private OleTxRecordBuilder() {
27  
28      }
29  
30      /**
31       *  Gets the instance of OleTxRecordBuilder.
32       *  If OleTxRecordBuilder is null it returns new instance else it returns existing instance.
33       * @return
34       */
35      public static OleTxRecordBuilder getInstance() {
36          if (null == oleTxRecordBuilder) {
37              oleTxRecordBuilder = new OleTxRecordBuilder();
38          }
39          return oleTxRecordBuilder;
40      }
41  
42      /**
43       * This method returns OleTxRecord.
44       * This method build the OleTxRecord based on lineItemOrder,list of profileAttribute,ediOrder
45       * @param lineItemOrder
46       * @param profileAttributeBos
47       * @param ediOrder
48       * @return  oleTxRecord
49       */
50      public OleTxRecord build(LineItemOrder lineItemOrder, List<ProfileAttributeBo> profileAttributeBos, EDIOrder ediOrder) throws Exception {
51          OleTxRecord oleTxRecord = new OleTxRecord();
52          oleTxRecord.setListPrice(getListPrice(lineItemOrder));
53          oleTxRecord.setQuantity(getQuantity(lineItemOrder));
54          oleTxRecord.setVendorItemIdentifier(getVendorItemIdentifier(lineItemOrder));
55          oleTxRecord.setVendorNumber(getVendorNumber(ediOrder));
56          oleTxRecord.setChartCode(getChartCode(profileAttributeBos));
57          oleTxRecord.setOrgCode(getAttributeValue(profileAttributeBos, OLEConstants.ORG_CODE));
58          oleTxRecord.setReceivingRequired(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.RECV_REQUIRED)));
59          oleTxRecord.setContractManager(getAttributeValue(profileAttributeBos, OLEConstants.CONTRACT_MANAGER));
60          oleTxRecord.setAssignToUser(getAttributeValue(profileAttributeBos, OLEConstants.ASSIGN_TO_USER));
61          oleTxRecord.setUseTaxIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.USE_TAXIND)));
62          oleTxRecord.setOrderType(getAttributeValue(profileAttributeBos, OLEConstants.ORDER_TYPE));
63          oleTxRecord.setFundingSource(getAttributeValue(profileAttributeBos, OLEConstants.FUNDING_SOURCE));
64          oleTxRecord.setPayReqPositiveApprovalReq(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PAYREQ_POSITIVE_APPROVAL)));
65          oleTxRecord.setPurchaseOrderConfirmationIndicator(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PURCHASE_CONFIRMATION_INDICATOR)));
66          oleTxRecord.setRequisitionSource(getAttributeValue(profileAttributeBos, OLEConstants.REQUISITION_SOURCE));
67          oleTxRecord.setDeliveryCampusCode(getAttributeValue(profileAttributeBos, OLEConstants.DELIVERY_CAMPUS));
68          oleTxRecord.setBuildingCode(getAttributeValue(profileAttributeBos, OLEConstants.BUILDING));
69          oleTxRecord.setVendorChoice(getAttributeValue(profileAttributeBos, OLEConstants.VENDOR_CHOICE));
70          oleTxRecord.setItemType(getAttributeValue(profileAttributeBos, OLEConstants.ITEM_TYPE));
71          oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.ROUTE_RQUESTER)));
72          oleTxRecord.setRouteToRequestor(Boolean.parseBoolean(getAttributeValue(profileAttributeBos, OLEConstants.PUBLIC_VIEW)));
73          oleTxRecord.setMethodOfPOTransmission(getAttributeValue(profileAttributeBos, OLEConstants.PO_TRAMISSION_METHOD));
74          oleTxRecord.setInternalPurchasingLimit(getAttributeValue(profileAttributeBos, OLEConstants.INTERNAL_PURCHASING_LIMIT));
75          oleTxRecord.setCostSource(getAttributeValue(profileAttributeBos, OLEConstants.COST_SOURCE));
76          oleTxRecord.setPercent(getAttributeValue(profileAttributeBos, OLEConstants.PERCENT));
77          oleTxRecord.setDefaultLocation(getAttributeValue(profileAttributeBos, OLEConstants.DEFAULT_LOCATION));
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     public Map<String, String> getAccountInfo(LineItemOrder lineItemOrder) throws Exception {
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)throws Exception{
125         //HashMap<String, String> fundCodes = new OLEAccountInfoExtractor().buildAccountInfoMap(vendorReferenceNumber);
126         HashMap<String, String> fundCodes = getVendorAccountObjectDetails(vendorReferenceNumber);
127         return fundCodes;
128     }
129 
130     private HashMap<String,String> getVendorAccountObjectDetails(String vendorReferenceNumber)throws Exception{
131         HashMap<String,String>  criteriaMap=new HashMap<String,String>();
132         criteriaMap.put("vendorRefNumber",vendorReferenceNumber);
133         OleVendorAccountInfo oleVendorAccountInfo = getOverlayRetrivalService().getAccountObjectForVendorRefNo(criteriaMap);
134         if(oleVendorAccountInfo==null)
135             return null;
136         HashMap<String,String> accountObjectMap=new HashMap<String, String>();
137         accountObjectMap.put(oleVendorAccountInfo.getAccountNumber(), oleVendorAccountInfo.getObjectCode());
138         return accountObjectMap;
139 
140     }
141 
142     /**
143      *  This method returns vendorItemReference number from the List of buyerReferenceInformation got from lineItemOrder.
144      * @param lineItemOrder
145      * @return vendorItemReference
146      */
147     public String getVendorItemIdentifier(LineItemOrder lineItemOrder) {
148         List<BuyerReferenceInformation> buyerReferenceInformationList = lineItemOrder.getBuyerReferenceInformation();
149         if (buyerReferenceInformationList.size() > 0) {
150             BuyerReferenceInformation buyerReferenceInformation = buyerReferenceInformationList.get(0);
151             List<BuyerLineItemReference> buyerLineItemReferenceList = buyerReferenceInformation.getBuyerLineItemReference();
152             if (buyerLineItemReferenceList.size() > 0) {
153                 BuyerLineItemReference buyerLineItemReferenceRef = buyerLineItemReferenceList.get(0);
154                 String buyersOrderLine = buyerLineItemReferenceRef.getBuyersOrderLine();
155                 String vendorItemReference = buyerLineItemReferenceRef.getOrderLineNumber();
156                 if (buyersOrderLine.equals("SLI")) {
157                     return vendorItemReference;
158                 }
159             }
160         }
161         return null;
162     }
163 
164     /**
165      * This method returns the Quantity from the list of QuantityInformation got from lineItemOrder.
166      * If there are no QuantityInformation then it return null.
167      * @param lineItemOrder
168      * @return Quantity
169      */
170     private String getQuantity(LineItemOrder lineItemOrder) {
171         List<QuantityInformation> quantityInformation = lineItemOrder.getQuantityInformation();
172         if (quantityInformation.size() > 0) {
173             List<Qunatity> qunatity = quantityInformation.get(0).getQunatity();
174             if (qunatity.size() > 0) {
175                 return qunatity.get(0).getQuantity();
176             }
177         }
178         return null;
179     }
180 
181     /**
182      *  This method returns ListPrice from the List of PriceInformation got from lineItemOrder.
183      *  If there are no PriceInformation then it return null.
184      * @param lineItemOrder
185      * @return  Price
186      */
187     private String getListPrice(LineItemOrder lineItemOrder) {
188         List<PriceInformation> priceInformation = lineItemOrder.getPriceInformation();
189         if (priceInformation.size() > 0) {
190             List<ItemPrice> itemPrice = priceInformation.get(0).getItemPrice();
191             if (itemPrice.size() > 0) {
192                 return itemPrice.get(0).getPrice();
193             }
194         }
195         return null;
196     }
197 
198     /**
199      * This method returns AttributeValue from List of profileAttribute with matching attributeName.
200      * If there are no profile attributes then it return null.
201      * @param profileAttributes
202      * @param attributeName
203      * @return  attributeValue
204      */
205     private String getAttributeValue(List<ProfileAttributeBo> profileAttributes, String attributeName) {
206         for (Iterator<ProfileAttributeBo> iterator = profileAttributes.iterator(); iterator.hasNext(); ) {
207             ProfileAttributeBo attribute = iterator.next();
208             if (attribute.getAttributeName().equals(attributeName)) {
209                 return attribute.getAttributeValue();
210             }
211         }
212         return null;
213     }
214 
215     public OverlayRetrivalService getOverlayRetrivalService() {
216         if(overlayRetrivalService == null){
217             overlayRetrivalService = GlobalResourceLoader.getService(OLEConstants.OVERLAY_RETRIVAL_SERVICE);
218         }
219         return overlayRetrivalService;
220     }
221 
222     public void setOverlayRetrivalService(OverlayRetrivalService overlayRetrivalService) {
223         this.overlayRetrivalService = overlayRetrivalService;
224     }
225 
226 }