1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
package org.kuali.rice.kew.actionitem.dao.impl; |
15 | |
|
16 | |
import java.sql.Timestamp; |
17 | |
import java.util.Collection; |
18 | |
import java.util.Date; |
19 | |
import java.util.HashMap; |
20 | |
import java.util.Iterator; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import org.apache.commons.collections.CollectionUtils; |
25 | |
import org.apache.log4j.Logger; |
26 | |
import org.apache.ojb.broker.query.Criteria; |
27 | |
import org.apache.ojb.broker.query.QueryByCriteria; |
28 | |
import org.apache.ojb.broker.query.QueryFactory; |
29 | |
import org.apache.ojb.broker.query.ReportQueryByCriteria; |
30 | |
import org.kuali.rice.kew.actionitem.ActionItem; |
31 | |
import org.kuali.rice.kew.actionitem.OutboxItemActionListExtension; |
32 | |
import org.kuali.rice.kew.actionitem.dao.ActionItemDAO; |
33 | |
import org.kuali.rice.kew.actionrequest.KimGroupRecipient; |
34 | |
import org.kuali.rice.kew.actionrequest.Recipient; |
35 | |
import org.kuali.rice.kew.util.KEWConstants; |
36 | |
import org.kuali.rice.kew.util.WebFriendlyRecipient; |
37 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
38 | |
import org.kuali.rice.kim.bo.Person; |
39 | |
import org.kuali.rice.kim.api.services.IdentityManagementService; |
40 | |
import org.springmodules.orm.ojb.support.PersistenceBrokerDaoSupport; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class ActionItemDAOOjbImpl extends PersistenceBrokerDaoSupport implements ActionItemDAO { |
47 | |
|
48 | |
|
49 | 0 | private static final Logger LOG = Logger.getLogger(ActionItemDAOOjbImpl.class); |
50 | |
|
51 | |
|
52 | |
public ActionItem findByActionItemId(Long actionItemId) { |
53 | 0 | Criteria crit = new Criteria(); |
54 | 0 | crit.addEqualTo("actionItemId", actionItemId); |
55 | 0 | return (ActionItem) this.getPersistenceBrokerTemplate().getObjectByQuery(new QueryByCriteria(ActionItem.class, crit)); |
56 | |
} |
57 | |
|
58 | |
public void deleteActionItems(Long actionRequestId) { |
59 | 0 | Criteria crit = new Criteria(); |
60 | 0 | crit.addEqualTo("actionRequestId", actionRequestId); |
61 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionItem.class, crit)); |
62 | 0 | } |
63 | |
|
64 | |
public void deleteActionItem(ActionItem actionItem) { |
65 | 0 | this.getPersistenceBrokerTemplate().delete(actionItem); |
66 | 0 | } |
67 | |
|
68 | |
public void deleteByDocumentIdWorkflowUserId(String documentId, String workflowUserId) { |
69 | 0 | Criteria crit = new Criteria(); |
70 | 0 | crit.addEqualTo("documentId", documentId); |
71 | 0 | crit.addEqualTo("principalId", workflowUserId); |
72 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionItem.class, crit)); |
73 | 0 | } |
74 | |
|
75 | |
public void deleteByDocumentId(String documentId) { |
76 | 0 | Criteria crit = new Criteria(); |
77 | 0 | crit.addEqualTo("documentId", documentId); |
78 | 0 | this.getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(ActionItem.class, crit)); |
79 | 0 | } |
80 | |
|
81 | |
public Collection<ActionItem> findByWorkflowUserDocumentId(String workflowId, String documentId) { |
82 | 0 | Criteria crit = new Criteria(); |
83 | 0 | crit.addEqualTo("principalId", workflowId); |
84 | 0 | crit.addEqualTo("documentId", documentId); |
85 | 0 | return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionItem.class, crit)); |
86 | |
} |
87 | |
|
88 | |
public Collection<ActionItem> findByDocumentId(String documentId) { |
89 | 0 | Criteria crit = new Criteria(); |
90 | 0 | crit.addEqualTo("documentId", documentId); |
91 | 0 | return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionItem.class, crit)); |
92 | |
} |
93 | |
|
94 | |
public Collection<ActionItem> findByActionRequestId(Long actionRequestId) { |
95 | 0 | Criteria crit = new Criteria(); |
96 | 0 | crit.addEqualTo("actionRequestId", actionRequestId); |
97 | 0 | return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(ActionItem.class, crit)); |
98 | |
} |
99 | |
|
100 | |
public Collection<ActionItem> findByDocumentTypeName(String documentTypeName) { |
101 | 0 | return getItemsByDocumentType(ActionItem.class, documentTypeName); |
102 | |
} |
103 | |
|
104 | |
public Collection<ActionItem> getOutboxItemsByDocumentType(String documentTypeName) { |
105 | 0 | return getItemsByDocumentType(OutboxItemActionListExtension.class, documentTypeName); |
106 | |
} |
107 | |
|
108 | |
private Collection<ActionItem> getItemsByDocumentType(Class<? extends ActionItem> objectClass, String documentTypeName) { |
109 | 0 | Criteria crit = new Criteria(); |
110 | 0 | crit.addEqualTo("docName", documentTypeName); |
111 | 0 | return this.getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(objectClass, crit)); |
112 | |
} |
113 | |
|
114 | |
public void saveActionItem(ActionItem actionItem) { |
115 | 0 | if (actionItem.getDateAssigned() == null) { |
116 | 0 | actionItem.setDateAssigned(new Timestamp(new Date().getTime())); |
117 | |
} |
118 | 0 | this.getPersistenceBrokerTemplate().store(actionItem); |
119 | 0 | } |
120 | |
|
121 | |
public Collection<Recipient> findSecondaryDelegators(String principalId) { |
122 | 0 | Criteria notNullWorkflowCriteria = new Criteria(); |
123 | 0 | notNullWorkflowCriteria.addNotNull("delegatorWorkflowId"); |
124 | 0 | Criteria notNullWorkgroupCriteria = new Criteria(); |
125 | 0 | notNullWorkgroupCriteria.addNotNull("delegatorGroupId"); |
126 | 0 | Criteria orCriteria = new Criteria(); |
127 | 0 | orCriteria.addOrCriteria(notNullWorkflowCriteria); |
128 | 0 | orCriteria.addOrCriteria(notNullWorkgroupCriteria); |
129 | 0 | Criteria criteria = new Criteria(); |
130 | 0 | criteria.addEqualTo("principalId", principalId); |
131 | 0 | criteria.addEqualTo("delegationType", KEWConstants.DELEGATION_SECONDARY); |
132 | 0 | criteria.addAndCriteria(orCriteria); |
133 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(ActionItem.class, criteria); |
134 | |
|
135 | 0 | query.setAttributes(new String[]{"delegatorWorkflowId", "delegatorGroupId"}); |
136 | 0 | Map<Object, Recipient> delegators = new HashMap<Object, Recipient>(); |
137 | 0 | Iterator iterator = this.getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); |
138 | 0 | while (iterator.hasNext()) { |
139 | 0 | Object[] ids = (Object[]) iterator.next(); |
140 | 0 | if (ids[0] != null && !delegators.containsKey((String) ids[0])) { |
141 | 0 | WebFriendlyRecipient rec = new WebFriendlyRecipient(KimApiServiceLocator.getPersonService().getPerson((String) ids[0])); |
142 | 0 | delegators.put((String) ids[0], rec); |
143 | 0 | } else if (ids[1] != null) { |
144 | 0 | String workgroupId = ids[1].toString(); |
145 | 0 | if (!delegators.containsKey(workgroupId)) { |
146 | 0 | delegators.put(workgroupId, new KimGroupRecipient(getIdentityManagementService().getGroup(workgroupId))); |
147 | |
} |
148 | |
} |
149 | 0 | } |
150 | 0 | return delegators.values(); |
151 | |
} |
152 | |
|
153 | |
public Collection<Recipient> findPrimaryDelegationRecipients(String principalId) { |
154 | 0 | List<String> workgroupIds = KimApiServiceLocator.getIdentityManagementService().getGroupIdsForPrincipal(principalId); |
155 | 0 | Criteria orCriteria = new Criteria(); |
156 | 0 | Criteria delegatorWorkflowIdCriteria = new Criteria(); |
157 | 0 | delegatorWorkflowIdCriteria.addEqualTo("delegatorWorkflowId", principalId); |
158 | 0 | if (CollectionUtils.isNotEmpty(workgroupIds)) { |
159 | 0 | Criteria delegatorWorkgroupCriteria = new Criteria(); |
160 | 0 | delegatorWorkgroupCriteria.addIn("delegatorGroupId", workgroupIds); |
161 | 0 | orCriteria.addOrCriteria(delegatorWorkgroupCriteria); |
162 | 0 | orCriteria.addOrCriteria(delegatorWorkflowIdCriteria); |
163 | 0 | } |
164 | |
else { |
165 | 0 | orCriteria.addAndCriteria(delegatorWorkflowIdCriteria); |
166 | |
} |
167 | 0 | Criteria criteria = new Criteria(); |
168 | 0 | criteria.addEqualTo("delegationType", KEWConstants.DELEGATION_PRIMARY); |
169 | 0 | criteria.addAndCriteria(orCriteria); |
170 | 0 | ReportQueryByCriteria query = QueryFactory.newReportQuery(ActionItem.class, criteria, true); |
171 | |
|
172 | 0 | query.setAttributes(new String[]{"principalId"}); |
173 | 0 | Map<Object, Recipient> delegators = new HashMap<Object, Recipient>(); |
174 | 0 | Iterator iterator = this.getPersistenceBrokerTemplate().getReportQueryIteratorByQuery(query); |
175 | 0 | while (iterator.hasNext()) { |
176 | 0 | Object[] ids = (Object[]) iterator.next(); |
177 | 0 | if (ids[0] != null && !delegators.containsKey((String) ids[0])) { |
178 | |
|
179 | 0 | Person person = KimApiServiceLocator.getPersonService().getPerson((String) ids[0]); |
180 | 0 | if (person != null) { |
181 | 0 | WebFriendlyRecipient rec = new WebFriendlyRecipient(person); |
182 | 0 | delegators.put((String) ids[0],rec); |
183 | 0 | LOG.warn("The name for " + (String) ids[0] + " was not added to the primary delegate drop down list because the delegate does not exist."); |
184 | |
} |
185 | |
|
186 | |
} |
187 | 0 | } |
188 | 0 | return delegators.values(); |
189 | |
} |
190 | |
|
191 | |
private IdentityManagementService getIdentityManagementService() { |
192 | 0 | return KimApiServiceLocator.getIdentityManagementService(); |
193 | |
} |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
public Collection<ActionItem> findByPrincipalId(String principalId) { |
201 | 0 | Criteria crit = new Criteria(); |
202 | 0 | crit.addEqualTo("principalId", principalId); |
203 | 0 | QueryByCriteria query = new QueryByCriteria(ActionItem.class, crit); |
204 | 0 | query.addOrderByAscending("documentId"); |
205 | 0 | return this.getPersistenceBrokerTemplate().getCollectionByQuery(query); |
206 | |
} |
207 | |
|
208 | |
} |