Containerization feature of SO
[so.git] / bpmn / mso-infrastructure-bpmn / src / main / java / org / onap / so / bpmn / common / workflow / service / ProcessEngineAwareService.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.so.bpmn.common.workflow.service;
23
24 import java.util.Optional;
25
26 import javax.ws.rs.ext.Provider;
27
28 import org.camunda.bpm.engine.ProcessEngineServices;
29 import org.camunda.bpm.engine.ProcessEngines;
30 import org.springframework.stereotype.Service;
31
32 /**
33  * Base class for services that must be process-engine aware. The only
34  * process engine currently supported is the "default" process engine.
35  */
36 @Service
37 public class ProcessEngineAwareService {
38         
39         private final String processEngineName = "default";
40         private volatile Optional<ProcessEngineServices> pes4junit = Optional.empty();
41         
42         /**
43          * Gets the process engine name.
44          * @return the process engine name
45          */
46         public String getProcessEngineName() {
47                 return processEngineName;
48         }
49
50         /**
51          * Gets process engine services.
52          * @return process engine services
53          */
54         public ProcessEngineServices getProcessEngineServices() {
55                 return pes4junit.orElse(ProcessEngines.getProcessEngine(
56                                 getProcessEngineName()));
57         }
58
59         /**
60          * Allows a particular process engine to be specified, overriding the
61          * usual process engine lookup by name.  Intended primarily for the
62          * unit test environment.
63          * @param pes process engine services
64          */
65         public void setProcessEngineServices4junit(ProcessEngineServices pes) {
66                 pes4junit = Optional.ofNullable(pes);
67         }
68 }