2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oran.dmaapadapter.repository;
23 import java.time.Duration;
24 import java.util.regex.Matcher;
25 import java.util.regex.Pattern;
29 import org.immutables.gson.Gson;
30 import org.oran.dmaapadapter.clients.AsyncRestClient;
35 public static class Parameters {
37 private String filter;
39 private BufferTimeout bufferTimeout;
41 public Parameters() {}
43 public Parameters(String filter, BufferTimeout bufferTimeout) {
45 this.bufferTimeout = bufferTimeout;
50 public static class BufferTimeout {
51 public BufferTimeout(int maxSize, int maxTimeMiliseconds) {
52 this.maxSize = maxSize;
53 this.maxTimeMiliseconds = maxTimeMiliseconds;
56 public BufferTimeout() {}
61 private int maxTimeMiliseconds;
63 public Duration getMaxTime() {
64 return Duration.ofMillis(maxTimeMiliseconds);
69 private final String id;
72 private final String callbackUrl;
75 private final InfoType type;
78 private final String owner;
81 private final Parameters parameters;
84 private final String lastUpdated;
86 private final Pattern jobDataFilter;
89 private final AsyncRestClient consumerRestClient;
91 public Job(String id, String callbackUrl, InfoType type, String owner, String lastUpdated, Parameters parameters,
92 AsyncRestClient consumerRestClient) {
94 this.callbackUrl = callbackUrl;
97 this.lastUpdated = lastUpdated;
98 this.parameters = parameters;
99 if (parameters != null && parameters.filter != null) {
100 jobDataFilter = Pattern.compile(parameters.filter);
102 jobDataFilter = null;
104 this.consumerRestClient = consumerRestClient;
107 public boolean isFilterMatch(String data) {
108 if (jobDataFilter == null) {
111 Matcher matcher = jobDataFilter.matcher(data);
112 return matcher.find();
115 public boolean isBuffered() {
116 return parameters != null && parameters.bufferTimeout != null && parameters.bufferTimeout.maxSize > 0
117 && parameters.bufferTimeout.maxTimeMiliseconds > 0;