/*
* Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 2019 IBM.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.ccsdk.cds.blueprintsprocessor.core
-import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintPathConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.context.properties.bind.Bindable
import org.springframework.boot.context.properties.bind.Binder
-import org.springframework.boot.context.properties.source.ConfigurationPropertySources
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Service
@Configuration
-open class BluePrintCoreConfiguration(private val bluePrintProperties: BlueprintProcessorProperties) {
+open class BluePrintCoreConfiguration(private val bluePrintPropertiesService: BluePrintPropertiesService) {
companion object {
+
const val PREFIX_BLUEPRINT_PROCESSOR = "blueprintsprocessor"
}
@Bean
- open fun bluePrintPathConfiguration(): BluePrintPathConfiguration {
- return bluePrintProperties
- .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BluePrintPathConfiguration::class.java)
+ open fun bluePrintLoadConfiguration(): BluePrintLoadConfiguration {
+ return bluePrintPropertiesService
+ .propertyBeanType(PREFIX_BLUEPRINT_PROCESSOR, BluePrintLoadConfiguration::class.java)
}
-
}
@Configuration
-open class BlueprintPropertyConfiguration {
+open class BluePrintPropertyConfiguration {
+
@Autowired
lateinit var environment: Environment
@Bean
open fun bluePrintPropertyBinder(): Binder {
- val configurationPropertySource = ConfigurationPropertySources.get(environment)
- return Binder(configurationPropertySource)
+ return Binder.get(environment)
}
}
@Service
-open class BlueprintProcessorProperties(private var bluePrintPropertyBinder: Binder) {
+open class BluePrintPropertiesService(private var bluePrintPropertyConfig: BluePrintPropertyConfiguration) {
+
+ private val log = logger(BluePrintPropertiesService::class)
+
fun <T> propertyBeanType(prefix: String, type: Class<T>): T {
- return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get()
+ return try {
+ bluePrintPropertyConfig.bluePrintPropertyBinder().bind(prefix, Bindable.of(type)).get()
+ } catch (e: NoSuchElementException) {
+ val errMsg = "Error: missing property \"$prefix\"... Check the application.properties file."
+ log.error(errMsg)
+ throw BluePrintProcessorException(e, errMsg)
+ }
}
}
BluePrintDependencyService.inject(applicationContext)
log.info("Dependency Management module created...")
}
-
-}
\ No newline at end of file
+}