package org.openecomp.mso.bpmn.core;
+import java.util.Objects;
+
+import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.Expression;
import org.camunda.bpm.engine.delegate.JavaDelegate;
protected String getOptionalStringField(Expression expression,
DelegateExecution execution, String fieldName) {
Object o = getFieldImpl(expression, execution, fieldName, true);
- if (o instanceof String) {
- return (String) o;
- } else if (o == null) {
- return null;
- } else {
- return o.toString();
- }
+ return Objects.toString(o, null);
}
/**
public String getTaskName() {
return getClass().getSimpleName();
}
+
+
+ /**
+ * Check if shouldFail variable is set to true.
+ * @param execution
+ * @return
+ */
+ protected boolean shouldFail(DelegateExecution execution) {
+ Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
+ return shouldFail != null && shouldFail;
+ }
}
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.Expression;
-
import org.openecomp.mso.logger.MsoLogger;
/**
msoLogger.debug("propertiesFile = " + thePropertiesFile);
}
- Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
-
- if (shouldFail != null && shouldFail) {
- throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
- }
+ if (shouldFail(execution)) {
+ throw new ProcessEngineException(getTaskName() + " Failed");
+ }
synchronized (ReadConfigTask.class) {
if (properties == null) {
properties = new Properties();
- InputStream stream = null;
-
- try {
- stream = getClass().getResourceAsStream(thePropertiesFile);
-
+ try(InputStream stream = getClass().getResourceAsStream(thePropertiesFile)) {
if (stream == null) {
throw new IOException("Resource not found: " + thePropertiesFile);
}
properties.load(stream);
-
- stream.close();
- stream = null;
-
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (Exception e) {
- // Do nothing
- }
- }
}
}
}
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.stream.Collectors;
import org.camunda.bpm.engine.ProcessEngineException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.Expression;
-
import org.openecomp.mso.logger.MsoLogger;
/**
+ "file = " + theFile);
}
- Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
-
- if (shouldFail != null && shouldFail) {
- throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
- }
+ if (shouldFail(execution)) {
+ throw new ProcessEngineException(getTaskName() + " Failed");
+ }
Object value = execution.getVariable(theInputVariable);
if (value == null) {
- InputStream xmlStream = null;
-
- try {
- xmlStream = getClass().getResourceAsStream(theFile);
+ try(InputStream xmlStream = getClass().getResourceAsStream(theFile)) {
if (xmlStream == null) {
throw new IOException("Resource not found: " + theFile);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(xmlStream));
- StringBuilder output = new StringBuilder();
- String line;
-
- while ((line = reader.readLine()) != null) {
- output.append(line);
- }
-
- xmlStream.close();
- xmlStream = null;
-
- value = output.toString();
-
- } finally {
- if (xmlStream != null) {
- try {
- xmlStream.close();
- } catch (Exception e) {
- // Do nothing
- }
- }
+ value = reader.lines().collect(Collectors.joining());
}
}
execution.setVariable(theInputVariable, value);
import java.io.InputStream;\r
import java.math.BigDecimal;\r
import java.net.URI;\r
-import java.util.Iterator;\r
\r
import javax.xml.transform.stream.StreamSource;\r
\r
import org.camunda.bpm.engine.delegate.DelegateExecution;\r
//import java.util.logging.Logger;\r
import org.camunda.bpm.engine.delegate.Expression;\r
-\r
import org.openecomp.mso.logger.MessageEnum;\r
import org.openecomp.mso.logger.MsoLogger;\r
\r
String[] atomicInputVariableArray = (theAtomicInputVariables == null)\r
? new String[0] : theAtomicInputVariables.split(",[ ]*");\r
\r
- Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");\r
-\r
- if (shouldFail != null && shouldFail) {\r
- throw new ProcessEngineException(getClass().getSimpleName() + " Failed");\r
- }\r
+ if (shouldFail(execution)) {\r
+ throw new ProcessEngineException(getTaskName() + " Failed");\r
+ }\r
\r
// The script could be compiled once and reused, but we are reading it\r
// and compiling it every time.\r
\r
// Evaluate the query and collect the output.\r
StringBuilder output = new StringBuilder();\r
- Iterator<XdmItem> xdmItems = evaluator.iterator();\r
- while (xdmItems.hasNext()) {\r
- XdmItem item = xdmItems.next();\r
+ for(XdmItem item : evaluator) {\r
\r
if (msoLogger.isDebugEnabled()) {\r
msoLogger.debug("XQuery result item = " + item);\r
*/\r
private XQueryExecutable compile(XQueryCompiler compiler, String resource)\r
throws Exception {\r
- InputStream xqStream = null;\r
- try {\r
- xqStream = getClass().getResourceAsStream(resource);\r
+ try(InputStream xqStream = getClass().getResourceAsStream(resource)) {\r
\r
if (xqStream == null) {\r
throw new IOException("Resource not found: " + resource);\r
}\r
\r
- XQueryExecutable executable = compiler.compile(xqStream);\r
- xqStream.close();\r
- xqStream = null;\r
- return executable;\r
- } finally {\r
- if (xqStream != null) {\r
- try {\r
- xqStream.close();\r
- } catch (Exception e) {\r
- // Do nothing\r
- }\r
- }\r
+ return compiler.compile(xqStream);\r
}\r
}\r
}
\ No newline at end of file