<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Creating REST API in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17762#M7874</link>
    <description>&lt;P&gt;Thank you for providing the help. But i want to fetch all the completed tasks of all the users without providing any workflow or process instance id.&lt;/P&gt;&lt;P&gt;Please do help me with the code.&lt;/P&gt;</description>
    <pubDate>Sat, 20 Feb 2021 11:57:07 GMT</pubDate>
    <dc:creator>Tabu</dc:creator>
    <dc:date>2021-02-20T11:57:07Z</dc:date>
    <item>
      <title>Creating REST API</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17760#M7872</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;I'am trying to fetch the task details with the state as completed without the workflow id but it's not working in this code.&lt;/P&gt;&lt;P&gt;protected Map&amp;lt;String, Object&amp;gt; buildModel(WorkflowModelBuilder modelBuilder, WebScriptRequest req, Status status, Cache cache)&lt;BR /&gt;{&lt;BR /&gt;Map&amp;lt;String, String&amp;gt; params = req.getServiceMatch().getTemplateVars();&lt;BR /&gt;Map&amp;lt;String, Object&amp;gt; filters = new HashMap&amp;lt;String, Object&amp;gt;(4);&lt;/P&gt;&lt;P&gt;// authority is not included into filters list as it will be taken into account before filtering&lt;BR /&gt;String authority = getAuthority(req);&lt;BR /&gt;&lt;BR /&gt;// state is also not included into filters list, for the same reason&lt;BR /&gt;WorkflowTaskState state = getState(req);&lt;BR /&gt;&lt;BR /&gt;// look for a workflow instance id&lt;BR /&gt;String workflowInstanceId = params.get(VAR_WORKFLOW_INSTANCE_ID);&lt;BR /&gt;&lt;BR /&gt;// determine if pooledTasks should be included, when appropriate i.e. when an authority is supplied&lt;BR /&gt;Boolean pooledTasksOnly = getPooledTasks(req);&lt;BR /&gt;&lt;BR /&gt;// get list of properties to include in the response&lt;BR /&gt;List&amp;lt;String&amp;gt; properties = getProperties(req);&lt;BR /&gt;&lt;BR /&gt;// get filter param values&lt;BR /&gt;filters.put(PARAM_PRIORITY, req.getParameter(PARAM_PRIORITY));&lt;BR /&gt;filters.put(PARAM_PROPERTY, req.getParameter(PARAM_PROPERTY));&lt;BR /&gt;processDateFilter(req, PARAM_DUE_BEFORE, filters);&lt;BR /&gt;processDateFilter(req, PARAM_DUE_AFTER, filters);&lt;BR /&gt;&lt;BR /&gt;String excludeParam = req.getParameter(PARAM_EXCLUDE);&lt;BR /&gt;if (excludeParam != null &amp;amp;&amp;amp; excludeParam.length() &amp;gt; 0)&lt;BR /&gt;{&lt;BR /&gt;filters.put(PARAM_EXCLUDE, new ExcludeFilter(excludeParam));&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;List&amp;lt;WorkflowTask&amp;gt; allTasks;&lt;/P&gt;&lt;P&gt;if (workflowInstanceId != null)&lt;BR /&gt;{&lt;BR /&gt;// a workflow instance id was provided so query for tasks&lt;BR /&gt;WorkflowTaskQuery taskQuery = new WorkflowTaskQuery();&lt;BR /&gt;taskQuery.setActive(null);&lt;BR /&gt;taskQuery.setProcessId(workflowInstanceId);&lt;BR /&gt;taskQuery.setTaskState(state);&lt;BR /&gt;taskQuery.setOrderBy(new OrderBy[]{OrderBy.TaskDue_Asc});&lt;BR /&gt;&lt;BR /&gt;if (authority != null)&lt;BR /&gt;{&lt;BR /&gt;taskQuery.setActorId(authority);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;allTasks = workflowService.queryTasks(taskQuery);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// default task state to IN_PROGRESS if not supplied&lt;BR /&gt;&lt;BR /&gt;if (state == null)&lt;BR /&gt;{&lt;BR /&gt;state = WorkflowTaskState.IN_PROGRESS;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// no workflow instance id is present so get all tasks&lt;BR /&gt;if (authority != null)&lt;BR /&gt;{&lt;BR /&gt;List&amp;lt;WorkflowTask&amp;gt; tasks = workflowService.getAssignedTasks(authority, state, true);&lt;BR /&gt;List&amp;lt;WorkflowTask&amp;gt; pooledTasks = workflowService.getPooledTasks(authority, true);&lt;BR /&gt;if (pooledTasksOnly != null)&lt;BR /&gt;{&lt;BR /&gt;if (pooledTasksOnly.booleanValue())&lt;BR /&gt;{&lt;BR /&gt;// only return pooled tasks the user can claim&lt;BR /&gt;allTasks = new ArrayList&amp;lt;WorkflowTask&amp;gt;(pooledTasks.size());&lt;BR /&gt;allTasks.addAll(pooledTasks);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// only return tasks assigned to the user&lt;BR /&gt;allTasks = new ArrayList&amp;lt;WorkflowTask&amp;gt;(tasks.size());&lt;BR /&gt;allTasks.addAll(tasks);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// include both assigned and unassigned tasks&lt;BR /&gt;allTasks = new ArrayList&amp;lt;WorkflowTask&amp;gt;(tasks.size() + pooledTasks.size());&lt;BR /&gt;allTasks.addAll(tasks);&lt;BR /&gt;allTasks.addAll(pooledTasks);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// sort tasks by due date&lt;BR /&gt;Collections.sort(allTasks, taskComparator);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;// authority was not provided -&amp;gt; return all active tasks in the system&lt;BR /&gt;WorkflowTaskQuery taskQuery = new WorkflowTaskQuery();&lt;BR /&gt;taskQuery.setTaskState(state);&lt;BR /&gt;taskQuery.setActive(null);&lt;BR /&gt;taskQuery.setOrderBy(new OrderBy[] { OrderBy.TaskDue_Asc });&lt;BR /&gt;allTasks = workflowService.queryTasks(taskQuery);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int maxItems = getIntParameter(req, PARAM_MAX_ITEMS, DEFAULT_MAX_ITEMS);&lt;BR /&gt;int skipCount = getIntParameter(req, PARAM_SKIP_COUNT, DEFAULT_SKIP_COUNT);&lt;BR /&gt;int totalCount = 0;&lt;BR /&gt;ArrayList&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt; results = new ArrayList&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt;();&lt;BR /&gt;&lt;BR /&gt;// Filter results&lt;BR /&gt;for (WorkflowTask task : allTasks)&lt;BR /&gt;{&lt;BR /&gt;if (matches(task, filters))&lt;BR /&gt;{&lt;BR /&gt;// Total-count needs to be based on matching tasks only, so we can't just use allTasks.size() for this&lt;BR /&gt;totalCount++;&lt;BR /&gt;if(totalCount &amp;gt; skipCount &amp;amp;&amp;amp; (maxItems &amp;lt; 0 || maxItems &amp;gt; results.size()))&lt;BR /&gt;{&lt;BR /&gt;// Only build the actual detail if it's in the range of items we need. This will&lt;BR /&gt;// drastically improve performance over paging after building the model&lt;BR /&gt;results.add(modelBuilder.buildSimple(task, properties));&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Map&amp;lt;String, Object&amp;gt; model = new HashMap&amp;lt;String, Object&amp;gt;();&lt;BR /&gt;model.put("taskInstances", results);&lt;BR /&gt;&lt;BR /&gt;if (maxItems != DEFAULT_MAX_ITEMS || skipCount != DEFAULT_SKIP_COUNT)&lt;BR /&gt;{&lt;BR /&gt;// maxItems or skipCount parameter was provided so we need to include paging into response&lt;BR /&gt;model.put("paging", ModelUtil.buildPaging(totalCount, maxItems == DEFAULT_MAX_ITEMS ? totalCount : maxItems, skipCount));&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;// create and return results, paginated if necessary&lt;BR /&gt;return model;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Retrieves the list of property names to include in the response.&lt;BR /&gt;*&lt;BR /&gt;* @param req The WebScript request&lt;BR /&gt;* @return List of property names&lt;BR /&gt;*/&lt;BR /&gt;private List&amp;lt;String&amp;gt; getProperties(WebScriptRequest req)&lt;BR /&gt;{&lt;BR /&gt;String propertiesStr = req.getParameter(PARAM_PROPERTIES);&lt;BR /&gt;if (propertiesStr != null)&lt;BR /&gt;{&lt;BR /&gt;return Arrays.asList(propertiesStr.split(","));&lt;BR /&gt;}&lt;BR /&gt;return null;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/**&lt;BR /&gt;* Retrieves the pooledTasks parameter.&lt;BR /&gt;*&lt;BR /&gt;* @param req The WebScript request&lt;BR /&gt;* @return null if not present, Boolean object otherwise&lt;BR /&gt;*/&lt;BR /&gt;private Boolean getPooledTasks(WebScriptRequest req)&lt;BR /&gt;{&lt;BR /&gt;Boolean result = null;&lt;BR /&gt;String includePooledTasks = req.getParameter(PARAM_POOLED_TASKS);&lt;BR /&gt;&lt;BR /&gt;if (includePooledTasks != null)&lt;BR /&gt;{&lt;BR /&gt;result = Boolean.valueOf(includePooledTasks);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;return result;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;/**&lt;BR /&gt;* Gets the specified {@link WorkflowTaskState}, null if not requested&lt;BR /&gt;*&lt;BR /&gt;* @param req WebScriptRequest&lt;BR /&gt;* @return WorkflowTaskState&lt;BR /&gt;*/&lt;BR /&gt;private WorkflowTaskState getState(WebScriptRequest req)&lt;BR /&gt;{&lt;BR /&gt;String stateName = req.getParameter(PARAM_STATE);&lt;BR /&gt;if (stateName != null)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;return WorkflowTaskState.valueOf(stateName.toUpperCase());&lt;BR /&gt;}&lt;BR /&gt;catch (IllegalArgumentException e)&lt;BR /&gt;{&lt;BR /&gt;String msg = "Unrecognised State parameter: " + stateName;&lt;BR /&gt;throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, msg);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;return null;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Returns the specified authority. If no authority is specified then returns the current Fully Authenticated user.&lt;BR /&gt;* @param req WebScriptRequest&lt;BR /&gt;* @return String&lt;BR /&gt;*/&lt;BR /&gt;private String getAuthority(WebScriptRequest req)&lt;BR /&gt;{&lt;BR /&gt;String authority = req.getParameter(PARAM_AUTHORITY);&lt;BR /&gt;if (authority == null || authority.length() == 0)&lt;BR /&gt;{&lt;BR /&gt;authority = null;&lt;BR /&gt;}&lt;BR /&gt;return authority;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Determine if the given task should be included in the response.&lt;BR /&gt;*&lt;BR /&gt;* @param task The task to check&lt;BR /&gt;* @param filters The list of filters the task must match to be included&lt;BR /&gt;* @return true if the task matches and should therefore be returned&lt;BR /&gt;*/&lt;BR /&gt;private boolean matches(WorkflowTask task, Map&amp;lt;String, Object&amp;gt; filters)&lt;BR /&gt;{&lt;BR /&gt;// by default we assume that workflow task should be included&lt;BR /&gt;boolean result = true;&lt;/P&gt;&lt;P&gt;for (String key : filters.keySet())&lt;BR /&gt;{&lt;BR /&gt;Object filterValue = filters.get(key);&lt;/P&gt;&lt;P&gt;// skip null filters (null value means that filter was not specified)&lt;BR /&gt;if (filterValue != null)&lt;BR /&gt;{&lt;BR /&gt;if (key.equals(PARAM_EXCLUDE))&lt;BR /&gt;{&lt;BR /&gt;ExcludeFilter excludeFilter = (ExcludeFilter)filterValue;&lt;BR /&gt;String type = task.getDefinition().getMetadata().getName().toPrefixString(this.namespaceService);&lt;BR /&gt;if (excludeFilter.isMatch(type))&lt;BR /&gt;{&lt;BR /&gt;result = false;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else if (key.equals(PARAM_DUE_BEFORE))&lt;BR /&gt;{&lt;BR /&gt;Date dueDate = (Date)task.getProperties().get(WorkflowModel.PROP_DUE_DATE);&lt;/P&gt;&lt;P&gt;if (!isDateMatchForFilter(dueDate, filterValue, true))&lt;BR /&gt;{&lt;BR /&gt;result = false;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else if (key.equals(PARAM_DUE_AFTER))&lt;BR /&gt;{&lt;BR /&gt;Date dueDate = (Date)task.getProperties().get(WorkflowModel.PROP_DUE_DATE);&lt;/P&gt;&lt;P&gt;if (!isDateMatchForFilter(dueDate, filterValue, false))&lt;BR /&gt;{&lt;BR /&gt;result = false;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else if (key.equals(PARAM_PRIORITY))&lt;BR /&gt;{&lt;BR /&gt;if (!filterValue.equals(task.getProperties().get(WorkflowModel.PROP_PRIORITY).toString()))&lt;BR /&gt;{&lt;BR /&gt;result = false;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else if(key.equals(PARAM_PROPERTY))&lt;BR /&gt;{&lt;BR /&gt;int propQNameEnd = filterValue.toString().indexOf('/');&lt;BR /&gt;if (propQNameEnd &amp;lt; 1)&lt;BR /&gt;{&lt;BR /&gt;if (LOGGER.isDebugEnabled())&lt;BR /&gt;{&lt;BR /&gt;LOGGER.debug("Ignoring invalid property filter:" + filterValue.toString());&lt;BR /&gt;}&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;String propValue = filterValue.toString().substring(propQNameEnd + 1);&lt;BR /&gt;if (propValue.isEmpty())&lt;BR /&gt;{&lt;BR /&gt;if (LOGGER.isDebugEnabled())&lt;BR /&gt;{&lt;BR /&gt;LOGGER.debug("Ignoring empty property value filter [" + propValue + "]");&lt;BR /&gt;}&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;String propQNameStr = filterValue.toString().substring(0, propQNameEnd);&lt;BR /&gt;QName propertyQName;&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;propertyQName = QName.createQName(propQNameStr, namespaceService);&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;if (LOGGER.isDebugEnabled())&lt;BR /&gt;{&lt;BR /&gt;LOGGER.debug("Ignoring invalid QName property filter [" + propQNameStr + "]");&lt;BR /&gt;}&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;if (LOGGER.isDebugEnabled())&lt;BR /&gt;{&lt;BR /&gt;LOGGER.debug("Filtering with property [" + propertyQName.toPrefixString(namespaceService) + "=" + propValue + "]");&lt;BR /&gt;}&lt;BR /&gt;Serializable value = task.getProperties().get(propertyQName);&lt;BR /&gt;if (value != null &amp;amp;&amp;amp; !value.equals(propValue))&lt;BR /&gt;{&lt;BR /&gt;result = false;&lt;BR /&gt;break;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return result;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;/**&lt;BR /&gt;* Comparator to sort workflow tasks by due date in ascending order.&lt;BR /&gt;*/&lt;BR /&gt;class WorkflowTaskDueAscComparator implements Comparator&amp;lt;WorkflowTask&amp;gt;&lt;BR /&gt;{&lt;BR /&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/33527"&gt;@override&lt;/A&gt;&lt;BR /&gt;public int compare(WorkflowTask o1, WorkflowTask o2)&lt;BR /&gt;{&lt;BR /&gt;Date date1 = (Date)o1.getProperties().get(WorkflowModel.PROP_DUE_DATE);&lt;BR /&gt;Date date2 = (Date)o2.getProperties().get(WorkflowModel.PROP_DUE_DATE);&lt;BR /&gt;&lt;BR /&gt;long time1 = date1 == null ? Long.MAX_VALUE : date1.getTime();&lt;BR /&gt;long time2 = date2 == null ? Long.MAX_VALUE : date2.getTime();&lt;BR /&gt;&lt;BR /&gt;long result = time1 - time2;&lt;BR /&gt;&lt;BR /&gt;return (result &amp;gt; 0) ? 1 : (result &amp;lt; 0 ? -1 : 0);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please help me with the solution. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 11:16:06 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17760#M7872</guid>
      <dc:creator>Tabu</dc:creator>
      <dc:date>2021-02-18T11:16:06Z</dc:date>
    </item>
    <item>
      <title>Re: Creating REST API</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17761#M7873</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/84285"&gt;@Tabu&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you looked at the&amp;nbsp;&lt;A href="https://hub.alfresco.com/t5/alfresco-process-services/is-this-posssible-to-get-details-of-completed-task-using/td-p/238965" target="_self" rel="nofollow noopener noreferrer"&gt;task history service&lt;/A&gt;? See &lt;A href="https://stackoverflow.com/questions/18350941/activiti-get-process-instance-details-java-api" target="_self" rel="nofollow noopener noreferrer"&gt;here&lt;/A&gt; too.&lt;/P&gt;
&lt;P&gt;HTH,&lt;/P&gt;</description>
      <pubDate>Thu, 18 Feb 2021 13:46:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17761#M7873</guid>
      <dc:creator>EddieMay</dc:creator>
      <dc:date>2021-02-18T13:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating REST API</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17762#M7874</link>
      <description>&lt;P&gt;Thank you for providing the help. But i want to fetch all the completed tasks of all the users without providing any workflow or process instance id.&lt;/P&gt;&lt;P&gt;Please do help me with the code.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2021 11:57:07 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/creating-rest-api/m-p/17762#M7874</guid>
      <dc:creator>Tabu</dc:creator>
      <dc:date>2021-02-20T11:57:07Z</dc:date>
    </item>
  </channel>
</rss>

