View Javadoc
1   package org.kuali.ole.select.lookup;
2   
3   import org.kuali.ole.coa.businessobject.Account;
4   import org.kuali.ole.select.OleSelectConstant;
5   import org.kuali.ole.sys.OLEKeyConstants;
6   import org.kuali.ole.sys.OLEPropertyConstants;
7   import org.kuali.ole.sys.context.SpringContext;
8   import org.kuali.ole.vnd.businessobject.VendorDetail;
9   import org.kuali.rice.coreservice.framework.parameter.ParameterService;
10  import org.kuali.rice.krad.bo.BusinessObject;
11  import org.kuali.rice.krad.lookup.LookupableImpl;
12  import org.kuali.rice.krad.service.BusinessObjectService;
13  import org.kuali.rice.krad.util.GlobalVariables;
14  import org.kuali.rice.krad.web.form.LookupForm;
15  
16  import java.util.ArrayList;
17  import java.util.HashMap;
18  import java.util.List;
19  import java.util.Map;
20  
21  /**
22   * Created with IntelliJ IDEA.
23   * User: anithaa
24   * Date: 7/11/13
25   * Time: 3:16 PM
26   * To change this template use File | Settings | File Templates.
27   */
28  
29  public class OLEAccountLookupableImpl extends LookupableImpl {
30      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OLEAccountLookupableImpl.class);
31      protected static ParameterService parameterService;
32  
33      public ParameterService getParameterService() {
34          if (parameterService == null) {
35              parameterService = SpringContext.getBean(ParameterService.class);
36          }
37          return parameterService;
38      }
39  
40      public List<? extends BusinessObject> getSearchResults(LookupForm form, Map<String, String> parameters, boolean unbounded) {
41          Map<String, String> activeMap = new HashMap<String, String>();
42          List<Account> accountDetails = new ArrayList<Account>();
43  
44          boolean flag = false;
45          if (parameters.containsKey(OLEPropertyConstants.CLOSED)) {
46              final String closedValue = parameters.get(OLEPropertyConstants.CLOSED);
47              if (closedValue != null && closedValue.length() != 0) {
48                  if ("Y1T".indexOf(closedValue) > -1) {
49                      parameters.put(OLEPropertyConstants.ACTIVE, "N");
50                  } else if ("N0F".indexOf(closedValue) > -1) {
51                      parameters.put(OLEPropertyConstants.ACTIVE, "Y");
52                  }
53              }
54  
55              parameters.remove(OLEPropertyConstants.CLOSED);
56          }
57  
58          // Modified for JIRA OLE-2519 starts
59  
60          final String restrictedValue = parameters.get(OleSelectConstant.RESTRICTED);
61          boolean containsChartCode = false;
62          if (!"".equals(parameters.get(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE))) {
63              containsChartCode = true;
64          }
65          if (parameters.containsKey(OleSelectConstant.RESTRICTED)) {
66  
67              if (restrictedValue.equalsIgnoreCase("Y")) {
68                  parameters.put(OLEPropertyConstants.ACCOUNT_RESTRICTED_STATUS_CODE, "T|R");
69              } else if (restrictedValue.equalsIgnoreCase("N")) {
70                  parameters.put(OLEPropertyConstants.ACCOUNT_RESTRICTED_STATUS_CODE, "U|N");
71              }
72          }
73          parameters.remove(OleSelectConstant.RESTRICTED);
74          String subFundGroupCodeValue = parameters.get(OleSelectConstant.SUBFUND_GROUP_CODE);
75          String vendorNameValue = parameters.get(OleSelectConstant.VENDOR_NAME);
76          String subFundGroupParameter = getParameterService()
77                  .getParameterValueAsString(Account.class, OleSelectConstant.SUB_FUND_GRP_CD);
78          if (subFundGroupCodeValue.equalsIgnoreCase(subFundGroupParameter) && vendorNameValue.isEmpty()) {
79  
80              parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
81              GlobalVariables.getMessageMap().putError(OleSelectConstant.VENDOR_NAME, OLEKeyConstants.ERROR_VENDOR_DEPOSIT_ACCOUNT);
82              flag = true;
83  
84          } else if ((!subFundGroupCodeValue.equalsIgnoreCase(subFundGroupParameter) || (subFundGroupCodeValue
85                  .isEmpty())) && !vendorNameValue.isEmpty()) {
86  
87              parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
88              GlobalVariables.getMessageMap().putError(OleSelectConstant.VENDOR_NAME, OLEKeyConstants.ERROR_SUBFUND_GROUP_CODE);
89              flag = true;
90          }
91          if (!flag) {
92              final String vendorDepositAccount = parameters.get(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
93              if (vendorDepositAccount.equalsIgnoreCase("true")) {    //exclude vendor deposit account
94  
95                  Map vendorMap = new HashMap();
96                  if (parameters.get("vendorName") != null) {
97                      vendorMap.put("vendorName", parameters.get("vendorName"));
98                  }
99                  List<VendorDetail> vendor = (List<VendorDetail>) SpringContext.getBean(BusinessObjectService.class).findMatching(VendorDetail.class, vendorMap);
100                 if (vendor.size() > 0) {
101                     Integer vendorHeaderGeneratedIdentifier = vendor.get(0).getVendorHeaderGeneratedIdentifier();
102                     parameters.put("vendorHeaderGeneratedIdentifier", vendorHeaderGeneratedIdentifier.toString());
103                 }
104 
105                 parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
106 
107                 parameters.put(OleSelectConstant.VENDOR_NAME, "");
108                 accountDetails = (List<Account>) super.getSearchResults(form, parameters, unbounded);
109                 for (int vendorKey = 0; vendorKey < accountDetails.size(); vendorKey++) {
110                     accountDetails.get(vendorKey).setVendorHeaderGeneratedIdentifier(null);
111                     accountDetails.get(vendorKey).setVendorDetailAssignedIdentifier(null);
112                 }
113 
114             } else {  //include vendor deposit account
115 
116                 parameters.remove(OleSelectConstant.VENDOR_DEPOSIT_ACCOUNT);
117                 parameters.remove(OleSelectConstant.VENDOR_NAME);
118                 accountDetails = (List<Account>) super.getSearchResults(form, parameters, unbounded);
119                 if (containsChartCode) {
120                     if (restrictedValue.equalsIgnoreCase("N")) {
121                         for (int i = 0; i < accountDetails.size(); i++) {
122                             if (accountDetails.get(i).getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_TEMPORARY_RESTRICTED_CODE) || accountDetails.get(i).getAccountRestrictedStatusCode().equalsIgnoreCase(OleSelectConstant.ACCOUNT_RESTRICTED_CODE)) {
123                                 accountDetails.remove(i);
124                             }
125                         }
126                     }
127                 }
128             }
129         }
130 
131         return accountDetails;
132     }
133 
134 
135 }
136 
137