2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.openecomp.mso.bpmn.core;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.Properties;
28 import org.camunda.bpm.engine.ProcessEngineException;
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.engine.delegate.Expression;
32 import org.openecomp.mso.logger.MsoLogger;
35 * Reads the contents of a resource file as a string and stores it in an
38 * Required fields:<br/><br/>
39 * file: the resource file path<br/>
40 * outputVariable: the output variable name<br/>
42 public class ReadConfigTask extends BaseTask {
44 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
45 private static Properties properties = null;
47 private Expression propertiesFile;
49 public void execute(DelegateExecution execution) throws Exception {
50 if (msoLogger.isDebugEnabled()) {
51 msoLogger.debug("Started Executing " + getTaskName());
54 String thePropertiesFile =
55 getStringField(propertiesFile, execution, "propertiesFile");
57 if (msoLogger.isDebugEnabled()) {
58 msoLogger.debug("propertiesFile = " + thePropertiesFile);
61 Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
63 if (shouldFail != null && shouldFail) {
64 throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
67 synchronized (ReadConfigTask.class) {
68 if (properties == null) {
69 properties = new Properties();
70 try (InputStream stream = getClass().getResourceAsStream(thePropertiesFile)) {
72 properties.load(stream);
74 } catch (Exception e) {
75 msoLogger.debug("Exception at readResourceFile stream: " + e);
80 for (Object objectKey : properties.keySet()) {
81 String key = (String) objectKey;
82 String value = properties.getProperty(key);
84 if (msoLogger.isDebugEnabled()) {
85 msoLogger.debug("Setting variable '" + key + "' to '" + value + "'");
88 execution.setVariable(key, value);
91 if (msoLogger.isDebugEnabled()) {
92 msoLogger.debug("Done Executing " + getTaskName());