summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsli/common/pom.xml40
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java21
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java14
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java125
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionFactory.java23
-rw-r--r--sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicStoreFactory.java4
-rw-r--r--sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java5
-rwxr-xr-xsli/provider/pom.xml9
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToProp.java (renamed from sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/PrintYangToProp.java)2
-rwxr-xr-xsli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java15
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java (renamed from sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java)3
-rwxr-xr-xsli/recording/pom.xml32
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java11
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java82
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java21
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java68
16 files changed, 180 insertions, 295 deletions
diff --git a/sli/common/pom.xml b/sli/common/pom.xml
index 7b4adb8b..2166760d 100755
--- a/sli/common/pom.xml
+++ b/sli/common/pom.xml
@@ -39,25 +39,9 @@
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.mariadb.jdbc</groupId>
- <artifactId>mariadb-java-client</artifactId>
- <type>jar</type>
- <scope>compile</scope>
- </dependency>
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
<artifactId>dblib-provider</artifactId>
@@ -70,32 +54,16 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
- <artifactId>rfc6991</artifactId>
- </dependency>
- <dependency>
- <groupId>org.onap.logging-analytics</groupId>
- <artifactId>logging-slf4j</artifactId>
- <version>1.5.0</version>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-core-api</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-api</artifactId>
- </dependency>
-
+ <groupId>org.onap.logging-analytics</groupId>
+ <artifactId>logging-slf4j</artifactId>
+ <version>1.5.0</version>
+ </dependency>
<!-- Testing Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java
index 0e39896e..5ededb9e 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/MessageWriter.java
@@ -28,13 +28,8 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;
-
import javax.sql.rowset.CachedRowSet;
-
import org.onap.ccsdk.sli.core.dblib.DbLibService;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -96,22 +91,6 @@ public class MessageWriter {
LOG.info(INCOMING_PROPERTY_NAME + ": " + incomingEnabled);
LOG.info(OUTGOING_PROPERTY_NAME + ": " + outgoingEnabled);
-
- if (dbLibService != null)
- return;
-
- BundleContext bctx = FrameworkUtil.getBundle(MessageWriter.class).getBundleContext();
-
- ServiceReference sref = bctx.getServiceReference(DBLIB_SERVICE);
-
- if (sref == null) {
- LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
- } else {
- dbLibService = (DbLibService) bctx.getService(sref);
- if (dbLibService == null) {
- LOG.warn("Could not find service reference for DBLIB service (" + DBLIB_SERVICE + ")");
- }
- }
}
public static void saveOutgoingRequest(
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
index aca904d1..b592c15f 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicContext.java
@@ -25,8 +25,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@@ -42,8 +40,6 @@ public class SvcLogicContext {
private HashMap<String, String> attributes;
- private DOMDataBroker domDataBroker;
-
private String status = "success";
public SvcLogicContext()
@@ -68,16 +64,6 @@ public class SvcLogicContext {
}
}
-
-
- public DOMDataBroker getDomDataBroker() {
- return domDataBroker;
- }
-
- public void setDomDataBroker(DOMDataBroker domDataBroker) {
- this.domDataBroker = domDataBroker;
- }
-
public String getAttribute(String name)
{
if (attributes.containsKey(name))
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
index 94ffcd99..dc3a560e 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicDblibStore.java
@@ -23,8 +23,6 @@ package org.onap.ccsdk.sli.core.sli;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Blob;
@@ -35,52 +33,24 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import javax.sql.rowset.CachedRowSet;
-import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.onap.ccsdk.sli.core.dblib.DbLibService;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SvcLogicDblibStore implements SvcLogicStore {
-
- private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
-
private static final Logger LOG = LoggerFactory.getLogger(SvcLogicDblibStore.class);
-
- private static final String DBLIB_SERVICE = "org.onap.ccsdk.sli.core.dblib.DbLibService";
-
private DbLibService dbSvc;
- public SvcLogicDblibStore()
- {
- // Does nothing, but needed so that argumentless constructor
- // still works.
- }
-
public SvcLogicDblibStore(DbLibService dbsvc) {
this.dbSvc = dbsvc;
}
- public SvcLogicDblibStore(Properties props) {
- try {
- dbSvc = new DBResourceManager(props);
- JavaSingleton.setInstance(dbSvc);
- } catch (Exception e) {
- LOG.warn("Caught exception trying to create DBResourceManager", e);
- }
- }
-
public Connection getConnection() throws SQLException {
return(dbSvc.getConnection());
}
@Override
public void init(Properties props) throws ConfigurationException {
-
- dbSvc = getDbLibService();
if(dbSvc == null) {
LOG.error("SvcLogic cannot acquire DBLIB_SERVICE");
return;
@@ -334,101 +304,6 @@ public class SvcLogicDblibStore implements SvcLogicStore {
}
}
- private DbLibService getDbLibService() {
-
- if (dbSvc != null) {
- return dbSvc;
- }
-
- // Get DbLibService interface object.
- ServiceReference sref = null;
- BundleContext bctx = null;
-
- Bundle bundle = FrameworkUtil.getBundle(SvcLogicDblibStore.class);
-
- if (bundle != null) {
- bctx = bundle.getBundleContext();
-
- if (bctx != null) {
- sref = bctx.getServiceReference(DBLIB_SERVICE);
- }
-
- if (sref == null) {
- LOG.warn("Could not find service reference for DBLIB service ({})", DBLIB_SERVICE);
- } else {
- dbSvc = (DbLibService) bctx.getService(sref);
- if (dbSvc == null) {
-
- LOG.warn("Could not find service reference for DBLIB service ({})", DBLIB_SERVICE);
- }
- }
- }
-
- // initialize a stand-alone instance of dblib resource
- else {
- // Try to create a DbLibService object from dblib properties
- if(JavaSingleton.getInstance() == null){
- Properties dblibProps = new Properties();
-
- String propDir = System.getenv(SDNC_CONFIG_DIR);
- if (propDir == null) {
-
- propDir = "/opt/sdnc/data/properties";
- }
- String propPath = propDir + "/dblib.properties";
-
- File propFile = new File(propPath);
-
- if (!propFile.exists()) {
-
- LOG.warn("Missing configuration properties file : {}", propFile);
- return null;
- }
-
- try {
-
- dblibProps.load(new FileInputStream(propFile));
- } catch (Exception e) {
- LOG.warn(
- "Could not load properties file " + propPath, e);
- return null;
-
- }
-
- try {
- dbSvc = new DBResourceManager(dblibProps);
- JavaSingleton.setInstance(dbSvc);
- } catch (Exception e) {
- LOG.warn("Caught exception trying to create DBResourceManager", e);
- }
- } else {
- dbSvc = JavaSingleton.getInstance();
- }
- }
- return dbSvc;
- }
-
-
- static class JavaSingleton {
- /* Private constructor */
- private JavaSingleton() {
- /* the body of the constructor here */
- }
-
- /* instance of the singleton declaration */
- private static volatile DbLibService INSTANCE ;
-
- /* Access point to the unique instance of the singleton */
- public static DbLibService getInstance() {
- return INSTANCE;
- }
-
- public static void setInstance(DbLibService dbresource) {
- INSTANCE = dbresource;
- }
- }
-
-
@Override
public void activate(String module, String rpc, String version, String mode) throws SvcLogicException {
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionFactory.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionFactory.java
index 9e9bfe0d..727c84b1 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionFactory.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicExpressionFactory.java
@@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.core.sli;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenStream;
@@ -72,27 +71,5 @@ public class SvcLogicExpressionFactory {
return(listener.getParsedExpr());
}
-
- public static void main(String argv[]) {
-
- System.setProperty(org.slf4j.impl.SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "debug");
-
- StringBuffer sbuff = new StringBuffer();
-
- for (int i = 0 ; i < argv.length ; i++)
- {
- if (sbuff.length() > 0)
- {
- sbuff.append(" ");
- }
- sbuff.append(argv[i]);
- }
-
- try {
- SvcLogicExpressionFactory.parse(sbuff.toString());
- } catch (IOException e) {
- LOG.error("Exception in SvcLogicExpressionFactory.parse",e);
- }
- }
}
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicStoreFactory.java b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicStoreFactory.java
index 532ad31b..b73925dd 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicStoreFactory.java
+++ b/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/SvcLogicStoreFactory.java
@@ -25,7 +25,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
-
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -81,7 +81,7 @@ public class SvcLogicStoreFactory {
retval = new SvcLogicJdbcStore();
} else if ("dblib".equalsIgnoreCase(storeType)) {
- retval = new SvcLogicDblibStore();
+ retval = new SvcLogicDblibStore(new DBResourceManager(props));
} else {
throw new ConfigurationException("unsupported dbtype (" + storeType
+ ")");
diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java
index 6f303a59..50eb917f 100644
--- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java
+++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java
@@ -26,7 +26,6 @@ package org.onap.ccsdk.sli.core.sli;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -38,12 +37,12 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
-
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -155,7 +154,7 @@ public class ITCaseSvcLogicParser {
props.load(propStr);
- SvcLogicDblibStore dblibStore = new SvcLogicDblibStore(props);
+ SvcLogicDblibStore dblibStore = new SvcLogicDblibStore(new DBResourceManager(props));
Connection dbConn = dblibStore.getConnection();
diff --git a/sli/provider/pom.xml b/sli/provider/pom.xml
index 265831da..95099ed2 100755
--- a/sli/provider/pom.xml
+++ b/sli/provider/pom.xml
@@ -70,7 +70,14 @@
<groupId>org.opendaylight.controller</groupId>
<artifactId>sal-binding-api</artifactId>
</dependency>
-
+ <dependency>
+ <groupId>org.opendaylight.mdsal.binding.model.ietf</groupId>
+ <artifactId>rfc6991</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-core-api</artifactId>
+ </dependency>
<!-- Testing Dependencies -->
<dependency>
<groupId>junit</groupId>
diff --git a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/PrintYangToProp.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToProp.java
index 5df136fd..a7f383f2 100644
--- a/sli/common/src/main/java/org/onap/ccsdk/sli/core/sli/PrintYangToProp.java
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToProp.java
@@ -21,7 +21,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.ccsdk.sli.core.sli;
+package org.onap.ccsdk.sli.core.sli.provider;
import java.io.PrintStream;
import java.io.FileDescriptor;
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java
index 9e91b751..49d0a382 100755
--- a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicServiceImpl.java
@@ -64,12 +64,6 @@ public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcL
@Override
public Properties execute(String module, String rpc, String version, String mode, Properties props)
throws SvcLogicException {
- return (execute(module, rpc, version, mode, props, null));
- }
-
- @Override
- public Properties execute(String module, String rpc, String version, String mode, Properties props,
- DOMDataBroker domDataBroker) throws SvcLogicException {
SvcLogicGraph graph = store.fetch(module, rpc, version, mode);
if (graph == null) {
@@ -84,12 +78,19 @@ public class SvcLogicServiceImpl extends SvcLogicServiceImplBase implements SvcL
ctx.setAttribute(CURRENT_GRAPH, graph.toString());
// To support legacy code we should not stop populating X-ECOMP-RequestID
ctx.setAttribute("X-ECOMP-RequestID", MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
- ctx.setDomDataBroker(domDataBroker);
execute(graph, ctx);
return (ctx.toProperties());
}
@Override
+ @Deprecated
+ // DomDataBroker is not being used, this should be removed eventually
+ public Properties execute(String module, String rpc, String version, String mode, Properties props,
+ DOMDataBroker domDataBroker) throws SvcLogicException {
+ return (execute(module, rpc, version, mode, props));
+ }
+
+ @Override
public SvcLogicStore getStore() throws SvcLogicException {
// Create and initialize SvcLogicStore object - used to access
// saved service logic.
diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java
index 14b4dcb7..50b7926a 100644
--- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/PrintYangToPropTest.java
+++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/PrintYangToPropTest.java
@@ -20,7 +20,7 @@
20 * ===================================================================
21 *
22 */
-package org.onap.ccsdk.sli.core.sli;
+package org.onap.ccsdk.sli.core.sli.provider;
import java.util.Enumeration;
import java.util.LinkedList;
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Properties;
import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.provider.PrintYangToProp;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput.Mode;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.TestResultsBuilder;
diff --git a/sli/recording/pom.xml b/sli/recording/pom.xml
index 76862c49..f37f42ad 100755
--- a/sli/recording/pom.xml
+++ b/sli/recording/pom.xml
@@ -17,20 +17,6 @@
<name>ccsdk-sli-core :: sli :: ${project.artifactId}</name>
<description>SLI Recording is an OSGi bundle that implements recording service for the service logic record node.</description>
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- </properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.onap.ccsdk.sli.core</groupId>
- <artifactId>dblib-provider</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<dependencies>
<dependency>
<groupId>org.onap.ccsdk.sli.core</groupId>
@@ -39,42 +25,24 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>jcl-over-slf4j</artifactId>
- </dependency>
-
- <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<scope>compile</scope>
</dependency>
-
- <dependency>
- <groupId>org.opendaylight.controller</groupId>
- <artifactId>sal-binding-api</artifactId>
- </dependency>
-
<!-- Testing Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
-
</dependencies>
</project>
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
index fd3364ca..b8e88f65 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
@@ -39,8 +39,8 @@ import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
-import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
@@ -1110,4 +1110,13 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
return changeFlag;
}
+ public static String containsKey(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String key = parameters.get("key");
+ Boolean keyFound = ctx.getAttributeKeySet().contains(key);
+ if (keyFound) {
+ return "true";
+ }
+ return "false";
+ }
+
}
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
index 888ef883..269c3766 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
@@ -39,10 +39,12 @@ import org.slf4j.LoggerFactory;
*/
public class SliStringUtils implements SvcLogicJavaPlugin {
private static final Logger LOG = LoggerFactory.getLogger(SliStringUtils.class);
-
+ public static final String INPUT_PARAM_KEY = "key";
public static final String INPUT_PARAM_SOURCE = "source";
public static final String INPUT_PARAM_TARGET = "target";
-
+ public static final String TRUE_CONSTANT = "true";
+ public static final String FALSE_CONSTANT = "false";
+
public SliStringUtils() {}
/**
@@ -125,11 +127,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String equalsIgnoreCase(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).equalsIgnoreCase(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).equalsIgnoreCase(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -189,11 +191,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String contains(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).contains(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).contains(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -213,11 +215,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String endsWith(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).endsWith(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).endsWith(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -237,11 +239,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String startsWith(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).startsWith(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).startsWith(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -302,8 +304,10 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void replace(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath","target","replacement"}, LOG);
- ctx.setAttribute(parameters.get("outputPath"), (parameters.get(INPUT_PARAM_SOURCE).replace(parameters.get("target"), parameters.get("replacement"))));
+ SliPluginUtils.checkParameters(parameters,
+ new String[] {INPUT_PARAM_SOURCE, "outputPath", INPUT_PARAM_TARGET, "replacement"}, LOG);
+ ctx.setAttribute(parameters.get("outputPath"), (parameters.get(INPUT_PARAM_SOURCE)
+ .replace(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement"))));
}
/**
@@ -324,8 +328,10 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void replaceAll(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath","target","replacement"}, LOG);
- ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE).replaceAll(parameters.get("target"), parameters.get("replacement")));
+ SliPluginUtils.checkParameters(parameters,
+ new String[] {INPUT_PARAM_SOURCE, "outputPath", INPUT_PARAM_TARGET, "replacement"}, LOG);
+ ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE)
+ .replaceAll(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement")));
}
/**
@@ -385,8 +391,9 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void concat( Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
- SliPluginUtils.checkParameters( parameters, new String[]{INPUT_PARAM_SOURCE,"target","outputPath"}, LOG );
- String result = parameters.get(INPUT_PARAM_SOURCE).concat(parameters.get("target"));
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET, "outputPath"},
+ LOG);
+ String result = parameters.get(INPUT_PARAM_SOURCE).concat(parameters.get(INPUT_PARAM_TARGET));
ctx.setAttribute(parameters.get("outputPath"), result);
}
@@ -475,4 +482,31 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
throw new SvcLogicException("problem with escapeJsonString", ex);
}
}
+
+ public static String isBlank(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String ctxLocation = parameters.get(INPUT_PARAM_KEY);
+ String str = ctx.getAttribute(ctxLocation);
+ if (str == null || str.isEmpty() || " ".equals(str)) {
+ return TRUE_CONSTANT;
+ }
+ return FALSE_CONSTANT;
+ }
+
+ public static String isEmpty(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String ctxLocation = parameters.get(INPUT_PARAM_KEY);
+ String str = ctx.getAttribute(ctxLocation);
+ if (str == null || str.isEmpty()) {
+ return TRUE_CONSTANT;
+ }
+ return FALSE_CONSTANT;
+ }
+
+ public static String isNull(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String ctxLocation = parameters.get(INPUT_PARAM_KEY);
+ String str = ctx.getAttribute(ctxLocation);
+ if (str == null) {
+ return TRUE_CONSTANT;
+ }
+ return FALSE_CONSTANT;
+ }
}
diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java
index 774aa1c8..08adc973 100644
--- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java
+++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java
@@ -24,10 +24,8 @@ package org.onap.ccsdk.sli.core.slipluginutils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-
import java.util.HashMap;
import java.util.Map;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -247,4 +245,23 @@ public class SliPluginUtils_StaticFunctionsTest {
SliPluginUtils.setTime(parameters, ctx);
assertNotNull(ctx.getAttribute(outputPath));
}
+
+ @Test
+ public void containsKey() throws Exception {
+ ctx = new SvcLogicContext();
+ parameters.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist");
+ String result = SliPluginUtils.containsKey(parameters, ctx);
+ assertEquals(SliStringUtils.FALSE_CONSTANT, result);
+
+ ctx.setAttribute("a", null);
+ parameters.put(SliStringUtils.INPUT_PARAM_KEY, "a");
+ result = SliPluginUtils.containsKey(parameters, ctx);
+ assertEquals(SliStringUtils.FALSE_CONSTANT, result);
+
+ ctx.setAttribute("a", "hellworld");
+ parameters.put(SliStringUtils.INPUT_PARAM_KEY, "a");
+ result = SliPluginUtils.containsKey(parameters, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+ }
+
}
diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java
index b88e8d2c..d8d78a0b 100644
--- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java
+++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java
@@ -26,10 +26,8 @@ package org.onap.ccsdk.sli.core.slipluginutils;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
-
import java.util.HashMap;
import java.util.Map;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -317,4 +315,70 @@ public class SliStringUtilsTest {
assertEquals("{\\\"image_name\\\":\\\"Ubuntu 14.04\\\",\\\"service-instance-id\\\":\\\"1\\\",\\\"vnf-model-customization-uuid\\\":\\\"2f\\\",\\\"vnf-id\\\":\\\"3b\\\"}", ctx.getAttribute(outputPath));
}
+ @Test
+ public void isEmpty() throws Exception {
+ ctx = new SvcLogicContext();
+ param = new HashMap<>();
+ String result = SliStringUtils.isEmpty(param, ctx);
+ param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist");
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", null);
+ param.put(SliStringUtils.INPUT_PARAM_KEY, "a");
+ result = SliStringUtils.isEmpty(param, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", "");
+ result = SliStringUtils.isEmpty(param, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", " ");
+ result = SliStringUtils.isEmpty(param, ctx);
+ assertEquals(SliStringUtils.FALSE_CONSTANT, result);
+ }
+
+ @Test
+ public void isBlank() throws Exception {
+ ctx = new SvcLogicContext();
+ param = new HashMap<>();
+ String result = SliStringUtils.isBlank(param, ctx);
+ param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist");
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", null);
+ param.put(SliStringUtils.INPUT_PARAM_KEY, "a");
+ result = SliStringUtils.isBlank(param, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", "");
+ result = SliStringUtils.isBlank(param, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", " ");
+ result = SliStringUtils.isBlank(param, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+ }
+
+ @Test
+ public void isNull() throws Exception {
+ ctx = new SvcLogicContext();
+ param = new HashMap<>();
+ String result = SliStringUtils.isNull(param, ctx);
+ param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist");
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", null);
+ param.put(SliStringUtils.INPUT_PARAM_KEY, "a");
+ result = SliStringUtils.isNull(param, ctx);
+ assertEquals(SliStringUtils.TRUE_CONSTANT, result);
+
+ ctx.setAttribute("a", "");
+ result = SliStringUtils.isNull(param, ctx);
+ assertEquals(SliStringUtils.FALSE_CONSTANT, result);
+
+ ctx.setAttribute("a", " ");
+ result = SliStringUtils.isNull(param, ctx);
+ assertEquals(SliStringUtils.FALSE_CONSTANT, result);
+ }
+
}