use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.
the class RuleServiceImpl method saveRule.
@Override
public void saveRule(NodeRef nodeRef, Rule rule) {
checkForLinkedRules(nodeRef);
if (this.permissionService.hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) {
disableRules();
try {
if (this.nodeService.exists(nodeRef) == false) {
throw new RuleServiceException("The node does not exist.");
}
NodeRef ruleNodeRef = rule.getNodeRef();
if (ruleNodeRef == null) {
if (this.nodeService.hasAspect(nodeRef, RuleModel.ASPECT_RULES) == false) {
// Add the actionable aspect
this.nodeService.addAspect(nodeRef, RuleModel.ASPECT_RULES, null);
}
// Create the action node
ruleNodeRef = this.nodeService.createNode(getSavedRuleFolderRef(nodeRef), ContentModel.ASSOC_CONTAINS, QName.createQName(RuleModel.RULE_MODEL_URI, ASSOC_NAME_RULES_PREFIX + GUID.generate()), RuleModel.TYPE_RULE).getChildRef();
// Set the rule node reference and the owning node reference
rule.setNodeRef(ruleNodeRef);
}
// Update the properties of the rule
this.nodeService.setProperty(ruleNodeRef, ContentModel.PROP_TITLE, rule.getTitle());
this.nodeService.setProperty(ruleNodeRef, ContentModel.PROP_DESCRIPTION, rule.getDescription());
this.nodeService.setProperty(ruleNodeRef, RuleModel.PROP_RULE_TYPE, (Serializable) rule.getRuleTypes());
this.nodeService.setProperty(ruleNodeRef, RuleModel.PROP_APPLY_TO_CHILDREN, rule.isAppliedToChildren());
this.nodeService.setProperty(ruleNodeRef, RuleModel.PROP_EXECUTE_ASYNC, rule.getExecuteAsynchronously());
this.nodeService.setProperty(ruleNodeRef, RuleModel.PROP_DISABLED, rule.getRuleDisabled());
// Save the rule's action
saveAction(ruleNodeRef, rule);
} finally {
enableRules();
// Drop the rules from the cache
nodeRulesCache.remove(nodeRef);
}
} else {
throw new RuleServiceException("Insufficient permissions to save a rule.");
}
}
use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.
the class RuleServiceImpl method saveAction.
/**
* Save the action related to the rule.
*
* @param ruleNodeRef the node reference representing the rule
* @param rule the rule
*/
private void saveAction(NodeRef ruleNodeRef, Rule rule) {
// Get the action definition from the rule
Action action = rule.getAction();
if (action == null) {
throw new RuleServiceException("An action must be specified when defining a rule.");
}
// Get the current action node reference
NodeRef actionNodeRef = null;
List<ChildAssociationRef> actions = this.nodeService.getChildAssocs(ruleNodeRef, RuleModel.ASSOC_ACTION, RuleModel.ASSOC_ACTION);
if (actions.size() == 1) {
// We need to check that the action is the same
actionNodeRef = actions.get(0).getChildRef();
if (actionNodeRef.getId().equals(action.getId()) == false) {
// Delete the old action
this.nodeService.deleteNode(actionNodeRef);
actionNodeRef = null;
}
} else if (actions.size() > 1) {
throw new RuleServiceException("The rule has become corrupt. More than one action is associated with the rule.");
}
// Create the new action node reference
if (actionNodeRef == null) {
actionNodeRef = this.runtimeActionService.createActionNodeRef(action, ruleNodeRef, RuleModel.ASSOC_ACTION, RuleModel.ASSOC_ACTION);
}
// Update the action node
this.runtimeActionService.saveActionImpl(actionNodeRef, action);
}
use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.
the class RuleServiceImpl method executeRule.
@Override
public void executeRule(Rule rule, NodeRef actionedUponNodeRef, Set<ExecutedRuleData> executedRules) {
// Get the action associated with the rule
Action action = rule.getAction();
if (action == null) {
throw new RuleServiceException("Attempting to execute a rule that does not have a rule specified.");
}
// Evaluate the condition
if (this.actionService.evaluateAction(action, actionedUponNodeRef) == true) {
if (executedRules != null) {
// Add the rule to the executed rule list
// (do this before this is executed to prevent rules being added to the pending list)
executedRules.add(new ExecutedRuleData(actionedUponNodeRef, rule));
if (logger.isDebugEnabled() == true) {
logger.debug(" ... Adding rule (" + rule.getTitle() + ") and nodeRef (" + actionedUponNodeRef.getId() + ") to executed list");
}
}
// Execute the rule
boolean executeAsync = rule.getExecuteAsynchronously();
// successful commit works in the context of a Rule but not for the InvitationService.
if (action.getActionDefinitionName().equals(CompositeActionExecuter.NAME)) {
for (Action subAction : ((CompositeAction) action).getActions()) {
if (subAction.getActionDefinitionName().equals(MailActionExecuter.NAME)) {
subAction.setParameterValue(MailActionExecuter.PARAM_SEND_AFTER_COMMIT, true);
}
}
} else if (action.getActionDefinitionName().equals(MailActionExecuter.NAME)) {
action.setParameterValue(MailActionExecuter.PARAM_SEND_AFTER_COMMIT, true);
}
executeAction(action, actionedUponNodeRef, executeAsync);
}
}
use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.
the class RuleServiceImpl method removeRule.
@Override
public void removeRule(NodeRef nodeRef, Rule rule) {
checkForLinkedRules(nodeRef);
if (this.permissionService.hasPermission(nodeRef, PermissionService.CHANGE_PERMISSIONS) == AccessStatus.ALLOWED) {
if (this.nodeService.exists(nodeRef) == true && this.nodeService.hasAspect(nodeRef, RuleModel.ASPECT_RULES) == true) {
disableRules(nodeRef);
try {
NodeRef ruleNodeRef = rule.getNodeRef();
if (ruleNodeRef != null) {
this.nodeService.removeChild(getSavedRuleFolderRef(nodeRef), ruleNodeRef);
}
} finally {
enableRules(nodeRef);
}
// If this was the last rule on the node, remove the aspect
if (countRules(nodeRef) == 0) {
// Since this is the last rule, unlink any linked rulesets
List<NodeRef> linkedFrom = getLinkedFromRuleNodes(nodeRef);
if (linkedFrom.isEmpty() == false) {
for (NodeRef linkedFromNodeRef : linkedFrom) {
NodeRef ruleFolder = getSavedRuleFolderAssoc(nodeRef).getChildRef();
nodeService.removeChild(linkedFromNodeRef, ruleFolder);
nodeService.removeAspect(linkedFromNodeRef, RuleModel.ASPECT_RULES);
}
}
this.nodeService.removeAspect(nodeRef, RuleModel.ASPECT_RULES);
}
}
// Drop the rules from the cache
nodeRulesCache.remove(nodeRef);
} else {
throw new RuleServiceException("Insufficient permissions to remove a rule.");
}
}
use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.
the class CopyActionExecuter method executeImpl.
@Override
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) {
if (!nodeService.exists(actionedUponNodeRef)) {
return;
}
NodeRef destinationParent = (NodeRef) ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
// Check the destination not to be in a pending delete list
// MNT-11695
Set<QName> destinationAspects = nodeService.getAspects(destinationParent);
if (destinationAspects.contains(ContentModel.ASPECT_PENDING_DELETE)) {
return;
}
// Get the deep copy value
boolean deepCopy = false;
Boolean deepCopyValue = (Boolean) ruleAction.getParameterValue(PARAM_DEEP_COPY);
if (deepCopyValue != null) {
deepCopy = deepCopyValue.booleanValue();
}
// Get the overwirte value
boolean overwrite = true;
Boolean overwriteValue = (Boolean) ruleAction.getParameterValue(PARAM_OVERWRITE_COPY);
if (overwriteValue != null) {
overwrite = overwriteValue.booleanValue();
}
// Since we are overwriting we need to figure out whether the destination node exists
NodeRef copyNodeRef = null;
if (overwrite == true) {
// Try and find copies of the actioned upon node reference.
// Include the parent folder because that's where the copy will be if this action
// had done the first copy.
PagingResults<CopyInfo> copies = copyService.getCopies(actionedUponNodeRef, destinationParent, new PagingRequest(1000));
for (CopyInfo copyInfo : copies.getPage()) {
NodeRef copy = copyInfo.getNodeRef();
// We know that it is in the destination parent, but avoid working copies
if (checkOutCheckInService.isWorkingCopy(copy)) {
continue;
}
if (copyNodeRef == null) {
copyNodeRef = copy;
} else {
throw new RuleServiceException(ERR_OVERWRITE);
}
}
}
if (copyNodeRef != null) {
// Overwrite the state of the destination node ref with the actioned upon node state
this.copyService.copy(actionedUponNodeRef, copyNodeRef);
} else {
ChildAssociationRef originalAssoc = nodeService.getPrimaryParent(actionedUponNodeRef);
// Create a new copy of the node
this.copyService.copyAndRename(actionedUponNodeRef, destinationParent, originalAssoc.getTypeQName(), originalAssoc.getQName(), deepCopy);
}
}
Aggregations