2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.core;
23 import java.util.Optional;
25 import org.camunda.bpm.engine.delegate.DelegateExecution;
26 import org.onap.so.logger.MsoLogger;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.context.annotation.Configuration;
29 import org.springframework.core.env.Environment;
30 import org.springframework.stereotype.Component;
34 * Read the URN property value from the execution object or from the spring environment object
38 public class UrnPropertiesReader {
39 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,UrnPropertiesReader.class);
40 private static Environment environment;
43 public void setEnvironment(Environment environment) {
44 this.environment = environment;
47 * Return the URN property value
48 * if property is present in the execution object, return the same
49 * else search in the environment object. If found, add it to the execution object and return the value
50 * otherwise return null
52 * @param variableName URN property name
53 * @param execution The flow's execution instance.
54 * @return URN property value
56 public static String getVariable(String variableName, DelegateExecution execution) {
57 Object value = execution.getVariable(variableName);
59 LOGGER.trace("Retrieved value for the URN variable, " + variableName + ", from the execution object: " + String.valueOf(value));
60 return String.valueOf(value);
62 String variableValue = null;
63 if (environment != null && environment.getProperty(variableName) != null) {
64 variableValue = environment.getProperty(variableName);
65 LOGGER.trace("Retrieved value for the URN variable, " + variableName + ", from the environment variable: " + variableValue);
66 execution.setVariable(variableName, variableValue);
73 * Return the URN property value from the environment object
74 * @param variableName URN property name
75 * @return URN property value
78 public static String getVariable(String variableName){
79 if (environment != null) {
80 return environment.getProperty(variableName);
86 public static String getVariable(String variableName, String defaultValue) {
87 return Optional.ofNullable(getVariable(variableName)).orElse(defaultValue);