Add unit test for vfc-nfvo-wfengine
[vfc/nfvo/wfengine.git] / activiti-extension / src / main / java / org / activiti / engine / impl / pvm / runtime / AtomicOperationProcessStart.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.activiti.engine.impl.pvm.runtime;
17
18 import java.util.List;
19 import java.util.Map;
20
21 import org.activiti.engine.delegate.event.ActivitiEventType;
22 import org.activiti.engine.delegate.event.impl.ActivitiEventBuilder;
23 import org.activiti.engine.impl.context.Context;
24 import org.activiti.engine.impl.pvm.process.ActivityImpl;
25 import org.activiti.engine.impl.pvm.process.ProcessDefinitionImpl;
26 import org.activiti.engine.impl.pvm.process.ScopeImpl;
27
28 public class AtomicOperationProcessStart extends AbstractEventAtomicOperation {
29   @Override
30   public boolean isAsync(InterpretableExecution execution) {
31     return true;
32   }
33
34   protected ScopeImpl getScope(InterpretableExecution execution) {
35     return execution.getProcessDefinition();
36   }
37
38   protected String getEventName() {
39     return "start";
40   }
41
42   protected void eventNotificationsCompleted(InterpretableExecution execution) {
43     if ((Context.getProcessEngineConfiguration() != null)
44         && (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled())) {
45       Map variablesMap = null;
46       try {
47         variablesMap = execution.getVariables();
48       } catch (Throwable localThrowable) {
49       }
50       Context
51           .getProcessEngineConfiguration()
52           .getEventDispatcher()
53           .dispatchEvent(
54               ActivitiEventBuilder.createEntityWithVariablesEvent(
55                   ActivitiEventType.ENTITY_INITIALIZED, execution, variablesMap, false));
56
57       Context
58           .getProcessEngineConfiguration()
59           .getEventDispatcher()
60           .dispatchEvent(
61               ActivitiEventBuilder.createProcessStartedEvent(execution, variablesMap, false));
62     }
63
64     ProcessDefinitionImpl processDefinition = execution.getProcessDefinition();
65     StartingExecution startingExecution = execution.getStartingExecution();
66     List initialActivityStack =
67         processDefinition.getInitialActivityStack(startingExecution.getInitial());
68     execution.setActivity((ActivityImpl) initialActivityStack.get(0));
69     execution.performOperation(PROCESS_START_INITIAL);
70   }
71 }