1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.service.impl;
17
18 import org.apache.commons.lang.StringEscapeUtils;
19 import org.kuali.ole.DataCarrierService;
20 import org.kuali.ole.OleOrderRecords;
21 import org.kuali.ole.batch.bo.OLEBatchProcessProfileBo;
22 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
23 import org.kuali.ole.module.purap.PurapConstants;
24 import org.kuali.ole.module.purap.PurapPropertyConstants;
25 import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
26 import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
27 import org.kuali.ole.module.purap.businessobject.RequisitionAccount;
28 import org.kuali.ole.module.purap.businessobject.RequisitionItem;
29 import org.kuali.ole.module.purap.document.RequisitionDocument;
30 import org.kuali.ole.module.purap.document.service.OlePurapService;
31 import org.kuali.ole.module.purap.document.service.RequisitionService;
32 import org.kuali.ole.pojo.OleOrderRecord;
33 import org.kuali.ole.pojo.OleTxRecord;
34 import org.kuali.ole.select.OleSelectConstant;
35 import org.kuali.ole.select.OleSelectNotificationConstant;
36 import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService;
37 import org.kuali.ole.select.batch.service.impl.RequisitionCreateDocumentServiceImpl;
38 import org.kuali.ole.select.bo.OLELinkPurapDonor;
39 import org.kuali.ole.select.businessobject.*;
40 import org.kuali.ole.select.document.OleRequisitionDocument;
41 import org.kuali.ole.select.document.service.OleRequestSourceService;
42 import org.kuali.ole.select.document.service.OleRequestorService;
43 import org.kuali.ole.select.document.service.OleSelectDocumentService;
44 import org.kuali.ole.select.service.BibInfoService;
45 import org.kuali.ole.select.service.OleReqPOCreateDocumentService;
46 import org.kuali.ole.sys.OLEConstants;
47 import org.kuali.ole.sys.OLEConstants.FinancialDocumentTypeCodes;
48 import org.kuali.ole.sys.businessobject.Building;
49 import org.kuali.ole.sys.context.SpringContext;
50 import org.kuali.ole.vnd.VendorConstants;
51 import org.kuali.ole.vnd.VendorPropertyConstants;
52 import org.kuali.ole.vnd.businessobject.VendorAddress;
53 import org.kuali.ole.vnd.businessobject.VendorContract;
54 import org.kuali.ole.vnd.businessobject.VendorDetail;
55 import org.kuali.ole.vnd.document.service.VendorService;
56 import org.kuali.rice.core.api.config.property.ConfigurationService;
57 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
58 import org.kuali.rice.core.api.util.type.KualiDecimal;
59 import org.kuali.rice.kew.api.exception.WorkflowException;
60 import org.kuali.rice.krad.UserSession;
61 import org.kuali.rice.krad.service.BusinessObjectService;
62 import org.kuali.rice.krad.service.DocumentService;
63 import org.kuali.rice.krad.util.GlobalVariables;
64 import org.kuali.rice.krad.util.ObjectUtils;
65 import org.springmodules.orm.ojb.OjbOperationException;
66
67 import javax.persistence.OptimisticLockException;
68 import java.math.BigDecimal;
69 import java.util.*;
70
71 public class OleReqPOCreateDocumentServiceImpl extends RequisitionCreateDocumentServiceImpl implements OleReqPOCreateDocumentService {
72 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OleReqPOCreateDocumentServiceImpl.class);
73
74 protected RequisitionCreateDocumentService requisitionCreateDocumentService;
75 protected OleRequestorService oleRequestorService;
76 protected VendorService vendorService;
77 protected OleRequestSourceService oleRequestSourceService;
78 protected OlePurapService olePurapService;
79 protected BusinessObjectService businessObjectService;
80 protected DocumentService documentService;
81 protected BibInfoService bibInfoService;
82 protected ConfigurationService kualiConfigurationService;
83 protected List reqList;
84 private DocstoreClientLocator docstoreClientLocator;
85 private OLEBatchProcessProfileBo oleBatchProcessProfileBo;
86 private OleRequisitionDocument requisitionDocument;
87 private OlePatronDocumentList olePatronDocumentList;
88 private OleSelectDocumentService oleSelectDocumentService;
89
90 public OleSelectDocumentService getOleSelectDocumentService() {
91 if (oleSelectDocumentService == null) {
92 oleSelectDocumentService = SpringContext.getBean(OleSelectDocumentService.class);
93 }
94 return oleSelectDocumentService;
95 }
96
97 public OlePatronDocumentList getOlePatronDocumentList() {
98 if (olePatronDocumentList == null) {
99 olePatronDocumentList = SpringContext.getBean(OlePatronDocumentList.class);
100 }
101 return olePatronDocumentList;
102 }
103
104 public DocstoreClientLocator getDocstoreClientLocator() {
105
106 if (docstoreClientLocator == null) {
107 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
108
109 }
110 return docstoreClientLocator;
111 }
112
113
114
115
116
117
118 public void saveRequisitionDocument(OleOrderRecords oleOrderRecords) throws Exception {
119 String docNumber = "";
120 String isValidBFN = "";
121 vendorService = getVendorService();
122 oleRequestorService = getOleRequestorService();
123 requisitionCreateDocumentService = getRequisitionCreateDocumentService();
124 oleRequestSourceService = getOleRequestSourceService();
125 olePurapService = getOlePurapService();
126 setUserFromStaffUpload(oleOrderRecords);
127 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(org.kuali.ole.OLEConstants.DATA_CARRIER_SERVICE);
128 oleBatchProcessProfileBo = (OLEBatchProcessProfileBo) dataCarrierService.getData(org.kuali.ole.OLEConstants.BATCH_PROFILE_BO);
129 String requisitionsForTitle = null;
130 if(oleBatchProcessProfileBo != null){
131 requisitionsForTitle = oleBatchProcessProfileBo.getRequisitionsforTitle();
132 }
133 if (oleBatchProcessProfileBo != null && (requisitionsForTitle.equalsIgnoreCase("None") || requisitionsForTitle.equalsIgnoreCase("One Requisition Per Title"))) {
134 reqList = new ArrayList(0);
135 HashMap<String, String> dataMap = new HashMap<String, String>();
136 List<OleOrderRecord> oleOrderRecordList = oleOrderRecords.getRecords();
137 for (OleOrderRecord oleOrderRecord : oleOrderRecordList) {
138 oleOrderRecord.getMessageMap().put("isApoRule", false);
139 String isValidRecord = ((oleOrderRecord.getMessageMap().get("isValidRecord"))).toString();
140 if ("true".equalsIgnoreCase(isValidRecord)) {
141 isValidBFN = ((oleOrderRecord.getMessageMap().get("isValidBFN"))).toString();
142 if (isValidBFN.equalsIgnoreCase("true")) {
143 String[] isbnDupFlag = (((List) oleOrderRecord.getMessageMap().get("rulesEvaluated")).get(0)).toString().split(":");
144 if ("false".equalsIgnoreCase(isbnDupFlag[1].trim()) && oleOrderRecord.getOleTxRecord() != null && oleOrderRecord.getOleBibRecord() != null) {
145 requisitionDocument = null;
146 try {
147 requisitionDocument = createRequisitionDocument();
148
149 requisitionDocument.setRequisitionSourceCode(oleOrderRecord.getOleTxRecord().getRequisitionSource());
150 if (oleOrderRecordList != null && oleOrderRecordList.size() > 0) {
151
152 if (oleOrderRecord.getOleTxRecord().getOrderType() != null) {
153 Map purchaseOrderTypeMap = new HashMap();
154 purchaseOrderTypeMap.put("purchaseOrderType", oleOrderRecord.getOleTxRecord().getOrderType());
155 org.kuali.rice.krad.service.BusinessObjectService
156 businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
157 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObjectService.findMatching(PurchaseOrderType.class, purchaseOrderTypeMap);
158 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
159 requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId());
160 }
161 }
162 else {
163 requisitionDocument.setPurchaseOrderTypeId(OLEConstants.DEFAULT_ORDER_TYPE_VALUE);
164 }
165 setDocumentValues(requisitionDocument, oleOrderRecord);
166 }
167 requisitionDocument.setItems(generateItemList(oleOrderRecord));
168 RequisitionService requisitionService = SpringContext.getBean(RequisitionService.class);
169
170 boolean apoRuleFlag = requisitionService.isAutomaticPurchaseOrderAllowed(requisitionDocument);
171 if (!apoRuleFlag) {
172 oleOrderRecord.getMessageMap().put("isApoRule", true);
173 }
174 if(LOG.isInfoEnabled()){
175 LOG.info("before calling saveRequisitionDocuments");
176 }
177 docNumber = requisitionCreateDocumentService.saveRequisitionDocuments(requisitionDocument);
178 reqList.add(requisitionDocument.getPurapDocumentIdentifier());
179 }
180 catch(OjbOperationException opl) {
181 LOG.error("OjbOperationException while performing saveRequisitionDocument"+opl);
182 opl.printStackTrace();
183 }
184 catch(OptimisticLockException ole){
185 LOG.error("OjbOperationException while performing saveRequisitionDocument"+ole);
186 ole.printStackTrace();
187 }
188 catch (Exception ex) {
189 LOG.error("####Rollback####" + ex);
190 ex.printStackTrace();
191 Iterator<OleRequisitionItem> iterator = requisitionDocument.getItems().iterator();
192 while (iterator.hasNext()) {
193 OleRequisitionItem item = iterator.next();
194
195 getDocstoreClientLocator().getDocstoreClient().deleteBib(item.getBibUUID());
196
197 }
198 LOG.error("####Rollback####" + ex);
199 throw ex;
200 }
201 }
202 }
203 }
204 }
205 }
206 else if(oleBatchProcessProfileBo != null && requisitionsForTitle.equalsIgnoreCase("One Requisition With All Titles")){
207 reqList = new ArrayList(0);
208 HashMap<String, String> dataMap = new HashMap<String, String>();
209 List<OleOrderRecord> oleOrderRecordList = oleOrderRecords.getRecords();
210 requisitionDocument = null;
211 List<OleOrderRecord> validRecords = new ArrayList<OleOrderRecord>();
212 for (OleOrderRecord oleOrderRecord : oleOrderRecordList) {
213 oleOrderRecord.getMessageMap().put("isApoRule", false);
214 String isValidRecord = ((oleOrderRecord.getMessageMap().get("isValidRecord"))).toString();
215 if ("true".equalsIgnoreCase(isValidRecord)) {
216 isValidBFN = ((oleOrderRecord.getMessageMap().get("isValidBFN"))).toString();
217 if (isValidBFN.equalsIgnoreCase("true")) {
218 String[] isbnDupFlag = (((List) oleOrderRecord.getMessageMap().get("rulesEvaluated")).get(0)).toString().split(":");
219 if ("false".equalsIgnoreCase(isbnDupFlag[1].trim()) && oleOrderRecord.getOleTxRecord() != null && oleOrderRecord.getOleBibRecord() != null) {
220 validRecords.add(oleOrderRecord);
221 }
222 }
223 }
224 }
225 try {
226 if(oleOrderRecordList.size() == validRecords.size()){
227 requisitionDocument = createRequisitionDocument();
228 requisitionDocument.setRequisitionSourceCode(oleOrderRecordList.get(0).getOleTxRecord().getRequisitionSource());
229 if (oleOrderRecordList != null && oleOrderRecordList.size() > 0) {
230 if (oleOrderRecordList.get(0).getOleTxRecord().getOrderType() != null) {
231 Map purchaseOrderTypeMap = new HashMap();
232 purchaseOrderTypeMap.put("purchaseOrderType", oleOrderRecordList.get(0).getOleTxRecord().getOrderType());
233 org.kuali.rice.krad.service.BusinessObjectService
234 businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
235 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) businessObjectService.findMatching(PurchaseOrderType.class, purchaseOrderTypeMap);
236 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
237 requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId());
238 }
239 }
240 else {
241 requisitionDocument.setPurchaseOrderTypeId(OLEConstants.DEFAULT_ORDER_TYPE_VALUE);
242 }
243 setDocumentValues(requisitionDocument, oleOrderRecordList.get(0));
244 }
245 requisitionDocument.setItems(generateMultipleItemsForOneRequisition(oleOrderRecordList));
246
247
248 RequisitionService requisitionService = SpringContext.getBean(RequisitionService.class);
249 requisitionDocument.getDocumentHeader().getWorkflowDocument();
250
251 docNumber = requisitionCreateDocumentService.saveRequisitionDocuments(requisitionDocument);
252 reqList.add(requisitionDocument.getPurapDocumentIdentifier());
253 }
254 else {
255 if(validRecords != null && validRecords.size() > 0){
256 List<String> uuidList = new ArrayList<>();
257 for(int recCount = 0;recCount<validRecords.size();recCount++) {
258 uuidList.add(validRecords.get(recCount).getOleBibRecord().getBibUUID());
259 }
260 getDocstoreClientLocator().getDocstoreClient().deleteBibs(uuidList);
261 }
262 }
263 }
264 catch(Exception ex){
265 LOG.error("####Rollback####" + ex);
266 ex.printStackTrace();
267 }
268 }
269 }
270
271
272
273
274
275
276
277 protected OleRequisitionDocument createRequisitionDocument() throws WorkflowException {
278 String user;
279 if (GlobalVariables.getUserSession() == null) {
280 kualiConfigurationService = SpringContext.getBean(ConfigurationService.class);
281 user = kualiConfigurationService.getPropertyValueAsString(OleSelectNotificationConstant.ACCOUNT_DOCUMENT_INTIATOR);
282 if(LOG.isInfoEnabled()){
283 LOG.info("createRequisitionDocument - user from session"+user);
284 }
285 GlobalVariables.setUserSession(new UserSession(user));
286 }
287
288 return (OleRequisitionDocument) SpringContext.getBean(DocumentService.class).getNewDocument(FinancialDocumentTypeCodes.REQUISITION);
289 }
290
291 private void setUserFromStaffUpload(OleOrderRecords oleOrderRecords) {
292 List<OleOrderRecord> oleOrderRecordList = oleOrderRecords.getRecords();
293 String user = null;
294 if (oleOrderRecordList.size() > 0) {
295 user = (String) oleOrderRecordList.get(0).getMessageMap().get(OLEConstants.USER_ID);
296 if (user == null) {
297 user = getConfigurationService().getPropertyValueAsString(
298 OleSelectNotificationConstant.ACCOUNT_DOCUMENT_INTIATOR);
299 }
300 GlobalVariables.setUserSession(new UserSession(user));
301 }
302 }
303
304
305
306
307
308
309
310
311 protected RequisitionDocument setDocumentValues(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) throws Exception {
312
313 requisitionDocument.getDocumentHeader().setDocumentDescription(getDocumentDescription(requisitionDocument, oleOrderRecord));
314 requisitionDocument.setStatusCode(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
315
316
317
318
319 requisitionDocument.setVendorPoNumber(oleOrderRecord.getOleTxRecord().getVendorItemIdentifier());
320
321
322 requisitionDocument.setChartOfAccountsCode(oleOrderRecord.getOleTxRecord().getChartCode());
323 requisitionDocument.setOrganizationCode(oleOrderRecord.getOleTxRecord().getOrgCode());
324 requisitionDocument.setDocumentFundingSourceCode(oleOrderRecord.getOleTxRecord().getFundingSource());
325 requisitionDocument.setUseTaxIndicator(true);
326
327 setDeliveryDetails(requisitionDocument, oleOrderRecord);
328 requisitionDocument.setDeliveryCampusCode(oleOrderRecord.getOleTxRecord().getDeliveryCampusCode());
329
330 setVendorDetails(requisitionDocument, oleOrderRecord);
331
332
333
334
335 requisitionDocument.setPurchaseOrderTransmissionMethodCode(oleOrderRecord.getOleTxRecord().getMethodOfPOTransmission());
336 requisitionDocument.setPurchaseOrderCostSourceCode(oleOrderRecord.getOleTxRecord().getCostSource());
337 requisitionDocument.setRequestorPersonName(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.REQUESTOR_PERSON_NAME));
338 requisitionDocument.setRequestorPersonPhoneNumber(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.REQUESTOR_PERSON_PHONE_NUMBER));
339 requisitionDocument.setRequestorPersonEmailAddress(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.REQUESTOR_PERSON_EMAIL_ADDRESS));
340
341
342
343
344
345
346
347 requisitionDocument.setOrganizationAutomaticPurchaseOrderLimit(new KualiDecimal(getConfigurationService().getPropertyValueAsString(VendorPropertyConstants.VENDOR_CONTRACT_DEFAULT_APO_LIMIT)));
348 requisitionDocument.setPurchaseOrderAutomaticIndicator(Boolean.parseBoolean(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.PURCHASE_ORDER_AUTOMATIC_INDICATIOR)));
349 requisitionDocument.setReceivingDocumentRequiredIndicator(oleOrderRecord.getOleTxRecord().isReceivingRequired());
350 requisitionDocument.setPaymentRequestPositiveApprovalIndicator(oleOrderRecord.getOleTxRecord().isPayReqPositiveApprovalReq());
351 requisitionDocument.setRequisitionSourceCode(oleOrderRecord.getOleTxRecord().getRequisitionSource());
352 return requisitionDocument;
353
354 }
355
356
357
358
359
360
361
362
363 private void setDeliveryDetails(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) {
364 if (LOG.isDebugEnabled())
365 LOG.debug("bibInfoBean.getDeliveryBuildingCode----------->" + oleOrderRecord.getOleTxRecord().getBuildingCode());
366
367 if (oleOrderRecord.getOleTxRecord().getDeliveryCampusCode() != null && oleOrderRecord.getOleTxRecord().getBuildingCode() != null) {
368 Building building = vendorService.getBuildingDetails(oleOrderRecord.getOleTxRecord().getDeliveryCampusCode(), oleOrderRecord.getOleTxRecord().getBuildingCode());
369 if (building != null) {
370 requisitionDocument.setDeliveryBuildingCode(building.getBuildingCode());
371 requisitionDocument.setDeliveryCampusCode(building.getCampusCode());
372 requisitionDocument.setDeliveryBuildingLine1Address(building.getBuildingStreetAddress());
373 requisitionDocument.setDeliveryBuildingName(building.getBuildingName());
374 requisitionDocument.setDeliveryCityName(building.getBuildingAddressCityName());
375 requisitionDocument.setDeliveryStateCode(building.getBuildingAddressStateCode());
376 requisitionDocument.setDeliveryPostalCode(building.getBuildingAddressZipCode());
377 requisitionDocument.setDeliveryCountryCode(building.getBuildingAddressCountryCode());
378 requisitionDocument.setDeliveryBuildingRoomNumber(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.DELIVERY_DEFAULT_ROOM_NUMBER));
379 requisitionDocument.setDeliveryToName(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.DELIVERY_TO_NAME));
380
381
382 requisitionDocument.setBillingCountryCode(building.getBuildingCode());
383 requisitionDocument.setBillingLine1Address(building.getBuildingStreetAddress());
384 requisitionDocument.setBillingName(building.getBuildingName());
385 requisitionDocument.setBillingCityName(building.getBuildingAddressCityName());
386 requisitionDocument.setBillingStateCode(building.getBuildingAddressStateCode());
387 requisitionDocument.setBillingPostalCode(building.getBuildingAddressZipCode());
388 requisitionDocument.setBillingCountryCode(building.getBuildingAddressCountryCode());
389 requisitionDocument.setBillingPhoneNumber(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.BILLING_PHONE_NUMBER));
390
391 }
392 }
393 }
394
395
396
397
398
399
400
401 private void setVendorDetails(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) {
402 if (oleOrderRecord.getOleTxRecord().getVendorNumber() != null) {
403 VendorDetail vendorDetail = vendorService.getVendorDetail(oleOrderRecord.getOleTxRecord().getVendorNumber());
404
405 requisitionDocument.setVendorCustomerNumber(oleOrderRecord.getOleTxRecord().getVendorInfoCustomer());
406 requisitionDocument.setVendorNumber(oleOrderRecord.getOleTxRecord().getVendorNumber());
407 requisitionDocument.setVendorNumber(vendorDetail.getVendorNumber());
408 requisitionDocument.setVendorName(vendorDetail.getVendorName());
409 requisitionDocument.setVendorHeaderGeneratedIdentifier(vendorDetail.getVendorHeaderGeneratedIdentifier());
410 requisitionDocument.setVendorDetailAssignedIdentifier(vendorDetail.getVendorDetailAssignedIdentifier());
411 requisitionDocument.setVendorDetail(vendorDetail);
412 String deliveryCampus = oleOrderRecord.getOleTxRecord().getDeliveryCampusCode();
413 Integer headerId = null;
414 Integer detailId = null;
415 int dashInd = vendorDetail.getVendorNumber().indexOf('-');
416
417 if (dashInd > 0 && dashInd < vendorDetail.getVendorNumber().length() - 1) {
418 headerId = new Integer(vendorDetail.getVendorNumber().substring(0, dashInd));
419 detailId = new Integer(vendorDetail.getVendorNumber().substring(dashInd + 1));
420 }
421 VendorAddress vendorAddress = vendorService.getVendorDefaultAddress(headerId, detailId, VendorConstants.AddressTypes.PURCHASE_ORDER, deliveryCampus);
422 setVendorAddress(vendorAddress, requisitionDocument);
423
424 List<VendorContract> vendorContracts = vendorDetail.getVendorContracts();
425 for (Iterator<VendorContract> vendorContract = vendorContracts.iterator(); vendorContract.hasNext(); ) {
426 requisitionDocument.setVendorContractGeneratedIdentifier((vendorContract.next()).getVendorContractGeneratedIdentifier());
427 }
428 }
429
430 }
431
432
433
434
435
436
437
438 private List<RequisitionItem> generateItemList(OleOrderRecord oleOrderRecord) throws Exception {
439 List<RequisitionItem> items = new ArrayList<RequisitionItem>();
440 int itemLineNumber = 1;
441 items.add(createRequisitionItem(oleOrderRecord, itemLineNumber));
442 return items;
443 }
444
445
446
447
448
449
450
451
452
453
454
455
456 private List<RequisitionItem> generateMultipleItemsForOneRequisition(List<OleOrderRecord> oleOrderRecordList) throws Exception {
457 List<RequisitionItem> items = new ArrayList<RequisitionItem>();
458 int itemLineNumber = 0;
459
460 for (OleOrderRecord oleOrderRecord : oleOrderRecordList) {
461 itemLineNumber++;
462 items.add(createRequisitionItem(oleOrderRecord, itemLineNumber));
463 }
464 return items;
465 }
466
467
468
469
470
471
472
473 @SuppressWarnings("deprecation")
474 protected RequisitionItem createRequisitionItem(OleOrderRecord oleOrderRecord, int itemLineNumber) throws Exception {
475 OleRequisitionItem item = new OleRequisitionItem();
476 item.setOleOrderRecord(oleOrderRecord);
477
478 item.setItemLineNumber(itemLineNumber);
479 item.setItemUnitOfMeasureCode(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.UOM));
480 item.setItemQuantity(new KualiDecimal(oleOrderRecord.getOleTxRecord().getQuantity()));
481
482 setItemDescription(oleOrderRecord,item);
483 item.setItemUnitPrice(new BigDecimal(oleOrderRecord.getOleTxRecord().getListPrice()));
484 item.setItemTypeCode(oleOrderRecord.getOleTxRecord().getItemType());
485 item.setItemListPrice(new KualiDecimal(oleOrderRecord.getOleTxRecord().getListPrice()));
486 item.setItemLocation(oleOrderRecord.getOleTxRecord().getDefaultLocation());
487 if (oleOrderRecord.getOleTxRecord().getOleDonors()!=null && oleOrderRecord.getOleTxRecord().getOleDonors().size()>0){
488 List<OLELinkPurapDonor> oleLinkPurapDonorList=new ArrayList<>();
489 for (String donor:oleOrderRecord.getOleTxRecord().getOleDonors()){
490 OLELinkPurapDonor oleLinkPurapDonor=new OLELinkPurapDonor();
491 oleLinkPurapDonor.setDonorCode(donor);
492 oleLinkPurapDonorList.add(oleLinkPurapDonor);
493 }
494 item.setOleDonors(oleLinkPurapDonorList);
495 }
496 if (ObjectUtils.isNotNull(oleOrderRecord.getOleBibRecord().getBibUUID())) {
497 item.setItemTitleId(oleOrderRecord.getOleBibRecord().getBibUUID());
498 }
499
500
501 org.kuali.ole.module.purap.businessobject.ItemType itemType = businessObjectService.findBySinglePrimaryKey(org.kuali.ole.module.purap.businessobject.ItemType.class, "ITEM");
502 item.setItemType(itemType);
503
504
505 RequisitionAccount requisitionAccount = new RequisitionAccount();
506
507
508
509
510 requisitionAccount.setChartOfAccountsCode(oleOrderRecord.getOleTxRecord().getItemChartCode());
511 requisitionAccount.setAccountNumber(oleOrderRecord.getOleTxRecord().getAccountNumber());
512 requisitionAccount.setFinancialObjectCode(oleOrderRecord.getOleTxRecord().getObjectCode());
513 requisitionAccount.setDebitCreditCode(OLEConstants.GL_DEBIT_CODE);
514 if (oleOrderRecord.getOleTxRecord().getListPrice() != null) {
515 requisitionAccount.setAmount(new KualiDecimal(oleOrderRecord.getOleTxRecord().getListPrice()));
516 }
517 if (oleOrderRecord.getOleTxRecord().getPercent() != null) {
518 requisitionAccount.setAccountLinePercent(new BigDecimal(oleOrderRecord.getOleTxRecord().getPercent()));
519 }
520 if (oleOrderRecord.getOleTxRecord().getAccountNumber() != null) {
521 List<PurApAccountingLine> sourceAccountingLines = item.getSourceAccountingLines();
522 if (sourceAccountingLines.size() == 0) {
523 sourceAccountingLines = new ArrayList<PurApAccountingLine>(0);
524 }
525 sourceAccountingLines.add((PurApAccountingLine) requisitionAccount);
526 item.setSourceAccountingLines(sourceAccountingLines);
527 }
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546 String requestorType = null;
547
548 if (requestorType == null || "".equals(requestorType)) {
549
550 requestorType = OleSelectConstant.REQUESTOR_TYPE_STAFF;
551 }
552
553 int requestorTypeId = getRequestorTypeId(requestorType);
554 item.setRequestorTypeId(requestorTypeId);
555 if (oleOrderRecord.getOleTxRecord().getRequisitionSource().equals(OleSelectConstant.REQUISITON_SRC_TYPE_WEBFORM)) {
556 OleRequisitionNotes note = new OleRequisitionNotes();
557 Map notes = new HashMap();
558 String noteType = OleSelectConstant.REQUESTOR_NOTES_PRE_ORDER_SERVICE;
559 notes.put("noteType", noteType);
560 List<OleNoteType> noteTypeList = (List) businessObjectService.findMatching(org.kuali.ole.select.businessobject.OleNoteType.class, notes);
561 note.setNoteTypeId(noteTypeList.get(0).getNoteTypeId());
562
563 item.getNotes().add(note);
564 }
565 setItemDescription(oleOrderRecord, item);
566 populateValuesFromProfileAttributesAndDataMapping(item);
567 return item;
568 }
569
570 private void populateValuesFromProfileAttributesAndDataMapping(OleRequisitionItem singleItem){
571 DataCarrierService dataCarrierService = GlobalResourceLoader.getService(org.kuali.ole.OLEConstants.DATA_CARRIER_SERVICE);
572 OleTxRecord oleTxRecord = (OleTxRecord)dataCarrierService.getData(org.kuali.ole.OLEConstants.OLE_TX_RECORD);
573 if(oleTxRecord != null){
574 if(oleTxRecord.getRequestorName() != null){
575 String fullName = oleTxRecord.getRequestorName();
576 String[] requestorNames = fullName.split(", ");
577 if(requestorNames.length == 2){
578 String lastName = requestorNames[0];
579 String firstName = requestorNames[1];
580 Map<String,String> requestorNameMap = new HashMap<>();
581 requestorNameMap.put(OLEConstants.OlePersonRequestorLookupable.FIRST_NAME,firstName);
582 requestorNameMap.put(OLEConstants.OlePersonRequestorLookupable.LAST_NAME,lastName);
583 List<OLERequestorPatronDocument> olePatronDocumentList = new ArrayList<OLERequestorPatronDocument>();
584 olePatronDocumentList = getOleSelectDocumentService().getPatronDocumentListFromWebService();
585 HashMap<String, List<OLERequestorPatronDocument>> patronListMap = new HashMap<String, List<OLERequestorPatronDocument>>();
586 patronListMap.put(requisitionDocument.getDocumentNumber(), olePatronDocumentList);
587 getOlePatronDocumentList().setPatronListMap(patronListMap);
588 if(olePatronDocumentList != null && olePatronDocumentList.size()>0){
589 for(int recCount = 0;recCount < olePatronDocumentList.size();recCount++) {
590 if(olePatronDocumentList.get(recCount).getFirstName().equalsIgnoreCase(firstName) && olePatronDocumentList.get(recCount).getLastName().equalsIgnoreCase(lastName)){
591 String patronId = olePatronDocumentList.get(recCount).getOlePatronId();
592 singleItem.setRequestorId(patronId);
593 singleItem.setRequestorFirstName(fullName);
594 break;
595 }
596 }
597 }
598 }
599 }
600 singleItem.setItemDiscount(new KualiDecimal(oleTxRecord.getDiscount()));
601 singleItem.setItemDiscountType(oleTxRecord.getDiscountType());
602 if(singleItem.getItemDiscount() != null && singleItem.getItemDiscountType() == null){
603 singleItem.setItemDiscountType(OLEConstants.PERCENTAGE);
604 }
605 singleItem.setItemUnitPrice(getOlePurapService().calculateDiscount(singleItem));
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622 singleItem.setItemStatus(oleTxRecord.getItemStatus());
623
624 }
625 }
626
627 private void setItemDescription(OleOrderRecord oleOrderRecord, OleRequisitionItem item) throws Exception {
628
629 String title = oleOrderRecord.getOleBibRecord().getBib().getTitle() != null ? oleOrderRecord.getOleBibRecord().getBib().getTitle()+ "," : "";
630 String author = oleOrderRecord.getOleBibRecord().getBib().getAuthor() != null ? oleOrderRecord.getOleBibRecord().getBib().getAuthor()+ "," : "";
631 String publisher = oleOrderRecord.getOleBibRecord().getBib().getPublisher() != null ? oleOrderRecord.getOleBibRecord().getBib().getPublisher()+ "," : "";
632 String isbn = oleOrderRecord.getOleBibRecord().getBib().getIsbn() != null ? oleOrderRecord.getOleBibRecord().getBib().getIsbn() + ",": "";
633
634
635
636
637
638
639
640
641
642
643
644
645
646 String description = title + author
647 + publisher + isbn;
648 item.setItemDescription(description.substring(0, (description.lastIndexOf(","))));
649 item.setItemTitle(oleOrderRecord.getOleBibRecord().getBib().getTitle());
650 item.setItemAuthor(oleOrderRecord.getOleBibRecord().getBib().getAuthor());
651 item.setBibUUID(oleOrderRecord.getOleBibRecord().getBibUUID());
652
653 }
654
655 public int getRequestorTypeId(String requestorType) {
656 int requestorTypeId;
657 Map requestorTypeMap = new HashMap();
658 requestorTypeMap.put("requestorType", requestorType);
659 BusinessObjectService businessObjectService = SpringContext.getBean(org.kuali.rice.krad.service.BusinessObjectService.class);
660 List<OleRequestorType> requestorTypeIdList = (List) businessObjectService.findMatching(OleRequestorType.class, requestorTypeMap);
661 Iterator itr = requestorTypeIdList.iterator();
662 requestorTypeId = requestorTypeIdList.iterator().next().getRequestorTypeId();
663 return requestorTypeId;
664 }
665
666
667
668
669
670
671
672 protected OleRequestor checkRequestorExist(OleOrderRecord oleOrderRecord) {
673
674 String requestorFirstName = getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.FIRST_NAME);
675 String requestorLastName = getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.LAST_NAME);
676 String firstName;
677 String lastName;
678 Map requestorName = new HashMap();
679 requestorName.put("requestorFirstName", requestorFirstName);
680 requestorName.put("requestorLastName", requestorLastName);
681 List<OleRequestor> requestorList = (List) businessObjectService.findMatching(OleRequestor.class, requestorName);
682 if (requestorList.size() < 1) {
683 return null;
684 } else {
685 for (int i = 0; i < requestorList.size(); i++) {
686 firstName = requestorList.get(i).getRequestorFirstName().toString();
687 lastName = requestorList.get(i).getRequestorLastName().toString();
688 if (requestorFirstName.equalsIgnoreCase(firstName) && requestorLastName.equalsIgnoreCase(lastName)) {
689 return requestorList.get(i);
690 }
691 }
692 return null;
693 }
694 }
695
696
697
698
699
700
701 protected OleRequestor saveRequestor(OleOrderRecord oleOrderRecord, OleRequestor oleRequestor) {
702 oleRequestor.setRequestorFirstName(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.FIRST_NAME));
703 oleRequestor.setRequestorLastName(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.LAST_NAME));
704 oleRequestor.setRequestorAddress1(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.ADDRESS1));
705 oleRequestor.setRequestorAddress2(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.ADDRESS2));
706 oleRequestor.setRequestorCityName(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.CITY));
707 oleRequestor.setRequestorStateCode(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.STATE_CODE));
708 oleRequestor.setRequestorPostalCode(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.POSTAL_CODE));
709 oleRequestor.setRequestorCountryCode(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.COUNTRY_CODE));
710 oleRequestor.setRequestorPhoneNumber(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.PHONE_NUMBER));
711 oleRequestor.setRequestorEmail(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.EMAIL));
712 oleRequestor.setRequestorSms(getConfigurationService().getPropertyValueAsString(PurapPropertyConstants.SMS));
713 oleRequestor.setRequestorTypeId(Integer.toString(getRequestorTypeId(OleSelectConstant.REQUESTOR_TYPE_BATCHINGEST)));
714 getOleRequestorService().saveRequestor(oleRequestor);
715 return oleRequestor;
716 }
717
718
719
720
721
722
723
724
725 protected void setVendorAddress(VendorAddress vendorAddress, RequisitionDocument requisitionDocument) {
726
727 if (vendorAddress != null) {
728 requisitionDocument.setVendorAddressGeneratedIdentifier(vendorAddress.getVendorAddressGeneratedIdentifier());
729 requisitionDocument.setVendorAddressInternationalProvinceName(vendorAddress.getVendorAddressInternationalProvinceName());
730 requisitionDocument.setVendorLine1Address(vendorAddress.getVendorLine1Address());
731 requisitionDocument.setVendorLine2Address(vendorAddress.getVendorLine2Address());
732 requisitionDocument.setVendorCityName(vendorAddress.getVendorCityName());
733 requisitionDocument.setVendorStateCode(vendorAddress.getVendorStateCode());
734 requisitionDocument.setVendorPostalCode(vendorAddress.getVendorZipCode());
735 requisitionDocument.setVendorCountryCode(vendorAddress.getVendorCountryCode());
736 }
737
738 }
739
740 public String getDocumentDescription(OleRequisitionDocument requisitionDocument, OleOrderRecord oleOrderRecord) {
741
742 String description = "";
743 description = ((requisitionDocument.getVendorName() != null && !requisitionDocument.getVendorName().isEmpty()) ? requisitionDocument.getVendorName() : OLEConstants.DOCUMENT_DESCRIPTION) + "_" +
744 ((requisitionDocument.getOrderType() != null) ? requisitionDocument.getOrderType().getDescription() : OLEConstants.ORDER_TYPE) + "_" +
745 ((olePurapService.getOperatorInitials() != null && !olePurapService.getOperatorInitials().isEmpty()) ? olePurapService.getOperatorInitials() : "") + "_" +
746 ((requisitionDocument.getCurrentDateTime() != null) ? requisitionDocument.getCurrentDateTime().toString() : "") + "_" +
747 ((oleOrderRecord.getOleTxRecord().getVendorItemIdentifier() != null && !oleOrderRecord.getOleTxRecord().getVendorItemIdentifier().isEmpty()) ? oleOrderRecord.getOleTxRecord().getVendorItemIdentifier() + "_" : "");
748 if (!description.equals("") && description != null)
749 description = description.substring(0, description.lastIndexOf("_"));
750 return description;
751 }
752
753 public RequisitionCreateDocumentService getRequisitionCreateDocumentService() {
754 return requisitionCreateDocumentService;
755 }
756
757 public void setRequisitionCreateDocumentService(RequisitionCreateDocumentService requisitionCreateDocumentService) {
758 this.requisitionCreateDocumentService = requisitionCreateDocumentService;
759 }
760
761 public OleRequestorService getOleRequestorService() {
762 return oleRequestorService;
763 }
764
765 public void setOleRequestorService(OleRequestorService oleRequestorService) {
766 this.oleRequestorService = oleRequestorService;
767 }
768
769 public VendorService getVendorService() {
770 return vendorService;
771 }
772
773 public void setVendorService(VendorService vendorService) {
774 this.vendorService = vendorService;
775 }
776
777 public OleRequestSourceService getOleRequestSourceService() {
778 return oleRequestSourceService;
779 }
780
781 public void setOleRequestSourceService(OleRequestSourceService oleRequestSourceService) {
782 this.oleRequestSourceService = oleRequestSourceService;
783 }
784
785 public OlePurapService getOlePurapService() {
786 return olePurapService;
787 }
788
789 public void setOlePurapService(OlePurapService olePurapService) {
790 this.olePurapService = olePurapService;
791 }
792
793 public BibInfoService getBibInfoService() {
794 return bibInfoService;
795 }
796
797 public void setBibInfoService(BibInfoService bibInfoService) {
798 this.bibInfoService = bibInfoService;
799 }
800
801 public BusinessObjectService getBusinessObjectService() {
802 return businessObjectService;
803 }
804
805 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
806 this.businessObjectService = businessObjectService;
807 }
808
809 public List getReqList() {
810 return reqList;
811 }
812
813 public ConfigurationService getConfigurationService() {
814 return kualiConfigurationService;
815 }
816
817 public void setConfigurationService(ConfigurationService kualiConfigurationService) {
818 this.kualiConfigurationService = kualiConfigurationService;
819 }
820
821 }