1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.dataaccess.impl;
17
18 import java.sql.Date;
19 import java.util.Iterator;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.ojb.broker.query.Criteria;
23 import org.apache.ojb.broker.query.QueryFactory;
24 import org.apache.ojb.broker.query.ReportQueryByCriteria;
25 import org.kuali.ole.coa.businessobject.AccountDelegate;
26 import org.kuali.ole.coa.dataaccess.AccountDelegateDao;
27 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
28 import org.kuali.rice.krad.maintenance.MaintenanceLock;
29 import org.kuali.rice.krad.util.KRADPropertyConstants;
30
31
32
33
34 public class AccountDelegateDaoOjb extends PlatformAwareDaoBaseOjb implements AccountDelegateDao {
35
36
37
38
39
40 public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
41 String lockingDocNumber = "";
42
43
44 Criteria criteria = new Criteria();
45 criteria.addEqualTo("lockingRepresentation", lockingRepresentation);
46
47
48
49 if (StringUtils.isNotBlank(documentNumber)) {
50 criteria.addNotEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber);
51 }
52
53
54 MaintenanceLock maintenanceLock = (MaintenanceLock) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria));
55
56
57
58 if (maintenanceLock != null) {
59 lockingDocNumber = maintenanceLock.getDocumentNumber();
60 }
61 return lockingDocNumber;
62 }
63
64
65
66
67 public Iterator<AccountDelegate> getAccountDelegationsForPerson(String principalId, boolean primary) {
68 Criteria criteria = new Criteria();
69 criteria.addEqualTo("accountDelegateSystemId", principalId);
70 criteria.addEqualTo("active", "Y");
71 criteria.addEqualTo("accountsDelegatePrmrtIndicator", primary);
72
73 return (Iterator<AccountDelegate>) getPersistenceBrokerTemplate().getIteratorByQuery(QueryFactory.newQuery(AccountDelegate.class, criteria));
74 }
75
76
77
78
79 public boolean isPrincipalInAnyWayShapeOrFormPrimaryAccountDelegate(String principalId, Date currentSqlDate) {
80 return queryPrincipalIsAccountDelegate(principalId, true, currentSqlDate);
81 }
82
83
84
85
86 public boolean isPrincipalInAnyWayShapeOrFormSecondaryAccountDelegate(String principalId, Date currentSqlDate) {
87 return queryPrincipalIsAccountDelegate(principalId, false, currentSqlDate);
88 }
89
90
91
92
93
94
95
96
97
98 protected boolean queryPrincipalIsAccountDelegate(String principalId, boolean primary, Date currentSqlDate) {
99 Criteria criteria = new Criteria();
100 criteria.addEqualTo("accountDelegateSystemId", principalId);
101 criteria.addEqualTo("accountsDelegatePrmrtIndicator", (primary ? "Y" : "N"));
102 criteria.addEqualTo("active", "Y");
103 criteria.addEqualTo("account.active", "Y");
104 criteria.addLessOrEqualThan("accountDelegateStartDate", currentSqlDate);
105
106 ReportQueryByCriteria reportQuery = QueryFactory.newReportQuery(AccountDelegate.class, criteria);
107 reportQuery.setAttributes(new String[] { "count(*)" });
108
109 int resultCount = 0;
110
111 Iterator iter = getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(reportQuery);
112 while (iter.hasNext()) {
113 final Object[] results = (Object[]) iter.next();
114 resultCount = (results[0] instanceof Number) ? ((Number) results[0]).intValue() : new Integer(results[0].toString()).intValue();
115 }
116 return resultCount > 0;
117 }
118 }