View Javadoc
1   package org.kuali.ole.select.service;
2   
3   import org.kuali.ole.OLEConstants;
4   import org.kuali.ole.select.bo.OLEPOClaimHistory;
5   import org.kuali.ole.select.businessobject.OlePurchaseOrderItem;
6   import org.kuali.ole.select.document.OlePurchaseOrderDocument;
7   import org.kuali.ole.select.form.OLEClaimingSearchForm;
8   import org.kuali.ole.sys.context.SpringContext;
9   import org.kuali.rice.krad.service.BusinessObjectService;
10  import org.kuali.rice.krad.service.KRADServiceLocator;
11  import org.kuali.rice.krad.util.GlobalVariables;
12  
13  import java.util.ArrayList;
14  import java.util.List;
15  
16  /**
17   * Created with IntelliJ IDEA.
18   * User: arunag
19   * Date: 4/7/14
20   * Time: 1:02 PM
21   * To change this template use File | Settings | File Templates.
22   */
23  public class OLEClaimingSearchService {
24      private BusinessObjectService businessObjectService;
25      public BusinessObjectService getBusinessObjectService() {
26          if (null == businessObjectService) {
27              businessObjectService = SpringContext.getBean(BusinessObjectService.class);
28          }
29          return businessObjectService;
30      }
31  
32      public void setBusinessObjectService(BusinessObjectService businessObjectService) {
33          this.businessObjectService = businessObjectService;
34      }
35  
36      public void getClaimResponse(OLEClaimingSearchForm oleClaimingSearchForm){
37          if (!GlobalVariables.getMessageMap().hasMessages()) {
38              oleClaimingSearchForm.setSuccessMsg("");
39              oleClaimingSearchForm.setClaimErrorMessage("");
40              String title = oleClaimingSearchForm.getTitle() != null ? oleClaimingSearchForm.getTitle() : "";
41              if (title.contains("*")) {
42                  title = title.replace("*", "").trim();
43              }
44              List<OLEPOClaimHistory> claimHistoryList = (List<OLEPOClaimHistory>) KRADServiceLocator.getBusinessObjectService().findAll(OLEPOClaimHistory.class);
45              List<OLEPOClaimHistory> claimHistoryFilterList = new ArrayList<>();
46              for (OLEPOClaimHistory claimHistory : claimHistoryList) {
47                  OlePurchaseOrderItem olePurchaseOrderItem = claimHistory.getOlePurchaseOrderItem();
48                  OlePurchaseOrderDocument olePurchaseOrderDocument = olePurchaseOrderItem.getPurapDocument();
49                  claimHistory.setVendorName(olePurchaseOrderDocument.getVendorName());
50                  claimHistory.setTitle(olePurchaseOrderItem.getItemDescription());
51                  if (((oleClaimingSearchForm.getVendorName() != null && !oleClaimingSearchForm.getVendorName().trim().isEmpty() && claimHistory.getVendorName().contains(oleClaimingSearchForm.getVendorName()))
52                          && (title == null || title.trim().isEmpty())
53                          && (oleClaimingSearchForm.getClaimDate() == null))  // VendorName Check
54                          || ((oleClaimingSearchForm.getVendorName() == null || oleClaimingSearchForm.getVendorName().trim().isEmpty())
55                          && (title != null && !title.trim().isEmpty() && claimHistory.getTitle().contains(title))
56                          && (oleClaimingSearchForm.getClaimDate() == null))  // Title Check
57                          || ((oleClaimingSearchForm.getVendorName() == null || oleClaimingSearchForm.getVendorName().trim().isEmpty())
58                          && (title == null || title.trim().isEmpty())
59                          && (oleClaimingSearchForm.getClaimDate() != null && oleClaimingSearchForm.getClaimDate().equals(claimHistory.getClaimDate()))) // ClaimDate Check
60                          || ((oleClaimingSearchForm.getVendorName() != null && !oleClaimingSearchForm.getVendorName().trim().isEmpty() && claimHistory.getVendorName().contains(oleClaimingSearchForm.getVendorName()))
61                          && (title != null && !title.trim().isEmpty() && claimHistory.getTitle().contains(title))
62                          && (oleClaimingSearchForm.getClaimDate() == null)) // VendorName and Title Check
63                          || ((oleClaimingSearchForm.getVendorName() != null && !oleClaimingSearchForm.getVendorName().trim().isEmpty() && claimHistory.getVendorName().contains(oleClaimingSearchForm.getVendorName()))
64                          && (title == null || title.trim().isEmpty())
65                          && (oleClaimingSearchForm.getClaimDate() != null && oleClaimingSearchForm.getClaimDate().equals(claimHistory.getClaimDate()))) // VendorName and ClaimDate Check
66                          || ((oleClaimingSearchForm.getVendorName() == null || oleClaimingSearchForm.getVendorName().trim().isEmpty())
67                          && (title != null && !title.trim().isEmpty() && claimHistory.getTitle().contains(title))
68                          && (oleClaimingSearchForm.getClaimDate() != null && oleClaimingSearchForm.getClaimDate().equals(claimHistory.getClaimDate())))  // Title and ClaimDate Check
69                          || ((oleClaimingSearchForm.getVendorName() != null && !oleClaimingSearchForm.getVendorName().trim().isEmpty() && claimHistory.getVendorName().contains(oleClaimingSearchForm.getVendorName()))
70                          && (title != null && !title.trim().isEmpty() && claimHistory.getTitle().contains(title))
71                          && (oleClaimingSearchForm.getClaimDate() != null && oleClaimingSearchForm.getClaimDate().equals(claimHistory.getClaimDate()))) // VendorName and Title and ClaimDate Check
72                          ) {
73                      claimHistoryFilterList.add(claimHistory);
74                  }
75              }
76              if (((oleClaimingSearchForm.getVendorName() == null || oleClaimingSearchForm.getVendorName().trim().isEmpty())
77                      && (title == null || title.trim().isEmpty())
78                      && (oleClaimingSearchForm.getClaimDate() == null))) {
79                  oleClaimingSearchForm.setOleClaimingSearchRecordList(claimHistoryList);
80              } else {
81                  oleClaimingSearchForm.setOleClaimingSearchRecordList(claimHistoryFilterList);
82              }
83              if (oleClaimingSearchForm.getOleClaimingSearchRecordList().size() == 0) {
84                  oleClaimingSearchForm.setClaimErrorMessage(OLEConstants.CLAIM_ERROR_MESSAGE);
85                  oleClaimingSearchForm.setOleClaimingSearchRecordList(null);
86              }
87          } else {
88              oleClaimingSearchForm.setOleClaimingSearchRecordList(null);
89          }
90  
91      }
92  
93      public void updateClaimNote(OLEClaimingSearchForm oleClaimingSearchForm ){
94          if (oleClaimingSearchForm.getOleClaimingSearchRecordList() != null && oleClaimingSearchForm.getOleClaimingSearchRecordList().size() > 0) {
95              KRADServiceLocator.getBusinessObjectService().save(oleClaimingSearchForm.getOleClaimingSearchRecordList());
96          }
97          oleClaimingSearchForm.setSuccessMsg("Updated Claim Response Information successfully");
98      }
99  
100 }