aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2018-08-06 15:51:35 +0300
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-08-07 07:00:42 +0000
commit4da15282e4715d6b359873f260399a7b9a3d8666 (patch)
tree92cf88d72301f30f32af42db163433794d5e028c /common
parent7381994de250aac82522c2bdd32768bff4f869a8 (diff)
Revert commit
Fixes of sonar violations sdc and refactor This reverts commit baf7f0a965d0ffebd5308d44758bfa9ba96c0c76. except the catalog files. the onbording files will be resubmited. Change-Id: I84c00cec41665211e0bd16ff9cc0c87073d6b897 Issue-ID: SDC-1484 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'common')
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/pom.xml5
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java2
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java159
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java8
-rw-r--r--common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/type/NonConfigResourceTest.java82
5 files changed, 79 insertions, 177 deletions
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml b/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml
index 46e4579aa6..78c378713a 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/pom.xml
@@ -106,11 +106,6 @@
<scope>test</scope>
<version>${junit.version}</version>
</dependency>
- <dependency>
- <groupId>io.vavr</groupId>
- <artifactId>vavr</artifactId>
- <version>0.9.2</version>
- </dependency>
</dependencies>
</project>
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
index 9782fc9969..db64f7f7fc 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/ConfigurationUtils.java
@@ -670,7 +670,7 @@ public class ConfigurationUtils {
Configuration dbConfig = ConfigurationRepository.lookup()
.getConfigurationFor(Constants.DEFAULT_TENANT, Constants.DB_NAMESPACE);
BasicConfigurationBuilder<AgglomerateConfiguration> builder =
- new BasicConfigurationBuilder<>(AgglomerateConfiguration.class);
+ new BasicConfigurationBuilder<AgglomerateConfiguration>(AgglomerateConfiguration.class);
builder.configure(
new Parameters().database()
.setDataSource(ConfigurationDataSource.lookup())
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java
index a63b455a16..830cdfef5a 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/NonConfigResource.java
@@ -1,104 +1,95 @@
package org.onap.config;
-import io.vavr.Function1;
-import io.vavr.collection.HashSet;
-import io.vavr.collection.Set;
-import io.vavr.control.Option;
-
import java.io.File;
-import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
-
-import static io.vavr.API.Option;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Predicate;
/**
* The type Non config resource.
*/
public class NonConfigResource {
- private Function1<String, String> propertyGetter;
- private Set<URL> urls;
- private Set<Path> files;
-
- private NonConfigResource(Function1<String, String> propertyGetter) {
- this.propertyGetter = propertyGetter;
- this.files = HashSet.empty();
- this.urls = HashSet.empty();
- }
+ private static Set<URL> urls = new HashSet<>();
+ private static Set<File> files = new HashSet<>();
- public static NonConfigResource create(Function1<String, String> propertyGetter) {
- return new NonConfigResource(propertyGetter);
- }
+ /**
+ * Add.
+ *
+ * @param url the url
+ */
+ public static void add(URL url) {
+ urls.add(url);
+ }
- /**
- * Add.
- *
- * @param url the url
- */
- public void add(URL url) {
- urls = urls.add(url);
- }
+ /**
+ * Add.
+ *
+ * @param file the file
+ */
+ public static void add(File file) {
+ files.add(file);
+ }
- /**
- * Add.
- *
- * @param file the file
- */
- public void add(File file) {
- files = files.add(file.toPath());
- }
-
- /**
- * Locate path.
- *
- * @param resource the resource
- * @return the path
- */
- public Path locate(String resource) {
- Path toReturn = null;
- try {
- if (resource != null) {
- toReturn = tryToLocateResource(resource).getOrNull();
- }
- } catch (Exception exception) {
- exception.printStackTrace();
+ /**
+ * Locate path.
+ *
+ * @param resource the resource
+ * @return the path
+ */
+ public static Path locate(String resource) {
+ try {
+ if (resource != null) {
+ File file = new File(resource);
+ if (file.exists()) {
+ return Paths.get(resource);
}
- return toReturn;
- }
-
- private Option<Path> tryToLocateResource(String resource) throws URISyntaxException {
- return new File(resource).exists() ? Option(Paths.get(resource)) : getPathForResourceAmongFiles(resource)
- .orElse(getPathForResourceBasedOnProperty(resource, "node.config.location"))
- .orElse(getPathForResourceBasedOnProperty(resource, "config.location"))
- .orElse(getPathForResourceAmongUrls(resource));
- }
-
- private Option<Path> getPathForResourceBasedOnProperty(String resource, String configPropertyKey) {
- return Option(propertyGetter.apply(configPropertyKey))
- .flatMap(el -> locate(new File(el), resource));
- }
-
- private Option<Path> getPathForResourceAmongFiles(String resource) {
- return files.map(Path::toAbsolutePath)
- .filter(path -> path.toFile().exists() && path.endsWith(resource))
- .headOption();
- }
-
- private Option<Path> getPathForResourceAmongUrls(String resource) throws URISyntaxException {
- return urls.filter(url -> url.getFile().endsWith(resource))
- .headOption()
- .flatMap(url -> Option(Paths.get(url.getPath())));
+ for (File availableFile : files) {
+ if (availableFile.getAbsolutePath().endsWith(resource) && availableFile.exists()) {
+ return Paths.get(availableFile.getAbsolutePath());
+ }
+ }
+ if (System.getProperty("node.config.location") != null) {
+ Path path = locate(new File(System.getProperty("node.config.location")), resource);
+ if (path != null) {
+ return path;
+ }
+ }
+ if (System.getProperty("config.location") != null) {
+ Path path = locate(new File(System.getProperty("config.location")), resource);
+ if (path != null) {
+ return path;
+ }
+ }
+ for (URL url : urls) {
+ if (url.getFile().endsWith(resource)) {
+ return Paths.get(url.toURI());
+ }
+ }
+ }
+ } catch (Exception exception) {
+ exception.printStackTrace();
}
+ return null;
+ }
- private Option<Path> locate(File root, String resource) {
- return root.exists() ? Option.ofOptional(ConfigurationUtils.getAllFiles(root, true, false)
- .stream()
- .filter(file -> !ConfigurationUtils.isConfig(file))
- .peek(this::add)
- .filter(file -> file.getAbsolutePath().endsWith(resource))
- .map(file -> Paths.get(file.getAbsolutePath()))
- .findAny()) : Option.none();
+ private static Path locate(File root, String resource) {
+ if (root.exists()) {
+ Collection<File> filesystemResources = ConfigurationUtils.getAllFiles(root, true, false);
+ Predicate<File> f1 = ConfigurationUtils::isConfig;
+ for (File file : filesystemResources) {
+ if (!f1.test(file)) {
+ add(file);
+ if (file.getAbsolutePath().endsWith(resource)) {
+ return Paths.get(file.getAbsolutePath());
+ }
+ }
+ }
}
+ return null;
+ }
}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java
index 56390ea54a..00725b1165 100644
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java
+++ b/common/onap-common-configuration-management/onap-configuration-management-core/src/main/java/org/onap/config/impl/ConfigurationImpl.java
@@ -1,6 +1,5 @@
package org.onap.config.impl;
-
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.DatabaseConfiguration;
import org.onap.config.ConfigurationUtils;
@@ -40,7 +39,6 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
;
};
private static boolean instantiated = false;
- private static NonConfigResource nonConfigResource = NonConfigResource.create(propertyName -> System.getProperties().getProperty(propertyName));
/**
* The Change notifier.
*/
@@ -68,7 +66,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
moduleConfig.addConfig(url);
} else {
- nonConfigResource.add(url);
+ NonConfigResource.add(url);
}
}
String configLocation = System.getProperty("config.location");
@@ -86,7 +84,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
}
moduleConfig.addConfig(file);
} else {
- nonConfigResource.add(file);
+ NonConfigResource.add(file);
}
}
}
@@ -455,7 +453,7 @@ public class ConfigurationImpl implements org.onap.config.api.Configuration {
if (String.class.equals(clazz)) {
if (obj.toString().startsWith("@") && ConfigurationUtils.isExternalLookup(processingHint)) {
String contents = ConfigurationUtils
- .getFileContents(nonConfigResource.locate(obj.toString().substring(1).trim()));
+ .getFileContents(NonConfigResource.locate(obj.toString().substring(1).trim()));
if (contents == null) {
contents = ConfigurationUtils.getFileContents(obj.toString().substring(1).trim());
}
diff --git a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/type/NonConfigResourceTest.java b/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/type/NonConfigResourceTest.java
deleted file mode 100644
index 0671996fb5..0000000000
--- a/common/onap-common-configuration-management/onap-configuration-management-core/src/test/java/org/onap/config/type/NonConfigResourceTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package org.onap.config.type;
-
-import com.google.common.collect.ImmutableMap;
-import org.junit.Test;
-import org.onap.config.NonConfigResource;
-
-import java.io.File;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Map;
-
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class NonConfigResourceTest {
-
- private final URL sampleUrlResource = NonConfigResourceTest.class.getResource("NonConfigResourceTest.class");
- private final String sampleResourcePath = sampleUrlResource.getPath();
- private final File sampleResourceFile = new File(sampleResourcePath);
-
- @Test
- public void testShouldLocateResourceWhenAbsPathProvided2() {
- Map<String, String> properties = ImmutableMap.of();
- Path actualResourcePath = NonConfigResource.create(properties::get).locate(sampleResourceFile.toString());
-
- assertTrue(actualResourcePath.compareTo(sampleResourceFile.toPath()) == 0);
- }
-
- @Test
- public void testShouldLocateResourceWhenPresentInFiles2() {
- Map<String, String> properties = ImmutableMap.of();
- NonConfigResource testedObject = NonConfigResource.create(properties::get);
- testedObject.add(sampleResourceFile);
-
- Path thisFilePath = testedObject.locate("NonConfigResourceTest.class");
-
- assertTrue(thisFilePath.compareTo(sampleResourceFile.toPath()) == 0);
- }
-
- @Test
- public void testShouldLocateResourceWhenNodeConfigPropertyIsSet2() throws URISyntaxException, MalformedURLException {
- Map<String, String> properties = ImmutableMap.of("node.config.location", new File(sampleResourcePath).getParentFile().getPath());
- NonConfigResource testedNonConfigResource = NonConfigResource.create(properties::get);
- System.getProperties().setProperty("node.config.location", new File(sampleResourcePath).getParentFile().getPath());
- Path thisFilePath = testedNonConfigResource.locate("NonConfigResourceTest.class");
-
- assertTrue(thisFilePath.compareTo(new File(sampleResourcePath).toPath()) == 0);
- }
-
- @Test
- public void testShouldLocateResourceWhenConfigPropertyIsSet2() {
- Map<String, String> properties = ImmutableMap.of("config.location", new File(sampleResourcePath).getParentFile().getPath());
- NonConfigResource testedNonConfigResource = NonConfigResource.create(properties::get);
- Path thisFilePath = testedNonConfigResource.locate("NonConfigResourceTest.class");
-
- assertTrue(thisFilePath.compareTo(new File(sampleResourcePath).toPath()) == 0);
- }
-
- @Test
- public void testShouldLocatePathWhenResourcePresentInUrls2() throws URISyntaxException {
- Map<String, String> properties = ImmutableMap.of();
- NonConfigResource testedObject = NonConfigResource.create(properties::get);
- testedObject.add(sampleUrlResource);
-
- Path thisFilePath = testedObject.locate("NonConfigResourceTest.class");
-
- assertTrue(thisFilePath.compareTo(Paths.get(sampleUrlResource.toURI())) == 0);
- }
-
- @Test
- public void testShouldNotLocateResource2() throws URISyntaxException {
- Map<String, String> properties = ImmutableMap.of();
- NonConfigResource testedObject = NonConfigResource.create(properties::get);
-
- Path thisFilePath = testedObject.locate("nonexistingresource");
-
- assertNull(thisFilePath);
- }
-}