diff options
author | Rob Daugherty <rd472p@att.com> | 2017-10-08 18:03:16 -0400 |
---|---|---|
committer | Rob Daugherty <rd472p@att.com> | 2017-10-08 18:03:16 -0400 |
commit | d53a72c4f5a613c1dee59a1eab9d1c8dd800d28a (patch) | |
tree | e862bcfbf1735c14d274b2345236fd978a473342 /bpmn/MSOCoreBPMN/src/main | |
parent | f3c69d5d9a4b1358f0de7545ffee287ee589034d (diff) |
Fixes for sonar coverage in bpmn
1. Coordinated jacoco and surefire JVM arg line options
2. Changed sonar plugin version to 2.19.1
3. Removed dead code (unused classes)
Issue: SO-193
Change-Id: I21b7a77510eec71f4d4ca9afde5b7f86f0e3cbd7
Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'bpmn/MSOCoreBPMN/src/main')
5 files changed, 0 insertions, 558 deletions
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/LogTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/LogTask.java deleted file mode 100644 index e98e65d5c1..0000000000 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/LogTask.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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 org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.Expression; - -import org.openecomp.mso.logger.MsoAlarmLogger; -import org.openecomp.mso.logger.MsoLogger; - -/** - * Logs a text message. The text may contain variable references. - * For example:<br/><br/> - * name=$name, address=$address - * <p> - * Required fields:<br/><br/> - * text: The text to log<br/> - * Optional fields:<br/><br/> - * level: The log level (TRACE, DEBUG, INFO, WARN, ERROR)<br/> - */ -public class LogTask extends BaseTask { - - - private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL); - private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); - - private Expression text; - private Expression level; - - public void execute(DelegateExecution execution) throws Exception { - String theText = getStringField(text, execution, "text"); - - - - StringBuilder out = new StringBuilder(); - StringBuilder var = new StringBuilder(); - boolean inVar = false; - - int pos = 0; - int len = theText.length(); - - while (pos < len) { - char c = theText.charAt(pos++); - - if (inVar && !Character.isLetterOrDigit(c) && c != '_') { - if (var.length() > 0) { - Object value = execution.getVariable(var.toString()); - - if (value != null) { - out.append(value.toString()); - } - - var.setLength(0); - } - - inVar = false; - } - - if (c == '$') { - inVar = true; - } else { - if (inVar) { - var.append(c); - } else { - out.append(c); - } - } - } - - if (inVar && var.length() > 0) { - Object value = execution.getVariable(var.toString()); - if (value != null) { - out.append(value.toString()); - } - } - - - - } -} 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 deleted file mode 100644 index b27a2fa64e..0000000000 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadConfigTask.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============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.IOException; -import java.io.InputStream; -import java.util.Properties; - -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; - -/** - * Reads the contents of a resource file as a string and stores it in an - * execution variable. - * <p> - * Required fields:<br/><br/> - * file: the resource file path<br/> - * outputVariable: the output variable name<br/> - */ -public class ReadConfigTask extends BaseTask { - - private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL); - private static Properties properties = null; - - private Expression propertiesFile; - - public void execute(DelegateExecution execution) throws Exception { - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("Started Executing " + getTaskName()); - } - - String thePropertiesFile = - getStringField(propertiesFile, execution, "propertiesFile"); - - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("propertiesFile = " + thePropertiesFile); - } - - Boolean shouldFail = (Boolean) execution.getVariable("shouldFail"); - - if (shouldFail != null && shouldFail) { - throw new ProcessEngineException(getClass().getSimpleName() + " Failed"); - } - - synchronized (ReadConfigTask.class) { - if (properties == null) { - properties = new Properties(); - try (InputStream stream = getClass().getResourceAsStream(thePropertiesFile)) { - - properties.load(stream); - - } catch (Exception e) { - msoLogger.debug("Exception at readResourceFile stream: " + e); - } - } - } - - for (Object objectKey : properties.keySet()) { - String key = (String) objectKey; - String value = properties.getProperty(key); - - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("Setting variable '" + key + "' to '" + value + "'"); - } - - execution.setVariable(key, value); - } - - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("Done Executing " + getTaskName()); - } - } -} 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 deleted file mode 100644 index af38053fac..0000000000 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/ReadFileTask.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ============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.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -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; - -/** - * Conditionally reads the contents of a resource file as a string and stores it - * in an execution variable. The file is read only if the value of the input - * variable is null. - * <p> - * Required fields:<br/><br/> - * file: the resource file path<br/> - * inputVariable: the input variable name<br/> - * outputVariable: the output variable name<br/> - */ -public class ReadFileTask extends BaseTask { - - private Expression file; - private Expression inputVariable; - private Expression outputVariable; - - private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL); - - public void execute(DelegateExecution execution) throws Exception { - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("Started Executing " + getTaskName()); - } - - String theInputVariable = - getStringField(inputVariable, execution, "inputVariable"); - String theOutputVariable = - getOutputField(outputVariable, execution, "outputVariable"); - String theFile =getStringField(file, execution, "file"); - - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("inputVariable = " + theInputVariable - + " outputVariable = " + theOutputVariable - + "file = " + theFile); - } - - Boolean shouldFail = (Boolean) execution.getVariable("shouldFail"); - - if (shouldFail != null && shouldFail) { - throw new ProcessEngineException(getClass().getSimpleName() + " Failed"); - } - - Object value = execution.getVariable(theInputVariable); - - if (value == null) { - 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); - } - value = output.toString(); - - } catch (Exception e) { - msoLogger.debug("Exception at readResourceFile stream: " + e); - } - } - execution.setVariable(theInputVariable, value); - execution.setVariable(theOutputVariable, value); - msoLogger.debug ("ServiceInput - " + execution.getVariable("gServiceInput")); - if (msoLogger.isDebugEnabled()) { - msoLogger.debug("Done Executing " + getTaskName()); - } - } -} diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/URNMappingsTask.java b/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/URNMappingsTask.java deleted file mode 100644 index d38c0dbf58..0000000000 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/URNMappingsTask.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. 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 org.camunda.bpm.engine.delegate.DelegateExecution; - -/** - * DEPRECATION WARNING: setting of URN mappings is now done by a plugin. - */ -@Deprecated -public class URNMappingsTask extends BaseTask { - public void execute(DelegateExecution execution) throws Exception { - } -} 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 deleted file mode 100644 index 419f4aacf5..0000000000 --- a/bpmn/MSOCoreBPMN/src/main/java/org/openecomp/mso/bpmn/core/XQueryScriptTask.java +++ /dev/null @@ -1,233 +0,0 @@ -/*- - * ============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; - - @Override - 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)) { - return compiler.compile(xqStream); - } catch (Exception e) { - msoLogger.debug ("Exception at resourceFile stream:", e); - return null; - } - } -}
\ No newline at end of file |