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;h=a57eeeb3350a705b4988fa0cfc7fdeadaf234049;hb=b0612ab177e14ffa133aae2538aa504d5cc10e99;hp=0c44eb65656b5721f651860cc40ab06eca7a7b4d;hpb=f09d7ed9c458244bd8edbf38f689cff75bd19790;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 index 0c44eb65..a57eeeb3 100644 --- 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 @@ -36,35 +36,38 @@ import reactor.core.publisher.Mono; * Callbacks to the Consumer. Notifies consumer according to the API (which this * class adapts to) */ -@SuppressWarnings("java:S3457") // No need to call "toString()" method as formatting and string .. @Component -public class ConsumerCallbacks implements InfoTypeSubscriptions.Callbacks { +public class ConsumerCallbacks implements InfoTypeSubscriptions.ConsumerCallbackHandler { private static Gson gson = new GsonBuilder().create(); private final AsyncRestClient restClient; - public ConsumerCallbacks(@Autowired ApplicationConfig config) { + 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) { - ConsumerTypeRegistrationInfo info = new ConsumerTypeRegistrationInfo(type.getJobDataSchema(), - ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.REGISTERED, type.getId()); - String body = gson.toJson(info); - + String body = body(type, ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.REGISTERED); return restClient.post(subscriptionInfo.getCallbackUrl(), body); - } @Override public Mono notifyTypeRemoved(InfoType type, InfoTypeSubscriptions.SubscriptionInfo subscriptionInfo) { - ConsumerTypeRegistrationInfo info = new ConsumerTypeRegistrationInfo(type.getJobDataSchema(), - ConsumerTypeRegistrationInfo.ConsumerTypeStatusValues.DEREGISTERED, type.getId()); - String body = gson.toJson(info); + 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); + } + }