UNPKG

@daedalus/wso2

Version:

This is a set of tools to help connect and manage interactions with various WSO2 products. Please see README.MD for more details.

378 lines (359 loc) 12 kB
const https = require("https"); const axios = require("axios").create({ httpsAgent: new https.Agent({ rejectUnauthorized: false }), proxy: false }); const serviceResource = "bpmn/runtime/tasks/"; const Task = require("../models/Task"); /* data = { server: { url: "" }, auth: { username: "", password: "" } } */ //GET //https://<Host Name>:<Port>/bpmn/runtime/tasks //This request will retrieve all the tasks in the server. const getAll = (data, callback) => { let size = data.size ? data.size : 500; let url = data.server.url + serviceResource + '?size=' + size; let options = { auth: data.auth }; axios .get(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //GET //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId} //This request is used to retrieve a task uniquely using the task Id. const get = (id, data, callback) => { let url = data.server.url + serviceResource + id; let options = { auth: data.auth }; axios .get(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //POST //https://<Host Name>:<Port>/bpmn/query/tasks //This request is used to query for a task, the query can be executed for any of //the attributes of a task. Please check the response body for the attributes. const query = (data, callback) => { let url = data.server.url + "bpmn/query/tasks"; let options = { auth: data.auth }; axios .post(url, data.body, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //PUT //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId} // //This request can be used to update any of the attributes of the task. All request //values are optional. For example, you can only include the assignee attribute in //the request body JSON-object, only updating the assignee of the task, leaving all //other fields unaffected. When an attribute is explicitly included and is set to null, //the task-value will be updated to null. For example, {"dueDate" : null} will clear //the due date of the task. //Not all fields have to be sent when a request is sent as the fields are optional. const update = (id, data, callback) => { let url = data.server.url + serviceResource + id; let options = { auth: data.auth }; axios .put(url, data.body, { auth: options.auth }) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //POST //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId} //This request can be used to complete a task. const complete = (id, data, callback) => { let body = data.body; body.action = "complete"; let url = data.server.url + serviceResource + id; let options = { auth: data.auth }; axios .post(url, body, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //POST //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId} //This request can be used to claim a task. You can claim a task only if there is no //assignee or it has been assigned to a candidate group and you are a part of that group. const claim = (id, data, callback) => { let body = { action: "claim", assignee: data.currentUser }; let url = data.server.url + serviceResource + id; let options = { auth: data.auth }; axios .post(url, body, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //POST //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId} //This request can be used to delegate a task. const delegate = (id, data, callback) => { let body = { action: "delegate", assignee: data.delegateUser }; let url = data.server.url + serviceResource + id; let options = { auth: data.auth }; axios .post(url, body, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //POST //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId} //This request can be used to resolve a task. const resolve = (id, data, callback) => { let body = { action: "resolve" }; let url = data.server.url + serviceResource + id; let options = { auth: data.auth }; axios .post(url, body, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //DELETE //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId}?cascadeHistory={cascadeHistory}&deleteReason={deleteReason} //This request is used to delete a task. A task can be deleted only if its not a part of a //workflow or if it is in the resolved or completed state. The request is compiled of the //taskId, which is the ID of the task to be deleted, cascadeHistory is a boolean value that //is used to indicate whether or not to delete the HistoricTask instance when deleting the //task (if applicable). If not provided, this value defaults to false. Delete reason is the //reason why the task is deleted. This value is ignored when cascadeHistory is true. //There is no response body provided when you delete a Task, but the service status “204” //indicates the task was found and deleted. A service status of “404” indicates the deployment was not found. const deleteTask = (id, data, callback) => { let url = data.server.url + serviceResource + id + "?cascadeHistory=" + data.cascadeHistory + "&deleteReason=" + data.deleteReason; let options = { auth: data.auth, }; axios .delete(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //POST //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId}/comments //This request is used to add a comment to the task. //Parameter saveProcessInstanceId is optional. If true, this saves the //process instance id of the task with the comment. const addComment = (id, data, callback) => { let body = { message: data.comment, saveProcessInstanceId: true }; let url = data.server.url + serviceResource + id + "/comments"; let options = { auth: data.auth }; axios .post(url, body, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //GET //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId}/comments //This request is used to retrieve all the comments in a task. const getAllComments = (data, callback) => { let url = data.server.url + serviceResource + id + "/comments"; let options = { auth: data.auth }; axios .get(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //GET //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId}/comments/{commentId} //This request is used to retrieve all the comments in a task. const getComment = (id, data, callback) => { let url = data.server.url + serviceResource + id + "/comments/" + data.commentId; let options = { auth: data.auth }; axios .get(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //DELETE //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId}/comments/{commentId} //This request is used to delete a specific comment on a task. There is no response //body provided when you delete a comment on a task, but the service status “204” //indicates the comment was found and deleted. A service status of “404” indicates //the deployment was not found. const deleteComment = (data, callback) => { let url = data.server.url + serviceResource + id + "/comments/" + data.commentId; let options = { auth: data.auth }; axios .delete(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; //GET //https://<Host Name>:<Port>/bpmn/runtime/tasks/{taskId}/variables //This request is used to retrieve the value of a variable in the task. //If it is a plain variable, the value is present in the response. const variables = (id, data, callback) => { let url = data.server.url + serviceResource + id + "/variables"; let options = { auth: data.auth }; axios .get(url, options) .then(response => { callback(null, response.data); }) .catch(error => { if (error.response && error.response.data) { callback(null, { success: false, msg: error.response.data}); } else { callback(null, { success: false, msg: 'Uknown Error from Axios'}); } }); }; module.exports = { getAll, get, query, update, complete, claim, delegate, resolve, delete: deleteTask, addComment, getAllComments, getComment, deleteComment, variables };