A1 Policy Management 56/125956/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 29 Nov 2021 08:29:17 +0000 (09:29 +0100)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 29 Nov 2021 09:58:11 +0000 (10:58 +0100)
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

a1-policy-management/api/pms-api.json
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFile.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/Consts.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTask.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java
docs/offeredapis/swagger/pms-api.json

index de01472..88196a9 100644 (file)
                     "description": "Select types with the given type name (type identity has the format <typename_version>)",
                     "required": false
                 },
-                {
-                    "schema": {"type": "string"},
-                    "in": "query",
-                    "name": "regexp",
-                    "description": "Select types with type identity that matches a regular expression.",
-                    "required": false
-                },
                 {
                     "schema": {"type": "string"},
                     "in": "query",
index 26f44bb..4af39c9 100644 (file)
@@ -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));
     }
index a79999e..5642100 100644 (file)
@@ -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";
 
index 134d6d7..9945e0a 100644 (file)
@@ -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);
     }
 
index c2a93cc..53dc55d 100644 (file)
@@ -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) {
index e488af5..7fd54a7 100644 (file)
@@ -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());
index f18953c..1901097 100644 (file)
@@ -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
index 762d800..bef619c 100644 (file)
@@ -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;
     }
index de01472..88196a9 100644 (file)
                     "description": "Select types with the given type name (type identity has the format <typename_version>)",
                     "required": false
                 },
-                {
-                    "schema": {"type": "string"},
-                    "in": "query",
-                    "name": "regexp",
-                    "description": "Select types with type identity that matches a regular expression.",
-                    "required": false
-                },
                 {
                     "schema": {"type": "string"},
                     "in": "query",