Workflow REST API fixes for variable query

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@55420 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tijs Rademakers
2013-09-17 15:55:22 +00:00
parent 403fd26ace
commit 9309ed04f5
5 changed files with 84 additions and 35 deletions

View File

@@ -29,10 +29,12 @@ import org.alfresco.rest.antlr.WhereClauseParser;
import org.alfresco.rest.framework.core.exceptions.ApiException;
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
import org.alfresco.rest.framework.resource.parameters.where.QueryHelper.WalkerCallbackAdapter;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ISO8601DateFormat;
import org.apache.commons.beanutils.ConversionException;
import org.apache.commons.beanutils.ConvertUtils;
@@ -151,7 +153,11 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
{
throw new InvalidArgumentException("Cannot use negated matching for property: " + property);
}
if (supportedMatchesParameters != null && supportedMatchesParameters.contains(property))
if (variablesEnabled && property.startsWith("variables/"))
{
processVariable(property, value, WhereClauseParser.MATCHES);
}
else if (supportedMatchesParameters != null && supportedMatchesParameters.contains(property))
{
matchesProperties.put(property, value);
}
@@ -168,27 +174,7 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
if (variablesEnabled && propertyName.startsWith("variables/"))
{
String localPropertyName = propertyName.replaceFirst("variables/", "");
Object actualValue = null;
if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" "))
{
String typeDef = propertyValue.substring(0, propertyValue.indexOf(' '));
try
{
QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
actualValue = DefaultTypeConverter.INSTANCE.convert(dictionaryService.getDataType(dataType),
propertyValue.substring(propertyValue.indexOf(' ') + 1));
}
catch (Exception e)
{
throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
}
}
else
{
actualValue = propertyValue;
}
variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue));
processVariable(propertyName, propertyValue, type);
}
else
{
@@ -346,6 +332,40 @@ public class MapBasedQueryWalker extends WalkerCallbackAdapter
// method indicates that AND is
// supported. OR is not supported at the same time.
}
protected void processVariable(String propertyName, String propertyValue, int type)
{
String localPropertyName = propertyName.replaceFirst("variables/", "");
Object actualValue = null;
if ((propertyValue.contains("_") || propertyValue.contains(":")) && propertyValue.contains(" "))
{
String typeDef = propertyValue.substring(0, propertyValue.indexOf(' '));
try
{
QName dataType = QName.createQName(typeDef.replace('_', ':'), namespaceService);
DataTypeDefinition dataTypeDefinition = dictionaryService.getDataType(dataType);
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.substring(propertyValue.indexOf(' ') + 1));
}
else
{
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition,
propertyValue.substring(propertyValue.indexOf(' ') + 1));
}
}
catch (Exception e)
{
throw new ApiException("Error translating propertyName " + propertyName + " with value " + propertyValue);
}
}
else
{
actualValue = propertyValue;
}
variableProperties.add(new QueryVariableHolder(localPropertyName, type, actualValue));
}
/**
* Called when unsupported property is encountered or comparison operator

View File

@@ -32,15 +32,15 @@ public class TaskVariablesWalkerCallback extends WalkerCallbackAdapter
@Override
public void comparison(int type, String propertyName, String propertyValue)
{
if(PROPERTY_SCOPE.equals(propertyName))
if (PROPERTY_SCOPE.equals(propertyName))
{
if(type != WhereClauseParser.EQUALS)
if (type != WhereClauseParser.EQUALS)
{
throw new InvalidQueryException("Only equals is allowed for 'scope' comparison.");
}
scope = VariableScope.getScopeForValue(propertyValue);
if(scope == null)
if (scope == null)
{
throw new InvalidQueryException("Invalid value for 'scope' used in query: " + propertyValue + ".");
}

View File

@@ -87,12 +87,12 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
private static final Set<String> TASK_COLLECTION_EQUALS_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
"status", "assignee", "owner", "candidateUser", "candidateGroup", "name", "description", "priority", "processId",
"processBusinessKey", "activityDefinitionId", "processDefinitionId", "processDefinitionName", "startedAt", "endedAt", "dueAt",
"includeTaskVariables", "includeProcessVariables"
"processBusinessKey", "activityDefinitionId", "processDefinitionId", "processDefinitionKey", "processDefinitionName", "startedAt",
"endedAt", "dueAt", "includeTaskVariables", "includeProcessVariables"
));
private static final Set<String> TASK_COLLECTION_MATCHES_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
"assignee", "owner", "name", "description", "processBusinessKey", "activityDefinitionId", "processDefinitionName"
"assignee", "owner", "name", "description", "processBusinessKey", "activityDefinitionId", "processDefinitionKey", "processDefinitionName"
));
private static final Set<String> TASK_COLLECTION_GREATERTHAN_QUERY_PROPERTIES = new HashSet<String>(Arrays.asList(
@@ -172,6 +172,8 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
String activityDefinitionId = propertyWalker.getProperty("activityDefinitionId", WhereClauseParser.EQUALS);
String activityDefinitionIdLike = propertyWalker.getProperty("activityDefinitionId", WhereClauseParser.MATCHES);
String processDefinitionId = propertyWalker.getProperty("processDefinitionId", WhereClauseParser.EQUALS);
String processDefinitionKey = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.EQUALS);
String processDefinitionKeyLike = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.MATCHES);
String processDefinitionName = propertyWalker.getProperty("processDefinitionName", WhereClauseParser.EQUALS);
String processDefinitionNameLike = propertyWalker.getProperty("processDefinitionName", WhereClauseParser.MATCHES);
Date startedAt = propertyWalker.getProperty("startedAt", WhereClauseParser.EQUALS, Date.class);
@@ -247,6 +249,8 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
if (activityDefinitionId != null) query.taskDefinitionKey(activityDefinitionId);
if (activityDefinitionIdLike != null) query.taskDefinitionKey(activityDefinitionIdLike);
if (processDefinitionId != null) query.processDefinitionId(processDefinitionId);
if (processDefinitionKey != null) query.processDefinitionKey(processDefinitionKey);
if (processDefinitionKeyLike != null) query.processDefinitionKeyLike(processDefinitionKeyLike);
if (processDefinitionName != null) query.processDefinitionName(processDefinitionName);
if (processDefinitionNameLike != null) query.processDefinitionNameLike(processDefinitionNameLike);
if (dueAt != null) query.dueDate(dueAt);
@@ -372,6 +376,8 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
if (activityDefinitionId != null) query.taskDefinitionKey(activityDefinitionId);
if (activityDefinitionIdLike != null) query.taskDefinitionKey(activityDefinitionIdLike);
if (processDefinitionId != null) query.processDefinitionId(processDefinitionId);
if (processDefinitionKey != null) query.processDefinitionKey(processDefinitionKey);
if (processDefinitionKeyLike != null) query.processDefinitionKeyLike(processDefinitionKeyLike);
if (processDefinitionName != null) query.processDefinitionName(processDefinitionName);
if (processDefinitionNameLike != null) query.processDefinitionNameLike(processDefinitionNameLike);
if (dueAt != null) query.taskDueDate(dueAt);
@@ -647,19 +653,21 @@ public class TasksImpl extends WorkflowRestImpl implements Tasks
// In case the action is claim, we gather all candidate groups for this tasks, since we already have
// the identity-links, there is no reason why we should check candidate using a DB-query
for(IdentityLink link : linksForTask) {
if(user.equals(link.getUserId()) && IdentityLinkType.STARTER.equals(link.getType()))
for (IdentityLink link : linksForTask)
{
if (user.equals(link.getUserId()) && IdentityLinkType.STARTER.equals(link.getType()))
{
authorized = true;
break;
}
if(taskAction == TaskStateTransition.CLAIMED && link.getGroupId() != null && link.getType().equals(IdentityLinkType.CANDIDATE)) {
if (taskAction == TaskStateTransition.CLAIMED && link.getGroupId() != null && link.getType().equals(IdentityLinkType.CANDIDATE))
{
candidateGroups.add(link.getGroupId());
}
if(taskAction == TaskStateTransition.CLAIMED &&
if (taskAction == TaskStateTransition.CLAIMED &&
link.getUserId() != null && link.getType().equals(IdentityLinkType.CANDIDATE) &&
user.equals(link.getUserId())) {
user.equals(link.getUserId()))
{
// User is a direct candidate for the task, authorized to claim
authorized = true;
break;

View File

@@ -34,7 +34,8 @@ public enum VariableScope
* a valid scope.
*/
public static VariableScope getScopeForValue(String scopeValue) {
for(VariableScope scope : values()) {
for(VariableScope scope : values())
{
if(scope.getValue().equals(scopeValue))
{
return scope;