aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-11-29 09:29:17 +0100
committerPatrikBuhr <patrik.buhr@est.tech>2021-11-29 10:58:11 +0100
commitc71ea987b1b5430710f6712e5660e0afb4232115 (patch)
tree34bc53c45726567e26b1eafcd657d3bd3099230c /a1-policy-management/src
parent3000fb33d26d5c043e9fc6ec506df176102deb80 (diff)
A1 Policy Management
Removed regexp parameter due to sonar warning. Skipping reading of config file unless it has been changed. Issue-ID: CCSDK-3495 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: I27bece78c99e0354cd476bb2e060788d40f2cbaf
Diffstat (limited to 'a1-policy-management/src')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java15
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java1
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java6
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java21
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java6
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java5
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java1
7 files changed, 19 insertions, 36 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java
index 26f44bb5..4af39c92 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java
@@ -51,9 +51,18 @@ public class ConfigurationFile {
this.appConfig = appConfig;
}
+ public long getLastModified() {
+ File file = new File(appConfig.getLocalConfigurationFilePath());
+ if (file.exists()) {
+ return file.lastModified();
+ }
+ return 0;
+ }
+
public synchronized Optional<JsonObject> readFile() {
String filepath = appConfig.getLocalConfigurationFilePath();
- if (!fileExists(filepath)) {
+ File file = new File(filepath);
+ if (!file.exists()) {
return Optional.empty();
}
@@ -79,10 +88,6 @@ public class ConfigurationFile {
return new FileWriter(filepath);
}
- private boolean fileExists(String filepath) {
- return (new File(filepath).exists());
- }
-
private JsonElement getJsonElement(InputStream inputStream) {
return JsonParser.parseReader(new InputStreamReader(inputStream));
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
index a79999e4..56421003 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
@@ -29,7 +29,6 @@ public class Consts {
public static final String MANAGED_ELEMENT_ID_PARAM = "managed_element_id";
public static final String TYPE_NAME_PARAM = "type_name";
public static final String COMPATIBLE_WITH_VERSION_PARAM = "compatible_with_version";
- public static final String REGEXP_PARAM = "regexp";
public static final String V2_API_ROOT = "/a1-policy/v2";
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
index 134d6d7a..9945e0ab 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
@@ -138,10 +138,6 @@ public class PolicyController {
description = "Select types with the given type name (type identity has the format <typename_version>)") //
@RequestParam(name = Consts.TYPE_NAME_PARAM, required = false) String typeName,
- @Parameter(name = Consts.REGEXP_PARAM, required = false, //
- description = "Select types with type identity that matches a regular expression.") //
- @RequestParam(name = Consts.REGEXP_PARAM, required = false) String regexp,
-
@Parameter(name = Consts.COMPATIBLE_WITH_VERSION_PARAM, required = false, //
description = "Select types that are compatible with the given version. This parameter is only applicable in conjunction with "
+ Consts.TYPE_NAME_PARAM
@@ -158,7 +154,7 @@ public class PolicyController {
Collection<PolicyType> types =
ricId != null ? rics.getRic(ricId).getSupportedPolicyTypes() : this.policyTypes.getAll();
- types = PolicyTypes.filterTypes(types, typeName, regexp, compatibleWithVersion);
+ types = PolicyTypes.filterTypes(types, typeName, compatibleWithVersion);
return new ResponseEntity<>(toPolicyTypeIdsJson(types), HttpStatus.OK);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
index c2a93cc6..53dc55db 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
@@ -35,8 +35,6 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.jetbrains.annotations.Nullable;
import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
@@ -90,21 +88,16 @@ public class PolicyTypes {
*
* @param types the types to select from
* @param typeName select types with given type name
- * @param regexp select types where the ID matches a regular
- * expression
* @param compatibleWithVersion select types that are compatible with given
* version string (major.minor.patch)
* @return the types that matches given criterias
* @throws ServiceException if there are errors in the given input
*/
public static Collection<PolicyType> filterTypes(Collection<PolicyType> types, @Nullable String typeName,
- @Nullable String regexp, @Nullable String compatibleWithVersion) throws ServiceException {
+ @Nullable String compatibleWithVersion) throws ServiceException {
if (typeName != null) {
types = filterTypeName(types, typeName);
}
- if (regexp != null) {
- types = filterRegexp(types, regexp);
- }
if (compatibleWithVersion != null) {
types = filterCompatibleWithVersion(types, compatibleWithVersion);
}
@@ -168,18 +161,6 @@ public class PolicyTypes {
return Path.of(getDatabaseDirectory());
}
- private static Collection<PolicyType> filterRegexp(Collection<PolicyType> types, String regexp) {
- Collection<PolicyType> result = new ArrayList<>();
- Pattern pattern = Pattern.compile(regexp);
- for (PolicyType type : types) {
- Matcher matcher = pattern.matcher(type.getId());
- if (matcher.find()) {
- result.add(type);
- }
- }
- return result;
- }
-
private static Collection<PolicyType> filterTypeName(Collection<PolicyType> types, String typeName) {
Collection<PolicyType> result = new ArrayList<>();
for (PolicyType type : types) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
index e488af5f..7fd54a7c 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
@@ -94,6 +94,8 @@ public class RefreshConfigTask {
private final PolicyTypes policyTypes;
private final AsyncRestClientFactory restClientFactory;
+ private long fileLastModified = 0;
+
@Autowired
public RefreshConfigTask(ConfigurationFile configurationFile, ApplicationConfig appConfig, Rics rics,
Policies policies, Services services, PolicyTypes policyTypes, A1ClientFactory a1ClientFactory) {
@@ -288,6 +290,10 @@ public class RefreshConfigTask {
* Reads the configuration from file.
*/
Flux<JsonObject> loadConfigurationFromFile() {
+ if (configurationFile.getLastModified() == fileLastModified) {
+ return Flux.empty();
+ }
+ fileLastModified = configurationFile.getLastModified();
Optional<JsonObject> readJson = configurationFile.readFile();
if (readJson.isPresent()) {
return Flux.just(readJson.get());
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
index f18953c4..19010970 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
@@ -641,11 +641,6 @@ class ApplicationTest {
url = "/policy-types?compatible_with_version=1.5.0";
testErrorCode(restClient().get(url), HttpStatus.BAD_REQUEST, "type_name");
-
- url = "/policy-types?regexp=type3_.*";
- rsp = restClient().get(url).block();
- expResp = createPolicyTypesJson(TYPE_ID_4);
- assertThat(rsp).isEqualTo(expResp);
}
@Test
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
index 762d800f..bef619cc 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
@@ -124,6 +124,7 @@ class RefreshConfigTaskTest {
new Services(appConfig), new PolicyTypes(appConfig), new A1ClientFactory(appConfig)));
if (stubConfigFileExists) {
when(configurationFileMock.readFile()).thenReturn(Optional.empty());
+ doReturn(123L).when(configurationFileMock).getLastModified();
}
return obj;
}