Search in sources :

Example 6 with HistoryService

use of org.activiti.engine.HistoryService in project carbon-business-process by wso2.

the class BPMNInstanceService method deleteProcessInstance.

/**
 * Delete process instance by passing instance ID
 *
 * @param instanceId
 * @throws BPSFault
 */
public void deleteProcessInstance(String instanceId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
    if (processInstances.isEmpty()) {
        HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
        List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
        if (historicProcessInstances.isEmpty()) {
            String msg = "No process instances with the ID: " + instanceId;
            log.error(msg);
            throw new BPSFault(msg);
        }
        historyService.deleteHistoricProcessInstance(instanceId);
        return;
    }
    runtimeService.deleteProcessInstance(instanceId, "Deleted by user: " + tenantId);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) HistoryService(org.activiti.engine.HistoryService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 7 with HistoryService

use of org.activiti.engine.HistoryService in project carbon-business-process by wso2.

the class BPMNInstanceService method getPaginatedHistoryInstances.

/**
 * Get paginated history instances
 *
 * @param start
 * @param size
 * @return list of BPMNInstances
 */
public BPMNInstance[] getPaginatedHistoryInstances(int start, int size) {
    BPMNInstance bpmnInstance;
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<BPMNInstance> bpmnInstances = new ArrayList<>();
    HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
    HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).finished().includeProcessVariables();
    historyInstanceCount = (int) query.count();
    List<HistoricProcessInstance> historicProcessInstances = query.listPage(start, size);
    for (HistoricProcessInstance instance : historicProcessInstances) {
        bpmnInstance = new BPMNInstance();
        bpmnInstance.setInstanceId(instance.getId());
        bpmnInstance.setProcessId(instance.getProcessDefinitionId());
        bpmnInstance.setStartTime(instance.getStartTime());
        bpmnInstance.setEndTime(instance.getEndTime());
        bpmnInstance.setVariables(formatVariables(instance.getProcessVariables()));
        bpmnInstances.add(bpmnInstance);
    }
    return bpmnInstances.toArray(new BPMNInstance[bpmnInstances.size()]);
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HistoryService(org.activiti.engine.HistoryService)

Example 8 with HistoryService

use of org.activiti.engine.HistoryService in project carbon-business-process by wso2.

the class HistoricTaskInstanceService method deleteTaskInstance.

@DELETE
@Path("/{taskId}")
public Response deleteTaskInstance(@PathParam("taskId") String taskId) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    historyService.deleteHistoricTaskInstance(taskId);
    return Response.ok().status(Response.Status.NO_CONTENT).build();
}
Also used : HistoryService(org.activiti.engine.HistoryService)

Example 9 with HistoryService

use of org.activiti.engine.HistoryService in project carbon-business-process by wso2.

the class HistoricTaskInstanceService method getTaskIdentityLinks.

@GET
@Path("/{taskId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getTaskIdentityLinks(@PathParam("taskId") String taskId) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    List<HistoricIdentityLink> identityLinks = historyService.getHistoricIdentityLinksForTask(taskId);
    List<HistoricIdentityLinkResponse> historicIdentityLinkResponseList = new ArrayList<>();
    if (identityLinks != null) {
        historicIdentityLinkResponseList = new RestResponseFactory().createHistoricIdentityLinkResponseList(identityLinks, uriInfo.getBaseUri().toString());
    }
    HistoricIdentityLinkResponseCollection historicIdentityLinkResponseCollection = new HistoricIdentityLinkResponseCollection();
    historicIdentityLinkResponseCollection.setHistoricIdentityLinkResponses(historicIdentityLinkResponseList);
    return Response.ok().entity(historicIdentityLinkResponseCollection).build();
}
Also used : HistoricIdentityLinkResponse(org.wso2.carbon.bpmn.rest.model.history.HistoricIdentityLinkResponse) HistoricIdentityLink(org.activiti.engine.history.HistoricIdentityLink) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricIdentityLinkResponseCollection(org.wso2.carbon.bpmn.rest.model.history.HistoricIdentityLinkResponseCollection) ArrayList(java.util.ArrayList) HistoryService(org.activiti.engine.HistoryService)

Example 10 with HistoryService

use of org.activiti.engine.HistoryService in project carbon-business-process by wso2.

the class HistoricVariableInstanceService method getVariableFromRequest.

protected RestVariable getVariableFromRequest(boolean includeBinary, String varInstanceId) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricVariableInstance varObject = historyService.createHistoricVariableInstanceQuery().id(varInstanceId).singleResult();
    if (varObject == null) {
        throw new ActivitiObjectNotFoundException("Historic variable instance '" + varInstanceId + "' couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(varObject.getVariableName(), varObject.getValue(), null, varInstanceId, RestResponseFactory.VARIABLE_HISTORY_VARINSTANCE, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Aggregations

HistoryService (org.activiti.engine.HistoryService)31 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)11 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)10 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)6 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)6 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 RuntimeService (org.activiti.engine.RuntimeService)4 HashMap (java.util.HashMap)3 HistoricVariableInstance (org.activiti.engine.history.HistoricVariableInstance)3 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 RepositoryService (org.activiti.engine.RepositoryService)2 HistoricActivityInstanceQuery (org.activiti.engine.history.HistoricActivityInstanceQuery)2 HistoricDetail (org.activiti.engine.history.HistoricDetail)2 HistoricDetailQuery (org.activiti.engine.history.HistoricDetailQuery)2