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.oransc.enrichment.controllers.r1consumer;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
26 import org.oransc.enrichment.clients.AsyncRestClient;
27 import org.oransc.enrichment.clients.AsyncRestClientFactory;
28 import org.oransc.enrichment.configuration.ApplicationConfig;
29 import org.oransc.enrichment.repository.InfoType;
30 import org.oransc.enrichment.repository.InfoTypeSubscriptions;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
33 import reactor.core.publisher.Mono;
36 * Callbacks to the Consumer. Notifies consumer according to the API (which this
39 @SuppressWarnings("java:S3457") // No need to call "toString()" method as formatting and string ..
41 public class ConsumerCallbacks implements InfoTypeSubscriptions.Callbacks {
43 private static Gson gson = new GsonBuilder().create();
45 private final AsyncRestClient restClient;
47 public ConsumerCallbacks(@Autowired ApplicationConfig config) {
48 AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
49 this.restClient = restClientFactory.createRestClientNoHttpProxy("");
53 public Mono<String> notifyTypeRegistered(InfoType type, InfoTypeSubscriptions.SubscriptionInfo subscriptionInfo) {
54 ConsumerTypeRegistrationInfo info = new ConsumerTypeRegistrationInfo(type.getJobDataSchema(),
55 ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.REGISTERED, type.getId());
56 String body = gson.toJson(info);
58 return restClient.post(subscriptionInfo.getCallbackUrl(), body);
63 public Mono<String> notifyTypeRemoved(InfoType type, InfoTypeSubscriptions.SubscriptionInfo subscriptionInfo) {
64 ConsumerTypeRegistrationInfo info = new ConsumerTypeRegistrationInfo(type.getJobDataSchema(),
65 ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.DEREGISTERED, type.getId());
66 String body = gson.toJson(info);
67 return restClient.post(subscriptionInfo.getCallbackUrl(), body);