Search in sources :

Example 1 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-remote-api by Alfresco.

the class AbstractRuleWebScript method parseJsonActionCondition.

protected ActionConditionImpl parseJsonActionCondition(JSONObject jsonActionCondition) throws JSONException {
    String id = jsonActionCondition.has("id") ? jsonActionCondition.getString("id") : GUID.generate();
    ActionConditionImpl result = new ActionConditionImpl(id, jsonActionCondition.getString("conditionDefinitionName"));
    if (jsonActionCondition.has("invertCondition")) {
        result.setInvertCondition(jsonActionCondition.getBoolean("invertCondition"));
    }
    if (jsonActionCondition.has("parameterValues")) {
        JSONObject jsonParameterValues = jsonActionCondition.getJSONObject("parameterValues");
        result.setParameterValues(parseJsonParameterValues(jsonParameterValues, result.getActionConditionDefinitionName(), false));
    }
    return result;
}
Also used : JSONObject(org.json.JSONObject) ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl)

Example 2 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testTextComparison.

/**
 * Test text comparison
 */
@Test
public void testTextComparison() {
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_TEXT);
    // Test default operations implied by presence and position of *
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.doc");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "*.xls");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my*");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bad*");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals operator
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, TEXT_VALUE);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test contains operator
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "Document");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test begins operator
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "my");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test ends operator
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "doc");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "bobbins");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Ensure other operators are invalid
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
        exception.printStackTrace();
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 3 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testOtherComparison.

/**
 * Test comparison of properties that do not have a registered comparitor
 */
@Test
public void testOtherComparison() {
    NodeRef badNodeRef = new NodeRef(this.testStoreRef, "badId");
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_NODEREF);
    // Test default operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.nodeValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, badNodeRef);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "this isn't even the correct type!");
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.nodeValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, badNodeRef);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Ensure other operators are invalid
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
        exception.printStackTrace();
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 4 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testTempFileNames.

/**
 * Test some combinations of test file names that had been failing
 */
@Test
public void testTempFileNames() {
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_TEXT);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, "~*.doc");
    this.nodeService.setProperty(this.nodeRef, PROP_TEXT, "~1234.doc");
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 5 with ActionConditionImpl

use of org.alfresco.repo.action.ActionConditionImpl in project alfresco-repository by Alfresco.

the class ComparePropertyValueEvaluatorTest method testDateComparison.

/**
 * Test date comparison
 */
@Test
public void testDateComparison() {
    ActionConditionImpl condition = new ActionConditionImpl(GUID.generate(), ComparePropertyValueEvaluator.NAME);
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_PROPERTY, PROP_DATETIME);
    // Test the default operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, new Date());
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test the equals operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.EQUALS.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, new Date());
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals greater than operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals greater than operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.GREATER_THAN_EQUAL.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals less than operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Test equals less than equals operation
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.LESS_THAN_EQUAL.toString());
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.afterDateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.dateValue);
    assertTrue(this.evaluator.evaluate(condition, this.nodeRef));
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_VALUE, this.beforeDateValue);
    assertFalse(this.evaluator.evaluate(condition, this.nodeRef));
    // Ensure other operators are invalid
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.BEGINS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
        exception.printStackTrace();
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.ENDS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
    condition.setParameterValue(ComparePropertyValueEvaluator.PARAM_OPERATION, ComparePropertyValueOperation.CONTAINS.toString());
    try {
        this.evaluator.evaluate(condition, this.nodeRef);
        fail("An exception should have been raised here.");
    } catch (ActionServiceException exception) {
    }
    ;
}
Also used : ActionConditionImpl(org.alfresco.repo.action.ActionConditionImpl) Date(java.util.Date) ActionServiceException(org.alfresco.service.cmr.action.ActionServiceException) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Aggregations

ActionConditionImpl (org.alfresco.repo.action.ActionConditionImpl)22 BaseSpringTest (org.alfresco.util.BaseSpringTest)16 Test (org.junit.Test)16 ActionCondition (org.alfresco.service.cmr.action.ActionCondition)12 ActionServiceException (org.alfresco.service.cmr.action.ActionServiceException)4 Date (java.util.Date)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 JSONObject (org.json.JSONObject)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 FailedThumbnailInfo (org.alfresco.service.cmr.thumbnail.FailedThumbnailInfo)1