NONRTRIC - dmaap adapter characteristic improvement 29/8829/2
authorPatrikBuhr <patrik.buhr@est.tech>
Thu, 4 Aug 2022 10:08:56 +0000 (12:08 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Thu, 4 Aug 2022 12:29:23 +0000 (14:29 +0200)
Minor refactoring

Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-773
Change-Id: Ibedc361673aad2a9362e31651d11853bd282df85

13 files changed:
src/main/java/org/oran/dmaapadapter/filter/Filter.java [moved from src/main/java/org/oran/dmaapadapter/repository/filters/Filter.java with 87% similarity]
src/main/java/org/oran/dmaapadapter/filter/FilterFactory.java [new file with mode: 0644]
src/main/java/org/oran/dmaapadapter/filter/JsltFilter.java [moved from src/main/java/org/oran/dmaapadapter/repository/filters/JsltFilter.java with 95% similarity]
src/main/java/org/oran/dmaapadapter/filter/JsonPathFilter.java [moved from src/main/java/org/oran/dmaapadapter/repository/filters/JsonPathFilter.java with 94% similarity]
src/main/java/org/oran/dmaapadapter/filter/PmReport.java [moved from src/main/java/org/oran/dmaapadapter/repository/filters/PmReport.java with 98% similarity]
src/main/java/org/oran/dmaapadapter/filter/PmReportFilter.java [moved from src/main/java/org/oran/dmaapadapter/repository/filters/PmReportFilter.java with 99% similarity]
src/main/java/org/oran/dmaapadapter/filter/RegexpFilter.java [moved from src/main/java/org/oran/dmaapadapter/repository/filters/RegexpFilter.java with 94% similarity]
src/main/java/org/oran/dmaapadapter/repository/Job.java
src/test/java/org/oran/dmaapadapter/ApplicationTest.java
src/test/java/org/oran/dmaapadapter/IntegrationWithKafka.java
src/test/java/org/oran/dmaapadapter/filter/JsltFilterTest.java [moved from src/test/java/org/oran/dmaapadapter/repository/filters/JsltFilterTest.java with 98% similarity]
src/test/java/org/oran/dmaapadapter/filter/JsonPathFilterTest.java [moved from src/test/java/org/oran/dmaapadapter/repository/filters/JsonPathFilterTest.java with 96% similarity]
src/test/java/org/oran/dmaapadapter/filter/PmReportFilterTest.java [moved from src/test/java/org/oran/dmaapadapter/repository/filters/PmReportFilterTest.java with 99% similarity]

  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 public interface Filter {
+
+    public enum Type {
+        REGEXP, JSLT, JSON_PATH, PM_DATA, NONE
+    }
+
     public String filter(String data);
 
 }
diff --git a/src/main/java/org/oran/dmaapadapter/filter/FilterFactory.java b/src/main/java/org/oran/dmaapadapter/filter/FilterFactory.java
new file mode 100644 (file)
index 0000000..8d51727
--- /dev/null
@@ -0,0 +1,59 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2022 Nordix Foundation
+ * %%
+ * 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.oran.dmaapadapter.filter;
+
+import com.google.gson.GsonBuilder;
+
+import java.lang.invoke.MethodHandles;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FilterFactory {
+    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+    private static com.google.gson.Gson gson = new GsonBuilder().disableHtmlEscaping().create();
+
+    private FilterFactory() {}
+
+    public static Filter create(Object filter, Filter.Type type) {
+        switch (type) {
+            case PM_DATA:
+                return new PmReportFilter(createPmFilterData(filter));
+            case REGEXP:
+                return new RegexpFilter(filter.toString());
+            case JSLT:
+                return new JsltFilter(filter.toString());
+            case JSON_PATH:
+                return new JsonPathFilter(filter.toString());
+            case NONE:
+                return null;
+            default:
+                logger.error("Not handeled filter type: {}", type);
+                return null;
+        }
+    }
+
+    private static PmReportFilter.FilterData createPmFilterData(Object filter) {
+        String str = gson.toJson(filter);
+        return gson.fromJson(str, PmReportFilter.FilterData.class);
+    }
+
+}
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import com.fasterxml.jackson.core.JsonFactory;
 import com.fasterxml.jackson.core.JsonParser;
@@ -31,7 +31,7 @@ import com.schibsted.spt.data.jslt.Parser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class JsltFilter implements Filter {
+class JsltFilter implements Filter {
 
     private Expression expression;
     private final ObjectMapper mapper = new ObjectMapper();
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import com.jayway.jsonpath.JsonPath;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class JsonPathFilter implements Filter {
+class JsonPathFilter implements Filter {
 
     private String expression;
     private static final Logger logger = LoggerFactory.getLogger(JsonPathFilter.class);
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -70,7 +70,6 @@ public class PmReportFilter implements Filter {
             return "";
         }
         return gson.toJson(report);
-
     }
 
     /**
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -26,7 +26,7 @@ import java.util.regex.Pattern;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class RegexpFilter implements Filter {
+class RegexpFilter implements Filter {
     private static final Logger logger = LoggerFactory.getLogger(RegexpFilter.class);
     private Pattern regexp;
 
index d296f8e..7201dad 100644 (file)
@@ -20,8 +20,6 @@
 
 package org.oran.dmaapadapter.repository;
 
-import com.google.gson.GsonBuilder;
-
 import java.lang.invoke.MethodHandles;
 import java.time.Duration;
 
@@ -30,18 +28,13 @@ import lombok.Setter;
 import lombok.ToString;
 
 import org.oran.dmaapadapter.clients.AsyncRestClient;
-import org.oran.dmaapadapter.repository.filters.Filter;
-import org.oran.dmaapadapter.repository.filters.JsltFilter;
-import org.oran.dmaapadapter.repository.filters.JsonPathFilter;
-import org.oran.dmaapadapter.repository.filters.PmReportFilter;
-import org.oran.dmaapadapter.repository.filters.RegexpFilter;
+import org.oran.dmaapadapter.filter.Filter;
+import org.oran.dmaapadapter.filter.FilterFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @ToString
 public class Job {
-
-    private static com.google.gson.Gson gson = new GsonBuilder().disableHtmlEscaping().create();
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
     public static class Parameters {
@@ -52,6 +45,7 @@ public class Job {
 
         @Setter
         private String filterType = REGEXP_TYPE;
+        @Getter
         private Object filter;
         @Getter
         private BufferTimeout bufferTimeout;
@@ -76,33 +70,20 @@ public class Job {
             return maxConcurrency == null || maxConcurrency == 0 ? 1 : maxConcurrency;
         }
 
-        public String getFilterAsString() {
-            return this.filter.toString();
-        }
-
-        public PmReportFilter.FilterData getPmFilter() {
-            String str = gson.toJson(this.filter);
-            return gson.fromJson(str, PmReportFilter.FilterData.class);
-        }
-
-        public enum FilterType {
-            REGEXP, JSLT, JSON_PATH, PM_DATA, NONE
-        }
-
-        public FilterType getFilterType() {
+        public Filter.Type getFilterType() {
             if (filter == null || filterType == null) {
-                return FilterType.NONE;
+                return Filter.Type.NONE;
             } else if (filterType.equalsIgnoreCase(JSLT_FILTER_TYPE)) {
-                return FilterType.JSLT;
+                return Filter.Type.JSLT;
             } else if (filterType.equalsIgnoreCase(JSON_PATH_FILTER_TYPE)) {
-                return FilterType.JSON_PATH;
+                return Filter.Type.JSON_PATH;
             } else if (filterType.equalsIgnoreCase(REGEXP_TYPE)) {
-                return FilterType.REGEXP;
+                return Filter.Type.REGEXP;
             } else if (filterType.equalsIgnoreCase(PM_FILTER_TYPE)) {
-                return FilterType.PM_DATA;
+                return Filter.Type.PM_DATA;
             } else {
                 logger.warn("Unsupported filter type: {}", this.filterType);
-                return FilterType.NONE;
+                return Filter.Type.NONE;
             }
         }
     }
@@ -156,33 +137,11 @@ public class Job {
         this.owner = owner;
         this.lastUpdated = lastUpdated;
         this.parameters = parameters;
-        filter = createFilter(parameters);
+        filter = parameters.filter == null ? null
+                : FilterFactory.create(parameters.getFilter(), parameters.getFilterType());
         this.consumerRestClient = consumerRestClient;
     }
 
-    private static Filter createFilter(Parameters parameters) {
-
-        if (parameters.filter == null) {
-            return null;
-        }
-
-        switch (parameters.getFilterType()) {
-            case PM_DATA:
-                return new PmReportFilter(parameters.getPmFilter());
-            case REGEXP:
-                return new RegexpFilter(parameters.getFilterAsString());
-            case JSLT:
-                return new JsltFilter(parameters.getFilterAsString());
-            case JSON_PATH:
-                return new JsonPathFilter(parameters.getFilterAsString());
-            case NONE:
-                return null;
-            default:
-                logger.error("Not handeled filter type: {}", parameters.getFilterType());
-                return null;
-        }
-    }
-
     public String filter(String data) {
         if (filter == null) {
             logger.debug("No filter used");
index 2d0d621..85c02b0 100644 (file)
@@ -47,13 +47,13 @@ import org.oran.dmaapadapter.configuration.ApplicationConfig;
 import org.oran.dmaapadapter.configuration.WebClientConfig;
 import org.oran.dmaapadapter.configuration.WebClientConfig.HttpProxyConfig;
 import org.oran.dmaapadapter.controllers.ProducerCallbacksController;
+import org.oran.dmaapadapter.filter.PmReport;
+import org.oran.dmaapadapter.filter.PmReportFilter;
 import org.oran.dmaapadapter.r1.ConsumerJobInfo;
 import org.oran.dmaapadapter.r1.ProducerJobInfo;
 import org.oran.dmaapadapter.repository.InfoTypes;
 import org.oran.dmaapadapter.repository.Job;
 import org.oran.dmaapadapter.repository.Jobs;
-import org.oran.dmaapadapter.repository.filters.PmReport;
-import org.oran.dmaapadapter.repository.filters.PmReportFilter;
 import org.oran.dmaapadapter.tasks.JobDataDistributor;
 import org.oran.dmaapadapter.tasks.ProducerRegstrationTask;
 import org.oran.dmaapadapter.tasks.TopicListener;
index 3bb3a4a..65a1366 100644 (file)
@@ -48,12 +48,12 @@ import org.oran.dmaapadapter.configuration.ApplicationConfig;
 import org.oran.dmaapadapter.configuration.WebClientConfig;
 import org.oran.dmaapadapter.configuration.WebClientConfig.HttpProxyConfig;
 import org.oran.dmaapadapter.exceptions.ServiceException;
+import org.oran.dmaapadapter.filter.PmReportFilter;
 import org.oran.dmaapadapter.r1.ConsumerJobInfo;
 import org.oran.dmaapadapter.repository.InfoType;
 import org.oran.dmaapadapter.repository.InfoTypes;
 import org.oran.dmaapadapter.repository.Job;
 import org.oran.dmaapadapter.repository.Jobs;
-import org.oran.dmaapadapter.repository.filters.PmReportFilter;
 import org.oran.dmaapadapter.tasks.KafkaTopicListener;
 import org.oran.dmaapadapter.tasks.TopicListener;
 import org.oran.dmaapadapter.tasks.TopicListeners;
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -18,7 +18,7 @@
  * ========================LICENSE_END===================================
  */
 
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
 
 import static org.assertj.core.api.Assertions.assertThat;