use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.
the class ApplicationCreationWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
if (application == null) {
// this is when complete method is executed through workflow rest api
application = applicationDAO.getApplication(getWorkflowReference());
}
WorkflowResponse response = workflowExecutor.complete(this);
// setting the workflow status from the one getting from the executor. this gives the executor developer
// to change the state as well.
setStatus(response.getWorkflowStatus());
String applicationState = "";
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Application Creation workflow complete: Approved");
}
getApiGateway().addApplication(application);
applicationState = APIMgtConstants.ApplicationStatus.APPLICATION_APPROVED;
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Application Creation workflow complete: Rejected");
}
applicationState = APIMgtConstants.ApplicationStatus.APPLICATION_REJECTED;
}
applicationDAO.updateApplicationState(getWorkflowReference(), applicationState);
updateWorkflowEntries(this);
return response;
}
use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.
the class DefaultWorkflowExecutor method complete.
/**
* Complete the external process status
* Based on the workflow status we will update the status column of the
* Application table
*
* @param workFlow - Workflow
*/
public WorkflowResponse complete(Workflow workFlow) throws WorkflowException {
if (log.isDebugEnabled()) {
log.debug("Executing complete() in Workflow for " + workFlow.getWorkflowType());
}
WorkflowResponse workflowResponse = new GeneralWorkflowResponse();
workflowResponse.setWorkflowStatus(workFlow.getStatus());
return workflowResponse;
}
use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.
the class SubscriptionDeletionWorkflow method completeWorkflow.
public WorkflowResponse completeWorkflow(WorkflowExecutor workflowExecutor) throws APIManagementException {
if (subscription == null) {
// this is when complete method is executed through workflow rest api
this.subscription = apiSubscriptionDAO.getAPISubscription(getWorkflowReference());
}
WorkflowResponse response = workflowExecutor.complete(this);
setStatus(response.getWorkflowStatus());
List<SubscriptionValidationData> subscriptionValidationDataList = null;
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription deletion workflow complete: Approved");
}
if (subscription.getApi() != null && subscription.getApplication() != null) {
subscriptionValidationDataList = apiSubscriptionDAO.getAPISubscriptionsOfAPIForValidation(subscription.getApi().getContext(), subscription.getApi().getVersion(), subscription.getApplication().getId());
}
apiSubscriptionDAO.deleteAPISubscription(getWorkflowReference());
} else if (WorkflowStatus.REJECTED == response.getWorkflowStatus()) {
if (log.isDebugEnabled()) {
log.debug("Subscription deletion workflow complete: Rejected");
}
}
updateWorkflowEntries(this);
if (WorkflowStatus.APPROVED == response.getWorkflowStatus()) {
if (subscriptionValidationDataList != null && !subscriptionValidationDataList.isEmpty()) {
apiGateway.deleteAPISubscription(subscriptionValidationDataList);
if (log.isDebugEnabled()) {
log.debug("Subscription for API : " + subscription.getApi().getName() + " with " + "application : " + subscription.getApplication().getName() + " has been successfully " + "removed from gateway");
}
}
}
return response;
}
use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImpl method workflowsWorkflowReferenceIdPut.
@Override
public Response workflowsWorkflowReferenceIdPut(String workflowReferenceId, WorkflowRequestDTO body, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
Workflow workflow = apiMgtAdminService.retrieveWorkflow(workflowReferenceId);
if (workflow == null) {
String errorMessage = "Workflow entry not found for: " + workflowReferenceId;
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.WORKFLOW_NOT_FOUND);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
if (WorkflowStatus.APPROVED == workflow.getStatus()) {
String errorMessage = "Workflow is already in complete state";
APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.WORKFLOW_ALREADY_COMPLETED);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
WorkflowExecutor workflowExecutor = WorkflowExecutorFactory.getInstance().getWorkflowExecutor(workflow.getWorkflowType());
if (body == null) {
RestApiUtil.handleBadRequest("Request payload is missing", log);
}
if (body.getDescription() != null) {
workflow.setWorkflowDescription(body.getDescription());
}
if (body.getStatus() == null) {
String errorMessage = "Workflow status is not defined";
APIManagementException e = new APIManagementException(errorMessage, ExceptionCodes.WORKFLOW_STATE_MISSING);
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} else {
workflow.setStatus(WorkflowStatus.valueOf(body.getStatus().toString()));
}
if (body.getAttributes() != null) {
Map<String, String> existingAttributs = workflow.getAttributes();
Map<String, String> newAttributes = body.getAttributes();
if (existingAttributs == null) {
workflow.setAttributes(newAttributes);
} else {
newAttributes.forEach(existingAttributs::putIfAbsent);
workflow.setAttributes(existingAttributs);
}
}
WorkflowResponse response = apiMgtAdminService.completeWorkflow(workflowExecutor, workflow);
WorkflowResponseDTO workflowResponseDTO = WorkflowMappingUtil.toWorkflowResponseDTO(response);
return Response.ok().entity(workflowResponseDTO).build();
}
}
} catch (APIManagementException e) {
String errorMessage = "Error while completing workflow for reference : " + workflowReferenceId + ". " + e.getMessage();
Map<String, String> paramList = new HashMap<>();
paramList.put(APIMgtConstants.ExceptionsConstants.WORKFLOW_REF_ID, workflowReferenceId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.humantask.core.engine.commands.Complete in project carbon-business-process by wso2.
the class ProcessStatisticsService method avgTaskTimeDurationForCompletedProcesses.
/**
* Average task duration for completed processes
*
* @param pId processDefintionId of the process selected to view the average time duration for each task
* @return list of completed tasks with the average time duration for the selected process
*/
@GET
@Path("/task-instances/duration/avarage/{pid}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public ResponseHolder avgTaskTimeDurationForCompletedProcesses(@PathParam("pid") String pId) {
RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
HistoryService historyService = BPMNOSGIService.getHistoryService();
long processCount = repositoryService.createProcessDefinitionQuery().processDefinitionTenantId(getTenantIdStr()).processDefinitionId(pId).count();
if (processCount == 0) {
throw new ActivitiObjectNotFoundException("Count not find a matching process with PID '" + pId + "'.");
}
ResponseHolder response = new ResponseHolder();
List<Object> taskListForProcess = new ArrayList<>();
HashMap<String, Long> map = new HashMap<>();
// Get the number of completed/finished process instance for each process definition
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(getTenantIdStr()).processDefinitionId(pId).finished();
// Get the count of the complete process instances
long noOfHistoricInstances = historicProcessInstanceQuery.count();
// If the deployed process does not have any completed process instances --> Ignore
if (noOfHistoricInstances == 0) {
response.setData(taskListForProcess);
} else // If the deployed process has completed process instances --> then
{
TaskInstanceAverageInfo tInstance;
// Get the list of completed tasks/activities in the completed process instance by passing the
// process definition id of the process
List<HistoricTaskInstance> taskList = BPMNOSGIService.getHistoryService().createHistoricTaskInstanceQuery().taskTenantId(getTenantIdStr()).processDefinitionId(pId).processFinished().list();
// Iterate through each completed task/activity and get the task name and duration
for (HistoricTaskInstance taskInstance : taskList) {
// Get the task name
String taskKey = taskInstance.getTaskDefinitionKey();
// Get the time duration taken for the task to be completed
long taskDuration = taskInstance.getDurationInMillis();
if (map.containsKey(taskKey)) {
long tt = map.get(taskKey);
map.put(taskKey, taskDuration + tt);
} else {
map.put(taskKey, taskDuration);
}
// Iterating Task List finished
}
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext()) {
String key = iterator.next().toString();
double value = map.get(key) / noOfHistoricInstances;
tInstance = new TaskInstanceAverageInfo();
tInstance.setTaskDefinitionKey(key);
tInstance.setAverageTimeForCompletion(value);
taskListForProcess.add(tInstance);
}
response.setData(taskListForProcess);
}
return response;
}
Aggregations