View Javadoc

1   /*
2    * Copyright 2005-2007 The Kuali Foundation
3    *
4    *
5    * Licensed under the Educational Community License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.opensource.org/licenses/ecl2.php
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package mocks;
18  
19  import java.io.InputStream;
20  import java.sql.Timestamp;
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.HashMap;
24  import java.util.Iterator;
25  import java.util.List;
26  import java.util.Map;
27  
28  import org.jdom.Element;
29  import org.kuali.rice.core.api.impex.ExportDataSet;
30  import org.kuali.rice.kew.doctype.bo.DocumentType;
31  import org.kuali.rice.kew.rule.RuleBaseValues;
32  import org.kuali.rice.kew.rule.RuleDelegation;
33  import org.kuali.rice.kew.rule.RuleResponsibility;
34  import org.kuali.rice.kew.rule.service.RuleService;
35  import org.kuali.rice.kew.util.KEWConstants;
36  import org.kuali.rice.kim.api.entity.principal.PrincipalContract;
37  
38  
39  
40  
41  public class MockRuleServiceImpl implements RuleService {
42  
43      Map rules = new HashMap();
44      Map<String, RuleBaseValues> rulesByName = new HashMap<String, RuleBaseValues>();
45      Map responsibilitiesByKey = new HashMap();
46      Map responsibilitiesById = new HashMap();
47      Map responsibilitiesByReviewer = new HashMap();
48      Map rulesByDocumentId = new HashMap();
49  
50      public RuleBaseValues getParentRule(Long ruleBaseValuesId) {
51          return null;
52      }
53      public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, boolean ignoreCache) {
54          return null;
55      }
56      public String isLockedForRouting(Long currentRuleBaseValuesId) {
57          return null;
58      }
59      public String routeRuleWithDelegate(String documentId, RuleBaseValues parentRule, RuleBaseValues delegateRule, PrincipalContract principal, String annotation, boolean blanketApprove) throws Exception {
60          return null;
61      }
62      public List search(String docTypeName, Long ruleId, Long ruleTemplateId, String ruleDescription, String workgroupId, String principalId, Boolean delegateRule, Boolean activeInd, Map extensionValues, String workflowIdDirective) {
63          return null;
64      }
65      public List search(String docTypeName, String ruleTemplateName, String ruleDescription, String groupId, String principalId, Boolean workgroupMember, Boolean delegateRule, Boolean activeInd, Map extensionValues, Collection<String> actionRequestCodes) {
66          return null;
67      }
68      public void notifyCacheOfRuleChange(RuleBaseValues rule, DocumentType documentType) {
69      }
70  
71  
72  
73      public void flushRuleCache() {
74  	// TODO ewestfal - THIS METHOD NEEDS JAVADOCS
75  
76      }
77      public RuleBaseValues getRuleByName(String name) {
78          return rulesByName.get(name);
79      }
80      public void addRule(RuleBaseValues rule) {
81          rules.put(rule.getRuleBaseValuesId(), rule);
82          if (rule.getName() != null) {
83              rulesByName.put(rule.getName(), rule);
84          }
85  
86          List routeHeaderList = null;
87          if(rulesByDocumentId.get(rule.getDocumentId()) != null){
88              routeHeaderList = (List)rulesByDocumentId.get(rule.getDocumentId());
89          } else {
90              routeHeaderList = new ArrayList();
91          }
92          routeHeaderList.add(rule);
93          rulesByDocumentId.put(rule.getDocumentId(), routeHeaderList);
94  
95          for (Iterator iter = rule.getResponsibilities().iterator(); iter.hasNext();) {
96              RuleResponsibility resp = (RuleResponsibility) iter.next();
97              responsibilitiesByKey.put(resp.getRuleResponsibilityKey(), resp);
98              responsibilitiesById.put(resp.getResponsibilityId(), resp);
99  
100             List respList = null;
101             if(responsibilitiesByReviewer.get(resp.getRuleResponsibilityName()) != null){
102                 respList = (List)responsibilitiesByReviewer.get(resp.getRuleResponsibilityName());
103             } else {
104                 respList = new ArrayList();
105             }
106             respList.add(resp);
107             responsibilitiesByReviewer.put(resp.getRuleResponsibilityName(), respList);
108         }
109     }
110 
111     public void delete(Long ruleBaseValuesId) {
112         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
113     }
114 
115     public RuleBaseValues findRuleBaseValuesByName(String name) {
116         return null;
117     }
118 
119     public RuleBaseValues findRuleBaseValuesById(Long ruleBaseValuesId) {
120         return (RuleBaseValues) rules.get(ruleBaseValuesId);
121     }
122 
123     public List search(String docTypeName, Long ruleTemplateId, Long workgroupId, String workflowId, Boolean delegateRule, Boolean activeInd, Map extensionValues) {
124         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
125     }
126 
127     public RuleResponsibility findRuleResponsibility(Long responsibilityId) {
128         return (RuleResponsibility) responsibilitiesById.get(responsibilityId);
129     }
130 
131     public void deleteRuleResponsibilityById(Long ruleResponsibilityId) {
132         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
133     }
134 
135     public RuleResponsibility findByRuleResponsibilityId(Long ruleResponsibilityId) {
136         return (RuleResponsibility) responsibilitiesByKey.get(ruleResponsibilityId);
137     }
138 
139     public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType) {
140         List ruleBaseValues = new ArrayList();
141 
142         for (Iterator iter = rules.values().iterator(); iter.hasNext();) {
143             RuleBaseValues rule = (RuleBaseValues) iter.next();
144             if(rule.getRuleTemplate().getName().equals(ruleTemplateName) && rule.getDocTypeName().equals(documentType)){
145                 ruleBaseValues.add(rule);
146             }
147         }
148         return ruleBaseValues;
149     }
150 
151     public List findByDocumentId(String documentId) {
152         return (List) rulesByDocumentId.get(documentId);
153     }
154 
155     public void makeCurrent(String documentId) {
156         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
157     }
158 
159     public void makeCurrent(RuleBaseValues rule, boolean isRetroactiveUpdatePermitted) {
160         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
161     }
162     
163     public void makeCurrent(RuleDelegation ruleDelegation, boolean isRetroactiveUpdatePermitted) {
164         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
165     }
166 
167     public List findRuleBaseValuesByResponsibilityReviewer(String reviewerName, String type) {
168         List rules = new ArrayList();
169         for (Iterator iter = ((List) responsibilitiesByReviewer.get(reviewerName)).iterator(); iter.hasNext();) {
170             RuleResponsibility resp = (RuleResponsibility) iter.next();
171             if(resp.getRuleResponsibilityType().equals(type)){
172                 rules.add(resp.getRuleBaseValues());
173             }
174         }
175         return rules;
176     }
177 
178     public List fetchAllRules(boolean currentRules) {
179         return new ArrayList(rules.values());
180     }
181 
182     public void saveDeactivationDate(RuleBaseValues rule) {
183         // do anything?
184     }
185 
186     public void validate2(RuleBaseValues ruleBaseValues, RuleDelegation ruleDelegation, List errors) throws Exception {
187     	throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
188     }
189 
190     public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, Timestamp effectiveDate) {
191         return null;
192     }
193 	public RuleBaseValues findDefaultRuleByRuleTemplateId(Long ruleTemplateId) {
194 		return null;
195 	}
196 
197     public void save2(RuleBaseValues ruleBaseValues) throws Exception {
198         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
199     }
200 
201     public void loadXml(InputStream inputStream, String principalId) {
202         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
203     }
204     public Element export(ExportDataSet dataSet) {
205         throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
206     }
207 	@Override
208 	public boolean supportPrettyPrint() {
209 		return true;
210 	}
211 	public void notifyCacheOfDocumentTypeChange(DocumentType documentType) {
212 
213 	}
214 	public String getRuleDocmentTypeName(List rules) {
215 		return KEWConstants.DEFAULT_RULE_DOCUMENT_NAME;
216 	}
217 	/**
218 	 * This overridden method ...
219 	 *
220 	 * @see org.kuali.rice.kew.rule.service.RuleService#findRuleBaseValuesByResponsibilityReviewerTemplateDoc(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
221 	 */
222 	public List findRuleBaseValuesByResponsibilityReviewerTemplateDoc(String ruleTemplateName, String documentType, String reviewerName, String type) {
223 	    throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
224 	}
225 	public Long getDuplicateRuleId(RuleBaseValues rule) {
226 		throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
227 	}
228 	public Long findResponsibilityIdForRule(String ruleName,
229 			String ruleResponsibilityName, String ruleResponsibilityType) {
230 		throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
231 	}
232 	public RuleBaseValues saveRule(RuleBaseValues rule,
233 			boolean isRetroactiveUpdatePermitted) {
234 		throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
235 	}
236 	public RuleDelegation saveRuleDelegation(RuleDelegation ruleDelegation,
237 			boolean isRetroactiveUpdatePermitted) {
238 		throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
239 	}
240 	public List<RuleDelegation> saveRuleDelegations(
241 			List<RuleDelegation> ruleDelegationsToSave, boolean isRetroactiveUpdatePermitted) {
242 		throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
243 	}
244 	public List<RuleBaseValues> saveRules(List<RuleBaseValues> rulesToSave, boolean isRetroactiveUpdatePermitted) {
245 		throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl");
246 	}
247 	
248 	
249 
250 
251 }