use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceImpl method setRetriesByProcessHistoricQueryBased.
@Override
public BatchDto setRetriesByProcessHistoricQueryBased(SetJobRetriesByProcessDto setJobRetriesDto) {
List<String> processInstanceIds = new ArrayList<String>();
HistoricProcessInstanceQueryDto queryDto = setJobRetriesDto.getHistoricProcessInstanceQuery();
if (queryDto != null) {
HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
List<HistoricProcessInstance> historicProcessInstances = query.list();
for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
processInstanceIds.add(historicProcessInstance.getId());
}
}
if (setJobRetriesDto.getProcessInstances() != null) {
processInstanceIds.addAll(setJobRetriesDto.getProcessInstances());
}
try {
ManagementService managementService = getProcessEngine().getManagementService();
Batch batch = managementService.setJobRetriesAsync(processInstanceIds, (ProcessInstanceQuery) null, setJobRetriesDto.getRetries());
return BatchDto.fromBatch(batch);
} catch (BadUserRequestException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
}
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class ProcessInstanceRestServiceImpl method deleteAsyncHistoricQueryBased.
@Override
public BatchDto deleteAsyncHistoricQueryBased(DeleteProcessInstancesDto deleteProcessInstancesDto) {
List<String> processInstanceIds = new ArrayList<String>();
HistoricProcessInstanceQueryDto queryDto = deleteProcessInstancesDto.getHistoricProcessInstanceQuery();
if (queryDto != null) {
HistoricProcessInstanceQuery query = queryDto.toQuery(getProcessEngine());
List<HistoricProcessInstance> historicProcessInstances = query.list();
for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
processInstanceIds.add(historicProcessInstance.getId());
}
}
if (deleteProcessInstancesDto.getProcessInstanceIds() != null) {
processInstanceIds.addAll(deleteProcessInstancesDto.getProcessInstanceIds());
}
try {
RuntimeService runtimeService = getProcessEngine().getRuntimeService();
Batch batch = runtimeService.deleteProcessInstancesAsync(processInstanceIds, null, deleteProcessInstancesDto.getDeleteReason(), deleteProcessInstancesDto.isSkipCustomListeners(), deleteProcessInstancesDto.isSkipSubprocesses());
return BatchDto.fromBatch(batch);
} catch (BadUserRequestException e) {
throw new InvalidRequestException(Status.BAD_REQUEST, e.getMessage());
}
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class HistoricProcessInstanceResourceImpl method getHistoricProcessInstance.
@Override
public HistoricProcessInstanceDto getHistoricProcessInstance() {
HistoryService historyService = engine.getHistoryService();
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if (instance == null) {
throw new InvalidRequestException(Status.NOT_FOUND, "Historic process instance with id " + processInstanceId + " does not exist");
}
return HistoricProcessInstanceDto.fromHistoricProcessInstance(instance);
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class RestartProcessInstancesCmd method execute.
@Override
public Void execute(final CommandContext commandContext) {
final Collection<String> processInstanceIds = collectProcessInstanceIds();
final List<AbstractProcessInstanceModificationCommand> instructions = builder.getInstructions();
ensureNotEmpty(BadUserRequestException.class, "Restart instructions cannot be empty", "instructions", instructions);
ensureNotEmpty(BadUserRequestException.class, "Process instance ids cannot be empty", "Process instance ids", processInstanceIds);
ensureNotContainsNull(BadUserRequestException.class, "Process instance ids cannot be null", "Process instance ids", processInstanceIds);
final ProcessDefinitionEntity processDefinition = getProcessDefinition(commandContext, builder.getProcessDefinitionId());
ensureNotNull("Process definition cannot be found", "processDefinition", processDefinition);
checkAuthorization(commandContext, processDefinition);
if (writeUserOperationLog) {
writeUserOperationLog(commandContext, processDefinition, processInstanceIds.size(), false);
}
final String processDefinitionId = builder.getProcessDefinitionId();
Runnable runnable = new Runnable() {
@Override
public void run() {
for (String processInstanceId : processInstanceIds) {
HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(commandContext, processInstanceId);
ensureNotNull(BadUserRequestException.class, "Historic process instance cannot be found", "historicProcessInstanceId", historicProcessInstance);
ensureHistoricProcessInstanceNotActive(historicProcessInstance);
ensureSameProcessDefinition(historicProcessInstance, processDefinitionId);
ProcessInstantiationBuilderImpl instantiationBuilder = getProcessInstantiationBuilder(commandExecutor, processDefinitionId);
applyProperties(instantiationBuilder, processDefinition, historicProcessInstance);
ProcessInstanceModificationBuilderImpl modificationBuilder = instantiationBuilder.getModificationBuilder();
modificationBuilder.setModificationOperations(instructions);
VariableMap variables = collectVariables(commandContext, historicProcessInstance);
instantiationBuilder.setVariables(variables);
instantiationBuilder.execute(builder.isSkipCustomListeners(), builder.isSkipIoMappings());
}
}
};
ProcessApplicationContextUtil.doContextSwitch(runnable, processDefinition);
return null;
}
use of org.camunda.bpm.engine.history.HistoricProcessInstance in project camunda-bpm-platform by camunda.
the class MigrationIncidentTest method historicIncidentRemainsOpenAfterMigration.
@Test
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL)
@Deployment(resources = { "org/camunda/bpm/engine/test/api/runtime/migration/calledProcess.bpmn", "org/camunda/bpm/engine/test/api/runtime/migration/calledProcess_v2.bpmn" })
public void historicIncidentRemainsOpenAfterMigration() {
// Given we create a new process instance
ProcessDefinition process1 = engineRule.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("calledProcess").singleResult();
ProcessInstance processInstance = engineRule.getRuntimeService().startProcessInstanceById(process1.getId());
LockedExternalTask task = engineRule.getExternalTaskService().fetchAndLock(1, "foo").topic("foo", 1000L).execute().get(0);
engineRule.getExternalTaskService().handleFailure(task.getId(), "foo", "error", 0, 1000L);
Incident incidentInProcess = engineRule.getRuntimeService().createIncidentQuery().processDefinitionId(process1.getId()).singleResult();
// when
ProcessDefinition process2 = engineRule.getRepositoryService().createProcessDefinitionQuery().processDefinitionKey("calledProcessV2").singleResult();
MigrationPlan migrationPlan = engineRule.getRuntimeService().createMigrationPlan(process1.getId(), process2.getId()).mapEqualActivities().mapActivities("ServiceTask_1p58ywb", "ServiceTask_V2").build();
engineRule.getRuntimeService().newMigration(migrationPlan).processInstanceIds(processInstance.getId()).execute();
// then
HistoricIncident historicIncidentAfterMigration = engineRule.getHistoryService().createHistoricIncidentQuery().singleResult();
assertNotNull(historicIncidentAfterMigration);
assertNull(historicIncidentAfterMigration.getEndTime());
assertTrue(historicIncidentAfterMigration.isOpen());
HistoricProcessInstance historicProcessInstanceAfterMigration = engineRule.getHistoryService().createHistoricProcessInstanceQuery().withIncidents().incidentStatus("open").singleResult();
assertNotNull(historicProcessInstanceAfterMigration);
Incident incidentAfterMigration = engineRule.getRuntimeService().createIncidentQuery().incidentId(incidentInProcess.getId()).singleResult();
assertEquals(process2.getId(), incidentAfterMigration.getProcessDefinitionId());
assertEquals("ServiceTask_V2", incidentAfterMigration.getActivityId());
}
Aggregations