X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fcontrollers%2Fr1consumer%2FConsumerCallbacks.java;fp=enrichment-coordinator-service%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fenrichment%2Fcontrollers%2Fr1consumer%2FConsumerCallbacks.java;h=0000000000000000000000000000000000000000;hb=c6916032d124066c6009e0db070a0cebb9c1ea5f;hp=a57eeeb3350a705b4988fa0cfc7fdeadaf234049;hpb=a28a4ad261601976c345425692116e5d7250b810;p=nonrtric.git diff --git a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerCallbacks.java b/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerCallbacks.java deleted file mode 100644 index a57eeeb3..00000000 --- a/enrichment-coordinator-service/src/main/java/org/oransc/enrichment/controllers/r1consumer/ConsumerCallbacks.java +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2021 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.oransc.enrichment.controllers.r1consumer; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -import org.oransc.enrichment.clients.AsyncRestClient; -import org.oransc.enrichment.clients.AsyncRestClientFactory; -import org.oransc.enrichment.configuration.ApplicationConfig; -import org.oransc.enrichment.repository.InfoType; -import org.oransc.enrichment.repository.InfoTypeSubscriptions; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import reactor.core.publisher.Mono; - -/** - * Callbacks to the Consumer. Notifies consumer according to the API (which this - * class adapts to) - */ -@Component -public class ConsumerCallbacks implements InfoTypeSubscriptions.ConsumerCallbackHandler { - - private static Gson gson = new GsonBuilder().create(); - - private final AsyncRestClient restClient; - - public static final String API_VERSION = "version_1"; - - public ConsumerCallbacks(@Autowired ApplicationConfig config, - @Autowired InfoTypeSubscriptions infoTypeSubscriptions) { - AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig()); - this.restClient = restClientFactory.createRestClientNoHttpProxy(""); - infoTypeSubscriptions.registerCallbackhandler(this, API_VERSION); - } - - @Override - public Mono notifyTypeRegistered(InfoType type, InfoTypeSubscriptions.SubscriptionInfo subscriptionInfo) { - String body = body(type, ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.REGISTERED); - return restClient.post(subscriptionInfo.getCallbackUrl(), body); - } - - @Override - public Mono notifyTypeRemoved(InfoType type, InfoTypeSubscriptions.SubscriptionInfo subscriptionInfo) { - String body = body(type, ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.DEREGISTERED); - return restClient.post(subscriptionInfo.getCallbackUrl(), body); - } - - private String body(InfoType type, ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues status) { - ConsumerTypeRegistrationInfo info = - new ConsumerTypeRegistrationInfo(type.getJobDataSchema(), status, type.getId()); - return gson.toJson(info); - } - -}