View Javadoc
1   package org.kuali.ole.select.service;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.apache.log4j.Logger;
5   import org.apache.ojb.broker.query.Criteria;
6   import org.apache.ojb.broker.query.QueryByCriteria;
7   import org.apache.ojb.broker.query.QueryFactory;
8   import org.kuali.ole.OLEConstants;
9   import org.kuali.ole.coa.businessobject.OleFundCodeAccountingLine;
10  import org.kuali.ole.module.purap.businessobject.PurApAccountingLine;
11  import org.kuali.rice.core.api.config.property.ConfigContext;
12  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
13  
14  import java.util.List;
15  
16  /**
17   * Created by angelind on 6/12/15.
18   */
19  public class OLESelectDaoOjb extends PlatformAwareDaoBaseOjb {
20      private static final Logger LOG = Logger.getLogger(OLESelectDaoOjb.class);
21  
22      public List<OleFundCodeAccountingLine> getFundCodeList(PurApAccountingLine purApAccountingLine) {
23          String dbVendor = ConfigContext.getCurrentContextConfig().getProperty("db.vendor");
24          Criteria criteria = new Criteria();
25          criteria.addEqualTo(OLEConstants.CHART_CODE, purApAccountingLine.getChartOfAccountsCode());
26          criteria.addEqualTo(OLEConstants.ACCOUNT_NUMBER, purApAccountingLine.getAccountNumber());
27          criteria.addEqualTo(OLEConstants.OBJECT_CODE, purApAccountingLine.getFinancialObjectCode());
28          criteria.addEqualTo(OLEConstants.ACCOUNT_LINE_PERCENT, purApAccountingLine.getAccountLinePercent());
29          if(StringUtils.isNotBlank(purApAccountingLine.getSubAccountNumber())){
30              criteria.addEqualTo(OLEConstants.SUB_ACCOUNT, purApAccountingLine.getSubAccountNumber());
31          } else {
32              if(dbVendor.equalsIgnoreCase("oracle")){
33                  criteria.addIsNull(OLEConstants.SUB_ACCOUNT);
34              }else{
35                  criteria.addEqualTo(OLEConstants.SUB_ACCOUNT, "");
36              }
37          }
38          if(StringUtils.isNotBlank(purApAccountingLine.getFinancialSubObjectCode())){
39              criteria.addEqualTo(OLEConstants.SUB_OBJECT, purApAccountingLine.getFinancialSubObjectCode());
40          } else {
41              if(dbVendor.equalsIgnoreCase("oracle")){
42                  criteria.addIsNull(OLEConstants.SUB_OBJECT);
43              } else {
44                  criteria.addEqualTo(OLEConstants.SUB_OBJECT, "");
45              }
46          }
47          if(StringUtils.isNotBlank(purApAccountingLine.getProjectCode())){
48              criteria.addEqualTo(OLEConstants.PROJECT, purApAccountingLine.getProjectCode());
49          } else {
50              if(dbVendor.equalsIgnoreCase("oracle")){
51                  criteria.addIsNull(OLEConstants.PROJECT);
52              } else {
53                  criteria.addEqualTo(OLEConstants.PROJECT,"");
54              }
55          }
56          if(StringUtils.isNotBlank(purApAccountingLine.getOrganizationReferenceId())){
57              criteria.addEqualTo(OLEConstants.ORG_REF_ID,purApAccountingLine.getOrganizationReferenceId());
58          } else {
59              if(dbVendor.equalsIgnoreCase("oracle")){
60                  criteria.addIsNull(OLEConstants.ORG_REF_ID);
61              } else {
62                  criteria.addEqualTo(OLEConstants.ORG_REF_ID, "");
63              }
64          }
65          QueryByCriteria query = QueryFactory.newQuery(OleFundCodeAccountingLine.class, criteria);
66          return (List<OleFundCodeAccountingLine>)getPersistenceBrokerTemplate().getCollectionByQuery
67                  (query);
68      }
69  
70  }