001 /*
002 * Copyright 2005-2007 The Kuali Foundation
003 *
004 *
005 * Licensed under the Educational Community License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.opensource.org/licenses/ecl2.php
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package mocks;
018
019 import java.io.InputStream;
020 import java.sql.Timestamp;
021 import java.util.ArrayList;
022 import java.util.Collection;
023 import java.util.HashMap;
024 import java.util.Iterator;
025 import java.util.List;
026 import java.util.Map;
027
028 import org.jdom.Element;
029 import org.kuali.rice.core.api.impex.ExportDataSet;
030 import org.kuali.rice.kew.doctype.bo.DocumentType;
031 import org.kuali.rice.kew.rule.RuleBaseValues;
032 import org.kuali.rice.kew.rule.RuleDelegation;
033 import org.kuali.rice.kew.rule.RuleResponsibility;
034 import org.kuali.rice.kew.rule.service.RuleService;
035 import org.kuali.rice.kew.util.KEWConstants;
036 import org.kuali.rice.kim.bo.entity.KimPrincipal;
037
038
039
040 public class MockRuleServiceImpl implements RuleService {
041
042 Map rules = new HashMap();
043 Map<String, RuleBaseValues> rulesByName = new HashMap<String, RuleBaseValues>();
044 Map responsibilitiesByKey = new HashMap();
045 Map responsibilitiesById = new HashMap();
046 Map responsibilitiesByReviewer = new HashMap();
047 Map rulesByRouteHeaderId = new HashMap();
048
049 public RuleBaseValues getParentRule(Long ruleBaseValuesId) {
050 return null;
051 }
052 public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, boolean ignoreCache) {
053 return null;
054 }
055 public Long isLockedForRouting(Long currentRuleBaseValuesId) {
056 return null;
057 }
058 public Long routeRuleWithDelegate(Long routeHeaderId, RuleBaseValues parentRule, RuleBaseValues delegateRule, KimPrincipal principal, String annotation, boolean blanketApprove) throws Exception {
059 return null;
060 }
061 public List search(String docTypeName, Long ruleId, Long ruleTemplateId, String ruleDescription, String workgroupId, String principalId, Boolean delegateRule, Boolean activeInd, Map extensionValues, String workflowIdDirective) {
062 return null;
063 }
064 public List search(String docTypeName, String ruleTemplateName, String ruleDescription, String groupId, String principalId, Boolean workgroupMember, Boolean delegateRule, Boolean activeInd, Map extensionValues, Collection<String> actionRequestCodes) {
065 return null;
066 }
067 public void notifyCacheOfRuleChange(RuleBaseValues rule, DocumentType documentType) {
068 }
069
070
071
072 public void flushRuleCache() {
073 // TODO ewestfal - THIS METHOD NEEDS JAVADOCS
074
075 }
076 public RuleBaseValues getRuleByName(String name) {
077 return rulesByName.get(name);
078 }
079 public void addRule(RuleBaseValues rule) {
080 rules.put(rule.getRuleBaseValuesId(), rule);
081 if (rule.getName() != null) {
082 rulesByName.put(rule.getName(), rule);
083 }
084
085 List routeHeaderList = null;
086 if(rulesByRouteHeaderId.get(rule.getRouteHeaderId()) != null){
087 routeHeaderList = (List)rulesByRouteHeaderId.get(rule.getRouteHeaderId());
088 } else {
089 routeHeaderList = new ArrayList();
090 }
091 routeHeaderList.add(rule);
092 rulesByRouteHeaderId.put(rule.getRouteHeaderId(), routeHeaderList);
093
094 for (Iterator iter = rule.getResponsibilities().iterator(); iter.hasNext();) {
095 RuleResponsibility resp = (RuleResponsibility) iter.next();
096 responsibilitiesByKey.put(resp.getRuleResponsibilityKey(), resp);
097 responsibilitiesById.put(resp.getResponsibilityId(), resp);
098
099 List respList = null;
100 if(responsibilitiesByReviewer.get(resp.getRuleResponsibilityName()) != null){
101 respList = (List)responsibilitiesByReviewer.get(resp.getRuleResponsibilityName());
102 } else {
103 respList = new ArrayList();
104 }
105 respList.add(resp);
106 responsibilitiesByReviewer.put(resp.getRuleResponsibilityName(), respList);
107 }
108 }
109
110 public void delete(Long ruleBaseValuesId) {
111 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
112 }
113
114 public RuleBaseValues findRuleBaseValuesByName(String name) {
115 return null;
116 }
117
118 public RuleBaseValues findRuleBaseValuesById(Long ruleBaseValuesId) {
119 return (RuleBaseValues) rules.get(ruleBaseValuesId);
120 }
121
122 public List search(String docTypeName, Long ruleTemplateId, Long workgroupId, String workflowId, Boolean delegateRule, Boolean activeInd, Map extensionValues) {
123 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
124 }
125
126 public RuleResponsibility findRuleResponsibility(Long responsibilityId) {
127 return (RuleResponsibility) responsibilitiesById.get(responsibilityId);
128 }
129
130 public void deleteRuleResponsibilityById(Long ruleResponsibilityId) {
131 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
132 }
133
134 public RuleResponsibility findByRuleResponsibilityId(Long ruleResponsibilityId) {
135 return (RuleResponsibility) responsibilitiesByKey.get(ruleResponsibilityId);
136 }
137
138 public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType) {
139 List ruleBaseValues = new ArrayList();
140
141 for (Iterator iter = rules.values().iterator(); iter.hasNext();) {
142 RuleBaseValues rule = (RuleBaseValues) iter.next();
143 if(rule.getRuleTemplate().getName().equals(ruleTemplateName) && rule.getDocTypeName().equals(documentType)){
144 ruleBaseValues.add(rule);
145 }
146 }
147 return ruleBaseValues;
148 }
149
150 public List findByRouteHeaderId(Long routeHeaderId) {
151 return (List) rulesByRouteHeaderId.get(routeHeaderId);
152 }
153
154 public void makeCurrent(Long routeHeaderId) {
155 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
156 }
157
158 public void makeCurrent(RuleBaseValues rule, boolean isRetroactiveUpdatePermitted) {
159 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
160 }
161
162 public void makeCurrent(RuleDelegation ruleDelegation, boolean isRetroactiveUpdatePermitted) {
163 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
164 }
165
166 public List findRuleBaseValuesByResponsibilityReviewer(String reviewerName, String type) {
167 List rules = new ArrayList();
168 for (Iterator iter = ((List) responsibilitiesByReviewer.get(reviewerName)).iterator(); iter.hasNext();) {
169 RuleResponsibility resp = (RuleResponsibility) iter.next();
170 if(resp.getRuleResponsibilityType().equals(type)){
171 rules.add(resp.getRuleBaseValues());
172 }
173 }
174 return rules;
175 }
176
177 public List fetchAllRules(boolean currentRules) {
178 return new ArrayList(rules.values());
179 }
180
181 public void saveDeactivationDate(RuleBaseValues rule) {
182 // do anything?
183 }
184
185 public void validate2(RuleBaseValues ruleBaseValues, RuleDelegation ruleDelegation, List errors) throws Exception {
186 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
187 }
188
189 public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, Timestamp effectiveDate) {
190 return null;
191 }
192 public RuleBaseValues findDefaultRuleByRuleTemplateId(Long ruleTemplateId) {
193 return null;
194 }
195
196 public void save2(RuleBaseValues ruleBaseValues) throws Exception {
197 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
198 }
199
200 public void loadXml(InputStream inputStream, String principalId) {
201 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
202 }
203 public Element export(ExportDataSet dataSet) {
204 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
205 }
206 @Override
207 public boolean supportPrettyPrint() {
208 return true;
209 }
210 public void notifyCacheOfDocumentTypeChange(DocumentType documentType) {
211
212 }
213 public String getRuleDocmentTypeName(List rules) {
214 return KEWConstants.DEFAULT_RULE_DOCUMENT_NAME;
215 }
216 /**
217 * This overridden method ...
218 *
219 * @see org.kuali.rice.kew.rule.service.RuleService#findRuleBaseValuesByResponsibilityReviewerTemplateDoc(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
220 */
221 public List findRuleBaseValuesByResponsibilityReviewerTemplateDoc(String ruleTemplateName, String documentType, String reviewerName, String type) {
222 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
223 }
224 public Long getDuplicateRuleId(RuleBaseValues rule) {
225 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
226 }
227 public Long findResponsibilityIdForRule(String ruleName,
228 String ruleResponsibilityName, String ruleResponsibilityType) {
229 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
230 }
231 public RuleBaseValues saveRule(RuleBaseValues rule,
232 boolean isRetroactiveUpdatePermitted) {
233 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
234 }
235 public RuleDelegation saveRuleDelegation(RuleDelegation ruleDelegation,
236 boolean isRetroactiveUpdatePermitted) {
237 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
238 }
239 public List<RuleDelegation> saveRuleDelegations(
240 List<RuleDelegation> ruleDelegationsToSave, boolean isRetroactiveUpdatePermitted) {
241 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
242 }
243 public List<RuleBaseValues> saveRules(List<RuleBaseValues> rulesToSave, boolean isRetroactiveUpdatePermitted) {
244 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
245 }
246
247
248
249
250 }