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.api.identity.principal.PrincipalContract; 037 038 039 040 041 public class MockRuleServiceImpl implements RuleService { 042 043 Map rules = new HashMap(); 044 Map<String, RuleBaseValues> rulesByName = new HashMap<String, RuleBaseValues>(); 045 Map responsibilitiesByKey = new HashMap(); 046 Map responsibilitiesById = new HashMap(); 047 Map responsibilitiesByReviewer = new HashMap(); 048 Map rulesByDocumentId = new HashMap(); 049 050 public RuleBaseValues getParentRule(String ruleBaseValuesId) { 051 return null; 052 } 053 public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, boolean ignoreCache) { 054 return null; 055 } 056 public String isLockedForRouting(String currentRuleBaseValuesId) { 057 return null; 058 } 059 public String routeRuleWithDelegate(String documentId, RuleBaseValues parentRule, RuleBaseValues delegateRule, PrincipalContract principal, String annotation, boolean blanketApprove) throws Exception { 060 return null; 061 } 062 public List<RuleBaseValues> search(String docTypeName, String ruleId, String ruleTemplateId, String ruleDescription, String workgroupId, String principalId, Boolean delegateRule, Boolean activeInd, Map extensionValues, String workflowIdDirective) { 063 return null; 064 } 065 public List<RuleBaseValues> searchByTemplate(String docTypeName, String ruleTemplateName, String ruleDescription, String groupId, String principalId, Boolean workgroupMember, Boolean delegateRule, Boolean activeInd, Map extensionValues, Collection<String> actionRequestCodes) { 066 return null; 067 } 068 public void notifyCacheOfRuleChange(RuleBaseValues rule, DocumentType documentType) { 069 } 070 071 072 073 public void flushRuleCache() { 074 // TODO ewestfal - THIS METHOD NEEDS JAVADOCS 075 076 } 077 public RuleBaseValues getRuleByName(String name) { 078 return rulesByName.get(name); 079 } 080 public void addRule(RuleBaseValues rule) { 081 rules.put(rule.getRuleBaseValuesId(), rule); 082 if (rule.getName() != null) { 083 rulesByName.put(rule.getName(), rule); 084 } 085 086 List routeHeaderList = null; 087 if(rulesByDocumentId.get(rule.getDocumentId()) != null){ 088 routeHeaderList = (List)rulesByDocumentId.get(rule.getDocumentId()); 089 } else { 090 routeHeaderList = new ArrayList(); 091 } 092 routeHeaderList.add(rule); 093 rulesByDocumentId.put(rule.getDocumentId(), routeHeaderList); 094 095 for (Iterator iter = rule.getResponsibilities().iterator(); iter.hasNext();) { 096 RuleResponsibility resp = (RuleResponsibility) iter.next(); 097 responsibilitiesByKey.put(resp.getRuleResponsibilityKey(), resp); 098 responsibilitiesById.put(resp.getResponsibilityId(), resp); 099 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(String 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(String 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(String responsibilityId) { 128 return (RuleResponsibility) responsibilitiesById.get(responsibilityId); 129 } 130 131 public void deleteRuleResponsibilityById(String ruleResponsibilityId) { 132 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl"); 133 } 134 135 public RuleResponsibility findByRuleResponsibilityId(String 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<RuleBaseValues> 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(String 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 String getDuplicateRuleId(RuleBaseValues rule) { 226 throw new UnsupportedOperationException("not implemented in MockRuleServiceImpl"); 227 } 228 public String 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 }