Activiti - Get Process Instance Details" Java API - business-process-management

I am using Activiti 5.12. As provided, in its user guide, REST API to get he details of a process instance is :
GET /process-instance/{processInstanceId}
Its response is something like this :
{
"id": "2",
"processDefinitionId": "financialReport:1",
"businessKey": "55",
"startTime": "2010-10-13T14:54:26.750+02:00",
"startActivityId": "startFinancialAnalysis",
"startUserId": "kermit",
"completed": false,
"tasks": [
{
"taskId": "3",
"taskName": "Analyze report",
"owner": null,
"assignee": "Kermit",
"startTime": "2010-10-13T14:53:26.750+02:00",
"completed": false
}
],
"activities": [
{
"activityId": "4",
"activityName": "Get report",
"activityType": "ServiceTask",
"startTime": "2010-10-13T14:53:25.950+02:00",
"completed": true,
"duration": 200
}
],
"variables": [
{
"variableName": "reportName",
"variableValue": "classified.pdf"
}
],
"historyVariables": [
{
"variableName": "reportName",
"variableValue": "classified.pdf",
"variableType": "String",
"revision": 1,
"time": "2010-10-13T14:53:26.750+02:00"
}
]
}
A JAVA API for the same is also provided, which is :
ProcessEngines.getProcessEngine(configuredProcessEngineName).getHistoryService().createHistoricProcessInstanceQuery().processInstanceId("somevalue").singleResult()
This Java API does not work, as teh return type HistoricProcessInstance does not have the method to get the task list.
My objective is to get the current state of a process instance, i.e which task it's presently at.
The REST API lists all tasks that process instance has carried out and the last task of the list is the one it's currently executing, as its property completed is false.
I want to achieve the same from java code.
Can you please help me out. Any alternative way to get to my objective is also fine with me.

You can use another query of HistoricService API:
List<HistoricTaskIntance> taskList = getHistoryService()
.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.list()
The current task status can be defined by HistoricTaskInstance.getEndTime() that will return null for open tasks.

I have tried this way out.
SELECT NAME_ FROM act_hi_taskinst where PROC_INST_ID_= 1000 and END_TIME_ IS NULL;"
act_hi_taskinst contains history tasks for each and every instance.
If the process with instance id is completed then you wont get any result, so you can check that condition before moving forward.
I have run this piece of SQL Statement to get the required task name.
The answer given by #Mike also meets the objective. Even here also you have to check whether process is incomplete.

Related

Modify Task.json at build step design time

i wanted to modify task.json on runtime means when i configure my CI task in vsts or tfs.
I created an extension that contribute a build task.
Through this build task i wanted to do something like this, i have done in jenkins. Please Refer screenshot:
1-Requirement) in this image we add global variable(fields) at runtime on clicking Add Global Variables button. It generates two fields one for GVName and another for its value.
2-Requirement) When we select global variable then respective value field change at runtime means it can be dropbox(picklist) or input field that depends on GV type.
3-Requirement) On Job design time we make an ajax call to server that return true/false on based of value we shows error like in image 2.
Is these requirements are feasible in VSTS task.json? If yes, can you help me to solve this.
No, but it can list the available items that returned from the server.
For example:
"inputs": [
{
"name": "APIURL",
"type": "connectedService:Generic",
"label": "API URL",
"required": true,
"helpMarkDown": ""
},
{
"name": "List1",
"type": "pickList",
"label": "List4",
"defaultValue": "",
"required": false,
"helpMarkDown": ""
}
],
"sourceDefinitions": [
{
"target": "List1",
"endpoint": "home/jsontest",
"selector": "jsonpath:$[*].id",
"authKey": "$(APIURL)"
}
],
A thread that may benefit you: Using a web API in task.json to fill picklists buildtask

How do I get a user reference in Microsoft Graph Groups API?

From the Group API and /Conversations endpoint you can get a list of conversations and when looking in the Groups App you can see the user with image.
But data returned from API doesn't have any good data to use for a user lookup.
I would expect an email address at least, not just the name which is far from unique. Is there a efficient way to get the user without traversing all the threads and posts?
Data from API:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('{id}')/threads",
"value": [{
"id": "{id}",
"topic": "Test main thread",
"hasAttachments": false,
"lastDeliveredDateTime": "2017-10-20T11:35:04Z",
"uniqueSenders": [
"Jonas Stensved"
],
"preview": "{message preview content}",
"isLocked": false
},
{
"id": "{id}",
"topic": "The new Test group is ready",
"hasAttachments": false,
"lastDeliveredDateTime": "2017-10-13T10:33:03Z",
"uniqueSenders": [
"Test"
],
"preview": "{message preview content}",
"isLocked": false
}
]
}
How a group in the Groups app looks:
[]
It might help to break down the object hierarchy here:
Group - parent to a collection of Conversation resources
Conversation - parent to a collection of Thread resources
Thread - parent to to a collection of Post resources
Post - the actual content sent to the Group by a User
In order to see which User resources map into a given Thread, you need to drill down another level to find the Post resources contained within the Thread.
You can do this using the $expand=posts parameter to expand the Posts collection. You can also a ($select=from) the $expand so you only return the properties you need to map back to the User resource.
So this query:
/v1.0/groups/{group-id}/threads?$expand=posts($select=from)
will provide you a Thread result like this:
{
"id": "{thread-id}",
"topic": "New Training Plans",
"hasAttachments": false,
"lastDeliveredDateTime": "2017-07-31T18:59:05Z",
"uniqueSenders": [
"HR Taskforce"
],
"preview": "{thread-preview}",
"isLocked": false,
"posts#odata.context": "https://graph.microsoft.com/v1.0/$metadata#groups('{group-id}')/threads('{thread-id}')/posts(from)",
"posts": [{
"#odata.etag": "W/\"CwAAABYAAADE9kXbLjqkSJUGeLzs6eumAAAAAA0/\"",
"id": "{post-id}",
"changeKey": "CwAAABYAAADE9kXbLjqkSJUGeLzs6eumAAAAAA0/",
"from": {
"emailAddress": {
"name": "HR Taskforce",
"address": "HRTaskforce#M365x214355.onmicrosoft.com"
}
}
}]
}
You can try this yourself using this Graph Explorer example.
You can get group members list and iterate over them. Depending on the size o the group this might require paging. You can find more information in the docs: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/group
I hope this helps.

rest/api/2/issue/<issue-id>/transitions returns empty array

I've created an issue that follows this workflow:
When I call rest/api/2/issue/<issue-id>/transitions after creating an issue (which is in OPEN status now) it returns the following JSON:
{
"expand": "transitions",
"transitions": [
{
"id": "4",
"name": "Start Progress",
"to": {
"self": "URL",
"description": "This issue is being actively worked on at the moment by the assignee.",
"iconUrl": "URL",
"name": "In Progress",
"id": "3",
"statusCategory": {
"self": "URL",
"id": 4,
"key": "indeterminate",
"colorName": "yellow",
"name": "In Progress"
}
},
"fields": {}
}
]
}
When I make the same call after I change the issue status to "IN PROGRESS" I get back
{
"expand": "transitions",
"transitions": []
}
My questions are:
In the first response shown above, I expected the transitions to "CLOSED" and "RESOLVED" along with the one to "IN PROGRESS". But I only get back the one leading to "IN PROGRESS". Why?
I expected the second response to contain the transitions to "CLOSED", "RESOLVED" and "OPEN", but it returns an empty array. Why?
Please explain the responses from this API
What call should I make to get the next possible transitions?
This is probably a permission issue. The API only shows the transitions that are available to the current user, thus if you are not allowed to execute the CLOSE or RESOLVE transitions due to conditions in the project workflow, they will not appear in the JSON object.
See getTransitions from the JIRA REST API :
Get a list of the transitions possible for this issue by the current user, along with fields that are required and their types.
In order to get the transitions, you can either log in with an account that has the required permissions (check the corresponding workflow) or modify the conditions of the transition in this workflow.

Dart Services API: how to access the /fixes through the API service?

I am looking at:
https://github.com/dart-lang/dart-services
And am trying to adapt the example given (https://dartpad.dartlang.org/2a7fd9328e0a567ee79b) to pull back information from '/api/dartservices/v1/fixes' rather than '/api/dartservices/v1/analyze'.
Apologies, if I am missing something obvious here but changing the path in the example to:
"https://dart-services.appspot.com/api/dartservices/v1/fixes";
returns an error. Does anyone know how I can get the information from '/api/dartservices/v1/fixes rather than '/api/dartservices/v1/analyze'? Or does anyone have an example of this working?
Thanks.
Sending a POST request to https://dart-services.appspot.com/api/dartservices/v1/fixes with the data the DartPad example sends yields the error message "Missing parameter: 'offset'".
Looking at the discovery doc for the service https://dart-services.appspot.com/api/discovery/v1/apis/dartservices/v1/rest I see both analyze and fixes operations take a SourceRequest:
"SourceRequest": {
"id": "SourceRequest",
"type": "object",
"properties": {
"source": {
"type": "string",
"description": "The Dart source.",
"required": true
},
"offset": {
"type": "integer",
"description": "An optional offset into the source code.",
"format": "int32"
},
"strongMode": {
"type": "boolean",
"description": "An optional signal whether the source should be processed in strong mode"
}
}
offset is not marked as required so maybe there is a bug in the implementation of fixes wrt that parameter.
To make the DartPad example work, change:
Map m = {'source': textArea.value};
to
Map m = {'source': textArea.value, 'offset': 0};

Query for all tasks in specific workspace that are not completed

I have the following cURL cmd running which returns all tasks for a specific userID within a specific workspaceID, but the "completed=false" part of the cmd doesn't influence the data returned. I am trying to exclude all "completed" tasks. Everything else is working as I expected. Below is the current cmd string and a snippet of the data returned back. As you can see one of the returned tasks indicates "completed" is true while the other indicates false.
Anyone see what I may be missing? Thanks in advance for your help.
cURL cmd:
curl -u <api-key>: "https://app.asana.com/api/1.0/tasks?workspace=<workspace>&assignee=<teamMemberId>&completed=false&opt_fields=name,assignee,assignee_status,notes,created_at,modified_at,completed_at,due_on,completed&opt_pretty"
output (partial)
{
"data": [
{
"id": <ID>,
"created_at": "2014-03-11T03:34:52.002Z",
"modified_at": "2014-03-11T23:33:07.544Z",
"name": "<nameoftask>",
"notes": "",
"assignee": {
"id": <ID>
},
"completed": true,
"assignee_status": "upcoming",
"completed_at": "2014-03-11T23:33:06.729Z",
"due_on": "2014-03-11"
},
{
"id": <ID>,
"created_at": "2014-03-11T23:33:07.196Z",
"modified_at": "2014-03-11T23:33:07.196Z",
"name": "<nameoftask>",
"notes": "",
"assignee": {
"id": ID>
},
"completed": false,
"assignee_status": "upcoming",
"completed_at": null,
"due_on": "2014-03-14"
},
TL;DR: You want completed_since=now, not completed=false.
The GET /tasks endpoint doesn't take a parameter completed - it does however take completed_since, which can take a timestamp (as provided by JS's .toISOString()) or the string "now". It always includes incomplete tasks. This is documented in the API Docs on Tasks (specifically the section on "Querying for tasks").
We're looking to improve the way you can filter tasks, but for right now what's documented there is all there is.

Resources