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 org.apache.commons.lang.StringUtils;
19 import org.apache.ojb.broker.query.Criteria;
20 import org.apache.ojb.broker.query.QueryFactory;
21 import org.kuali.ole.coa.dataaccess.AccountDelegateGlobalDao;
22 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
23 import org.kuali.rice.krad.maintenance.MaintenanceLock;
24 import org.kuali.rice.krad.util.KRADPropertyConstants;
25
26
27
28
29 public class AccountDelegateGlobalDaoOjb extends PlatformAwareDaoBaseOjb implements AccountDelegateGlobalDao {
30
31
32
33
34
35
36 public String getLockingDocumentNumber(String lockingRepresentation, String documentNumber) {
37 String lockingDocNumber = "";
38
39 lockingRepresentation = convertForLikeCriteria(lockingRepresentation);
40
41
42 Criteria criteria = new Criteria();
43 criteria.addLike("lockingRepresentation", lockingRepresentation);
44
45
46
47 if (StringUtils.isNotBlank(documentNumber)) {
48 criteria.addNotEqualTo(KRADPropertyConstants.DOCUMENT_NUMBER, documentNumber);
49 }
50
51
52 MaintenanceLock maintenanceLock = (MaintenanceLock) getPersistenceBrokerTemplate().getObjectByQuery(QueryFactory.newQuery(MaintenanceLock.class, criteria));
53
54
55
56 if (maintenanceLock != null) {
57 lockingDocNumber = maintenanceLock.getDocumentNumber();
58 }
59 return lockingDocNumber;
60 }
61
62
63
64
65
66
67
68
69 protected String convertForLikeCriteria(String lockingRepresentation) {
70
71 String[] values = StringUtils.split(lockingRepresentation, "::");
72 StringBuilder sb = new StringBuilder();
73 for (String val : values) {
74 if (val.startsWith("financialDocumentTypeCode")) {
75 String[] meh = StringUtils.split(val, "^^");
76 meh[1] = "%";
77 val = meh[0] +"^^"+meh[1];
78 sb.append(val);
79 break;
80 } else {
81 sb.append(val+"::");
82 }
83 }
84
85 return sb.toString();
86 }
87 }