Workflow query on custom props fails with datetime prop datatype

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Established Member

Workflow query on custom props fails with datetime prop datatype

Hi,
I want to query workflow instances using property filter.
Query on String datatype are working well, but query on DateTime datatype fails with exception below.
Any Idea ?

My code:

 WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery();
 Map<QName, Object> filters = new HashMap<QName, Object>;
 filters.put(PropertyQName, DateParam);
 workflowInstanceQuery.setCustomProps(filters);
 this.workflowService.getWorkflows(workflowInstanceQuery, maxItems, skipCount);

Exception:

2018-07-29 23:16:46,476  ERROR [extensions.webscripts.AbstractRuntime] [http-apr-8080-exec-2] Exception from executeScript: java.util.Date cannot be cast to java.util.Map
 java.lang.ClassCastException: java.util.Date cannot be cast to java.util.Map
        at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.createQuery(ActivitiWorkflowEngine.java:2556)
        at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.getWorkflowsInternal(ActivitiWorkflowEngine.java:2403)
        at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.getWorkflows(ActivitiWorkflowEngine.java:2388)
        at org.alfresco.repo.workflow.WorkflowServiceImpl.getWorkflows(WorkflowServiceImpl.java:502)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.service.cmr.workflow.WorkflowPermissionInterceptor.invoke(WorkflowPermissionInterceptor.java:64)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:166)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at com.sun.proxy.$Proxy77.getWorkflows(Unknown Source)

2 Replies
Highlighted
Master

Re: Workflow query on custom props fails with datetime prop datatype

Alfresco has explicit special handling for date properties. Since it is very unlikely someone would be searching on an exact timestamp, Alfresco support a date-based condition to be a map with the following allowed entries:

  • key: DatePosition.BEFORE, value: date value compared against using less or equals
  • key: DatePosition.AFTER, value: date value compared against using greater or equals

You can see that by looking at the source of the class referenced by the error stacktrace.

Highlighted
Established Member

Re: Workflow query on custom props fails with datetime prop datatype

Yes, Many thanks ! Code below is working fine:

WorkflowInstanceQuery workflowInstanceQuery = new WorkflowInstanceQuery();
 Map<QName, Object> filters = new HashMap<QName, Object>;

Map<DatePosition, Date> dateParams = new HashMap<DatePosition, Date>();

dateParams.put(DatePosition.BEFORE, endRangeDate);

dateParams.put(DatePosition.AFTER, startRangeDate);

 filters.put(propertyQName, dateParams);
 workflowInstanceQuery.setCustomProps(filters);
 this.workflowService.getWorkflows(workflowInstanceQuery, maxItems, skipCount);