org.kuali.rice.kew.rule.service.impl
Class RuleServiceImpl

java.lang.Object
  extended by org.kuali.rice.kew.rule.service.impl.RuleServiceImpl
All Implemented Interfaces:
XmlExporter, XmlLoader, RuleService

public class RuleServiceImpl
extends Object
implements RuleService


Nested Class Summary
 class RuleServiceImpl.RuleDelegationSorter
          A comparator implementation which compares RuleBaseValues and puts all delegate rules first.
 
Constructor Summary
RuleServiceImpl()
           
 
Method Summary
protected  RuleBaseValues createNewRuleVersion(RuleBaseValues existingRule, Long documentId)
           
 void delete(Long ruleBaseValuesId)
           
 void deleteRuleResponsibilityById(Long ruleResponsibilityId)
           
 org.jdom.Element export(ExportDataSet dataSet)
           
 List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType)
           
 List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, boolean ignoreCache)
           
 List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName, String documentType, Timestamp effectiveDate)
           
 List fetchAllRules(boolean currentRules)
           
 List findByRouteHeaderId(Long routeHeaderId)
           
 RuleResponsibility findByRuleResponsibilityId(Long ruleResponsibilityId)
           
 RuleBaseValues findDefaultRuleByRuleTemplateId(Long ruleTemplateId)
           
 Long findResponsibilityIdForRule(String ruleName, String ruleResponsibilityName, String ruleResponsibilityType)
           
 RuleBaseValues findRuleBaseValuesById(Long ruleBaseValuesId)
           
 List findRuleBaseValuesByResponsibilityReviewer(String reviewerName, String type)
           
 List findRuleBaseValuesByResponsibilityReviewerTemplateDoc(String ruleTemplateName, String documentType, String reviewerName, String type)
           
 RuleResponsibility findRuleResponsibility(Long responsibilityId)
           
protected  void flushDocumentTypeFromCache(String documentTypeName)
           
protected  void flushListFromCache(String ruleTemplateName, String documentTypeName)
           
 void flushRuleCache()
           
 ActionRequestService getActionRequestService()
           
protected  String getDocumentTypeRuleCacheGroupName(String documentTypeName)
           
 DocumentTypeService getDocumentTypeService()
           
 Long getDuplicateRuleId(RuleBaseValues rule)
          Checks if the Rule with the given value is a duplicate of an existing rule in the system.
 IdentityManagementService getIdentityManagementService()
           
protected  List<RuleBaseValues> getListFromCache(String ruleTemplateName, String documentTypeName)
           
 RuleBaseValues getParentRule(Long ruleBaseValuesId)
           
 RuleBaseValues getParentRule(RuleBaseValues rule)
           
 RuleBaseValues getRuleByName(String name)
          Returns a Rule based on unique name.
protected  String getRuleCacheKey(String ruleTemplateName, String docTypeName)
          Returns the key of the rule cache.
 RuleDAO getRuleDAO()
           
protected  RuleDelegation getRuleDelegationForDelegateRule(RuleBaseValues rule)
           
protected  String getRuleDlgnCacheKey(Long responsibilityId)
           
 String getRuleDocmentTypeName(List rules)
          This configuration is currently stored in a system parameter named "CUSTOM_DOCUMENT_TYPES ", long term we should come up with a better solution.
 RuleResponsibilityDAO getRuleResponsibilityDAO()
           
 RuleTemplateService getRuleTemplateService()
           
protected  void hookUpDelegateRuleToParentRule(RuleBaseValues newParentRule, RuleBaseValues newDelegationRule, RuleDelegation existingRuleDelegation)
           
 Long isLockedForRouting(Long currentRuleBaseValuesId)
          Determines if the given rule is locked for routing.
protected  List<RuleBaseValues> loadRules(List<Long> ruleIds)
           
 void loadXml(InputStream inputStream, String principalId)
           
 void makeCurrent(List rules)
           
 void makeCurrent(Long routeHeaderId)
           
 void makeCurrent(RuleBaseValues rule, boolean isRetroactiveUpdatePermitted)
          makeCurrent(RuleBaseValues) is the version of makeCurrent which is initiated from the new Routing Rule Maintenance document.
 void makeCurrent(RuleDelegation ruleDelegation, boolean isRetroactiveUpdatePermitted)
           
protected  void makeCurrent(RuleDelegation ruleDelegation, RuleBaseValues rule, boolean isRetroactiveUpdatePermitted)
           
 void makeCurrent2(List rules)
          TODO consolidate this method with makeCurrent.
 void notifyCacheOfDocumentTypeChange(DocumentType documentType)
          Notifies the Rule system that the given DocumentType has been changed.
protected  void notifyCacheOfDocumentTypeChangeFromParent(DocumentType documentType)
          Flushes rules cached for the given DocumentType and then recursivley flushes rules cached for all children DocumentTypes.
protected  void notifyCacheOfDocumentTypeChangeFromRoot(DocumentType rootDocumentType, DocumentType documentType)
          Flushes rules cached from the root of the DocumentType hierarchy (at the given root DocumentType).
 void notifyCacheOfRuleChange(RuleBaseValues rule, DocumentType documentType)
           
protected  void putListInCache(String ruleTemplateName, String documentTypeName, List<RuleBaseValues> rules)
           
 Long routeRuleWithDelegate(Long routeHeaderId, RuleBaseValues parentRule, RuleBaseValues delegateRule, KimPrincipal principal, String annotation, boolean blanketApprove)
           
 void save2(RuleBaseValues ruleBaseValues)
           
 void save2(RuleBaseValues ruleBaseValues, RuleDelegation ruleDelegation, boolean saveDelegations)
           
 RuleBaseValues saveRule(RuleBaseValues rule, boolean isRetroactiveUpdatePermitted)
           
 RuleDelegation saveRuleDelegation(RuleDelegation ruleDelegation, boolean isRetroactiveUpdatePermitted)
           
 List<RuleDelegation> saveRuleDelegations(List<RuleDelegation> ruleDelegationsToSave, boolean isRetroactiveUpdatePermitted)
           
 List<RuleBaseValues> saveRules(List<RuleBaseValues> rulesToSave, boolean isRetroactiveUpdatePermitted)
           
 List search(String docTypeName, Long ruleId, Long ruleTemplateId, String ruleDescription, String groupId, String principalId, Boolean delegateRule, Boolean activeInd, Map extensionValues, String workflowIdDirective)
           
 List search(String docTypeName, String ruleTemplateName, String ruleDescription, String groupId, String principalId, Boolean workgroupMember, Boolean delegateRule, Boolean activeInd, Map extensionValues, Collection<String> actionRequestCodes)
           
 void setRuleDAO(RuleDAO ruleDAO)
           
 void setRuleResponsibilityDAO(RuleResponsibilityDAO ruleResponsibilityDAO)
           
protected  boolean shouldChangeRuleInvolvement(Long documentId, RuleBaseValues rule)
          If a rule has been modified and is no longer current since the original request was made, we need to be sure to NOT update the rule.
 boolean supportPrettyPrint()
           
 void validate(RuleBaseValues ruleBaseValues, List errors)
           
 void validate2(RuleBaseValues ruleBaseValues, RuleDelegation ruleDelegation, List errors)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RuleServiceImpl

public RuleServiceImpl()
Method Detail

getRuleResponsibilityDAO

public RuleResponsibilityDAO getRuleResponsibilityDAO()

getRuleByName

public RuleBaseValues getRuleByName(String name)
Description copied from interface: RuleService
Returns a Rule based on unique name. Returns null if name is null.

Specified by:
getRuleByName in interface RuleService
Parameters:
name - the rule name
Returns:
the Rule if found, null if not found or null name

findDefaultRuleByRuleTemplateId

public RuleBaseValues findDefaultRuleByRuleTemplateId(Long ruleTemplateId)
Specified by:
findDefaultRuleByRuleTemplateId in interface RuleService

setRuleResponsibilityDAO

public void setRuleResponsibilityDAO(RuleResponsibilityDAO ruleResponsibilityDAO)

save2

public void save2(RuleBaseValues ruleBaseValues)
           throws Exception
Specified by:
save2 in interface RuleService
Throws:
Exception

save2

public void save2(RuleBaseValues ruleBaseValues,
                  RuleDelegation ruleDelegation,
                  boolean saveDelegations)
           throws Exception
Throws:
Exception

makeCurrent

public void makeCurrent(Long routeHeaderId)
Specified by:
makeCurrent in interface RuleService

makeCurrent

public void makeCurrent(List rules)

makeCurrent2

public void makeCurrent2(List rules)
TODO consolidate this method with makeCurrent. The reason there's a seperate implementation is because the original makeCurrent(...) could not properly handle versioning a List of multiple rules (including multiple delegates rules for a single parent. ALso, this work is being done for a patch so we want to mitigate the impact on the existing rule code.

This version will only work for remove/replace operations where rules aren't being added or removed. This is why it doesn't perform some of the functions like checking for delegation rules that were removed from a parent rule.


makeCurrent

public void makeCurrent(RuleBaseValues rule,
                        boolean isRetroactiveUpdatePermitted)
makeCurrent(RuleBaseValues) is the version of makeCurrent which is initiated from the new Routing Rule Maintenance document. Because of the changes in the data model and the front end here, this method can be much less complicated than the previous 2!

Specified by:
makeCurrent in interface RuleService

makeCurrent

public void makeCurrent(RuleDelegation ruleDelegation,
                        boolean isRetroactiveUpdatePermitted)
Specified by:
makeCurrent in interface RuleService

makeCurrent

protected void makeCurrent(RuleDelegation ruleDelegation,
                           RuleBaseValues rule,
                           boolean isRetroactiveUpdatePermitted)

getRuleDlgnCacheKey

protected String getRuleDlgnCacheKey(Long responsibilityId)

getParentRule

public RuleBaseValues getParentRule(Long ruleBaseValuesId)
Specified by:
getParentRule in interface RuleService

notifyCacheOfDocumentTypeChange

public void notifyCacheOfDocumentTypeChange(DocumentType documentType)
Description copied from interface: RuleService
Notifies the Rule system that the given DocumentType has been changed. When a DocumentType changes this could result in the change to the DocumentType hierarchy. In these cases we want to ensure that all Rules within that DocumentType hierarchy get flushed from the cache so they can be re-cached with the proper DocumentType hierarchy in place.

Specified by:
notifyCacheOfDocumentTypeChange in interface RuleService

notifyCacheOfDocumentTypeChangeFromParent

protected void notifyCacheOfDocumentTypeChangeFromParent(DocumentType documentType)
Flushes rules cached for the given DocumentType and then recursivley flushes rules cached for all children DocumentTypes.


notifyCacheOfDocumentTypeChangeFromRoot

protected void notifyCacheOfDocumentTypeChangeFromRoot(DocumentType rootDocumentType,
                                                       DocumentType documentType)
Flushes rules cached from the root of the DocumentType hierarchy (at the given root DocumentType). Stops when it hits the given DocumentType. This method exists because of the nature of DocumentTypeService.findRootDocumentType(...). Whenever we have a modification to child document type and we call findRootDocumentType(...) on it, we end up getting back a version of the root document type which is cached in the OJB transaction cache and doesn't have the appropriate child document type attached. A better way to handle this would be to go into the DocumentType service and fix how it versions document types in versionAndSave to prevent this issue from occurring.

If such a fix was made then we could simply pass the root DocumentType into notifyCacheOfDocumentTypeChange and be gauranteed that we will see all appropriate children as we call getChildrenDocTypes().

One last note, we don't necesarily have to stop this cache flusing at the given DocumentType but there's no reason to duplicate the work that is going to be done in notifyCacheOfDocumentTypeChangeFromParent.


notifyCacheOfRuleChange

public void notifyCacheOfRuleChange(RuleBaseValues rule,
                                    DocumentType documentType)
Specified by:
notifyCacheOfRuleChange in interface RuleService

getRuleCacheKey

protected String getRuleCacheKey(String ruleTemplateName,
                                 String docTypeName)
Returns the key of the rule cache.


getDocumentTypeRuleCacheGroupName

protected String getDocumentTypeRuleCacheGroupName(String documentTypeName)

getListFromCache

protected List<RuleBaseValues> getListFromCache(String ruleTemplateName,
                                                String documentTypeName)

putListInCache

protected void putListInCache(String ruleTemplateName,
                              String documentTypeName,
                              List<RuleBaseValues> rules)

flushDocumentTypeFromCache

protected void flushDocumentTypeFromCache(String documentTypeName)

flushListFromCache

protected void flushListFromCache(String ruleTemplateName,
                                  String documentTypeName)

flushRuleCache

public void flushRuleCache()
Specified by:
flushRuleCache in interface RuleService

routeRuleWithDelegate

public Long routeRuleWithDelegate(Long routeHeaderId,
                                  RuleBaseValues parentRule,
                                  RuleBaseValues delegateRule,
                                  KimPrincipal principal,
                                  String annotation,
                                  boolean blanketApprove)
                           throws Exception
Specified by:
routeRuleWithDelegate in interface RuleService
Throws:
Exception

validate

public void validate(RuleBaseValues ruleBaseValues,
                     List errors)

validate2

public void validate2(RuleBaseValues ruleBaseValues,
                      RuleDelegation ruleDelegation,
                      List errors)
Specified by:
validate2 in interface RuleService

findByRouteHeaderId

public List findByRouteHeaderId(Long routeHeaderId)
Specified by:
findByRouteHeaderId in interface RuleService

search

public List search(String docTypeName,
                   Long ruleId,
                   Long ruleTemplateId,
                   String ruleDescription,
                   String groupId,
                   String principalId,
                   Boolean delegateRule,
                   Boolean activeInd,
                   Map extensionValues,
                   String workflowIdDirective)
Specified by:
search in interface RuleService

search

public List search(String docTypeName,
                   String ruleTemplateName,
                   String ruleDescription,
                   String groupId,
                   String principalId,
                   Boolean workgroupMember,
                   Boolean delegateRule,
                   Boolean activeInd,
                   Map extensionValues,
                   Collection<String> actionRequestCodes)
Specified by:
search in interface RuleService

delete

public void delete(Long ruleBaseValuesId)
Specified by:
delete in interface RuleService

findRuleBaseValuesById

public RuleBaseValues findRuleBaseValuesById(Long ruleBaseValuesId)
Specified by:
findRuleBaseValuesById in interface RuleService

findRuleResponsibility

public RuleResponsibility findRuleResponsibility(Long responsibilityId)
Specified by:
findRuleResponsibility in interface RuleService

fetchAllCurrentRulesForTemplateDocCombination

public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName,
                                                          String documentType,
                                                          boolean ignoreCache)
Specified by:
fetchAllCurrentRulesForTemplateDocCombination in interface RuleService

fetchAllCurrentRulesForTemplateDocCombination

public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName,
                                                          String documentType)
Specified by:
fetchAllCurrentRulesForTemplateDocCombination in interface RuleService

fetchAllCurrentRulesForTemplateDocCombination

public List fetchAllCurrentRulesForTemplateDocCombination(String ruleTemplateName,
                                                          String documentType,
                                                          Timestamp effectiveDate)
Specified by:
fetchAllCurrentRulesForTemplateDocCombination in interface RuleService

fetchAllRules

public List fetchAllRules(boolean currentRules)
Specified by:
fetchAllRules in interface RuleService

isLockedForRouting

public Long isLockedForRouting(Long currentRuleBaseValuesId)
Determines if the given rule is locked for routing. In the case of a root rule edit, this method will take the rule id of the rule being edited. In the case of a new delegate rule or a delegate rule edit, this method will take the id of it's parent.

Specified by:
isLockedForRouting in interface RuleService

getParentRule

public RuleBaseValues getParentRule(RuleBaseValues rule)

getRuleDocmentTypeName

public String getRuleDocmentTypeName(List rules)
This configuration is currently stored in a system parameter named "CUSTOM_DOCUMENT_TYPES ", long term we should come up with a better solution. The format of this constant is a comma-separated list of entries of the following form: <>:<>:<>:<> Rule type indicates either main or delegation rules. A main rule is indicated by the character 'M' and a delegate rule is indicated by the character 'D'. So, if you wanted to route "main" rules made for the "MyDocType" document with the rule template name "MyRuleTemplate" using the "MyMainRuleDocType" doc type, it would be specified as follows: MyDocType:MyRuleTemplate:M:MyMainRuleDocType If you also wanted to route "delegate" rules made for the "MyDocType" document with rule template name "MyDelegateTemplate" using the "MyDelegateRuleDocType", you would then set the constant as follows: MyDocType:MyRuleTemplate:M:MyMainRuleDocType,MyDocType:MyDelegateTemplate:D:MyDelegateRuleDocType TODO this method ended up being a mess, we should get rid of this as soon as we can

Specified by:
getRuleDocmentTypeName in interface RuleService

setRuleDAO

public void setRuleDAO(RuleDAO ruleDAO)

getRuleDAO

public RuleDAO getRuleDAO()

deleteRuleResponsibilityById

public void deleteRuleResponsibilityById(Long ruleResponsibilityId)
Specified by:
deleteRuleResponsibilityById in interface RuleService

findByRuleResponsibilityId

public RuleResponsibility findByRuleResponsibilityId(Long ruleResponsibilityId)
Specified by:
findByRuleResponsibilityId in interface RuleService

findRuleBaseValuesByResponsibilityReviewer

public List findRuleBaseValuesByResponsibilityReviewer(String reviewerName,
                                                       String type)
Specified by:
findRuleBaseValuesByResponsibilityReviewer in interface RuleService

findRuleBaseValuesByResponsibilityReviewerTemplateDoc

public List findRuleBaseValuesByResponsibilityReviewerTemplateDoc(String ruleTemplateName,
                                                                  String documentType,
                                                                  String reviewerName,
                                                                  String type)
Specified by:
findRuleBaseValuesByResponsibilityReviewerTemplateDoc in interface RuleService

getRuleTemplateService

public RuleTemplateService getRuleTemplateService()

getDocumentTypeService

public DocumentTypeService getDocumentTypeService()

getIdentityManagementService

public IdentityManagementService getIdentityManagementService()

getActionRequestService

public ActionRequestService getActionRequestService()

loadXml

public void loadXml(InputStream inputStream,
                    String principalId)
Specified by:
loadXml in interface XmlLoader

export

public org.jdom.Element export(ExportDataSet dataSet)
Specified by:
export in interface XmlExporter

supportPrettyPrint

public boolean supportPrettyPrint()
Specified by:
supportPrettyPrint in interface XmlExporter

loadRules

protected List<RuleBaseValues> loadRules(List<Long> ruleIds)

shouldChangeRuleInvolvement

protected boolean shouldChangeRuleInvolvement(Long documentId,
                                              RuleBaseValues rule)
If a rule has been modified and is no longer current since the original request was made, we need to be sure to NOT update the rule.


getRuleDelegationForDelegateRule

protected RuleDelegation getRuleDelegationForDelegateRule(RuleBaseValues rule)

hookUpDelegateRuleToParentRule

protected void hookUpDelegateRuleToParentRule(RuleBaseValues newParentRule,
                                              RuleBaseValues newDelegationRule,
                                              RuleDelegation existingRuleDelegation)

createNewRuleVersion

protected RuleBaseValues createNewRuleVersion(RuleBaseValues existingRule,
                                              Long documentId)
                                       throws Exception
Throws:
Exception

getDuplicateRuleId

public Long getDuplicateRuleId(RuleBaseValues rule)
Description copied from interface: RuleService
Checks if the Rule with the given value is a duplicate of an existing rule in the system.

Specified by:
getDuplicateRuleId in interface RuleService
Returns:
the id of the duplicate rule if one exists, null otherwise

saveRule

public RuleBaseValues saveRule(RuleBaseValues rule,
                               boolean isRetroactiveUpdatePermitted)
Specified by:
saveRule in interface RuleService

saveRules

public List<RuleBaseValues> saveRules(List<RuleBaseValues> rulesToSave,
                                      boolean isRetroactiveUpdatePermitted)
Specified by:
saveRules in interface RuleService

saveRuleDelegation

public RuleDelegation saveRuleDelegation(RuleDelegation ruleDelegation,
                                         boolean isRetroactiveUpdatePermitted)
Specified by:
saveRuleDelegation in interface RuleService

saveRuleDelegations

public List<RuleDelegation> saveRuleDelegations(List<RuleDelegation> ruleDelegationsToSave,
                                                boolean isRetroactiveUpdatePermitted)
Specified by:
saveRuleDelegations in interface RuleService

findResponsibilityIdForRule

public Long findResponsibilityIdForRule(String ruleName,
                                        String ruleResponsibilityName,
                                        String ruleResponsibilityType)
Specified by:
findResponsibilityIdForRule in interface RuleService


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.