diff options
16 files changed, 302 insertions, 362 deletions
diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleRequest.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleRequest.java index 0f16fdf538..ba576e36b2 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleRequest.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleRequest.java @@ -58,7 +58,7 @@ public class UpdateVfModuleRequest extends VfRequestCommon { private Boolean failIfExists; private Boolean backout; - private Map<String,String> vfModuleParams = new HashMap<String, String>(); + private Map<String,String> vfModuleParams = new HashMap<>(); private MsoRequest msoRequest = new MsoRequest(); public String getCloudSiteId() { diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleResponse.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleResponse.java index 6e84185704..bf50008bc7 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleResponse.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVfModuleResponse.java @@ -34,7 +34,7 @@ public class UpdateVfModuleResponse extends VfResponseCommon { private String vnfId; private String vfModuleId; private String vfModuleStackId; - private Map<String,String> vfModuleOutputs = new HashMap<String, String>(); + private Map<String,String> vfModuleOutputs = new HashMap<>(); public UpdateVfModuleResponse() { super(); diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupRequest.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupRequest.java index 61fd9ccf87..2cd2cd49fb 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupRequest.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupRequest.java @@ -43,7 +43,7 @@ public class UpdateVolumeGroupRequest extends VfRequestCommon { private String vnfVersion; private String vfModuleType; private String modelCustomizationUuid; - private Map<String,String> volumeGroupParams = new HashMap<String, String>(); + private Map<String,String> volumeGroupParams = new HashMap<>(); private MsoRequest msoRequest = new MsoRequest(); public UpdateVolumeGroupRequest() { diff --git a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupResponse.java b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupResponse.java index babf5476e6..7f1c70314f 100644 --- a/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupResponse.java +++ b/adapters/mso-adapters-rest-interface/src/main/java/org/openecomp/mso/adapters/vnfrest/UpdateVolumeGroupResponse.java @@ -39,7 +39,7 @@ public class UpdateVolumeGroupResponse extends VfResponseCommon { public UpdateVolumeGroupResponse() { super(); - this.volumeGroupOutputs = new HashMap<String, String>(); + this.volumeGroupOutputs = new HashMap<>(); } public UpdateVolumeGroupResponse( diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java index c2d5fe241c..8c503aa43e 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java @@ -64,7 +64,7 @@ public class VfcManager { private static Map<String, String> nfvoUrlMap; static { - nfvoUrlMap = new HashMap<String, String>(); + nfvoUrlMap = new HashMap<>(); nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); @@ -399,7 +399,7 @@ public class VfcManager { */ private String getUrl(String variable, String step) { - String url = CommonConstant.STR_EMPTY; + String url; String originalUrl; originalUrl = (String)nfvoUrlMap.get(step); url = String.format(originalUrl, variable); diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java index 67e263c3a7..a4f1046df9 100644 --- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java +++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/BpelRestClient.java @@ -142,9 +142,10 @@ public class BpelRestClient { } public void setRetryCount(int retryCount) { - if (retryCount < 0) - retryCount = DEFAULT_RETRY_COUNT; - this.retryCount = retryCount; + int newRetryCount = retryCount; + if (newRetryCount < 0) + newRetryCount = DEFAULT_RETRY_COUNT; + this.retryCount = newRetryCount; } public int getRetryInterval() { @@ -164,14 +165,14 @@ public class BpelRestClient { } public String getRetryList() { - if (retryList.size() == 0) + if (retryList.isEmpty()) return ""; String t = retryList.toString(); return t.substring(1, t.length()-1); } public void setRetryList(String retryList) { - Set<Integer> s = new TreeSet<Integer>(); + Set<Integer> s = new TreeSet<>(); for (String t : retryList.split("[, ]")) { try { s.add(Integer.parseInt(t)); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java index 3b7089153f..bfd0d7dee4 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/appc/ApplicationControllerSupport.java @@ -108,7 +108,7 @@ public class ApplicationControllerSupport { try { return (Status) statusReader.invoke(response); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - throw new RuntimeException(String.format("Unable to obtain status from LCM Kit response"), e); + throw new RuntimeException("Unable to obtain status from LCM Kit response", e); } } return new Status(); diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java index 6249040342..b27a2fa64e 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java @@ -67,29 +67,12 @@ public class ReadConfigTask extends BaseTask { synchronized (ReadConfigTask.class) { if (properties == null) { properties = new Properties(); - - InputStream stream = null; - - try { - stream = getClass().getResourceAsStream(thePropertiesFile); - - if (stream == null) { - throw new IOException("Resource not found: " + thePropertiesFile); - } + try (InputStream stream = getClass().getResourceAsStream(thePropertiesFile)) { properties.load(stream); - stream.close(); - stream = null; - - } finally { - if (stream != null) { - try { - stream.close(); - } catch (Exception e) { - msoLogger.debug("Exception:", e); - } - } + } catch (Exception e) { + msoLogger.debug("Exception at readResourceFile stream: " + e); } } } diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java index 6b3cb5a1db..af38053fac 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java @@ -76,36 +76,18 @@ public class ReadFileTask extends BaseTask { Object value = execution.getVariable(theInputVariable); if (value == null) { - InputStream xmlStream = null; - - try { - xmlStream = getClass().getResourceAsStream(theFile); - - if (xmlStream == null) { - throw new IOException("Resource not found: " + theFile); - } - - BufferedReader reader = new BufferedReader(new InputStreamReader(xmlStream)); + try (InputStream xmlStream = getClass().getResourceAsStream(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) { - msoLogger.debug("Exception ", e); - } - } + } catch (Exception e) { + msoLogger.debug("Exception at readResourceFile stream: " + e); } } execution.setVariable(theInputVariable, value); diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java index 4b34ddf0f0..6080768cee 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java @@ -1,244 +1,233 @@ -/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.bpmn.core;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigDecimal;
-import java.net.URI;
-import java.util.Iterator;
-
-import javax.xml.transform.stream.StreamSource;
-
-import org.camunda.bpm.engine.ProcessEngineException;
-import org.camunda.bpm.engine.delegate.DelegateExecution;
-//import java.util.logging.Logger;
-import org.camunda.bpm.engine.delegate.Expression;
-
-import org.openecomp.mso.logger.MessageEnum;
-import org.openecomp.mso.logger.MsoLogger;
-
-import net.sf.saxon.Configuration;
-import net.sf.saxon.s9api.DocumentBuilder;
-import net.sf.saxon.s9api.Processor;
-import net.sf.saxon.s9api.QName;
-import net.sf.saxon.s9api.XQueryCompiler;
-import net.sf.saxon.s9api.XQueryEvaluator;
-import net.sf.saxon.s9api.XQueryExecutable;
-import net.sf.saxon.s9api.XdmAtomicValue;
-import net.sf.saxon.s9api.XdmItem;
-import net.sf.saxon.s9api.XdmNode;
-
-/**
- * Executes an XQuery script.
- * <p>
- * Required fields:<br/><br/>
- * scriptFile: the XQuery script file path<br/>
- * outputVariable: the output variable name<br/>
- * <p>
- * Optional fields:<br/><br/>
- * xmlInputVariables: CSV list of variables containing
- * XML data to be injected into the script<br/>
- * atomicInputVariables: CSV list of variables containing
- * atomic data to be injected into the script<br/>
- */
-public class XQueryScriptTask extends BaseTask {
-
- private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
-
- private Expression scriptFile;
- private Expression xmlInputVariables;
- private Expression atomicInputVariables;
- private Expression outputVariable;
-
- public void execute(DelegateExecution execution) throws Exception {
- if (msoLogger.isDebugEnabled()) {
- msoLogger.debug("Started Executing " + getTaskName());
- }
-
- String theScriptFile =
- getStringField(scriptFile, execution, "scriptFile");
- String theXmlInputVariables =
- getOptionalStringField(xmlInputVariables, execution, "xmlInputVariables");
- String theAtomicInputVariables =
- getOptionalStringField(atomicInputVariables, execution, "atomicInputVariables");
- String theOutputVariable =
- getStringField(outputVariable, execution, "outputVariable");
-
- if (msoLogger.isDebugEnabled()) {
- msoLogger.debug ("scriptFile = " + theScriptFile
- + " xmlInputVariables = " + theXmlInputVariables
- + " atomicInputVariables = " + theAtomicInputVariables
- + "outputVariable = " + theOutputVariable);
- }
-
- String[] xmlInputVariableArray = (theXmlInputVariables == null)
- ? new String[0] : theXmlInputVariables.split(",[ ]*");
-
- String[] atomicInputVariableArray = (theAtomicInputVariables == null)
- ? new String[0] : theAtomicInputVariables.split(",[ ]*");
-
- Boolean shouldFail = (Boolean) execution.getVariable("shouldFail");
-
- if (shouldFail != null && shouldFail) {
- throw new ProcessEngineException(getClass().getSimpleName() + " Failed");
- }
-
- // The script could be compiled once and reused, but we are reading it
- // and compiling it every time.
- Configuration configuration = new Configuration();
- Processor processor = new Processor(configuration);
- XQueryCompiler compiler = processor.newXQueryCompiler();
- XQueryExecutable executable = compile(compiler, theScriptFile);
-
- // The evaluator must not be shared by multiple threads. Here is where
- // the initial context may be set, as well as values of external variables.
- XQueryEvaluator evaluator = executable.load();
-
- // Convert XML string variable content to document-node objects and inject
- // these into the evaluator. Note: the script must accept the document-node
- // type. Most MSO scripts today expect element() input, not document-node
- // input. TODO: figure out how to pass the variable data as element() types.
-
- for (String xmlInputVariable : xmlInputVariableArray) {
- if (msoLogger.isDebugEnabled()) {
- msoLogger.debug("Injecting XML variable '" + xmlInputVariable + "'");
- msoLogger.debug("printing the variable content>>'" + execution.getVariable(xmlInputVariable) +"'");
- }
-
- String xml = (String) execution.getVariable(xmlInputVariable);
- DocumentBuilder documentBuilder = processor.newDocumentBuilder();
- StreamSource source = new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8")));
- XdmNode xdmNode = documentBuilder.build(source);
-
- // Inject the document-node object into the XQueryEvaluator.
- // TODO: transform it to an element()
- QName variable = new QName(xmlInputVariable);
- evaluator.setExternalVariable(variable, xdmNode);
- }
-
- // Inject atomic variables into the evaluator.
-
- for (String atomicInputVariable : atomicInputVariableArray) {
-
- if (msoLogger.isDebugEnabled()) {
- msoLogger.debug ("Injecting object variable '"
- + atomicInputVariable + "'");
- }
-
- QName variable = new QName(atomicInputVariable);
- Object value = execution.getVariable(atomicInputVariable);
-
- if (value == null) {
- // The variable value is null, so we have no way to know what
- // type it is. I don't know how to deal with this, so for
- // now, just skip it.
-
- msoLogger.warn (MessageEnum.BPMN_VARIABLE_NULL, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.DataError, atomicInputVariable);
-
- continue;
- }
-
- // There might be a better way to do this...
- if (value instanceof BigDecimal) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((BigDecimal) value));
- } else if (value instanceof Boolean) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((Boolean) value));
- } else if (value instanceof Double) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((Double) value));
- } else if (value instanceof Float) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((Float) value));
- } else if (value instanceof Long) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((Long) value));
- } else if (value instanceof String) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((String) value));
- } else if (value instanceof URI) {
- evaluator.setExternalVariable(variable,
- new XdmAtomicValue((URI) value));
- } else {
- throw new BadInjectedFieldException(
- "atomicInputVariables", getTaskName(),
- "'" + atomicInputVariable + "' type is not supported: "
- + value.getClass());
- }
- }
-
- // Evaluate the query and collect the output.
- StringBuilder output = new StringBuilder();
- Iterator<XdmItem> xdmItems = evaluator.iterator();
- while (xdmItems.hasNext()) {
- XdmItem item = xdmItems.next();
-
- if (msoLogger.isDebugEnabled()) {
- msoLogger.debug("XQuery result item = " + item);
- }
-
- output.append(item.toString());
- }
-
- // Set the output variable.
- execution.setVariable(theOutputVariable, output.toString());
-
- if (msoLogger.isDebugEnabled()) {
- msoLogger.debug("Done Executing " + getTaskName());
- }
- }
-
- /**
- * Compiles an XQuery script contained in a resource (file).
- * @param compiler the XQueryCompiler
- * @param resource the resource path
- * @return an XQueryExecutable
- * @throws Exception on error
- */
- private XQueryExecutable compile(XQueryCompiler compiler, String resource)
- throws Exception {
- InputStream xqStream = null;
- try {
- xqStream = getClass().getResourceAsStream(resource);
-
- if (xqStream == null) {
- throw new IOException("Resource not found: " + resource);
- }
-
- XQueryExecutable executable = compiler.compile(xqStream);
- xqStream.close();
- xqStream = null;
- return executable;
- } finally {
- if (xqStream != null) {
- try {
- xqStream.close();
- } catch (Exception e) {
- msoLogger.debug ("Exception:", e);
- }
- }
- }
- }
+/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.bpmn.core; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.net.URI; +import java.util.Iterator; + +import javax.xml.transform.stream.StreamSource; + +import org.camunda.bpm.engine.ProcessEngineException; +import org.camunda.bpm.engine.delegate.DelegateExecution; +//import java.util.logging.Logger; +import org.camunda.bpm.engine.delegate.Expression; + +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; + +import net.sf.saxon.Configuration; +import net.sf.saxon.s9api.DocumentBuilder; +import net.sf.saxon.s9api.Processor; +import net.sf.saxon.s9api.QName; +import net.sf.saxon.s9api.XQueryCompiler; +import net.sf.saxon.s9api.XQueryEvaluator; +import net.sf.saxon.s9api.XQueryExecutable; +import net.sf.saxon.s9api.XdmAtomicValue; +import net.sf.saxon.s9api.XdmItem; +import net.sf.saxon.s9api.XdmNode; + +/** + * Executes an XQuery script. + * <p> + * Required fields:<br/><br/> + * scriptFile: the XQuery script file path<br/> + * outputVariable: the output variable name<br/> + * <p> + * Optional fields:<br/><br/> + * xmlInputVariables: CSV list of variables containing + * XML data to be injected into the script<br/> + * atomicInputVariables: CSV list of variables containing + * atomic data to be injected into the script<br/> + */ +public class XQueryScriptTask extends BaseTask { + + private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL); + + private Expression scriptFile; + private Expression xmlInputVariables; + private Expression atomicInputVariables; + private Expression outputVariable; + + public void execute(DelegateExecution execution) throws Exception { + if (msoLogger.isDebugEnabled()) { + msoLogger.debug("Started Executing " + getTaskName()); + } + + String theScriptFile = + getStringField(scriptFile, execution, "scriptFile"); + String theXmlInputVariables = + getOptionalStringField(xmlInputVariables, execution, "xmlInputVariables"); + String theAtomicInputVariables = + getOptionalStringField(atomicInputVariables, execution, "atomicInputVariables"); + String theOutputVariable = + getStringField(outputVariable, execution, "outputVariable"); + + if (msoLogger.isDebugEnabled()) { + msoLogger.debug ("scriptFile = " + theScriptFile + + " xmlInputVariables = " + theXmlInputVariables + + " atomicInputVariables = " + theAtomicInputVariables + + "outputVariable = " + theOutputVariable); + } + + String[] xmlInputVariableArray = (theXmlInputVariables == null) + ? new String[0] : theXmlInputVariables.split(",[ ]*"); + + String[] atomicInputVariableArray = (theAtomicInputVariables == null) + ? new String[0] : theAtomicInputVariables.split(",[ ]*"); + + Boolean shouldFail = (Boolean) execution.getVariable("shouldFail"); + + if (shouldFail != null && shouldFail) { + throw new ProcessEngineException(getClass().getSimpleName() + " Failed"); + } + + // The script could be compiled once and reused, but we are reading it + // and compiling it every time. + Configuration configuration = new Configuration(); + Processor processor = new Processor(configuration); + XQueryCompiler compiler = processor.newXQueryCompiler(); + XQueryExecutable executable = compile(compiler, theScriptFile); + if (executable == null) { + throw new ProcessEngineException(getClass().getSimpleName() + " Failed"); + } + + // The evaluator must not be shared by multiple threads. Here is where + // the initial context may be set, as well as values of external variables. + XQueryEvaluator evaluator = executable.load(); + + // Convert XML string variable content to document-node objects and inject + // these into the evaluator. Note: the script must accept the document-node + // type. Most MSO scripts today expect element() input, not document-node + // input. TODO: figure out how to pass the variable data as element() types. + + for (String xmlInputVariable : xmlInputVariableArray) { + if (msoLogger.isDebugEnabled()) { + msoLogger.debug("Injecting XML variable '" + xmlInputVariable + "'"); + msoLogger.debug("printing the variable content>>'" + execution.getVariable(xmlInputVariable) +"'"); + } + + String xml = (String) execution.getVariable(xmlInputVariable); + DocumentBuilder documentBuilder = processor.newDocumentBuilder(); + StreamSource source = new StreamSource(new ByteArrayInputStream(xml.getBytes("UTF-8"))); + XdmNode xdmNode = documentBuilder.build(source); + + // Inject the document-node object into the XQueryEvaluator. + // TODO: transform it to an element() + QName variable = new QName(xmlInputVariable); + evaluator.setExternalVariable(variable, xdmNode); + } + + // Inject atomic variables into the evaluator. + + for (String atomicInputVariable : atomicInputVariableArray) { + + if (msoLogger.isDebugEnabled()) { + msoLogger.debug ("Injecting object variable '" + + atomicInputVariable + "'"); + } + + QName variable = new QName(atomicInputVariable); + Object value = execution.getVariable(atomicInputVariable); + + if (value == null) { + // The variable value is null, so we have no way to know what + // type it is. I don't know how to deal with this, so for + // now, just skip it. + + msoLogger.warn (MessageEnum.BPMN_VARIABLE_NULL, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.DataError, atomicInputVariable); + + continue; + } + + // There might be a better way to do this... + if (value instanceof BigDecimal) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((BigDecimal) value)); + } else if (value instanceof Boolean) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((Boolean) value)); + } else if (value instanceof Double) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((Double) value)); + } else if (value instanceof Float) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((Float) value)); + } else if (value instanceof Long) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((Long) value)); + } else if (value instanceof String) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((String) value)); + } else if (value instanceof URI) { + evaluator.setExternalVariable(variable, + new XdmAtomicValue((URI) value)); + } else { + throw new BadInjectedFieldException( + "atomicInputVariables", getTaskName(), + "'" + atomicInputVariable + "' type is not supported: " + + value.getClass()); + } + } + + // Evaluate the query and collect the output. + StringBuilder output = new StringBuilder(); + Iterator<XdmItem> xdmItems = evaluator.iterator(); + while (xdmItems.hasNext()) { + XdmItem item = xdmItems.next(); + + if (msoLogger.isDebugEnabled()) { + msoLogger.debug("XQuery result item = " + item); + } + + output.append(item.toString()); + } + + // Set the output variable. + execution.setVariable(theOutputVariable, output.toString()); + + if (msoLogger.isDebugEnabled()) { + msoLogger.debug("Done Executing " + getTaskName()); + } + } + + /** + * Compiles an XQuery script contained in a resource (file). + * @param compiler the XQueryCompiler + * @param resource the resource path + * @return an XQueryExecutable + * @throws Exception on error + */ + private XQueryExecutable compile(XQueryCompiler compiler, String resource) + throws Exception { + try (InputStream xqStream = getClass().getResourceAsStream(resource)) { + XQueryExecutable executable = compiler.compile(xqStream); + return executable; + } catch (Exception e) { + msoLogger.debug ("Exception at resourceFile stream:", e); + return null; + } + } }
\ No newline at end of file diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java index 1cf434052c..c2b832812e 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/xml/XmlTool.java @@ -312,15 +312,10 @@ public final class XmlTool { * @throws IOException if there is a problem reading the file */ private static String readResourceFile(String file) throws IOException { - InputStream stream = null; - try { - stream = XmlTool.class.getClassLoader().getResourceAsStream(file); - if (stream == null) { - throw new FileNotFoundException("No such resource file: " + file); - } + try (InputStream stream = XmlTool.class.getClassLoader().getResourceAsStream(file); + Reader reader = new InputStreamReader(stream, "UTF-8")) { - Reader reader = new InputStreamReader(stream, "UTF-8"); StringBuilder out = new StringBuilder(); char[] buf = new char[1024]; int n; @@ -328,18 +323,10 @@ public final class XmlTool { while ((n = reader.read(buf)) >= 0) { out.append(buf, 0, n); } - - stream.close(); - stream = null; return out.toString(); - } finally { - if (stream != null) { - try { - stream.close(); - } catch (Exception e) { - LOGGER.debug("Exception at readResourceFile close stream: " + e); - } - } + } catch (Exception e) { + LOGGER.debug("Exception at readResourceFile stream: " + e); + return null; } } diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncVlOperationTask.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncVlOperationTask.java index 8b26d01432..212711e5f3 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncVlOperationTask.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncVlOperationTask.java @@ -89,23 +89,21 @@ public abstract class AbstractSdncVlOperationTask extends BaseTask { } catch (Exception e) { System.out.println(e); logger.error(MessageEnum.GENERAL_EXCEPTION, " getMsbIp catch exception: ", "", this.getTaskName(), MsoLogger.ErrorCode.UnknownError, e.getClass().toString()); - } finally { - return defaultValue; } + return defaultValue; } private Integer getInteger(DelegateExecution execution, String name, Integer defaultValue) { Integer vlaue = (Integer) execution.getVariable(name); try { - if (vlaue != null && vlaue instanceof Integer) { + if (vlaue != null) { return vlaue; } } catch (Exception e) { System.out.println(e); logger.error(MessageEnum.GENERAL_EXCEPTION, " getMsbIp catch exception: ", "", this.getTaskName(), MsoLogger.ErrorCode.UnknownError, e.getClass().toString()); - } finally { - return defaultValue; } + return defaultValue; } public String getProcessKey(DelegateExecution execution) { diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java index cf8e94a733..b4e7b7e068 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/CamundaTaskClient.java @@ -51,7 +51,7 @@ public class CamundaTaskClient extends RequestClient{ StringEntity input = new StringEntity(jsonReq);
input.setContentType(CommonConstants.CONTENT_TYPE_JSON);
- String encryptedCredentials = null;
+ String encryptedCredentials;
if(props!=null){
encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);
if(encryptedCredentials != null){
@@ -92,7 +92,7 @@ public class CamundaTaskClient extends RequestClient{ throws ClientProtocolException, IOException{
HttpGet get = new HttpGet(url);
msoLogger.debug("Camunda Task url is: "+ url);
- String encryptedCredentials = null;
+ String encryptedCredentials;
if(props!=null){
encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH,null);
if(encryptedCredentials != null){
diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ResponseHandler.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ResponseHandler.java index e90989deb8..6722a930ae 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ResponseHandler.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/openecomp/mso/apihandler/common/ResponseHandler.java @@ -131,36 +131,36 @@ public class ResponseHandler { } private int setStatus(int statusCode){ - int status = 0; + int httpStatus; switch(statusCode) { case HttpStatus.SC_ACCEPTED: case HttpStatus.SC_OK: - status = HttpStatus.SC_ACCEPTED; + httpStatus = HttpStatus.SC_ACCEPTED; break; case HttpStatus.SC_BAD_REQUEST: - status = HttpStatus.SC_BAD_REQUEST; + httpStatus = HttpStatus.SC_BAD_REQUEST; break; case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_FORBIDDEN: - status = HttpStatus.SC_INTERNAL_SERVER_ERROR; + httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; case HttpStatus.SC_NOT_FOUND: - status = HttpStatus.SC_NOT_IMPLEMENTED; + httpStatus = HttpStatus.SC_NOT_IMPLEMENTED; break; case HttpStatus.SC_INTERNAL_SERVER_ERROR: - status = HttpStatus.SC_BAD_GATEWAY; + httpStatus = HttpStatus.SC_BAD_GATEWAY; break; case HttpStatus.SC_SERVICE_UNAVAILABLE: - status = HttpStatus.SC_SERVICE_UNAVAILABLE; + httpStatus = HttpStatus.SC_SERVICE_UNAVAILABLE; break; case HttpStatus.SC_NO_CONTENT: - status = HttpStatus.SC_NO_CONTENT; + httpStatus = HttpStatus.SC_NO_CONTENT; break; default: - status = HttpStatus.SC_INTERNAL_SERVER_ERROR; + httpStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; break; } - return status; + return httpStatus; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java index 8ee106efc1..9b975facc6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/MsoRequest.java @@ -586,20 +586,20 @@ public class MsoRequest { public Map<String, List<String>> getOrchestrationFilters (MultivaluedMap<String, String> queryParams) throws ValidationException { String queryParam = null; - Map<String, List<String>> orchestrationFilterParams = new HashMap<String, List<String>>(); + Map<String, List<String>> orchestrationFilterParams = new HashMap<>(); for (Entry<String,List<String>> entry : queryParams.entrySet()) { queryParam = entry.getKey(); try{ - if(queryParam.equalsIgnoreCase("filter")){ + if("filter".equalsIgnoreCase(queryParam)){ for(String value : entry.getValue()) { StringTokenizer st = new StringTokenizer(value, ":"); int counter=0; String mapKey=null; - List<String> orchestrationList = new ArrayList<String>(); + List<String> orchestrationList = new ArrayList<>(); while (st.hasMoreElements()) { if(counter == 0){ mapKey = st.nextElement() + ""; diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java index 254ae3bf39..b426c39176 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/openecomp/mso/requestsdb/RequestsDatabase.java @@ -226,37 +226,37 @@ public class RequestsDatabase { if(instanceName != null && !instanceName.equals("")) { - if(requestScope.equals("service")){ + if("service".equals(requestScope)){ criteria.add (Restrictions.eq (SERVICE_INSTANCE_NAME, instanceName)); - } else if(requestScope.equals("vnf")){ + } else if("vnf".equals(requestScope)){ criteria.add (Restrictions.eq (VNF_INSTANCE_NAME, instanceName)); - } else if(requestScope.equals("volumeGroup")){ + } else if("volumeGroup".equals(requestScope)){ criteria.add (Restrictions.eq (VOLUME_GROUP_INSTANCE_NAME, instanceName)); - } else if(requestScope.equals("vfModule")){ + } else if("vfModule".equals(requestScope)){ criteria.add (Restrictions.eq (VFMODULE_INSTANCE_NAME, instanceName)); - } else if(requestScope.equals("network")){ + } else if("network".equals(requestScope)){ criteria.add (Restrictions.eq (NETWORK_INSTANCE_NAME, instanceName)); } } else { if(instanceIdMap != null){ - if(requestScope.equals("service") && instanceIdMap.get("serviceInstanceId") != null){ + if("service".equals(requestScope) && instanceIdMap.get("serviceInstanceId") != null){ criteria.add (Restrictions.eq (SERVICE_INSTANCE_ID, instanceIdMap.get("serviceInstanceId"))); } - if(requestScope.equals("vnf") && instanceIdMap.get("vnfInstanceId") != null){ + if("vnf".equals(requestScope) && instanceIdMap.get("vnfInstanceId") != null){ criteria.add (Restrictions.eq (VNF_INSTANCE_ID, instanceIdMap.get("vnfInstanceId"))); } - if(requestScope.equals("vfModule") && instanceIdMap.get("vfModuleInstanceId") != null){ + if("vfModule".equals(requestScope) && instanceIdMap.get("vfModuleInstanceId") != null){ criteria.add (Restrictions.eq (VFMODULE_INSTANCE_ID, instanceIdMap.get("vfModuleInstanceId"))); } - if(requestScope.equals("volumeGroup") && instanceIdMap.get("volumeGroupInstanceId") != null){ + if("volumeGroup".equals(requestScope) && instanceIdMap.get("volumeGroupInstanceId") != null){ criteria.add (Restrictions.eq (VOLUME_GROUP_INSTANCE_ID, instanceIdMap.get("volumeGroupInstanceId"))); } - if(requestScope.equals("network") && instanceIdMap.get("networkInstanceId") != null){ + if("network".equals(requestScope) && instanceIdMap.get("networkInstanceId") != null){ criteria.add (Restrictions.eq (NETWORK_INSTANCE_ID, instanceIdMap.get("networkInstanceId"))); } } @@ -270,7 +270,7 @@ public class RequestsDatabase { InfraActiveRequests infraActiveRequests = null; - if(dupList != null && dupList.size() > 0){ + if(dupList != null && !dupList.isEmpty()){ infraActiveRequests = dupList.get(0); } @@ -284,40 +284,40 @@ public class RequestsDatabase { for (Map.Entry<String, List<String>> entry : orchestrationMap.entrySet()) { String mapKey = entry.getKey(); - if(mapKey.equalsIgnoreCase("serviceInstanceId")) { + if("serviceInstanceId".equalsIgnoreCase(mapKey)) { mapKey = "serviceInstanceId"; - } else if(mapKey.equalsIgnoreCase("serviceInstanceName")) { + } else if("serviceInstanceName".equalsIgnoreCase(mapKey)) { mapKey = "serviceInstanceName"; - } else if(mapKey.equalsIgnoreCase("vnfInstanceId")){ + } else if("vnfInstanceId".equalsIgnoreCase(mapKey)){ mapKey = "vnfId"; - } else if(mapKey.equalsIgnoreCase("vnfInstanceName")) { + } else if("vnfInstanceName".equalsIgnoreCase(mapKey)) { mapKey = "vnfName"; - } else if(mapKey.equalsIgnoreCase("vfModuleInstanceId")) { + } else if("vfModuleInstanceId".equalsIgnoreCase(mapKey)) { mapKey = "vfModuleId"; - } else if(mapKey.equalsIgnoreCase("vfModuleInstanceName")) { + } else if("vfModuleInstanceName".equalsIgnoreCase(mapKey)) { mapKey = "vfModuleName"; - } else if(mapKey.equalsIgnoreCase("volumeGroupInstanceId")) { + } else if("volumeGroupInstanceId".equalsIgnoreCase(mapKey)) { mapKey = "volumeGroupId"; - } else if(mapKey.equalsIgnoreCase("volumeGroupInstanceName")) { + } else if("volumeGroupInstanceName".equalsIgnoreCase(mapKey)) { mapKey = "volumeGroupName"; - } else if(mapKey.equalsIgnoreCase("networkInstanceId")) { + } else if("networkInstanceId".equalsIgnoreCase(mapKey)) { mapKey = "networkId"; - } else if(mapKey.equalsIgnoreCase("networkInstanceName")) { + } else if("networkInstanceName".equalsIgnoreCase(mapKey)) { mapKey = "networkName"; - } else if(mapKey.equalsIgnoreCase("lcpCloudRegionId")) { + } else if("lcpCloudRegionId".equalsIgnoreCase(mapKey)) { mapKey = "aicCloudRegion"; - } else if(mapKey.equalsIgnoreCase("tenantId")) { + } else if("tenantId".equalsIgnoreCase(mapKey)) { mapKey = "tenantId"; - } else if(mapKey.equalsIgnoreCase("modelType")) { + } else if("modelType".equalsIgnoreCase(mapKey)) { mapKey = "requestScope"; - } else if(mapKey.equalsIgnoreCase("requestorId")) { + } else if("requestorId".equalsIgnoreCase(mapKey)) { mapKey = "requestorId"; - } else if(mapKey.equalsIgnoreCase("requestExecutionDate")) { + } else if("requestExecutionDate".equalsIgnoreCase(mapKey)) { mapKey = "startTime"; } String propertyValue = entry.getValue().get(1); - if (mapKey.equals("startTime")) { + if ("startTime".equals(mapKey)) { SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy"); try { Date thisDate = format.parse(propertyValue); |