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;
}
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) {
}
;
}
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) {
}
;
}
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));
}
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) {
}
;
}
Aggregations