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