* ========================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);
}
--- /dev/null
+/*-
+ * ========================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);
+ }
+
+}
* ========================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;
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);
* ========================LICENSE_END===================================
*/
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
import java.util.ArrayList;
import java.util.Collection;
* ========================LICENSE_END===================================
*/
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
import java.util.ArrayList;
import java.util.Collection;
return "";
}
return gson.toJson(report);
-
}
/**
* ========================LICENSE_END===================================
*/
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
import java.util.regex.Matcher;
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;
package org.oran.dmaapadapter.repository;
-import com.google.gson.GsonBuilder;
-
import java.lang.invoke.MethodHandles;
import java.time.Duration;
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 {
@Setter
private String filterType = REGEXP_TYPE;
+ @Getter
private Object filter;
@Getter
private BufferTimeout bufferTimeout;
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;
}
}
}
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");
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;
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;
* ========================LICENSE_END===================================
*/
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
import static org.assertj.core.api.Assertions.assertThat;
* ========================LICENSE_END===================================
*/
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
import static org.assertj.core.api.Assertions.assertThat;
* ========================LICENSE_END===================================
*/
-package org.oran.dmaapadapter.repository.filters;
+package org.oran.dmaapadapter.filter;
import static org.assertj.core.api.Assertions.assertThat;