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.util.regex.Matcher;
24 import java.util.regex.Pattern;
28 import org.immutables.gson.Gson;
33 public static class Parameters {
35 public BufferTimeout bufferTimeout;
40 public Parameters(String filter, BufferTimeout bufferTimeout) {
42 this.bufferTimeout = bufferTimeout;
45 public static class BufferTimeout {
46 public BufferTimeout(int maxSize, int maxTimeMiliseconds) {
47 this.maxSize = maxSize;
48 this.maxTimeMiliseconds = maxTimeMiliseconds;
51 public BufferTimeout() {
55 public int maxTimeMiliseconds;
60 private final String id;
63 private final String callbackUrl;
66 private final InfoType type;
69 private final String owner;
72 private final Parameters parameters;
75 private final String lastUpdated;
77 private final Pattern jobDataFilter;
79 public Job(String id, String callbackUrl, InfoType type, String owner, String lastUpdated, Parameters parameters) {
81 this.callbackUrl = callbackUrl;
84 this.lastUpdated = lastUpdated;
85 this.parameters = parameters;
86 if (parameters != null && parameters.filter != null) {
87 jobDataFilter = Pattern.compile(parameters.filter);
93 public boolean isFilterMatch(String data) {
94 if (jobDataFilter == null) {
97 Matcher matcher = jobDataFilter.matcher(data);
98 return matcher.find();
101 public boolean isBuffered() {
102 return parameters != null && parameters.bufferTimeout != null && parameters.bufferTimeout.maxSize > 0
103 && parameters.bufferTimeout.maxTimeMiliseconds > 0;