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;
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() {
}
@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
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");