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