1 | |
package org.kuali.rice.kim.impl.responsibility; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.apache.commons.logging.Log; |
5 | |
import org.apache.commons.logging.LogFactory; |
6 | |
import org.kuali.rice.core.api.criteria.CriteriaLookupService; |
7 | |
import org.kuali.rice.core.api.criteria.GenericQueryResults; |
8 | |
import org.kuali.rice.core.api.criteria.LookupCustomizer; |
9 | |
import org.kuali.rice.core.api.criteria.Predicate; |
10 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
11 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
12 | |
import org.kuali.rice.core.api.exception.RiceIllegalStateException; |
13 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
14 | |
import org.kuali.rice.kim.api.common.delegate.DelegateType; |
15 | |
import org.kuali.rice.kim.api.common.template.Template; |
16 | |
import org.kuali.rice.kim.api.common.template.TemplateQueryResults; |
17 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
18 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityAction; |
19 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityQueryResults; |
20 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityService; |
21 | |
import org.kuali.rice.kim.api.role.Role; |
22 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
23 | |
import org.kuali.rice.kim.api.role.RoleResponsibilityAction; |
24 | |
import org.kuali.rice.kim.api.role.RoleService; |
25 | |
import org.kuali.rice.kim.api.type.KimType; |
26 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService; |
27 | |
import org.kuali.rice.kim.impl.common.attribute.AttributeTransform; |
28 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo; |
29 | |
import org.kuali.rice.kim.impl.role.RoleResponsibilityActionBo; |
30 | |
import org.kuali.rice.kim.impl.role.RoleResponsibilityBo; |
31 | |
import org.kuali.rice.kim.util.KIMPropertyConstants; |
32 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
33 | |
|
34 | |
import java.util.ArrayList; |
35 | |
import java.util.Collection; |
36 | |
import java.util.Collections; |
37 | |
import java.util.HashMap; |
38 | |
import java.util.Iterator; |
39 | |
import java.util.List; |
40 | |
import java.util.Map; |
41 | |
|
42 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.*; |
43 | |
|
44 | 0 | public class ResponsibilityServiceImpl implements ResponsibilityService { |
45 | |
|
46 | 0 | private static final Integer DEFAULT_PRIORITY_NUMBER = Integer.valueOf(1); |
47 | 0 | private static final Log LOG = LogFactory.getLog(ResponsibilityServiceImpl.class); |
48 | |
|
49 | |
private BusinessObjectService businessObjectService; |
50 | |
private CriteriaLookupService criteriaLookupService; |
51 | |
private KimResponsibilityTypeService defaultResponsibilityTypeService; |
52 | |
private KimTypeInfoService kimTypeInfoService; |
53 | |
private RoleService roleService; |
54 | |
|
55 | |
@Override |
56 | |
public Responsibility createResponsibility(final Responsibility responsibility) throws RiceIllegalArgumentException, RiceIllegalStateException { |
57 | 0 | if (responsibility == null) { |
58 | 0 | throw new RiceIllegalArgumentException("responsibility is null"); |
59 | |
} |
60 | |
|
61 | 0 | if (StringUtils.isNotBlank(responsibility.getId()) && getResponsibility(responsibility.getId()) != null) { |
62 | 0 | throw new RiceIllegalStateException("the responsibility to create already exists: " + responsibility); |
63 | |
} |
64 | 0 | List<ResponsibilityAttributeBo> attrBos = KimAttributeDataBo.createFrom(ResponsibilityAttributeBo.class, responsibility.getAttributes(), responsibility.getTemplate().getKimTypeId()); |
65 | 0 | ResponsibilityBo bo = ResponsibilityBo.from(responsibility); |
66 | 0 | bo.setAttributeDetails(attrBos); |
67 | 0 | return ResponsibilityBo.to(businessObjectService.save(bo)); |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public Responsibility updateResponsibility(final Responsibility responsibility) throws RiceIllegalArgumentException, RiceIllegalStateException { |
72 | 0 | if (responsibility == null) { |
73 | 0 | throw new RiceIllegalArgumentException("responsibility is null"); |
74 | |
} |
75 | |
|
76 | 0 | if (StringUtils.isBlank(responsibility.getId()) || getResponsibility(responsibility.getId()) == null) { |
77 | 0 | throw new RiceIllegalStateException("the responsibility does not exist: " + responsibility); |
78 | |
} |
79 | |
|
80 | 0 | List<ResponsibilityAttributeBo> attrBos = KimAttributeDataBo.createFrom(ResponsibilityAttributeBo.class, responsibility.getAttributes(), responsibility.getTemplate().getKimTypeId()); |
81 | 0 | ResponsibilityBo bo = ResponsibilityBo.from(responsibility); |
82 | 0 | bo.getAttributeDetails().addAll(attrBos); |
83 | 0 | return ResponsibilityBo.to(businessObjectService.save(bo)); |
84 | |
} |
85 | |
|
86 | |
@Override |
87 | |
public Responsibility getResponsibility(final String id) { |
88 | 0 | if (id == null) { |
89 | 0 | throw new RiceIllegalArgumentException("id is null"); |
90 | |
} |
91 | |
|
92 | 0 | return ResponsibilityBo.to(businessObjectService.findBySinglePrimaryKey(ResponsibilityBo.class, id)); |
93 | |
} |
94 | |
|
95 | |
@Override |
96 | |
public Responsibility findRespByNamespaceCodeAndName(final String namespaceCode, final String name) { |
97 | 0 | if (namespaceCode == null) { |
98 | 0 | throw new RiceIllegalArgumentException("namespaceCode is null"); |
99 | |
} |
100 | |
|
101 | 0 | if (name == null) { |
102 | 0 | throw new RiceIllegalArgumentException("name is null"); |
103 | |
} |
104 | |
|
105 | 0 | final Map<String, String> crit = new HashMap<String, String>(); |
106 | 0 | crit.put("namespaceCode", namespaceCode); |
107 | 0 | crit.put("name", name); |
108 | 0 | crit.put("active", "Y"); |
109 | |
|
110 | 0 | final Collection<ResponsibilityBo> bos = businessObjectService.findMatching(ResponsibilityBo.class, Collections.unmodifiableMap(crit)); |
111 | |
|
112 | 0 | if (bos != null) { |
113 | 0 | if (bos.size() > 1) { |
114 | 0 | throw new RiceIllegalStateException("more than one Responsibility found with namespace code: " + namespaceCode + " and name: " + name); |
115 | |
} |
116 | |
|
117 | 0 | final Iterator<ResponsibilityBo> i = bos.iterator(); |
118 | 0 | return i.hasNext() ? ResponsibilityBo.to(i.next()) : null; |
119 | |
} |
120 | 0 | return null; |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
public Template getResponsibilityTemplate(final String id) { |
125 | 0 | if (id == null) { |
126 | 0 | throw new RiceIllegalArgumentException("id is null"); |
127 | |
} |
128 | |
|
129 | 0 | return ResponsibilityTemplateBo.to(businessObjectService.findBySinglePrimaryKey(ResponsibilityTemplateBo.class, id)); |
130 | |
} |
131 | |
|
132 | |
@Override |
133 | |
public Template findRespTemplateByNamespaceCodeAndName(final String namespaceCode, final String name) { |
134 | 0 | if (namespaceCode == null) { |
135 | 0 | throw new RiceIllegalArgumentException("namespaceCode is null"); |
136 | |
} |
137 | |
|
138 | 0 | if (name == null) { |
139 | 0 | throw new RiceIllegalArgumentException("name is null"); |
140 | |
} |
141 | |
|
142 | 0 | final Map<String, String> crit = new HashMap<String, String>(); |
143 | 0 | crit.put("namespaceCode", namespaceCode); |
144 | 0 | crit.put("name", name); |
145 | 0 | crit.put("active", "Y"); |
146 | |
|
147 | 0 | final Collection<ResponsibilityTemplateBo> bos = businessObjectService.findMatching(ResponsibilityTemplateBo.class, Collections.unmodifiableMap(crit)); |
148 | 0 | if (bos != null) { |
149 | 0 | if (bos.size() > 1) { |
150 | 0 | throw new RiceIllegalStateException("more than one Responsibility Template found with namespace code: " + namespaceCode + " and name: " + name); |
151 | |
} |
152 | |
|
153 | 0 | final Iterator<ResponsibilityTemplateBo> i = bos.iterator(); |
154 | 0 | return i.hasNext() ? ResponsibilityTemplateBo.to(i.next()) : null; |
155 | |
} |
156 | 0 | return null; |
157 | |
} |
158 | |
|
159 | |
@Override |
160 | |
public boolean hasResponsibility(final String principalId, final String namespaceCode, final String respName, final Map<String, String> qualification, final Map<String, String> responsibilityDetails) { |
161 | |
|
162 | 0 | final List<Responsibility> responsibilities = Collections.singletonList(findRespByNamespaceCodeAndName(namespaceCode, respName)); |
163 | 0 | return hasResp(principalId, namespaceCode, responsibilities, qualification, responsibilityDetails); |
164 | |
} |
165 | |
|
166 | |
@Override |
167 | |
public boolean hasResponsibilityByTemplateName(final String principalId, final String namespaceCode, final String respTemplateName, final Map<String, String> qualification, final Map<String, String> responsibilityDetails) { |
168 | |
|
169 | 0 | final List<Responsibility> responsibilities = findRespsByNamespaceCodeAndTemplateName(namespaceCode, respTemplateName); |
170 | 0 | return hasResp(principalId, namespaceCode, responsibilities, qualification, responsibilityDetails); |
171 | |
} |
172 | |
|
173 | |
private boolean hasResp(final String principalId, final String namespaceCode, final List<Responsibility> responsibilities, final Map<String, String> qualification, final Map<String, String> responsibilityDetails) { |
174 | |
|
175 | 0 | final List<String> ids = new ArrayList<String>(); |
176 | 0 | for (Responsibility r : getMatchingResponsibilities(responsibilities, responsibilityDetails)) { |
177 | 0 | ids.add(r.getId()); |
178 | |
} |
179 | 0 | final List<String> roleIds = getRoleIdsForResponsibilities(ids, qualification); |
180 | 0 | return roleService.principalHasRole(principalId, roleIds, qualification); |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public List<ResponsibilityAction> getResponsibilityActions(final String namespaceCode, final String responsibilityName, final Map<String, String> qualification, final Map<String, String> responsibilityDetails) { |
185 | |
|
186 | 0 | List<Responsibility> responsibilities = Collections.singletonList(findRespByNamespaceCodeAndName(namespaceCode, responsibilityName)); |
187 | 0 | return getRespActions(namespaceCode, responsibilities, qualification, responsibilityDetails); |
188 | |
} |
189 | |
|
190 | |
@Override |
191 | |
public List<ResponsibilityAction> getResponsibilityActionsByTemplateName(final String namespaceCode, final String respTemplateName, final Map<String, String> qualification, final Map<String, String> responsibilityDetails) { |
192 | |
|
193 | 0 | List<Responsibility> responsibilities = findRespsByNamespaceCodeAndTemplateName(namespaceCode, respTemplateName); |
194 | 0 | return getRespActions(namespaceCode, responsibilities, qualification, responsibilityDetails); |
195 | |
} |
196 | |
|
197 | |
private List<ResponsibilityAction> getRespActions(final String namespaceCode, final List<Responsibility> responsibilities, final Map<String, String> qualification, final Map<String, String> responsibilityDetails) { |
198 | |
|
199 | 0 | List<Responsibility> applicableResponsibilities = getMatchingResponsibilities(responsibilities, responsibilityDetails); |
200 | 0 | List<ResponsibilityAction> results = new ArrayList<ResponsibilityAction>(); |
201 | 0 | for (Responsibility r : applicableResponsibilities) { |
202 | 0 | List<String> roleIds = getRoleIdsForResponsibility(r.getId(), qualification); |
203 | 0 | results.addAll(getActionsForResponsibilityRoles(r, roleIds, qualification)); |
204 | 0 | } |
205 | 0 | return results; |
206 | |
} |
207 | |
|
208 | |
private List<ResponsibilityAction> getActionsForResponsibilityRoles(Responsibility responsibility, List<String> roleIds, Map<String, String> qualification) { |
209 | 0 | List<ResponsibilityAction> results = new ArrayList<ResponsibilityAction>(); |
210 | 0 | Collection<RoleMembership> roleMembers = roleService.getRoleMembers(roleIds,qualification); |
211 | 0 | for (RoleMembership rm : roleMembers) { |
212 | |
|
213 | 0 | if (StringUtils.isNotBlank(rm.getMemberId())) { |
214 | 0 | final ResponsibilityAction.Builder rai = ResponsibilityAction.Builder.create(); |
215 | 0 | rai.setMemberRoleId(rm.getEmbeddedRoleId()); |
216 | 0 | rai.setRoleId(rm.getRoleId()); |
217 | 0 | rai.setQualifier(rm.getQualifier()); |
218 | 0 | final List<DelegateType.Builder> bs = new ArrayList<DelegateType.Builder>(); |
219 | 0 | for (DelegateType d : rm.getDelegates()) { |
220 | 0 | bs.add(DelegateType.Builder.create(d)); |
221 | |
} |
222 | 0 | rai.setDelegates(bs); |
223 | 0 | rai.setResponsibilityId(responsibility.getId()); |
224 | 0 | rai.setResponsibilityName(responsibility.getName()); |
225 | 0 | rai.setResponsibilityNamespaceCode(responsibility.getNamespaceCode()); |
226 | |
|
227 | 0 | if (rm.getMemberTypeCode().equals(Role.PRINCIPAL_MEMBER_TYPE)) { |
228 | 0 | rai.setPrincipalId(rm.getMemberId()); |
229 | |
} else { |
230 | 0 | rai.setGroupId(rm.getMemberId()); |
231 | |
} |
232 | |
|
233 | 0 | RoleResponsibilityAction action = getResponsibilityAction(rm.getRoleId(), responsibility.getId(), rm.getRoleMemberId()); |
234 | 0 | if (action == null) { |
235 | 0 | LOG.error("Unable to get responsibility action record for role/responsibility/roleMember: " |
236 | |
+ rm.getRoleId() + "/" + responsibility.getId() + "/" + rm.getRoleMemberId()); |
237 | 0 | LOG.error("Skipping this role member in getActionsForResponsibilityRoles()"); |
238 | 0 | continue; |
239 | |
} |
240 | |
|
241 | 0 | rai.setActionTypeCode(action.getActionTypeCode()); |
242 | 0 | rai.setActionPolicyCode(action.getActionPolicyCode()); |
243 | 0 | rai.setPriorityNumber(action.getPriorityNumber() == null ? DEFAULT_PRIORITY_NUMBER : action.getPriorityNumber()); |
244 | 0 | rai.setForceAction(action.isForceAction()); |
245 | 0 | rai.setParallelRoutingGroupingCode((rm.getRoleSortingCode() == null) ? "" : rm.getRoleSortingCode()); |
246 | 0 | rai.setRoleResponsibilityActionId(action.getId()); |
247 | 0 | results.add(rai.build()); |
248 | 0 | } |
249 | |
} |
250 | 0 | return results; |
251 | |
} |
252 | |
|
253 | |
private RoleResponsibilityAction getResponsibilityAction(String roleId, String responsibilityId, String roleMemberId) { |
254 | 0 | final Predicate p = |
255 | |
or( |
256 | |
and( |
257 | |
equal("roleResponsibility.responsibilityId", responsibilityId), |
258 | |
equal("roleResponsibility.roleId", roleId), |
259 | |
equal("roleResponsibility.active", "Y"), |
260 | |
or( |
261 | |
equal(KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId), |
262 | |
equal(KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, "*") |
263 | |
) |
264 | |
), |
265 | |
and( |
266 | |
equal("roleResponsibilityId", "*"), |
267 | |
equal(KIMPropertyConstants.RoleMember.ROLE_MEMBER_ID, roleMemberId) |
268 | |
) |
269 | |
); |
270 | |
|
271 | 0 | final QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); |
272 | 0 | builder.setPredicates(p); |
273 | 0 | final GenericQueryResults<RoleResponsibilityActionBo> results = criteriaLookupService.lookup(RoleResponsibilityActionBo.class, builder.build()); |
274 | 0 | final List<RoleResponsibilityActionBo> bos = results.getResults(); |
275 | |
|
276 | 0 | return !bos.isEmpty() ? RoleResponsibilityActionBo.to(bos.get(0)) : null; |
277 | |
} |
278 | |
|
279 | |
@Override |
280 | |
public List<String> getRoleIdsForResponsibility(String id, Map<String, String> qualification) { |
281 | 0 | if (StringUtils.isBlank(id)) { |
282 | 0 | throw new RiceIllegalArgumentException("id is blank"); |
283 | |
} |
284 | |
|
285 | 0 | if (qualification == null) { |
286 | 0 | throw new RiceIllegalArgumentException("qualification is null"); |
287 | |
} |
288 | |
|
289 | 0 | final List<String> roleIds = getRoleIdsForPredicate(and(equal("responsibilityId", id), equal("active", "Y"))); |
290 | |
|
291 | |
|
292 | 0 | return roleIds; |
293 | |
} |
294 | |
|
295 | |
@Override |
296 | |
public ResponsibilityQueryResults findResponsibilities(final QueryByCriteria queryByCriteria) { |
297 | 0 | if (queryByCriteria == null) { |
298 | 0 | throw new RiceIllegalArgumentException("queryByCriteria is null"); |
299 | |
} |
300 | |
|
301 | 0 | LookupCustomizer.Builder<ResponsibilityBo> lc = LookupCustomizer.Builder.create(); |
302 | 0 | lc.setPredicateTransform(AttributeTransform.getInstance()); |
303 | |
|
304 | 0 | GenericQueryResults<ResponsibilityBo> results = criteriaLookupService.lookup(ResponsibilityBo.class, queryByCriteria, lc.build()); |
305 | |
|
306 | 0 | ResponsibilityQueryResults.Builder builder = ResponsibilityQueryResults.Builder.create(); |
307 | 0 | builder.setMoreResultsAvailable(results.isMoreResultsAvailable()); |
308 | 0 | builder.setTotalRowCount(results.getTotalRowCount()); |
309 | |
|
310 | 0 | final List<Responsibility.Builder> ims = new ArrayList<Responsibility.Builder>(); |
311 | 0 | for (ResponsibilityBo bo : results.getResults()) { |
312 | 0 | ims.add(Responsibility.Builder.create(bo)); |
313 | |
} |
314 | |
|
315 | 0 | builder.setResults(ims); |
316 | 0 | return builder.build(); |
317 | |
} |
318 | |
|
319 | |
@Override |
320 | |
public TemplateQueryResults findResponsibilityTemplates(final QueryByCriteria queryByCriteria) { |
321 | 0 | if (queryByCriteria == null) { |
322 | 0 | throw new RiceIllegalArgumentException("queryByCriteria is null"); |
323 | |
} |
324 | |
|
325 | 0 | GenericQueryResults<ResponsibilityTemplateBo> results = criteriaLookupService.lookup(ResponsibilityTemplateBo.class, queryByCriteria); |
326 | |
|
327 | 0 | TemplateQueryResults.Builder builder = TemplateQueryResults.Builder.create(); |
328 | 0 | builder.setMoreResultsAvailable(results.isMoreResultsAvailable()); |
329 | 0 | builder.setTotalRowCount(results.getTotalRowCount()); |
330 | |
|
331 | 0 | final List<Template.Builder> ims = new ArrayList<Template.Builder>(); |
332 | 0 | for (ResponsibilityTemplateBo bo : results.getResults()) { |
333 | 0 | ims.add(Template.Builder.create(bo)); |
334 | |
} |
335 | |
|
336 | 0 | builder.setResults(ims); |
337 | 0 | return builder.build(); |
338 | |
} |
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
private List<Responsibility> getMatchingResponsibilities(List<Responsibility> responsibilities, Map<String, String> responsibilityDetails) { |
345 | |
|
346 | 0 | if (responsibilityDetails == null || responsibilityDetails.isEmpty()) { |
347 | 0 | return responsibilities; |
348 | |
} |
349 | |
|
350 | 0 | final List<Responsibility> applicableResponsibilities = new ArrayList<Responsibility>(); |
351 | |
|
352 | |
|
353 | 0 | Map<String, KimResponsibilityTypeService> responsibilityTypeServices = getResponsibilityTypeServicesByTemplateId(responsibilities); |
354 | |
|
355 | 0 | Map<String, List<Responsibility>> responsibilityMap = groupResponsibilitiesByTemplate(responsibilities); |
356 | |
|
357 | |
|
358 | 0 | for (Map.Entry<String, List<Responsibility>> respEntry : responsibilityMap.entrySet()) { |
359 | 0 | KimResponsibilityTypeService responsibilityTypeService = responsibilityTypeServices.get(respEntry.getKey()); |
360 | 0 | List<Responsibility> responsibilityInfos = respEntry.getValue(); |
361 | 0 | if (responsibilityTypeService == null) { |
362 | 0 | responsibilityTypeService = defaultResponsibilityTypeService; |
363 | |
} |
364 | 0 | applicableResponsibilities.addAll(responsibilityTypeService.getMatchingResponsibilities(responsibilityDetails, responsibilityInfos)); |
365 | 0 | } |
366 | 0 | return applicableResponsibilities; |
367 | |
} |
368 | |
|
369 | |
private Map<String, KimResponsibilityTypeService> getResponsibilityTypeServicesByTemplateId(Collection<Responsibility> responsibilities) { |
370 | 0 | Map<String, KimResponsibilityTypeService> responsibilityTypeServices = new HashMap<String, KimResponsibilityTypeService>(responsibilities.size()); |
371 | 0 | for (Responsibility responsibility : responsibilities) { |
372 | 0 | final Template t = responsibility.getTemplate(); |
373 | 0 | final KimType type = kimTypeInfoService.getKimType(t.getKimTypeId()); |
374 | |
|
375 | 0 | final String serviceName = type.getServiceName(); |
376 | 0 | if (serviceName != null) { |
377 | 0 | KimResponsibilityTypeService responsibiltyTypeService = GlobalResourceLoader.getService(serviceName); |
378 | 0 | if (responsibiltyTypeService != null) { |
379 | 0 | responsibilityTypeServices.put(responsibility.getTemplate().getId(), responsibiltyTypeService); |
380 | |
} else { |
381 | 0 | responsibilityTypeServices.put(responsibility.getTemplate().getId(), defaultResponsibilityTypeService); |
382 | |
} |
383 | |
} |
384 | 0 | } |
385 | 0 | return responsibilityTypeServices; |
386 | |
} |
387 | |
|
388 | |
private Map<String, List<Responsibility>> groupResponsibilitiesByTemplate(Collection<Responsibility> responsibilities) { |
389 | 0 | final Map<String, List<Responsibility>> results = new HashMap<String, List<Responsibility>>(); |
390 | 0 | for (Responsibility responsibility : responsibilities) { |
391 | 0 | List<Responsibility> responsibilityInfos = results.get(responsibility.getTemplate().getId()); |
392 | 0 | if (responsibilityInfos == null) { |
393 | 0 | responsibilityInfos = new ArrayList<Responsibility>(); |
394 | 0 | results.put(responsibility.getTemplate().getId(), responsibilityInfos); |
395 | |
} |
396 | 0 | responsibilityInfos.add(responsibility); |
397 | 0 | } |
398 | 0 | return results; |
399 | |
} |
400 | |
|
401 | |
private List<String> getRoleIdsForResponsibilities(Collection<String> ids, Map<String, String> qualification) { |
402 | 0 | final List<String> roleIds = getRoleIdsForPredicate(and(in("responsibilityId", ids.toArray()), equal("active", "Y"))); |
403 | |
|
404 | |
|
405 | 0 | return roleIds; |
406 | |
} |
407 | |
|
408 | |
private List<String> getRoleIdsForPredicate(Predicate p) { |
409 | 0 | final QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); |
410 | 0 | builder.setPredicates(p); |
411 | 0 | final GenericQueryResults<RoleResponsibilityBo> qr = criteriaLookupService.lookup(RoleResponsibilityBo.class, builder.build()); |
412 | |
|
413 | 0 | final List<String> roleIds = new ArrayList<String>(); |
414 | 0 | for (RoleResponsibilityBo bo : qr.getResults()) { |
415 | 0 | roleIds.add(bo.getRoleId()); |
416 | |
} |
417 | 0 | return roleIds; |
418 | |
} |
419 | |
|
420 | |
private List<Responsibility> findRespsByNamespaceCodeAndTemplateName(final String namespaceCode, final String templateName) { |
421 | 0 | if (namespaceCode == null) { |
422 | 0 | throw new RiceIllegalArgumentException("namespaceCode is null"); |
423 | |
} |
424 | |
|
425 | 0 | if (templateName == null) { |
426 | 0 | throw new RiceIllegalArgumentException("name is null"); |
427 | |
} |
428 | |
|
429 | 0 | final Map<String, String> crit = new HashMap<String, String>(); |
430 | 0 | crit.put("namespaceCode", namespaceCode); |
431 | 0 | crit.put("name", templateName); |
432 | 0 | crit.put("active", "Y"); |
433 | |
|
434 | 0 | final Collection<ResponsibilityBo> bos = businessObjectService.findMatching(ResponsibilityBo.class, Collections.unmodifiableMap(crit)); |
435 | 0 | final List<Responsibility> ims = new ArrayList<Responsibility>(); |
436 | 0 | if (bos != null) { |
437 | 0 | for (ResponsibilityBo bo : bos) { |
438 | 0 | if (bo != null) { |
439 | 0 | ims.add(ResponsibilityBo.to(bo)); |
440 | |
} |
441 | |
} |
442 | |
} |
443 | |
|
444 | 0 | return Collections.unmodifiableList(ims); |
445 | |
} |
446 | |
|
447 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
448 | 0 | this.businessObjectService = businessObjectService; |
449 | 0 | } |
450 | |
|
451 | |
public void setCriteriaLookupService(final CriteriaLookupService criteriaLookupService) { |
452 | 0 | this.criteriaLookupService = criteriaLookupService; |
453 | 0 | } |
454 | |
|
455 | |
public void setDefaultResponsibilityTypeService(final KimResponsibilityTypeService defaultResponsibilityTypeService) { |
456 | 0 | this.defaultResponsibilityTypeService = defaultResponsibilityTypeService; |
457 | 0 | } |
458 | |
|
459 | |
public void setKimTypeInfoService(final KimTypeInfoService kimTypeInfoService) { |
460 | 0 | this.kimTypeInfoService = kimTypeInfoService; |
461 | 0 | } |
462 | |
|
463 | |
public void setRoleService(final RoleService roleService) { |
464 | 0 | this.roleService = roleService; |
465 | 0 | } |
466 | |
} |