1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule.service.impl; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.jdom.Element; |
20 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
21 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorException; |
22 | |
import org.kuali.rice.kew.exception.WorkflowServiceErrorImpl; |
23 | |
import org.kuali.rice.kew.rule.RuleDelegationBo; |
24 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateBo; |
25 | |
import org.kuali.rice.kew.rule.dao.RuleDelegationDAO; |
26 | |
import org.kuali.rice.kew.rule.service.RuleDelegationService; |
27 | |
import org.kuali.rice.kew.rule.service.RuleTemplateService; |
28 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
29 | |
import org.kuali.rice.kew.xml.RuleXmlParser; |
30 | |
import org.kuali.rice.kew.xml.export.RuleDelegationXmlExporter; |
31 | |
import org.kuali.rice.kim.api.group.Group; |
32 | |
import org.kuali.rice.kim.api.group.GroupService; |
33 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
34 | |
|
35 | |
import java.io.InputStream; |
36 | |
import java.util.ArrayList; |
37 | |
import java.util.Collection; |
38 | |
import java.util.Collections; |
39 | |
import java.util.List; |
40 | |
import java.util.Map; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class RuleDelegationServiceImpl implements RuleDelegationService { |
47 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger |
48 | |
.getLogger(RuleDelegationServiceImpl.class); |
49 | |
|
50 | |
private static final String XML_PARSE_ERROR = "general.error.parsexml"; |
51 | |
|
52 | |
private RuleDelegationDAO dao; |
53 | |
|
54 | |
public List<RuleDelegationBo> findByDelegateRuleId(String ruleId) { |
55 | 0 | if (ruleId == null) return Collections.EMPTY_LIST; |
56 | 0 | return dao.findByDelegateRuleId(ruleId); |
57 | |
} |
58 | |
|
59 | |
public void save(RuleDelegationBo ruleDelegation) { |
60 | 0 | dao.save(ruleDelegation); |
61 | 0 | } |
62 | |
|
63 | |
public void setRuleDelegationDAO(RuleDelegationDAO dao) { |
64 | 0 | this.dao = dao; |
65 | 0 | } |
66 | |
public List<RuleDelegationBo> findAllCurrentRuleDelegations(){ |
67 | 0 | return dao.findAllCurrentRuleDelegations(); |
68 | |
} |
69 | |
public void delete(String ruleDelegationId){ |
70 | 0 | dao.delete(ruleDelegationId); |
71 | 0 | } |
72 | |
|
73 | |
public RuleDelegationBo findByRuleDelegationId(String ruleDelegationId){ |
74 | 0 | return dao.findByRuleDelegationId(ruleDelegationId); |
75 | |
} |
76 | |
|
77 | |
public List<RuleDelegationBo> findByResponsibilityId(String responsibilityId) { |
78 | |
|
79 | 0 | return findByResponsibilityId(responsibilityId, false); |
80 | |
} |
81 | |
|
82 | |
public List<RuleDelegationBo> search(String parentRuleBaseVaueId, String parentResponsibilityId, String docTypeName, String ruleId, String ruleTemplateId, String ruleDescription, String groupId, String principalId, |
83 | |
String delegationType, Boolean activeInd, Map extensionValues, String workflowIdDirective) { |
84 | 0 | return dao.search(parentRuleBaseVaueId, parentResponsibilityId, docTypeName, ruleId, ruleTemplateId, ruleDescription, groupId, principalId, delegationType, |
85 | |
activeInd, extensionValues, workflowIdDirective); |
86 | |
} |
87 | |
|
88 | |
public List<RuleDelegationBo> searchByTemplate(String parentRuleBaseVaueId, String parentResponsibilityId, String docTypeName, String ruleTemplateName, String ruleDescription, String groupId, String principalId, |
89 | |
Boolean workgroupMember, String delegationType, Boolean activeInd, Map extensionValues, Collection<String> actionRequestCodes) { |
90 | |
|
91 | 0 | if ( (StringUtils.isEmpty(docTypeName)) && |
92 | |
(StringUtils.isEmpty(ruleTemplateName)) && |
93 | |
(StringUtils.isEmpty(ruleDescription)) && |
94 | |
(StringUtils.isEmpty(groupId)) && |
95 | |
(StringUtils.isEmpty(principalId)) && |
96 | |
(extensionValues.isEmpty()) && |
97 | |
(actionRequestCodes.isEmpty()) ) { |
98 | |
|
99 | 0 | throw new IllegalArgumentException("At least one criterion must be sent"); |
100 | |
} |
101 | |
|
102 | 0 | RuleTemplateBo ruleTemplate = getRuleTemplateService().findByRuleTemplateName(ruleTemplateName); |
103 | 0 | String ruleTemplateId = null; |
104 | 0 | if (ruleTemplate != null) { |
105 | 0 | ruleTemplateId = ruleTemplate.getId(); |
106 | |
} |
107 | |
|
108 | 0 | if ( ( (extensionValues != null) && (!extensionValues.isEmpty()) ) && |
109 | |
(ruleTemplateId == null) ) { |
110 | |
|
111 | 0 | throw new IllegalArgumentException("A Rule Template Name must be given if using Rule Extension values"); |
112 | |
} |
113 | |
|
114 | 0 | Collection<String> workgroupIds = new ArrayList<String>(); |
115 | 0 | if (principalId != null) { |
116 | 0 | if ( (workgroupMember == null) || (workgroupMember.booleanValue()) ) { |
117 | 0 | workgroupIds = getGroupService().getGroupIdsByPrincipalId(principalId); |
118 | |
} else { |
119 | |
|
120 | |
} |
121 | 0 | } else if (groupId != null) { |
122 | 0 | Group group = KEWServiceLocator.getIdentityHelperService().getGroup(groupId); |
123 | 0 | if (group == null) { |
124 | 0 | throw new IllegalArgumentException("Group does not exist in for given group id: " + groupId); |
125 | |
} else { |
126 | 0 | workgroupIds.add(group.getId()); |
127 | |
} |
128 | |
} |
129 | |
|
130 | 0 | return dao.search(parentRuleBaseVaueId, parentResponsibilityId, docTypeName, ruleTemplateId, ruleDescription, workgroupIds, principalId, |
131 | |
delegationType,activeInd, extensionValues, actionRequestCodes); |
132 | |
} |
133 | |
|
134 | |
public void loadXml(InputStream inputStream, String principalId) { |
135 | 0 | RuleXmlParser parser = new RuleXmlParser(); |
136 | |
try { |
137 | 0 | parser.parseRuleDelegations(inputStream); |
138 | 0 | } catch (Exception e) { |
139 | 0 | LOG.error("Error loading xml file", e); |
140 | 0 | WorkflowServiceErrorException wsee = new WorkflowServiceErrorException("Error loading xml file", new WorkflowServiceErrorImpl("Error loading xml file", XML_PARSE_ERROR)); |
141 | 0 | wsee.initCause(e); |
142 | 0 | throw wsee; |
143 | 0 | } |
144 | 0 | } |
145 | |
|
146 | |
public Element export(ExportDataSet dataSet) { |
147 | 0 | RuleDelegationXmlExporter exporter = new RuleDelegationXmlExporter(); |
148 | 0 | return exporter.export(dataSet); |
149 | |
} |
150 | |
|
151 | |
@Override |
152 | |
public boolean supportPrettyPrint() { |
153 | 0 | return true; |
154 | |
} |
155 | |
|
156 | |
private GroupService getGroupService() { |
157 | 0 | return KimApiServiceLocator.getGroupService(); |
158 | |
} |
159 | |
|
160 | |
private RuleTemplateService getRuleTemplateService() { |
161 | 0 | return KEWServiceLocator.getRuleTemplateService(); |
162 | |
} |
163 | |
|
164 | |
|
165 | |
|
166 | |
public List findByResponsibilityId(String responsibilityId, boolean ignoreCache) { |
167 | 0 | return dao.findByResponsibilityIdWithCurrentRule(responsibilityId); |
168 | |
} |
169 | |
} |