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.openecomp.mso.bpmn.core;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.Properties;
27 import org.camunda.bpm.engine.ProcessEngineException;
28 import org.camunda.bpm.engine.delegate.DelegateExecution;
29 import org.camunda.bpm.engine.delegate.Expression;
31 import org.openecomp.mso.logger.MsoLogger;
34 * Reads the contents of a resource file as a string and stores it in an
37 * Required fields:<br/><br/>
38 * file: the resource file path<br/>
39 * outputVariable: the output variable name<br/>
41 public class ReadConfigTask extends BaseTask {
43 private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
44 private static Properties properties = null;
46 private Expression propertiesFile;
48 public void execute(DelegateExecution execution) throws Exception {
49 if (msoLogger.isDebugEnabled()) {
50 msoLogger.debug("Started Executing " + getTaskName());
53 String thePropertiesFile =
54 getStringField(propertiesFile, execution, "propertiesFile");
56 if (msoLogger.isDebugEnabled()) {
57 msoLogger.debug("propertiesFile = " + thePropertiesFile);
60 Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
62 if (shouldFail != null && shouldFail) {
63 throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
66 synchronized (ReadConfigTask.class) {
67 if (properties == null) {
68 properties = new Properties();
70 InputStream stream = null;
73 stream = getClass().getResourceAsStream(thePropertiesFile);
76 throw new IOException("Resource not found: " + thePropertiesFile);
79 properties.load(stream);
88 } catch (Exception e) {
96 for (Object objectKey : properties.keySet()) {
97 String key = (String) objectKey;
98 String value = properties.getProperty(key);
100 if (msoLogger.isDebugEnabled()) {
101 msoLogger.debug("Setting variable '" + key + "' to '" + value + "'");
104 execution.setVariable(key, value);
107 if (msoLogger.isDebugEnabled()) {
108 msoLogger.debug("Done Executing " + getTaskName());