NONRTRIC - ECS updates of the NBI
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / BeanFactory.java
index ce41956..1d493bb 100644 (file)
@@ -22,12 +22,15 @@ package org.oransc.enrichment;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
 
+import java.lang.invoke.MethodHandles;
+
 import org.apache.catalina.connector.Connector;
-import org.oransc.enrichment.clients.ProducerCallbacks;
 import org.oransc.enrichment.configuration.ApplicationConfig;
-import org.oransc.enrichment.repository.EiJobs;
-import org.oransc.enrichment.repository.EiProducers;
-import org.oransc.enrichment.repository.EiTypes;
+import org.oransc.enrichment.controllers.r1producer.ProducerCallbacks;
+import org.oransc.enrichment.repository.InfoJobs;
+import org.oransc.enrichment.repository.InfoTypes;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
 import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
@@ -41,6 +44,11 @@ class BeanFactory {
     private int httpPort = 0;
 
     private final ApplicationConfig applicationConfig = new ApplicationConfig();
+    private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+    private ProducerCallbacks producerCallbacks;
+    private InfoTypes infoTypes;
+    private InfoJobs infoJobs;
 
     @Bean
     public ObjectMapper mapper() {
@@ -57,18 +65,37 @@ class BeanFactory {
     }
 
     @Bean
-    public EiJobs eiJobs() {
-        return new EiJobs();
+    public InfoJobs infoJobs() {
+        if (infoJobs == null) {
+            infoJobs = new InfoJobs(getApplicationConfig(), producerCallbacks());
+            try {
+                infoJobs.restoreJobsFromDatabase();
+            } catch (Exception e) {
+                logger.error("Could not restore jobs from database: {}", e.getMessage());
+            }
+        }
+        return infoJobs;
     }
 
     @Bean
-    public EiTypes eiTypes() {
-        return new EiTypes();
+    public InfoTypes infoTypes() {
+        if (this.infoTypes == null) {
+            infoTypes = new InfoTypes(getApplicationConfig());
+            try {
+                infoTypes.restoreTypesFromDatabase();
+            } catch (Exception e) {
+                logger.error("Could not restore Information Types from database: {}", e.getMessage());
+            }
+        }
+        return infoTypes;
     }
 
     @Bean
-    public EiProducers eiProducers() {
-        return new EiProducers();
+    public ProducerCallbacks producerCallbacks() {
+        if (this.producerCallbacks == null) {
+            producerCallbacks = new ProducerCallbacks(getApplicationConfig());
+        }
+        return this.producerCallbacks;
     }
 
     @Bean
@@ -76,11 +103,6 @@ class BeanFactory {
         return this.applicationConfig;
     }
 
-    @Bean
-    public ProducerCallbacks getProducerCallbacks() {
-        return new ProducerCallbacks(this.applicationConfig);
-    }
-
     private static Connector getHttpConnector(int httpPort) {
         Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
         connector.setScheme("http");