use of org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl in project Activiti by Activiti.
the class TimerEventDefinitionParseHandler method createTimer.
protected TimerDeclarationImpl createTimer(BpmnParse bpmnParse, TimerEventDefinition timerEventDefinition, ScopeImpl timerActivity, String jobHandlerType) {
TimerDeclarationType type = null;
Expression expression = null;
Expression endDate = null;
Expression calendarName = null;
ExpressionManager expressionManager = bpmnParse.getExpressionManager();
if (StringUtils.isNotEmpty(timerEventDefinition.getTimeDate())) {
// TimeDate
type = TimerDeclarationType.DATE;
expression = expressionManager.createExpression(timerEventDefinition.getTimeDate());
} else if (StringUtils.isNotEmpty(timerEventDefinition.getTimeCycle())) {
// TimeCycle
type = TimerDeclarationType.CYCLE;
expression = expressionManager.createExpression(timerEventDefinition.getTimeCycle());
//support for endDate
if (StringUtils.isNotEmpty(timerEventDefinition.getEndDate())) {
endDate = expressionManager.createExpression(timerEventDefinition.getEndDate());
}
} else if (StringUtils.isNotEmpty(timerEventDefinition.getTimeDuration())) {
// TimeDuration
type = TimerDeclarationType.DURATION;
expression = expressionManager.createExpression(timerEventDefinition.getTimeDuration());
}
if (StringUtils.isNotEmpty(timerEventDefinition.getCalendarName())) {
calendarName = expressionManager.createExpression(timerEventDefinition.getCalendarName());
}
// neither date, cycle or duration configured!
if (expression == null) {
logger.warn("Timer needs configuration (either timeDate, timeCycle or timeDuration is needed) (" + timerActivity.getId() + ")");
}
String jobHandlerConfiguration = timerActivity.getId();
if (jobHandlerType.equalsIgnoreCase(TimerExecuteNestedActivityJobHandler.TYPE) || jobHandlerType.equalsIgnoreCase(TimerCatchIntermediateEventJobHandler.TYPE) || jobHandlerType.equalsIgnoreCase(TimerStartEventJobHandler.TYPE)) {
jobHandlerConfiguration = TimerStartEventJobHandler.createConfiguration(timerActivity.getId(), endDate, calendarName);
}
// Parse the timer declaration
// TODO move the timer declaration into the bpmn activity or next to the
// TimerSession
TimerDeclarationImpl timerDeclaration = new TimerDeclarationImpl(expression, type, jobHandlerType, endDate, calendarName);
timerDeclaration.setJobHandlerConfiguration(jobHandlerConfiguration);
timerDeclaration.setExclusive(true);
return timerDeclaration;
}
use of org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl in project Activiti by Activiti.
the class TimerEventDefinitionParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, TimerEventDefinition timerEventDefinition) {
ActivityImpl timerActivity = bpmnParse.getCurrentActivity();
if (bpmnParse.getCurrentFlowElement() instanceof StartEvent) {
ProcessDefinitionEntity processDefinition = bpmnParse.getCurrentProcessDefinition();
timerActivity.setProperty("type", "startTimerEvent");
TimerDeclarationImpl timerDeclaration = createTimer(bpmnParse, timerEventDefinition, timerActivity, TimerStartEventJobHandler.TYPE);
String jobHandlerConfiguration = timerDeclaration.getJobHandlerConfiguration();
Map<String, JobHandler> jobHandlers = Context.getProcessEngineConfiguration().getJobHandlers();
JobHandler jobHandler = jobHandlers.get(TimerStartEventJobHandler.TYPE);
jobHandlerConfiguration = ((TimerEventHandler) jobHandler).setProcessDefinitionKeyToConfiguration(jobHandlerConfiguration, processDefinition.getKey());
jobHandlerConfiguration = ((TimerEventHandler) jobHandler).setActivityIdToConfiguration(jobHandlerConfiguration, timerActivity.getId());
timerDeclaration.setJobHandlerConfiguration(jobHandlerConfiguration);
List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) processDefinition.getProperty(PROPERTYNAME_START_TIMER);
if (timerDeclarations == null) {
timerDeclarations = new ArrayList<TimerDeclarationImpl>();
processDefinition.setProperty(PROPERTYNAME_START_TIMER, timerDeclarations);
}
timerDeclarations.add(timerDeclaration);
} else if (bpmnParse.getCurrentFlowElement() instanceof IntermediateCatchEvent) {
timerActivity.setProperty("type", "intermediateTimer");
TimerDeclarationImpl timerDeclaration = createTimer(bpmnParse, timerEventDefinition, timerActivity, TimerCatchIntermediateEventJobHandler.TYPE);
if (getPrecedingEventBasedGateway(bpmnParse, (IntermediateCatchEvent) bpmnParse.getCurrentFlowElement()) != null) {
addTimerDeclaration(timerActivity.getParent(), timerDeclaration);
} else {
addTimerDeclaration(timerActivity, timerDeclaration);
timerActivity.setScope(true);
}
} else if (bpmnParse.getCurrentFlowElement() instanceof BoundaryEvent) {
timerActivity.setProperty("type", "boundaryTimer");
TimerDeclarationImpl timerDeclaration = createTimer(bpmnParse, timerEventDefinition, timerActivity, TimerExecuteNestedActivityJobHandler.TYPE);
// ACT-1427
BoundaryEvent boundaryEvent = (BoundaryEvent) bpmnParse.getCurrentFlowElement();
boolean interrupting = boundaryEvent.isCancelActivity();
if (interrupting) {
timerDeclaration.setInterruptingTimer(true);
}
addTimerDeclaration(timerActivity.getParent(), timerDeclaration);
if (timerActivity.getParent() instanceof ActivityImpl) {
((ActivityImpl) timerActivity.getParent()).setScope(true);
}
timerActivity.setActivityBehavior(bpmnParse.getActivityBehaviorFactory().createBoundaryEventActivityBehavior((BoundaryEvent) bpmnParse.getCurrentFlowElement(), interrupting, timerActivity));
}
}
use of org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl in project Activiti by Activiti.
the class BpmnDeployer method addTimerDeclarations.
@SuppressWarnings("unchecked")
protected void addTimerDeclarations(ProcessDefinitionEntity processDefinition, List<TimerEntity> timers) {
List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_START_TIMER);
if (timerDeclarations != null) {
for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
TimerEntity timer = timerDeclaration.prepareTimerEntity(null);
if (timer != null) {
timer.setProcessDefinitionId(processDefinition.getId());
// Inherit timer (if appliccable)
if (processDefinition.getTenantId() != null) {
timer.setTenantId(processDefinition.getTenantId());
}
timers.add(timer);
}
}
}
}
use of org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl in project Activiti by Activiti.
the class DeploymentEntityManager method deleteDeployment.
public void deleteDeployment(String deploymentId, boolean cascade) {
List<ProcessDefinition> processDefinitions = getDbSqlSession().createProcessDefinitionQuery().deploymentId(deploymentId).list();
// Remove the deployment link from any model.
// The model will still exists, as a model is a source for a deployment model and has a different lifecycle
List<Model> models = getDbSqlSession().createModelQueryImpl().deploymentId(deploymentId).list();
for (Model model : models) {
ModelEntity modelEntity = (ModelEntity) model;
modelEntity.setDeploymentId(null);
getModelManager().updateModel(modelEntity);
}
if (cascade) {
// delete process instances
for (ProcessDefinition processDefinition : processDefinitions) {
String processDefinitionId = processDefinition.getId();
getProcessInstanceManager().deleteProcessInstancesByProcessDefinition(processDefinitionId, "deleted deployment", cascade);
}
}
for (ProcessDefinition processDefinition : processDefinitions) {
String processDefinitionId = processDefinition.getId();
// remove related authorization parameters in IdentityLink table
getIdentityLinkManager().deleteIdentityLinksByProcDef(processDefinitionId);
// event subscriptions
List<EventSubscriptionEntity> eventSubscriptionEntities = getEventSubscriptionManager().findEventSubscriptionsByTypeAndProcessDefinitionId(null, processDefinitionId, // null type ==> all types
processDefinition.getTenantId());
for (EventSubscriptionEntity eventSubscriptionEntity : eventSubscriptionEntities) {
eventSubscriptionEntity.delete();
}
getProcessDefinitionInfoManager().deleteProcessDefinitionInfo(processDefinitionId);
}
// delete process definitions from db
getProcessDefinitionManager().deleteProcessDefinitionsByDeploymentId(deploymentId);
for (ProcessDefinition processDefinition : processDefinitions) {
// remove timer start events for current process definition:
List<Job> timerStartJobs = Context.getCommandContext().getJobEntityManager().findJobsByTypeAndProcessDefinitionId(TimerStartEventJobHandler.TYPE, processDefinition.getId());
if (timerStartJobs != null && timerStartJobs.size() > 0) {
for (Job timerStartJob : timerStartJobs) {
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.JOB_CANCELED, timerStartJob, null, null, processDefinition.getId()));
}
((JobEntity) timerStartJob).delete();
}
}
// If previous process definition version has a timer/message/signal start event, it must be added
ProcessDefinitionEntity latestProcessDefinition = findLatestProcessDefinition(processDefinition);
// Only if the currently deleted process definition is the latest version, we fall back to the previous start event type
if (processDefinition.getId().equals(latestProcessDefinition.getId())) {
// Try to find a previous version (it could be some versions are missing due to deletions)
ProcessDefinition previousProcessDefinition = findNewLatestProcessDefinitionAfterRemovalOf(processDefinition);
if (previousProcessDefinition != null) {
// Need to resolve process definition to make sure it's parsed
ProcessDefinitionEntity resolvedProcessDefinition = Context.getProcessEngineConfiguration().getDeploymentManager().resolveProcessDefinition((ProcessDefinitionEntity) previousProcessDefinition);
// Timer start
List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) resolvedProcessDefinition.getProperty(BpmnParse.PROPERTYNAME_START_TIMER);
if (timerDeclarations != null) {
for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
TimerEntity timer = timerDeclaration.prepareTimerEntity(null);
timer.setProcessDefinitionId(previousProcessDefinition.getId());
if (previousProcessDefinition.getTenantId() != null) {
timer.setTenantId(previousProcessDefinition.getTenantId());
}
Context.getCommandContext().getJobEntityManager().schedule(timer);
}
}
// Signal / Message start
List<EventSubscriptionDeclaration> signalEventDefinitions = (List<EventSubscriptionDeclaration>) resolvedProcessDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
if (signalEventDefinitions != null) {
for (EventSubscriptionDeclaration eventDefinition : signalEventDefinitions) {
if (eventDefinition.getEventType().equals("signal") && eventDefinition.isStartEvent()) {
SignalEventSubscriptionEntity subscriptionEntity = new SignalEventSubscriptionEntity();
subscriptionEntity.setEventName(eventDefinition.getEventName());
subscriptionEntity.setActivityId(eventDefinition.getActivityId());
subscriptionEntity.setProcessDefinitionId(previousProcessDefinition.getId());
subscriptionEntity.setTenantId(previousProcessDefinition.getTenantId());
subscriptionEntity.insert();
} else if (eventDefinition.getEventType().equals("message") && eventDefinition.isStartEvent()) {
MessageEventSubscriptionEntity newSubscription = new MessageEventSubscriptionEntity();
newSubscription.setEventName(eventDefinition.getEventName());
newSubscription.setActivityId(eventDefinition.getActivityId());
newSubscription.setConfiguration(previousProcessDefinition.getId());
newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());
newSubscription.setTenantId(previousProcessDefinition.getTenantId());
newSubscription.insert();
}
}
}
}
}
}
getResourceManager().deleteResourcesByDeploymentId(deploymentId);
getDbSqlSession().delete("deleteDeployment", deploymentId);
}
use of org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl in project Activiti by Activiti.
the class ExecutionEntity method initialize.
// scopes ///////////////////////////////////////////////////////////////////
@SuppressWarnings("unchecked")
public void initialize() {
log.debug("initializing {}", this);
ScopeImpl scope = getScopeObject();
ensureParentInitialized();
// initialize the lists of referenced objects (prevents db queries)
variableInstances = new HashMap<String, VariableInstanceEntity>();
eventSubscriptions = new ArrayList<EventSubscriptionEntity>();
// Cached entity-state initialized to null, all bits are zero, indicating NO entities present
cachedEntityState = 0;
List<TimerDeclarationImpl> timerDeclarations = (List<TimerDeclarationImpl>) scope.getProperty(BpmnParse.PROPERTYNAME_TIMER_DECLARATION);
if (timerDeclarations != null) {
for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
TimerEntity timer = timerDeclaration.prepareTimerEntity(this);
if (timer != null) {
Context.getCommandContext().getJobEntityManager().schedule(timer);
}
}
}
// create event subscriptions for the current scope
List<EventSubscriptionDeclaration> eventSubscriptionDeclarations = (List<EventSubscriptionDeclaration>) scope.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
if (eventSubscriptionDeclarations != null) {
for (EventSubscriptionDeclaration eventSubscriptionDeclaration : eventSubscriptionDeclarations) {
if (!eventSubscriptionDeclaration.isStartEvent()) {
EventSubscriptionEntity eventSubscriptionEntity = eventSubscriptionDeclaration.prepareEventSubscriptionEntity(this);
if (getTenantId() != null) {
eventSubscriptionEntity.setTenantId(getTenantId());
}
eventSubscriptionEntity.insert();
}
}
}
}
Aggregations