New EI Consumer API, aligned to ORAN WG2
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / clients / ProducerCallbacks.java
index 7f28a12..87d1dba 100644 (file)
@@ -30,7 +30,6 @@ import org.oransc.enrichment.repository.EiJob;
 import org.oransc.enrichment.repository.EiProducer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -42,15 +41,16 @@ import reactor.core.publisher.Mono;
 public class ProducerCallbacks {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-    private static Gson gson = new GsonBuilder() //
-        .serializeNulls() //
-        .create(); //
+    private static Gson gson = new GsonBuilder().create();
 
-    @Autowired
-    ApplicationConfig applicationConfig;
+    private final AsyncRestClient restClient;
+
+    public ProducerCallbacks(ApplicationConfig config) {
+        AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config.getWebClientConfig());
+        this.restClient = restClientFactory.createRestClient("");
+    }
 
     public void notifyProducersJobDeleted(EiJob eiJob) {
-        AsyncRestClient restClient = restClient();
         ProducerJobInfo request = new ProducerJobInfo(eiJob);
         String body = gson.toJson(request);
         for (EiProducer producer : eiJob.type().getProducers()) {
@@ -81,7 +81,6 @@ public class ProducerCallbacks {
      * @return the body of the response from the REST call
      */
     public Mono<String> notifyProducerJobStarted(EiProducer producer, EiJob eiJob) {
-        AsyncRestClient restClient = restClient();
         ProducerJobInfo request = new ProducerJobInfo(eiJob);
         String body = gson.toJson(request);
 
@@ -93,8 +92,4 @@ public class ProducerCallbacks {
             });
     }
 
-    private AsyncRestClient restClient() {
-        return new AsyncRestClient("", this.applicationConfig.getWebClientConfig());
-    }
-
 }