View Javadoc
1   package org.kuali.ole.select.document.service.impl;
2   
3   import org.apache.commons.lang.StringUtils;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.coa.businessobject.Account;
6   import org.kuali.ole.coa.businessobject.Chart;
7   import org.kuali.ole.coa.businessobject.ObjectCode;
8   import org.kuali.ole.coa.service.AccountService;
9   import org.kuali.ole.describe.bo.OleLocation;
10  import org.kuali.ole.docstore.engine.service.storage.DocstoreRDBMSStorageService;
11  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
12  import org.kuali.ole.module.purap.document.PurchaseOrderDocument;
13  import org.kuali.ole.select.businessobject.*;
14  import org.kuali.ole.select.document.OlePurchaseOrderDocument;
15  import org.kuali.ole.select.document.service.OlePurchaseOrderService;
16  import org.kuali.ole.sys.context.SpringContext;
17  import org.kuali.ole.vnd.businessobject.VendorAddress;
18  import org.kuali.ole.vnd.businessobject.VendorDetail;
19  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20  import org.kuali.rice.core.api.util.type.KualiDecimal;
21  import org.kuali.rice.core.api.util.type.KualiInteger;
22  import org.kuali.rice.kew.api.KewApiConstants;
23  import org.kuali.rice.kew.api.exception.WorkflowException;
24  import org.kuali.rice.krad.UserSession;
25  import org.kuali.rice.krad.bo.AdHocRoutePerson;
26  import org.kuali.rice.krad.exception.ValidationException;
27  import org.kuali.rice.krad.service.BusinessObjectService;
28  import org.kuali.rice.krad.util.GlobalVariables;
29  import org.springframework.transaction.PlatformTransactionManager;
30  import org.springframework.transaction.TransactionStatus;
31  import org.springframework.transaction.UnexpectedRollbackException;
32  import org.springframework.transaction.support.TransactionCallback;
33  import org.springframework.transaction.support.TransactionTemplate;
34  
35  import javax.servlet.ServletException;
36  import java.io.IOException;
37  import java.math.BigDecimal;
38  import java.text.SimpleDateFormat;
39  import java.util.*;
40  import java.util.concurrent.Callable;
41  
42  /**
43   * Created by pvsubrah on 6/10/15.
44   */
45  public class BulkPOChangeExecutor implements Callable {
46      List<Chart> charts = new ArrayList<>();
47      List<Account> accounts = new ArrayList<>();
48      List<ObjectCode> objects = new ArrayList<>();
49      List<VendorDetail> vendorDetails = new ArrayList<VendorDetail>();
50      List<OleCategory> categories = new ArrayList<OleCategory>();
51      List<OleFormatType> formatTypes = new ArrayList<OleFormatType>();
52      List<OleItemPriceSource> itemPriceSources = new ArrayList<OleItemPriceSource>();
53      List<OleRequestSourceType> requestSourceTypes = new ArrayList<OleRequestSourceType>();
54      List<OleLocation> locations = new ArrayList<OleLocation>();
55      List<String> chartList = new ArrayList<>();
56      List<String> accountList = new ArrayList<>();
57      List<String> objectCodeList = new ArrayList<>();
58      List<String> vendorDetailList = new ArrayList<>();
59      List<String> categoryList = new ArrayList<>();
60      List<String> formatList = new ArrayList<>();
61      List<String> requestSourceList = new ArrayList<>();
62      List<String> priceSourceList = new ArrayList<>();
63      List<String> locationList = new ArrayList<>();
64  
65      private final List<Map> poListToProcess;
66      private final String pobaDocNumber;
67      private OlePurchaseOrderService olePurchaseOrderService;
68      private StringBuilder message = new StringBuilder();
69      private BusinessObjectService businessObjectService;
70      private UserSession userSession;
71      boolean validationResult = true;
72      private PlatformTransactionManager transactionManager;
73  
74      public BulkPOChangeExecutor(String pobaDocNumber, List<Map> poListToProcess) {
75          this.pobaDocNumber = pobaDocNumber;
76          this.poListToProcess = poListToProcess;
77      }
78  
79      @Override
80      public Object call() throws Exception {
81          long startTime = System.currentTimeMillis();
82          Map<String, String> resultMap = new HashMap<>();
83          GlobalVariables.setUserSession(new UserSession(userSession.getPrincipalName()));
84          OlePurchaseOrderDocument olePurchaseOrderDocument = null;
85          String result = null;
86          String poId = null;
87          for (Iterator<Map> iterator = poListToProcess.iterator(); iterator.hasNext(); ) {
88              Map<String, String> map = iterator.next();
89              poId = map.get("purapDocumentIdentifier");
90              if (olePurchaseOrderDocument == null) {
91                  olePurchaseOrderDocument = getPODocumentByPOId(poId);
92              }
93              validationResult &= validatePOFields(map);
94              if (validationResult) {
95                  updatePurchaseOrderDocument(olePurchaseOrderDocument, map);
96              } else {
97                  message.append("POA Creation Failed for PO Num: + ").append(poId);
98              }
99  
100         }
101         if (validationResult) {
102             result = getOlePurchaseOrderService().createPurchaseOrderAmendmentDocument
103                     (olePurchaseOrderDocument,
104                             pobaDocNumber);
105             if (StringUtils.isNotBlank(result)) {
106                 message.append(result);
107             } else {
108                 message.append("Successfully created POA document for PO# : ").append(olePurchaseOrderDocument.getPurapDocumentIdentifier()).append(" ");
109             }
110 
111         }
112         resultMap.put(poId, message.toString());
113         long endTime = System.currentTimeMillis();
114         System.out.println("Time taken to create POA for PO doc: " + poId + "is " + (endTime-startTime) + " " +
115                 "milliseconds");
116         return resultMap;
117     }
118 
119 
120     private OlePurchaseOrderDocument getPODocumentByPOId(String poId) {
121         Map criteriaMap = new HashMap();
122         criteriaMap.put("purapDocumentIdentifier", poId);
123         criteriaMap.put("purchaseOrderCurrentIndicator", true);
124         OlePurchaseOrderDocument olePurchaseOrderDocument = getBusinessObjectService().findByPrimaryKey(OlePurchaseOrderDocument.class, criteriaMap);
125         return olePurchaseOrderDocument;
126     }
127 
128     public boolean validatePOFields(Map map) {
129         boolean result = true;
130         if (!vendorDetailList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER))) {
131             message.append("Invalid Vendor Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER));
132             message.append("\n");
133             result = result & false;
134         }
135         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).equals("null") && !categoryList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD))) {
136             message.append("Invalid Category Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD));
137             message.append("\n");
138             result = result & false;
139         }
140         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).equals("null") && !formatList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD))) {
141             message.append("Invalid Format Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD));
142             message.append("\n");
143             result = result & false;
144         }
145         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).equals("null") && !priceSourceList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE))) {
146             message.append("Invalid Item Price Source Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE));
147             message.append("\n");
148             result = result & false;
149         }
150         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).equals("null") && !requestSourceList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE))) {
151             message.append("Invalid Request Source Type : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE));
152             message.append("\n");
153             result = result & false;
154         }
155         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC).equals("null") && !locationList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC))) {
156             message.append("Invalid Location code : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC));
157             message.append("\n");
158             result = result & false;
159         }
160         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD) != null && !chartList.contains(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD))) {
161             message.append("Invalid Chart code : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD));
162             message.append("\n");
163             result = result & false;
164         }
165         String accountNumber = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).toString() + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString();
166         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO) != null && !accountList.contains(accountNumber)) {
167             message.append("Invalid Account Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO));
168             message.append("\n");
169             result = result & false;
170         }
171         String objectCode = map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).toString() + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString();
172         if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD) != null && !objectCodeList.contains(objectCode)) {
173             message.append("Invalid Financial Object Number : " + map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD));
174             message.append("\n");
175             result = result & false;
176         }
177         return result;
178     }
179 
180     public void updatePurchaseOrderDocument(OlePurchaseOrderDocument olePurchaseOrderDocument, Map map) {
181         try {
182             updateDocument(olePurchaseOrderDocument, map);
183             updateVendor(olePurchaseOrderDocument, map);
184             int lineNumber = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIN_NO).toString());
185             updateItem(olePurchaseOrderDocument, lineNumber, map);
186             updateAccount(olePurchaseOrderDocument, lineNumber, map);
187         } catch (UnexpectedRollbackException re) {
188             message.append(re.getMessage());
189             message.append("\n");
190         } catch (ValidationException ve) {
191             message.append(ve.getMessage());
192             message.append("\n");
193         } catch (Exception ex) {
194             message.append("Failed to create POA document for PO document number : " + olePurchaseOrderDocument.getDocumentNumber());
195             message.append("\n");
196 
197         }
198         //sendFyiForAccount(olePurchaseOrderDocument);
199     }
200 
201 
202     public void sendFyiForAccount(PurchaseOrderDocument po) {
203 
204         List<AdHocRoutePerson> fyiList = createFyiFiscalOfficerListForAmendGlEntries(po);
205         String annotation = "Amendment to Purchase Order " + po.getPurapDocumentIdentifier() + "( Document id " + po.getDocumentNumber() + ")" +
206                 " in the batch process(POBA).";
207         String responsibilityNote = " ";
208         if (fyiList != null && fyiList.size() > 0) {
209             for (AdHocRoutePerson adHocPerson : fyiList) {
210                 try {
211                     po.appSpecificRouteDocumentToUser(
212                             po.getDocumentHeader().getWorkflowDocument(),
213                             adHocPerson.getPerson().getPrincipalId(),
214                             annotation,
215                             responsibilityNote);
216                 } catch (WorkflowException e) {
217                     throw new RuntimeException("Error routing fyi for document with id " + po.getDocumentNumber(), e);
218                 }
219             }
220         }
221     }
222 
223     protected List<AdHocRoutePerson> createFyiFiscalOfficerListForAmendGlEntries(PurchaseOrderDocument po) {
224 
225         List<AdHocRoutePerson> adHocRoutePersons = new ArrayList<AdHocRoutePerson>();
226         Map fiscalOfficers = new HashMap();
227         AdHocRoutePerson adHocRoutePerson = null;
228         for (PurApAccountingLine account : (List<PurApAccountingLine>) po.getSourceAccountingLines()) {
229             Account acct = SpringContext.getBean(AccountService.class).getByPrimaryId(account.getChartOfAccountsCode(),
230                     account.getAccountNumber());
231             if (acct != null) {
232                 String principalName = acct.getAccountFiscalOfficerUser().getPrincipalName();
233                 // String principalName = account.getAccount().getAccountFiscalOfficerUser().getPrincipalName();
234                 if (fiscalOfficers.containsKey(principalName) == false) {
235                     fiscalOfficers.put(principalName, principalName);
236                     adHocRoutePerson = new AdHocRoutePerson();
237                     adHocRoutePerson.setId(principalName);
238                     adHocRoutePerson.setActionRequested(KewApiConstants.ACTION_REQUEST_FYI_REQ);
239                     adHocRoutePersons.add(adHocRoutePerson);
240                 }
241             }
242         }
243         return adHocRoutePersons;
244     }
245 
246 
247     public OlePurchaseOrderDocument updateItem(OlePurchaseOrderDocument purchaseOrderDocument, int itemLineNumber, Map map) throws Exception {
248         for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderDocument.getItemsActiveOnly()) {
249             if (olePurchaseOrderItem.getItemLineNumber() != null && olePurchaseOrderItem.getItemLineNumber() == itemLineNumber) {
250                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_ITEM_NO).equals("null")) {
251                     olePurchaseOrderItem.setVendorItemPoNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_ITEM_NO).toString());
252                 } else {
253                     olePurchaseOrderItem.setVendorItemPoNumber("");
254                 }
255                 if (map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC) != null) {
256                     olePurchaseOrderItem.setItemLocation(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LOC).toString());
257                 }
258                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIST_PRC).equals("null")) {
259                     olePurchaseOrderItem.setItemListPrice(new KualiDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_LIST_PRC).toString()));
260                 }
261                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_QTY).equals("null")) {
262                     olePurchaseOrderItem.setItemQuantity(new KualiDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_QTY).toString()));
263                 }
264                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).equals("null")) {
265                     olePurchaseOrderItem.setItemNoOfParts(new KualiInteger(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).toString()));
266                 }
267                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_PUB_VIEW_IND).equals("null")) {
268                     boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_PUB_VIEW_IND).toString());
269                     olePurchaseOrderItem.setItemPublicViewIndicator(indicator);
270                 }
271                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DO_NOT_CLAIM).equals("null")) {
272                     boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DO_NOT_CLAIM).toString());
273                     olePurchaseOrderItem.setDoNotClaim(indicator);
274                 }
275                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_ROUTE_IND).equals("null")) {
276                     boolean indicator = Boolean.parseBoolean(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITEM_ROUTE_IND).toString());
277                     olePurchaseOrderItem.setItemRouteToRequestorIndicator(indicator);
278                 }
279                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).equals("null")) {
280                     olePurchaseOrderItem.setItemNoOfParts(new KualiInteger(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_NO_OF_PARTS).toString()));
281                 }
282                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_COPY_NO).equals("null")) {
283                     olePurchaseOrderItem.setCopyNumber((map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_COPY_NO).toString()));
284                 }
285                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).equals("null")) {
286                     if (getFormatId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).toString()) != null) {
287                         olePurchaseOrderItem.setFormatTypeId(getFormatId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.FORMAT_CD).toString()));
288                     }
289                 }
290                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).equals("null")) {
291                     if (getCategoryId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).toString()) != null) {
292                         olePurchaseOrderItem.setCategoryId(getCategoryId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CATEORY_CD).toString()));
293                     }
294                 }
295                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).equals("null")) {
296                     if (getItemPriceSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).toString()) != null) {
297                         olePurchaseOrderItem.setItemPriceSourceId(getItemPriceSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ITM_PRICE_SOURCE).toString()));
298                     }
299                 }
300                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).equals("null")) {
301                     if (getRequestSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).toString()) != null) {
302                         olePurchaseOrderItem.setRequestSourceTypeId(getRequestSourceId(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.REQUEST_SOURCE).toString()));
303                     }
304                 }
305             }
306         }
307         return purchaseOrderDocument;
308 
309     }
310 
311     public OlePurchaseOrderDocument updateAccount(OlePurchaseOrderDocument purchaseOrderDocument, int itemLineNumber, Map map) {
312         for (OlePurchaseOrderItem olePurchaseOrderItem : purchaseOrderDocument.getItemsActiveOnly()) {
313             if (olePurchaseOrderItem.getItemLineNumber() != null && olePurchaseOrderItem.getItemLineNumber() == itemLineNumber) {
314                 //for (PurApAccountingLine accountingLine : olePurchaseOrderItem.getSourceAccountingLines()) {
315                 if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LINE_INDEX).equals("null")) {
316                     int index = Integer.parseInt(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LINE_INDEX).toString()) - 1;
317                     PurApAccountingLine accountingLine = olePurchaseOrderItem.getSourceAccountingLines().get(index);
318                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).equals("null")) {
319                         accountingLine.setChartOfAccountsCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.CHART_CD).toString());
320                     }
321                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).equals("null")) {
322                         accountingLine.setAccountNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_NO).toString());
323                     }
324                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).equals("null")) {
325                         accountingLine.setFinancialObjectCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.OBJ_CD).toString());
326                     }
327                     if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LIN_PERC).equals("null")) {
328                         accountingLine.setAccountLinePercent(new BigDecimal(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ACC_LIN_PERC).toString()));
329                     }
330 
331                 }
332             }
333         }
334         return purchaseOrderDocument;
335     }
336 
337     public OlePurchaseOrderDocument updateDocument(OlePurchaseOrderDocument purchaseOrderDocument, Map map) {
338 
339         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ST_CD).equals("null")) {
340             purchaseOrderDocument.setDeliveryStateCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ST_CD).toString());
341         }
342         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ROOM_NO).equals("null")) {
343             purchaseOrderDocument.setDeliveryBuildingRoomNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_ROOM_NO).toString());
344         }
345         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE1_ADDR).equals("null")) {
346             purchaseOrderDocument.setDeliveryBuildingLine1Address(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE1_ADDR).toString());
347         }
348         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE2_ADDR).equals("null")) {
349             purchaseOrderDocument.setDeliveryBuildingLine2Address(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_LINE2_ADDR).toString());
350         }
351         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_CAMPUS_CD).equals("null")) {
352             purchaseOrderDocument.setDeliveryCampusCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_CAMPUS_CD).toString());
353         }
354         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_COUNTRY_CD).equals("null")) {
355             purchaseOrderDocument.setDeliveryCountryCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_COUNTRY_CD).toString());
356         }
357         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_POSTAL_CD).equals("null")) {
358             purchaseOrderDocument.setDeliveryPostalCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_POSTAL_CD).toString());
359         }
360         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_BUL_CD).equals("null")) {
361             purchaseOrderDocument.setDeliveryBuildingCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_BUL_CD).toString());
362         }
363         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_EMAIL_ADDR).equals("null")) {
364             purchaseOrderDocument.setDeliveryToEmailAddress(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_EMAIL_ADDR).toString());
365         }
366         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_NAME).equals("null")) {
367             purchaseOrderDocument.setDeliveryToName(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_NAME).toString());
368         }
369         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_PHONE_NO).equals("null")) {
370             purchaseOrderDocument.setDeliveryToPhoneNumber(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_TO_PHONE_NO).toString());
371         }
372         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_INST_NT).equals("null")) {
373             purchaseOrderDocument.setDeliveryInstructionText(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DEL_INST_NT).toString());
374         }
375 
376         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DOCUMENT_DESC).equals("null")) {
377             purchaseOrderDocument.getDocumentHeader().setDocumentDescription(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.DOCUMENT_DESC).toString());
378         }
379         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ASSIGN_TO_PRCPL_NM).equals("null")) {
380             purchaseOrderDocument.setAssignedUserPrincipalName(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.ASSIGN_TO_PRCPL_NM).toString());
381         }
382         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).equals("")) {
383             purchaseOrderDocument.setRecurringPaymentTypeCode(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.RECUR_PAY_TYP_CD).toString());
384         } else {
385             purchaseOrderDocument.setRecurringPaymentTypeCode(null);
386         }
387         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).equals("")) {
388             SimpleDateFormat format = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.TIMESTAMP_FORMAT);
389             purchaseOrderDocument.setPurchaseOrderBeginDate(java.sql.Date.valueOf(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_BEGIN_DT).toString()));
390         } else {
391             purchaseOrderDocument.setPurchaseOrderBeginDate(null);
392         }
393         if (!map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).equals("null") && !map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).equals("")) {
394             SimpleDateFormat format = new SimpleDateFormat(OLEConstants.OLEPurchaseOrderBulkAmendment.TIMESTAMP_FORMAT);
395             purchaseOrderDocument.setPurchaseOrderEndDate(java.sql.Date.valueOf(map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.PO_END_DATE).toString()));
396         } else {
397             purchaseOrderDocument.setPurchaseOrderEndDate(null);
398         }
399 
400         return purchaseOrderDocument;
401     }
402 
403     public OlePurchaseOrderDocument updateVendor(OlePurchaseOrderDocument purchaseOrderDocument, Map map) {
404         Map vendorMap = new HashMap();
405         vendorMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER, map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VENDOR_NUMBER));
406         vendorMap.put(OLEConstants.OLEPurchaseOrderBulkAmendment.VEN_DTL_ASSIGN_ID, map.get(OLEConstants.OLEPurchaseOrderBulkAmendment.VEN_DTL_ASSIGN_ID));
407         VendorDetail vendorDetail = getBusinessObjectService().findByPrimaryKey(VendorDetail.class, vendorMap);
408         if (vendorDetail != null) {
409             purchaseOrderDocument.setVendorName(vendorDetail.getVendorName());
410             purchaseOrderDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier());
411             purchaseOrderDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier());
412             purchaseOrderDocument.setVendorAliasName("");
413             purchaseOrderDocument.setVendorPaymentTermsCode(vendorDetail.getVendorPaymentTermsCode());
414             purchaseOrderDocument.setVendorShippingPaymentTermsCode(vendorDetail.getVendorShippingPaymentTermsCode());
415             for (VendorAddress vendorAddress : vendorDetail.getVendorAddresses()) {
416                 if (vendorAddress.isActive() && vendorAddress.isVendorDefaultAddressIndicator()) {
417                     purchaseOrderDocument.setVendorCityName(vendorAddress.getVendorCityName());
418                     purchaseOrderDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address());
419                     purchaseOrderDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address());
420                     purchaseOrderDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode());
421                     purchaseOrderDocument.setVendorStateCode(vendorAddress.getVendorStateCode());
422                     purchaseOrderDocument.setVendorPostalCode(vendorAddress.getVendorZipCode());
423                 }
424             }
425         }
426         return purchaseOrderDocument;
427     }
428 
429     public Integer getFormatId(String name) {
430         Integer id = null;
431         Map idMap = new HashMap();
432         idMap.put("formatTypeName", name);
433         OleFormatType formatType = getBusinessObjectService().findByPrimaryKey(OleFormatType.class, idMap);
434         if (formatType != null) {
435             return formatType.getFormatTypeId().intValue();
436         }
437         return id;
438     }
439 
440     public Integer getItemPriceSourceId(String name) {
441         Integer id = null;
442         Map idMap = new HashMap();
443         idMap.put("itemPriceSource", name);
444         OleItemPriceSource itemPriceSource = getBusinessObjectService().findByPrimaryKey(OleItemPriceSource.class, idMap);
445         if (itemPriceSource != null) {
446             return itemPriceSource.getItemPriceSourceId().intValue();
447         }
448         return id;
449     }
450 
451     public Integer getRequestSourceId(String name) {
452         Integer id = null;
453         Map idMap = new HashMap();
454         idMap.put("requestSourceType", name);
455         OleRequestSourceType requestSourceType = getBusinessObjectService().findByPrimaryKey(OleRequestSourceType.class, idMap);
456         if (requestSourceType != null) {
457             return requestSourceType.getRequestSourceTypeId().intValue();
458         }
459         return id;
460     }
461 
462 
463     private BusinessObjectService getBusinessObjectService() {
464         if (null == businessObjectService) {
465             businessObjectService = SpringContext.getBean(BusinessObjectService.class);
466         }
467         return businessObjectService;
468     }
469 
470     public Integer getCategoryId(String name) {
471         Integer id = null;
472         Map idMap = new HashMap();
473         idMap.put("category", name);
474         OleCategory category = getBusinessObjectService().findByPrimaryKey(OleCategory.class, idMap);
475         if (category != null) {
476             return category.getCategoryId().intValue();
477         }
478         return id;
479     }
480 
481 
482     public OlePurchaseOrderService getOlePurchaseOrderService() {
483         if (olePurchaseOrderService == null) {
484             olePurchaseOrderService = (OlePurchaseOrderService) SpringContext.getService("olePurchaseOrderService");
485         }
486         return olePurchaseOrderService;
487     }
488 
489     public void setCharts(List<Chart> charts) {
490         this.charts = charts;
491     }
492 
493     public void setAccounts(List<Account> accounts) {
494         this.accounts = accounts;
495     }
496 
497     public void setObjects(List<ObjectCode> objects) {
498         this.objects = objects;
499     }
500 
501     public void setVendorDetails(List<VendorDetail> vendorDetails) {
502         this.vendorDetails = vendorDetails;
503     }
504 
505     public void setCategories(List<OleCategory> categories) {
506         this.categories = categories;
507     }
508 
509     public void setFormatTypes(List<OleFormatType> formatTypes) {
510         this.formatTypes = formatTypes;
511     }
512 
513     public void setItemPriceSources(List<OleItemPriceSource> itemPriceSources) {
514         this.itemPriceSources = itemPriceSources;
515     }
516 
517     public void setRequestSourceTypes(List<OleRequestSourceType> requestSourceTypes) {
518         this.requestSourceTypes = requestSourceTypes;
519     }
520 
521     public void setLocations(List<OleLocation> locations) {
522         this.locations = locations;
523     }
524 
525     public void setChartList(List<String> chartList) {
526         this.chartList = chartList;
527     }
528 
529     public void setAccountList(List<String> accountList) {
530         this.accountList = accountList;
531     }
532 
533     public void setObjectCodeList(List<String> objectCodeList) {
534         this.objectCodeList = objectCodeList;
535     }
536 
537     public void setVendorDetailList(List<String> vendorDetailList) {
538         this.vendorDetailList = vendorDetailList;
539     }
540 
541     public void setCategoryList(List<String> categoryList) {
542         this.categoryList = categoryList;
543     }
544 
545     public void setFormatList(List<String> formatList) {
546         this.formatList = formatList;
547     }
548 
549     public void setRequestSourceList(List<String> requestSourceList) {
550         this.requestSourceList = requestSourceList;
551     }
552 
553     public void setPriceSourceList(List<String> priceSourceList) {
554         this.priceSourceList = priceSourceList;
555     }
556 
557     public void setLocationList(List<String> locationList) {
558         this.locationList = locationList;
559     }
560 
561     public void setOlePurchaseOrderService(OlePurchaseOrderService olePurchaseOrderService) {
562         this.olePurchaseOrderService = olePurchaseOrderService;
563     }
564 
565     public void setBusinessObjectService(BusinessObjectService businessObjectService) {
566         this.businessObjectService = businessObjectService;
567     }
568 
569     public StringBuilder getMessage() {
570         return message;
571     }
572 
573     public List<Chart> getCharts() {
574         return charts;
575     }
576 
577     public List<Account> getAccounts() {
578         return accounts;
579     }
580 
581     public List<ObjectCode> getObjects() {
582         return objects;
583     }
584 
585     public List<VendorDetail> getVendorDetails() {
586         return vendorDetails;
587     }
588 
589     public List<OleCategory> getCategories() {
590         return categories;
591     }
592 
593     public List<OleFormatType> getFormatTypes() {
594         return formatTypes;
595     }
596 
597     public List<OleItemPriceSource> getItemPriceSources() {
598         return itemPriceSources;
599     }
600 
601     public List<OleRequestSourceType> getRequestSourceTypes() {
602         return requestSourceTypes;
603     }
604 
605     public List<OleLocation> getLocations() {
606         return locations;
607     }
608 
609     public List<String> getChartList() {
610         return chartList;
611     }
612 
613     public List<String> getAccountList() {
614         return accountList;
615     }
616 
617     public List<String> getObjectCodeList() {
618         return objectCodeList;
619     }
620 
621     public List<String> getVendorDetailList() {
622         return vendorDetailList;
623     }
624 
625     public List<String> getCategoryList() {
626         return categoryList;
627     }
628 
629     public List<String> getFormatList() {
630         return formatList;
631     }
632 
633     public List<String> getRequestSourceList() {
634         return requestSourceList;
635     }
636 
637     public List<String> getPriceSourceList() {
638         return priceSourceList;
639     }
640 
641     public List<String> getLocationList() {
642         return locationList;
643     }
644 
645     public List<Map> getPoListToProcess() {
646         return poListToProcess;
647     }
648 
649     public String getPobaDocNumber() {
650         return pobaDocNumber;
651     }
652 
653     public UserSession getUserSession() {
654         return userSession;
655     }
656 
657     public void setUserSession(UserSession userSession) {
658         this.userSession = userSession;
659     }
660 
661     public PlatformTransactionManager getTransactionManager() {
662         if (transactionManager == null) {
663             transactionManager = GlobalResourceLoader.getService("transactionManager");
664         }
665         return this.transactionManager;
666     }
667 }