added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / camunda / service / ProcessEngineAwareService.java
diff --git a/otf-camunda/src/main/java/org/oran/otf/camunda/service/ProcessEngineAwareService.java b/otf-camunda/src/main/java/org/oran/otf/camunda/service/ProcessEngineAwareService.java
new file mode 100644 (file)
index 0000000..6c8215b
--- /dev/null
@@ -0,0 +1,68 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.oran.otf.camunda.service;\r
+\r
+import org.oran.otf.camunda.configuration.OtfCamundaConfiguration;\r
+import java.util.Optional;\r
+import org.camunda.bpm.engine.ProcessEngineServices;\r
+import org.camunda.bpm.engine.ProcessEngines;\r
+import org.springframework.stereotype.Service;\r
+\r
+/**\r
+ * Base class for services that must be process-engine aware. The only process engine currently\r
+ * supported is the "default" process engine.\r
+ */\r
+@Service\r
+public class ProcessEngineAwareService {\r
+\r
+  //  private final String processEngineName = OTFProcessEngineConfiguration.processEngineName;\r
+  private final String processEngineName = OtfCamundaConfiguration.processEngineName;\r
+  private volatile Optional<ProcessEngineServices> pes4junit = Optional.empty();\r
+\r
+  /**\r
+   * Gets the process engine name.\r
+   *\r
+   * @return the process engine name\r
+   */\r
+  public String getProcessEngineName() {\r
+    return processEngineName;\r
+  }\r
+\r
+  /**\r
+   * Gets process engine services.\r
+   *\r
+   * @return process engine services\r
+   */\r
+  public ProcessEngineServices getProcessEngineServices() {\r
+    return pes4junit.orElse(ProcessEngines.getProcessEngine(getProcessEngineName()));\r
+  }\r
+\r
+  /**\r
+   * Allows a particular process engine to be specified, overriding the usual process engine lookup\r
+   * by name. Intended primarily for the unit test environment.\r
+   *\r
+   * @param pes process engine services\r
+   */\r
+  public void setProcessEngineServices4junit(ProcessEngineServices pes) {\r
+    pes4junit = Optional.ofNullable(pes);\r
+  }\r
+}\r