summaryrefslogtreecommitdiffstats
path: root/utils/provider
diff options
context:
space:
mode:
Diffstat (limited to 'utils/provider')
-rwxr-xr-x[-rw-r--r--]utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java2
-rwxr-xr-x[-rw-r--r--]utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java10
-rwxr-xr-xutils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/BundleContextFileResolver.java80
-rwxr-xr-xutils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolver.java41
-rwxr-xr-xutils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolver.java38
-rwxr-xr-x[-rw-r--r--]utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java10
-rw-r--r--utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java8
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/BundleContexFileResolverTest.java16
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolverTest.java25
-rw-r--r--utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolverTest.java24
10 files changed, 248 insertions, 6 deletions
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
index 3e438d1a9..5e87412a5 100644..100755
--- a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/EnvVarFileResolver.java
@@ -27,7 +27,7 @@ import java.nio.file.Paths;
import java.util.Optional;
/**
- * Resolves dblib properties files relative to the directory identified by the <code>SDNC_CONFIG_DIR</code>
+ * Resolves properties files relative to the directory identified by the <code>SDNC_CONFIG_DIR</code>
* environment variable.
*/
public abstract class EnvVarFileResolver implements PropertiesFileResolver {
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
index 5cd6c3606..844c6949c 100644..100755
--- a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/JREFileResolver.java
@@ -23,13 +23,15 @@ package org.onap.ccsdk.sli.core.utils;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
import org.osgi.framework.FrameworkUtil;
+import org.slf4j.LoggerFactory;
/**
- * Resolves dblib properties files relative to the directory identified by the JRE property
+ * Resolves project properties files relative to the directory identified by the JRE property
* <code>dblib.properties</code>.
*/
public class JREFileResolver implements PropertiesFileResolver {
@@ -37,7 +39,6 @@ public class JREFileResolver implements PropertiesFileResolver {
/**
* Key for JRE argument representing the configuration directory
*/
- private static final String DBLIB_JRE_PROPERTY_KEY = "dblib.properties";
private final String successMessage;
private final Class clazz;
@@ -55,14 +56,15 @@ public class JREFileResolver implements PropertiesFileResolver {
@Override
public Optional<File> resolveFile(final String filename) {
final URL jreArgumentUrl = FrameworkUtil.getBundle(this.clazz)
- .getResource(DBLIB_JRE_PROPERTY_KEY);
+ .getResource(filename);
try {
if (jreArgumentUrl == null) {
return Optional.empty();
}
final Path dblibPath = Paths.get(jreArgumentUrl.toURI());
return Optional.of(dblibPath.resolve(filename).toFile());
- } catch(final URISyntaxException e) {
+ } catch(final URISyntaxException | FileSystemNotFoundException e) {
+ LoggerFactory.getLogger(this.getClass()).error("", e);
return Optional.empty();
}
}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/BundleContextFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/BundleContextFileResolver.java
new file mode 100755
index 000000000..9496d90e2
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/BundleContextFileResolver.java
@@ -0,0 +1,80 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * 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.onap.ccsdk.sli.core.utils.common;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
+
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+import org.osgi.framework.FrameworkUtil;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Strings;
+
+/**
+ * Resolves properties files from runtime property value <code>SDNC_CONFIG_DIR</code> defined in the osgi properties.
+ */
+public class BundleContextFileResolver implements PropertiesFileResolver {
+
+ /**
+ * Key for osgi variable representing the configuration directory
+ */
+ private static final String SDNC_CONFIG_DIR_PROP_KEY = "SDNC_CONFIG_DIR";
+
+ private final String successMessage;
+ private final Class<?> clazz;
+
+ public BundleContextFileResolver(final String successMessage, final Class<?> clazz) {
+ this.successMessage = successMessage;
+ this.clazz = clazz;
+ }
+
+ /**
+ * Parse a properties file location based on JRE argument
+ *
+ * @return an Optional File containing the location if it exists, or an empty Optional
+ */
+ @Override
+ public Optional<File> resolveFile(final String filename) {
+ if(FrameworkUtil.getBundle(clazz) == null) {
+ return Optional.empty();
+ } else {
+ try {
+ final String pathProperty = FrameworkUtil.getBundle(this.clazz).getBundleContext().getProperty(SDNC_CONFIG_DIR_PROP_KEY);
+ if(Strings.isNullOrEmpty(pathProperty)) {
+ return Optional.empty();
+ }
+ final Path dblibPath = Paths.get(pathProperty);
+ return Optional.of(dblibPath.resolve(filename).toFile());
+ } catch(final Exception e) {
+ LoggerFactory.getLogger(this.getClass()).error("", e);
+ return Optional.empty();
+ }
+ }
+ }
+
+ @Override
+ public String getSuccessfulResolutionMessage() {
+ return this.successMessage;
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolver.java
new file mode 100755
index 000000000..4d7e90261
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolver.java
@@ -0,0 +1,41 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * 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.onap.ccsdk.sli.core.utils.common;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.onap.ccsdk.sli.core.utils.DefaultFileResolver;
+
+/**
+ * Resolve properties file location based on the default directory name.
+ */
+public class CoreDefaultFileResolver extends DefaultFileResolver {
+
+ /**
+ * Default path to look for the configuration directory
+ */
+ private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("/opt", "sdnc", "data", "properties");
+
+ public CoreDefaultFileResolver(final String successMessage) {
+ super(successMessage, DEFAULT_DBLIB_PROP_DIR);
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolver.java
new file mode 100755
index 000000000..51b6134f7
--- /dev/null
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolver.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * onap
+ * ================================================================================
+ * Copyright (C) 2016 - 2017 ONAP
+ * ================================================================================
+ * 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.onap.ccsdk.sli.core.utils.common;
+
+import org.onap.ccsdk.sli.core.utils.EnvVarFileResolver;
+
+/**
+ * Resolve properties file location based on the default directory name.
+ */
+public class SdncConfigEnvVarFileResolver extends EnvVarFileResolver {
+
+ /**
+ * Key for environment variable representing the configuration directory
+ */
+ private static final String SDNC_CONFIG_DIR_PROP_KEY = "SDNC_CONFIG_DIR";
+
+ public SdncConfigEnvVarFileResolver(final String successMessage) {
+ super(successMessage, SDNC_CONFIG_DIR_PROP_KEY);
+ }
+}
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java
index 56b4ca1b6..082bdf403 100644..100755
--- a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibDefaultFileResolver.java
@@ -4,12 +4,20 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import org.onap.ccsdk.sli.core.utils.DefaultFileResolver;
+/**
+ * Resolve properties file location based on the default directory name.
+ *
+ * @deprecated
+ * This class has been replaced by generic version of this class
+ * {@link #CoreDefaultFileResolver} in common package.
+ */
+@Deprecated
public class DblibDefaultFileResolver extends DefaultFileResolver {
/**
* Default path to look for the configuration directory
*/
- private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("opt", "sdnc", "data", "properties");
+ private static final Path DEFAULT_DBLIB_PROP_DIR = Paths.get("/opt", "sdnc", "data", "properties");
public DblibDefaultFileResolver(final String successMessage) {
super(successMessage, DEFAULT_DBLIB_PROP_DIR);
diff --git a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java
index 9eef4cee2..959271cb7 100644
--- a/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java
+++ b/utils/provider/src/main/java/org/onap/ccsdk/sli/core/utils/dblib/DblibEnvVarFileResolver.java
@@ -2,6 +2,14 @@ package org.onap.ccsdk.sli.core.utils.dblib;
import org.onap.ccsdk.sli.core.utils.EnvVarFileResolver;
+/**
+ * Resolve properties file location based on the default directory name.
+ *
+ * @deprecated
+ * This class has been replaced by generic version of this class
+ * {@link #SdncConfigEnvVarFileResolver} in common package.
+ */
+@Deprecated
public class DblibEnvVarFileResolver extends EnvVarFileResolver {
/**
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/BundleContexFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/BundleContexFileResolverTest.java
new file mode 100644
index 000000000..4ec5e1b48
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/BundleContexFileResolverTest.java
@@ -0,0 +1,16 @@
+package org.onap.ccsdk.sli.core.utils.common;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+
+public class BundleContexFileResolverTest {
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new BundleContextFileResolver("success", BundleContexFileResolverTest.class);
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolverTest.java
new file mode 100644
index 000000000..a4f8817fa
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/CoreDefaultFileResolverTest.java
@@ -0,0 +1,25 @@
+package org.onap.ccsdk.sli.core.utils.common;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+
+public class CoreDefaultFileResolverTest {
+
+ @Test
+ public void resolveFile() throws Exception {
+ final PropertiesFileResolver resolver = new CoreDefaultFileResolver("success");
+ final Optional<File> file = resolver.resolveFile("doesnotexist.cfg");
+ assertFalse(file.isPresent());
+ }
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new CoreDefaultFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file
diff --git a/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolverTest.java b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolverTest.java
new file mode 100644
index 000000000..0f3536b78
--- /dev/null
+++ b/utils/provider/src/test/java/org/onap/ccsdk/sli/core/utils/common/SdncConfigEnvVarFileResolverTest.java
@@ -0,0 +1,24 @@
+package org.onap.ccsdk.sli.core.utils.common;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Optional;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.utils.PropertiesFileResolver;
+
+public class SdncConfigEnvVarFileResolverTest {
+ @Test
+ public void resolveFile() throws Exception {
+ final PropertiesFileResolver resolver = new SdncConfigEnvVarFileResolver("success");
+ final Optional<File> file = resolver.resolveFile("doesnotexist.cfg");
+ assertFalse(file.isPresent());
+ }
+
+ @Test
+ public void getSuccessfulResolutionMessage() throws Exception {
+ final PropertiesFileResolver resolver = new SdncConfigEnvVarFileResolver("success");
+ assertEquals("success", resolver.getSuccessfulResolutionMessage());
+ }
+
+} \ No newline at end of file