Merged 5.2.N (5.2.1) to HEAD (5.2)

130451 jkaabimofrad: SHA-1598: Minor tweaks of parsing of the property parameter based on GavinC review.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130936 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2016-09-27 13:58:55 +00:00
parent a8edbc04e1
commit e511f5a13c
2 changed files with 42 additions and 9 deletions

View File

@@ -42,9 +42,10 @@ import org.alfresco.service.cmr.workflow.WorkflowTask;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery; import org.alfresco.service.cmr.workflow.WorkflowTaskQuery;
import org.alfresco.service.cmr.workflow.WorkflowTaskQuery.OrderBy; import org.alfresco.service.cmr.workflow.WorkflowTaskQuery.OrderBy;
import org.alfresco.service.cmr.workflow.WorkflowTaskState; import org.alfresco.service.cmr.workflow.WorkflowTaskState;
import org.alfresco.service.namespace.NamespaceException;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.ModelUtil; import org.alfresco.util.ModelUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
@@ -59,6 +60,8 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
*/ */
public class TaskInstancesGet extends AbstractWorkflowWebscript public class TaskInstancesGet extends AbstractWorkflowWebscript
{ {
private static final Log LOGGER = LogFactory.getLog(TaskInstancesGet.class);
public static final String PARAM_AUTHORITY = "authority"; public static final String PARAM_AUTHORITY = "authority";
public static final String PARAM_STATE = "state"; public static final String PARAM_STATE = "state";
public static final String PARAM_PRIORITY = "priority"; public static final String PARAM_PRIORITY = "priority";
@@ -346,22 +349,44 @@ public class TaskInstancesGet extends AbstractWorkflowWebscript
} }
else if(key.equals(PARAM_PROPERTY)) else if(key.equals(PARAM_PROPERTY))
{ {
String[] propertyValuePair = filterValue.toString().split("/"); int propQNameEnd = filterValue.toString().indexOf('/');
if (propertyValuePair.length != 2) if (propQNameEnd < 1)
{ {
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Ignoring invalid property filter:" + filterValue.toString());
}
break; break;
} }
String propValue = filterValue.toString().substring(propQNameEnd + 1);
if (propValue.isEmpty())
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Ignoring empty property value filter [" + propValue + "]");
}
break;
}
String propQNameStr = filterValue.toString().substring(0, propQNameEnd);
QName propertyQName; QName propertyQName;
try try
{ {
propertyQName = QName.createQName(propertyValuePair[0], namespaceService); propertyQName = QName.createQName(propQNameStr, namespaceService);
} }
catch (NamespaceException ne) catch (Exception ex)
{ {
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Ignoring invalid QName property filter [" + propQNameStr + "]");
}
break; break;
} }
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Filtering with property [" + propertyQName.toPrefixString(namespaceService) + "=" + propValue + "]");
}
Serializable value = task.getProperties().get(propertyQName); Serializable value = task.getProperties().get(propertyQName);
if (value != null && !value.equals(propertyValuePair[1])) if (value != null && !value.equals(propValue))
{ {
result = false; result = false;
break; break;

View File

@@ -332,7 +332,7 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName()); wfDefinition = workflowService.getDefinitionByName(getReviewPooledWorkflowDefinitionName());
params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP)); params.put(WorkflowModel.ASSOC_GROUP_ASSIGNEE, groupManager.get(GROUP));
params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null)); params.put(WorkflowModel.ASSOC_PACKAGE, workflowService.createPackage(null));
params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest2"); params.put(WorkflowModel.PROP_WORKFLOW_DESCRIPTION, "descTest2/withSlash");
wfPath = workflowService.startWorkflow(wfDefinition.getId(), params); wfPath = workflowService.startWorkflow(wfDefinition.getId(), params);
workflowId = wfPath.getInstance().getId(); workflowId = wfPath.getInstance().getId();
@@ -356,13 +356,13 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
assertEquals("descTest1", properties.getString("bpm_description")); assertEquals("descTest1", properties.getString("bpm_description"));
//Check USER2's tasks With filtering where property bpm:description should match "descTest2" //Check USER2's tasks With filtering where property bpm:description should match "descTest2"
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest2"), 200); response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/descTest2/withSlash"), 200);
results = getJsonArray(response, 1); results = getJsonArray(response, 1);
result = results.getJSONObject(0); result = results.getJSONObject(0);
assertNotNull(result); assertNotNull(result);
properties = result.getJSONObject("properties"); properties = result.getJSONObject("properties");
assertNotNull(properties); assertNotNull(properties);
assertEquals("descTest2", properties.getString("bpm_description")); assertEquals("descTest2/withSlash", properties.getString("bpm_description"));
/* /*
* -ve tests * -ve tests
@@ -383,6 +383,14 @@ public abstract class AbstractWorkflowRestApiTest extends BaseWebScriptTest
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/"), 200); response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=bpm:description/"), 200);
getJsonArray(response, 2); getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=descTest1"), 200);
getJsonArray(response, 2);
// Not well-formed parameter
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER2) + "&property=/descTest1"), 200);
getJsonArray(response, 2);
// Check USER3's tasks without filtering. It should return 0 task as USER3 is not a member of the GROUP // Check USER3's tasks without filtering. It should return 0 task as USER3 is not a member of the GROUP
personManager.setUser(USER3); personManager.setUser(USER3);
response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200); response = sendRequest(new GetRequest(MessageFormat.format(URL_USER_TASKS, USER3)), 200);