Workflow REST API fix for variable scope

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55723 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tijs Rademakers
2013-09-20 09:30:23 +00:00
parent ec90eb3725
commit 1b7dcb26b8
4 changed files with 212 additions and 61 deletions

View File

@@ -337,34 +337,58 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
{
String localPropertyName = propertyName.replaceFirst("variables/", "");
Object actualValue = null;
DataTypeDefinition dataTypeDefinition = null;
// variable scope global is default
String scopeDef = "global";
// look for variable scope
if (localPropertyName.contains("local/"))
{
scopeDef = "local";
localPropertyName = localPropertyName.replaceFirst("local/", "");
}
if (localPropertyName.contains("global/"))
{
localPropertyName = localPropertyName.replaceFirst("global/", "");
}
// look for variable type definition
if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" "))
{
String typeDef = propertyValue.substring(0, propertyValue.indexOf(' '));
try
int indexOfSpace = propertyValue.indexOf(' ');
if ((propertyValue.contains("_") && indexOfSpace > propertyValue.indexOf("_")) ||
(propertyValue.contains(":") && indexOfSpace > propertyValue.indexOf(":")))
{
QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
DataTypeDefinition dataTypeDefinition = dictionaryService.getDataType(dataType);
if (dataTypeDefinition != null && "java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName()))
String typeDef = propertyValue.substring(0, indexOfSpace);
try
{
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
actualValue = ISO8601DateFormat.parse(propertyValue.substring(propertyValue.indexOf(' ') + 1));
QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
dataTypeDefinition = dictionaryService.getDataType(dataType);
propertyValue = propertyValue.substring(indexOfSpace + 1);
}
else
catch (Exception e)
{
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition,
propertyValue.substring(propertyValue.indexOf(' ') + 1));
throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
}
}
catch (Exception e)
{
throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
}
}
}
if (dataTypeDefinition != null && "java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName()))
{
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
actualValue = ISO8601DateFormat.parse(propertyValue);
}
else if (dataTypeDefinition != null)
{
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, propertyValue);
}
else
{
actualValue = propertyValue;
}
variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue));
variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue, scopeDef));
}
/**
@@ -387,13 +411,15 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
private String propertyName;
private int operator;
private Object propertyValue;
private String scope;
public QueryVariableHolder() {}
public QueryVariableHolder(String propertyName, int operator, Object propertyValue) {
public QueryVariableHolder(String propertyName, int operator, Object propertyValue, String scope) {
this.propertyName = propertyName;
this.operator = operator;
this.propertyValue = propertyValue;
this.scope = scope;
}
public String getPropertyName()
@@ -420,5 +446,16 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
{
this.propertyValue = propertyValue;
}
public String getScope()
{
return scope;
}
public void setScope(String scope)
{
this.scope = scope;
}
public boolean isGlobalScope() {
return "global".equals(scope);
}
}
}

View File

@@ -274,24 +274,59 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
for (QueryVariableHolder queryVariableHolder : variableProperties)
{
if (queryVariableHolder.getOperator() == WhereClauseParser.EQUALS)
{
query.taskVariableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
{
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHAN)
{
query.taskVariableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHANOREQUALS)
{
query.taskVariableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHAN)
{
query.taskVariableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHANOREQUALS)
{
query.taskVariableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.MATCHES)
{
@@ -299,11 +334,26 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
{
throw new InvalidArgumentException("the matches operator can only be used with a String value for property " + queryVariableHolder.getPropertyName());
}
query.taskVariableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.NEGATION)
{
query.taskVariableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else
{
@@ -404,24 +454,59 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
for (QueryVariableHolder queryVariableHolder : variableProperties)
{
if (queryVariableHolder.getOperator() == WhereClauseParser.EQUALS)
{
query.taskVariableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
{
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHAN)
{
query.taskVariableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHANOREQUALS)
{
query.taskVariableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHAN)
{
query.taskVariableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHANOREQUALS)
{
query.taskVariableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.MATCHES)
{
@@ -429,11 +514,26 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
{
throw new InvalidArgumentException("the matches operator can only be used with a String value for property " + queryVariableHolder.getPropertyName());
}
query.taskVariableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
}
}
else if (queryVariableHolder.getOperator() == WhereClauseParser.NEGATION)
{
query.taskVariableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
if (queryVariableHolder.isGlobalScope())
{
query.processVariableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
else
{
query.taskVariableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
}
}
else
{