Search in sources :

Example 11 with RuleServiceException

use of org.alfresco.service.cmr.rule.RuleServiceException in project alfresco-repository by Alfresco.

the class RuleServiceCoverageTest method testContainsTextCondition.

/**
 * Test:
 *          rule type:  inbound
 *          condition:  match-text(
 *          				text = .doc,
 *          				operation = CONTAINS)
 *          action:     add-features(
 *                          aspect-name = versionable)
 */
public void testContainsTextCondition() {
    Map<String, Serializable> actionParams = new HashMap<String, Serializable>(1);
    actionParams.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);
    // ActionCondition parameter's
    Map<String, Serializable> condParams = new HashMap<String, Serializable>(1);
    condParams.put(ComparePropertyValueEvaluator.PARAM_VALUE, ".doc");
    Rule rule = createRule(RuleType.INBOUND, AddFeaturesActionExecuter.NAME, actionParams, ComparePropertyValueEvaluator.NAME, condParams);
    this.ruleService.saveRule(this.nodeRef, rule);
    // Test condition failure
    Map<QName, Serializable> props1 = new HashMap<QName, Serializable>();
    props1.put(ContentModel.PROP_NAME, "bobbins.txt");
    // props1.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    NodeRef newNodeRef = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, props1).getChildRef();
    addContentToNode(newNodeRef);
    // Map<QName, Serializable> map = this.nodeService.getProperties(newNodeRef);
    // String value = (String)this.nodeService.getProperty(newNodeRef, ContentModel.PROP_NAME);
    assertFalse(this.nodeService.hasAspect(newNodeRef, ContentModel.ASPECT_VERSIONABLE));
    // Test condition success
    Map<QName, Serializable> props2 = new HashMap<QName, Serializable>();
    props2.put(ContentModel.PROP_NAME, "bobbins.doc");
    // props2.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    NodeRef newNodeRef2 = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, props2).getChildRef();
    addContentToNode(newNodeRef2);
    assertTrue(this.nodeService.hasAspect(newNodeRef2, ContentModel.ASPECT_VERSIONABLE));
    try {
        // Test name not set
        NodeRef newNodeRef3 = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, getContentProperties()).getChildRef();
        addContentToNode(newNodeRef3);
    } catch (RuleServiceException exception) {
    // Correct since text-match is a mandatory property
    }
    // Test begins with
    Map<String, Serializable> condParamsBegins = new HashMap<String, Serializable>(1);
    condParamsBegins.put(ComparePropertyValueEvaluator.PARAM_VALUE, "bob*");
    rule.getAction().removeAllActionConditions();
    ActionCondition condition1 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME, condParamsBegins);
    rule.getAction().addActionCondition(condition1);
    this.ruleService.saveRule(this.nodeRef, rule);
    Map<QName, Serializable> propsx = new HashMap<QName, Serializable>();
    propsx.put(ContentModel.PROP_NAME, "mybobbins.doc");
    // propsx.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    NodeRef newNodeRefx = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsx).getChildRef();
    addContentToNode(newNodeRefx);
    assertFalse(this.nodeService.hasAspect(newNodeRefx, ContentModel.ASPECT_VERSIONABLE));
    Map<QName, Serializable> propsy = new HashMap<QName, Serializable>();
    propsy.put(ContentModel.PROP_NAME, "bobbins.doc");
    // propsy.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    NodeRef newNodeRefy = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsy).getChildRef();
    addContentToNode(newNodeRefy);
    assertTrue(this.nodeService.hasAspect(newNodeRefy, ContentModel.ASPECT_VERSIONABLE));
    // Test ends with
    Map<String, Serializable> condParamsEnds = new HashMap<String, Serializable>(1);
    condParamsEnds.put(ComparePropertyValueEvaluator.PARAM_VALUE, "*s.doc");
    rule.getAction().removeAllActionConditions();
    ActionCondition condition2 = this.actionService.createActionCondition(ComparePropertyValueEvaluator.NAME, condParamsEnds);
    rule.getAction().addActionCondition(condition2);
    this.ruleService.saveRule(this.nodeRef, rule);
    Map<QName, Serializable> propsa = new HashMap<QName, Serializable>();
    propsa.put(ContentModel.PROP_NAME, "bobbins.document");
    // propsa.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    NodeRef newNodeRefa = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsa).getChildRef();
    addContentToNode(newNodeRefa);
    assertFalse(this.nodeService.hasAspect(newNodeRefa, ContentModel.ASPECT_VERSIONABLE));
    Map<QName, Serializable> propsb = new HashMap<QName, Serializable>();
    propsb.put(ContentModel.PROP_NAME, "bobbins.doc");
    // propsb.put(ContentModel.PROP_CONTENT, CONTENT_DATA_TEXT);
    NodeRef newNodeRefb = this.nodeService.createNode(this.nodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(TEST_NAMESPACE, "children"), ContentModel.TYPE_CONTENT, propsb).getChildRef();
    addContentToNode(newNodeRefb);
    assertTrue(this.nodeService.hasAspect(newNodeRefb, ContentModel.ASPECT_VERSIONABLE));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) RuleServiceException(org.alfresco.service.cmr.rule.RuleServiceException) QName(org.alfresco.service.namespace.QName) Rule(org.alfresco.service.cmr.rule.Rule) ActionCondition(org.alfresco.service.cmr.action.ActionCondition)

Aggregations

RuleServiceException (org.alfresco.service.cmr.rule.RuleServiceException)11 NodeRef (org.alfresco.service.cmr.repository.NodeRef)9 Action (org.alfresco.service.cmr.action.Action)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 QName (org.alfresco.service.namespace.QName)4 CompositeAction (org.alfresco.service.cmr.action.CompositeAction)3 Rule (org.alfresco.service.cmr.rule.Rule)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 PagingRequest (org.alfresco.query.PagingRequest)2 CopyInfo (org.alfresco.service.cmr.repository.CopyService.CopyInfo)2 Locale (java.util.Locale)1 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)1 ParameterDefinition (org.alfresco.service.cmr.action.ParameterDefinition)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)1 NoTransformerException (org.alfresco.service.cmr.repository.NoTransformerException)1 TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)1 BaseSpringTest (org.alfresco.util.BaseSpringTest)1 Test (org.junit.Test)1