use of org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity in project camunda-bpm-platform by camunda.
the class SetProcessDefinitionVersionCmd method execute.
public Void execute(CommandContext commandContext) {
ProcessEngineConfigurationImpl configuration = commandContext.getProcessEngineConfiguration();
// check that the new process definition is just another version of the same
// process definition that the process instance is using
ExecutionManager executionManager = commandContext.getExecutionManager();
final ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
if (processInstance == null) {
throw new ProcessEngineException("No process instance found for id = '" + processInstanceId + "'.");
} else if (!processInstance.isProcessInstanceExecution()) {
throw new ProcessEngineException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
}
ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();
DeploymentCache deploymentCache = configuration.getDeploymentCache();
ProcessDefinitionEntity currentProcessDefinition;
if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
} else {
currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());
}
ProcessDefinitionEntity newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());
validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
HistoryLevel historyLevel = configuration.getHistoryLevel();
if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {
@Override
public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
return producer.createProcessInstanceUpdateEvt(processInstance);
}
});
}
// switch all sub-executions of the process instance to the new process definition version
List<ExecutionEntity> childExecutions = executionManager.findExecutionsByProcessInstanceId(processInstanceId);
for (ExecutionEntity executionEntity : childExecutions) {
validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
}
// switch all jobs to the new process definition version
List<JobEntity> jobs = commandContext.getJobManager().findJobsByProcessInstanceId(processInstanceId);
List<JobDefinitionEntity> currentJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(currentProcessDefinition.getId());
List<JobDefinitionEntity> newVersionJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(newProcessDefinition.getId());
Map<String, String> jobDefinitionMapping = getJobDefinitionMapping(currentJobDefinitions, newVersionJobDefinitions);
for (JobEntity jobEntity : jobs) {
switchVersionOfJob(jobEntity, newProcessDefinition, jobDefinitionMapping);
}
// switch all incidents to the new process definition version
List<IncidentEntity> incidents = commandContext.getIncidentManager().findIncidentsByProcessInstance(processInstanceId);
for (IncidentEntity incidentEntity : incidents) {
switchVersionOfIncident(commandContext, incidentEntity, newProcessDefinition);
}
// add an entry to the op log
PropertyChange change = new PropertyChange("processDefinitionVersion", currentProcessDefinition.getVersion(), processDefinitionVersion);
commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_MODIFY_PROCESS_INSTANCE, processInstanceId, null, null, Collections.singletonList(change));
return null;
}
use of org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity in project camunda-bpm-platform by camunda.
the class DefaultHistoryEventProducer method initHistoricIncidentEvent.
protected void initHistoricIncidentEvent(HistoricIncidentEventEntity evt, Incident incident, HistoryEventType eventType) {
// init properties
evt.setId(incident.getId());
evt.setProcessDefinitionId(incident.getProcessDefinitionId());
evt.setProcessInstanceId(incident.getProcessInstanceId());
evt.setExecutionId(incident.getExecutionId());
evt.setCreateTime(incident.getIncidentTimestamp());
evt.setIncidentType(incident.getIncidentType());
evt.setActivityId(incident.getActivityId());
evt.setCauseIncidentId(incident.getCauseIncidentId());
evt.setRootCauseIncidentId(incident.getRootCauseIncidentId());
evt.setConfiguration(incident.getConfiguration());
evt.setIncidentMessage(incident.getIncidentMessage());
evt.setTenantId(incident.getTenantId());
evt.setJobDefinitionId(incident.getJobDefinitionId());
IncidentEntity incidentEntity = (IncidentEntity) incident;
ProcessDefinitionEntity definition = incidentEntity.getProcessDefinition();
if (definition != null) {
evt.setProcessDefinitionKey(definition.getKey());
}
// init event type
evt.setEventType(eventType.getEventName());
// init state
IncidentState incidentState = IncidentState.DEFAULT;
if (HistoryEventTypes.INCIDENT_DELETE.equals(eventType)) {
incidentState = IncidentState.DELETED;
} else if (HistoryEventTypes.INCIDENT_RESOLVE.equals(eventType)) {
incidentState = IncidentState.RESOLVED;
}
evt.setIncidentState(incidentState.getStateCode());
}
use of org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity in project camunda-bpm-platform by camunda.
the class MigratingInstanceParser method parse.
public MigratingProcessInstance parse(String processInstanceId, MigrationPlan migrationPlan, MigratingProcessInstanceValidationReportImpl processInstanceReport) {
CommandContext commandContext = Context.getCommandContext();
List<EventSubscriptionEntity> eventSubscriptions = fetchEventSubscriptions(commandContext, processInstanceId);
List<ExecutionEntity> executions = fetchExecutions(commandContext, processInstanceId);
List<ExternalTaskEntity> externalTasks = fetchExternalTasks(commandContext, processInstanceId);
List<IncidentEntity> incidents = fetchIncidents(commandContext, processInstanceId);
List<JobEntity> jobs = fetchJobs(commandContext, processInstanceId);
List<TaskEntity> tasks = fetchTasks(commandContext, processInstanceId);
List<VariableInstanceEntity> variables = fetchVariables(commandContext, processInstanceId);
ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);
processInstance.restoreProcessInstance(executions, eventSubscriptions, variables, tasks, jobs, incidents, externalTasks);
ProcessDefinitionEntity targetProcessDefinition = Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedProcessDefinitionById(migrationPlan.getTargetProcessDefinitionId());
List<JobDefinitionEntity> targetJobDefinitions = fetchJobDefinitions(commandContext, targetProcessDefinition.getId());
final MigratingInstanceParseContext parseContext = new MigratingInstanceParseContext(this, migrationPlan, processInstance, targetProcessDefinition).eventSubscriptions(eventSubscriptions).externalTasks(externalTasks).incidents(incidents).jobs(jobs).tasks(tasks).targetJobDefinitions(targetJobDefinitions).variables(variables);
ActivityInstance activityInstance = engine.getRuntimeService().getActivityInstance(processInstanceId);
ActivityInstanceWalker activityInstanceWalker = new ActivityInstanceWalker(activityInstance);
activityInstanceWalker.addPreVisitor(new TreeVisitor<ActivityInstance>() {
@Override
public void visit(ActivityInstance obj) {
activityInstanceHandler.handle(parseContext, obj);
}
});
activityInstanceWalker.walkWhile();
CompensationEventSubscriptionWalker compensateSubscriptionsWalker = new CompensationEventSubscriptionWalker(parseContext.getMigratingActivityInstances());
compensateSubscriptionsWalker.addPreVisitor(new TreeVisitor<EventSubscriptionEntity>() {
@Override
public void visit(EventSubscriptionEntity obj) {
compensationInstanceHandler.handle(parseContext, obj);
}
});
compensateSubscriptionsWalker.walkWhile();
for (IncidentEntity incidentEntity : incidents) {
incidentHandler.handle(parseContext, incidentEntity);
}
parseContext.validateNoEntitiesLeft(processInstanceReport);
return parseContext.getMigratingProcessInstance();
}
use of org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity in project camunda-bpm-platform by camunda.
the class PvmExecutionImpl method resolveIncident.
/**
* Resolves an incident with given id.
*
* @param incidentId
*/
@Override
public void resolveIncident(final String incidentId) {
IncidentEntity incident = (IncidentEntity) Context.getCommandContext().getIncidentManager().findIncidentById(incidentId);
IncidentHandler incidentHandler = findIncidentHandler(incident.getIncidentType());
if (incidentHandler == null) {
incidentHandler = new DefaultIncidentHandler(incident.getIncidentType());
}
IncidentContext incidentContext = new IncidentContext(incident);
incidentHandler.resolveIncident(incidentContext);
}
Aggregations