diff options
Diffstat (limited to 'ms/controllerblueprints/modules/service')
18 files changed, 492 insertions, 562 deletions
diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java deleted file mode 100644 index 9aeee1771..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.service.repository; - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import javax.validation.constraints.NotNull; -import java.util.List; -import java.util.Optional; - -/** - * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ControllerBlueprintModelSearchRepository extends JpaRepository<BlueprintModelSearch, Long> { - - /** - * This is a findById method - * - * @param id id - * @return Optional<BlueprintModelSearch> - */ - @NotNull - Optional<BlueprintModelSearch> findById(@NotNull String id); - - /** - * This is a findAll method - * @return List<BlueprintModelSearch> - */ - @Override - List<BlueprintModelSearch> findAll(); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional<AsdcArtifacts> - */ - Optional<BlueprintModelSearch> findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional<BlueprintModelSearch> - */ - List<BlueprintModelSearch> findByTagsContainingIgnoreCase(String tags); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java deleted file mode 100644 index 314ac6a4e..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.service.repository; - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.Optional; - -/** - * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository - * - * @author Brinda Santh - * @version 1.0 - */ -@Repository -public interface ResourceDictionaryRepository extends JpaRepository<ResourceDictionary, String> { - - - /** - * This is a findByName method - * - * @param name name - * @return Optional<ResourceMapping> - */ - Optional<ResourceDictionary> findByName(String name); - - /** - * This is a findByNameIn method - * - * @param names names - * @return Optional<ResourceMapping> - */ - List<ResourceDictionary> findByNameIn(List<String> names); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional<ModelType> - */ - List<ResourceDictionary> findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByName method - * - * @param name name - */ - void deleteByName(String name); - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt index 8ede9f208..e1fa1882d 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt @@ -72,8 +72,8 @@ open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRe @Throws(BluePrintException::class) override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) - return if (dbResourceDictionary.isPresent) { - dbResourceDictionary.get().definition + return if (dbResourceDictionary != null) { + dbResourceDictionary.definition } else { throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt index 0509e970e..341d63bf0 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt @@ -1,5 +1,6 @@ /* * 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. @@ -19,6 +20,7 @@ package org.onap.ccsdk.cds.controllerblueprints.service.controller import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler +import kotlinx.coroutines.runBlocking import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -27,30 +29,30 @@ import org.springframework.web.bind.annotation.* open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) { @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) - fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? { - return modelTypeHandler.getModelTypeByName(name) + fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking { + modelTypeHandler.getModelTypeByName(name) } @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) - fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> { - return modelTypeHandler.searchModelTypes(tags) + fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking { + modelTypeHandler.searchModelTypes(tags) } @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) @ResponseBody - fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> { - return modelTypeHandler.getModelTypeByDefinitionType(definitionType) + fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking { + modelTypeHandler.getModelTypeByDefinitionType(definitionType) } @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE)) @ResponseBody @Throws(BluePrintException::class) - fun saveModelType(@RequestBody modelType: ModelType): ModelType { - return modelTypeHandler.saveModel(modelType) + fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking { + modelTypeHandler.saveModel(modelType) } @DeleteMapping(path = arrayOf("/{name}")) - fun deleteModelTypeByName(@PathVariable(value = "name") name: String) { + fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking { modelTypeHandler.deleteByModelName(name) } }
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt index e21639715..d728fc229 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt @@ -20,6 +20,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary import org.onap.ccsdk.cds.controllerblueprints.service.handler.ResourceDictionaryHandler +import kotlinx.coroutines.runBlocking import org.springframework.http.MediaType import org.springframework.web.bind.annotation.* @@ -30,39 +31,39 @@ open class ResourceDictionaryController(private val resourceDictionaryHandler: R @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary { - return resourceDictionaryHandler.getResourceDictionaryByName(name) + fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking { + resourceDictionaryHandler.getResourceDictionaryByName(name) } @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody @Throws(BluePrintException::class) - fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary { - return resourceDictionaryHandler.saveResourceDictionary(dataDictionary) + fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking { + resourceDictionaryHandler.saveResourceDictionary(dataDictionary) } @DeleteMapping(path = ["/{name}"]) - fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) { + fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking { resourceDictionaryHandler.deleteResourceDictionary(name) } @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> { - return resourceDictionaryHandler.searchResourceDictionaryByNames(names) + fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking { + resourceDictionaryHandler.searchResourceDictionaryByNames(names) } @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> { - return resourceDictionaryHandler.searchResourceDictionaryByTags(tags) + fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking { + resourceDictionaryHandler.searchResourceDictionaryByTags(tags) } @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) @ResponseBody - fun getResourceSourceMapping(): ResourceSourceMapping { - return resourceDictionaryHandler.getResourceSourceMapping() + fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking { + resourceDictionaryHandler.getResourceSourceMapping() } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt index 5c1a1652c..f602437ed 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt @@ -1,5 +1,6 @@ /* * 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. @@ -34,10 +35,15 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @param modelTypeName modelTypeName * @return ModelType */ - fun getModelTypeByName(modelTypeName: String): ModelType? { + suspend fun getModelTypeByName(modelTypeName: String): ModelType { log.info("Searching : $modelTypeName") check(modelTypeName.isNotBlank()) { "Model Name Information is missing." } - return modelTypeRepository.findByModelName(modelTypeName) + val modelType = modelTypeRepository.findByModelName(modelTypeName) + return if (modelType != null) { + modelType + } else { + throw BluePrintException("couldn't get modelType($modelTypeName)") + } } @@ -47,7 +53,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @param tags tags * @return List<ModelType> </ModelType> */ - fun searchModelTypes(tags: String): List<ModelType> { + suspend fun searchModelTypes(tags: String): List<ModelType> { check(tags.isNotBlank()) { "No Search Information provide" } return modelTypeRepository.findByTagsContainingIgnoreCase(tags) } @@ -60,7 +66,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - open fun saveModel(modelType: ModelType): ModelType { + suspend open fun saveModel(modelType: ModelType): ModelType { lateinit var dbModel: ModelType ModelTypeValidator.validateModelType(modelType) val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) @@ -86,7 +92,7 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param modelName modelName */ - open fun deleteByModelName(modelName: String) { + suspend open fun deleteByModelName(modelName: String) { check(modelName.isNotBlank()) { "Model Name Information is missing." } modelTypeRepository.deleteByModelName(modelName) @@ -97,8 +103,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param definitionType definitionType * @return List<ModelType> - */ - fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { + */ + suspend fun getModelTypeByDefinitionType(definitionType: String): List<ModelType> { check(definitionType.isNotBlank()) { "Model definitionType Information is missing." } return modelTypeRepository.findByDefinitionType(definitionType) } @@ -108,8 +114,8 @@ open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository * * @param derivedFrom derivedFrom * @return List<ModelType> - */ - fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { + */ + suspend fun getModelTypeByDerivedFrom(derivedFrom: String): List<ModelType> { check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } return modelTypeRepository.findByDerivedFrom(derivedFrom) } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt index f6e95de2d..df8cffdba 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt @@ -40,11 +40,11 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @throws BluePrintException BluePrintException */ @Throws(BluePrintException::class) - fun getResourceDictionaryByName(name: String): ResourceDictionary { + suspend fun getResourceDictionaryByName(name: String): ResourceDictionary { Preconditions.checkArgument(StringUtils.isNotBlank(name), "Resource dictionary Name Information is missing.") val resourceDictionaryDb = resourceDictionaryRepository.findByName(name) - return if (resourceDictionaryDb.isPresent) { - resourceDictionaryDb.get() + return if (resourceDictionaryDb != null) { + resourceDictionaryDb } else { throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)) } @@ -56,7 +56,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @param names names * @return List<ResourceDictionary> </ResourceDictionary> */ - fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { + suspend fun searchResourceDictionaryByNames(names: List<String>): List<ResourceDictionary> { Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide") return resourceDictionaryRepository.findByNameIn(names) } @@ -67,7 +67,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @param tags tags * @return List<ResourceDictionary> </ResourceDictionary> */ - fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { + suspend fun searchResourceDictionaryByTags(tags: String): List<ResourceDictionary> { Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide") return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags) } @@ -79,7 +79,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * @return DataDictionary */ @Throws(BluePrintException::class) - fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { + suspend fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { var resourceDictionary = resourceDictionary val resourceDefinition = resourceDictionary.definition @@ -101,8 +101,8 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour validateResourceDictionary(resourceDictionary) val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) - if (dbResourceDictionaryData.isPresent) { - val dbResourceDictionary = dbResourceDictionaryData.get() + if (dbResourceDictionaryData != null) { + val dbResourceDictionary = dbResourceDictionaryData dbResourceDictionary.name = resourceDictionary.name dbResourceDictionary.definition = resourceDictionary.definition @@ -124,7 +124,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour * * @param name name */ - fun deleteResourceDictionary(name: String) { + suspend fun deleteResourceDictionary(name: String) { check(name.isNotBlank()) { "Resource dictionary name is missing." } resourceDictionaryRepository.deleteByName(name) } @@ -132,7 +132,7 @@ class ResourceDictionaryHandler(private val resourceDictionaryRepository: Resour /** * This is a getResourceSourceMapping service */ - fun getResourceSourceMapping(): ResourceSourceMapping { + suspend fun getResourceSourceMapping(): ResourceSourceMapping { return ResourceSourceMappingFactory.getRegisterSourceMapping() } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt index bffdccda7..eca7ce1bf 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -17,11 +18,8 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking -import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile import org.springframework.stereotype.Service import java.io.File @@ -30,38 +28,28 @@ open class BluePrintCatalogLoadService(private val bluePrintCatalogService: Blue private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java) - open fun loadPathsBluePrintModelCatalog(paths: List<String>) { + open suspend fun loadPathsBluePrintModelCatalog(paths: List<String>) { paths.forEach { loadPathBluePrintModelCatalog(it) } } - open fun loadPathBluePrintModelCatalog(path: String) { + open suspend fun loadPathBluePrintModelCatalog(path: String) { - val files = File(path).listFiles() - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in files) { - deferredResults += async { - loadBluePrintModelCatalog(errorBuilder, file) - } - } - - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } + val files = normalizedFile(path).listFiles() + val errors = mutableListOf<String>() + files.forEach { + loadBluePrintModelCatalog(errors, it) + } + if (!errors.isEmpty()) { + log.error(errors.joinToString("\n")) } } - open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) { + open suspend fun loadBluePrintModelCatalog(errorBuilder: MutableList<String>, file: File) { try { + log.info("loading blueprint cba(${file.absolutePath})") bluePrintCatalogService.saveToDatabase(file) } catch (e: Exception) { - errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}") + errorBuilder.add("Couldn't load BlueprintModel(${file.name}: ${e.message}") } } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt index e6f6498df..4a3168d65 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -33,7 +34,7 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: @EventListener(ApplicationReadyEvent::class) - open fun init() { + open fun init() = runBlocking { if (bluePrintLoadConfiguration.loadInitialData) { initModelTypes() initResourceDictionary() @@ -41,23 +42,22 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: } else { log.info("Initial data load is disabled") } + } - open fun initModelTypes() { + open suspend fun initModelTypes() { log.info("model types load configuration(${bluePrintLoadConfiguration.loadModelType}) " + "under paths(${bluePrintLoadConfiguration.loadModeTypePaths})") if (bluePrintLoadConfiguration.loadModelType) { val paths = bluePrintLoadConfiguration.loadModeTypePaths?.split(",") paths?.let { - runBlocking { - modelTypeLoadService.loadPathsModelType(paths) - } + modelTypeLoadService.loadPathsModelType(paths) } } } - open fun initResourceDictionary() { + open suspend fun initResourceDictionary() { log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " + "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") @@ -69,7 +69,7 @@ open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: } } - open fun initBluePrintCatalog() { + open suspend fun initBluePrintCatalog() { log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " + "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt index c3533979b..ff87ad465 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -17,18 +18,21 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.* +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope import org.apache.commons.io.FilenameUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler import org.springframework.stereotype.Service import java.io.File -import java.nio.charset.Charset @Service open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) { @@ -37,65 +41,57 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) private val updateBySystem = "System" open suspend fun loadPathsModelType(modelTypePaths: List<String>) { - modelTypePaths.forEach { runBlocking { loadPathModelType(it) } } + modelTypePaths.forEach { + loadPathModelType(it) + } } /** * Load the Model Type file content from the defined path, Load of sequencing should be maintained. */ - open suspend fun loadPathModelType(modelTypePath: String) = runBlocking { + open suspend fun loadPathModelType(modelTypePath: String) { log.info(" *************************** loadModelType **********************") try { val errorBuilder = StrBuilder() coroutineScope { - val dataTypeFiles = File("$modelTypePath/data_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in dataTypeFiles) deferredResults += async { - loadModelType(file, DataType::class.java, errorBuilder) + val dataTypeFiles = normalizedFile("$modelTypePath", "data_type").listFiles() + val deferred = dataTypeFiles.map { + async { + loadModelType(it, DataType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val artifactTypeFiles = File("$modelTypePath/artifact_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in artifactTypeFiles) deferredResults += async { - loadModelType(file, - ArtifactType::class.java, errorBuilder) + val artifactTypeFiles = normalizedFile("$modelTypePath", "artifact_type").listFiles() + val deferred = artifactTypeFiles.map { + async { + loadModelType(it, ArtifactType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val relationshipTypeFiles = File("$modelTypePath/relationship_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in relationshipTypeFiles) deferredResults += async { - loadModelType(file, - RelationshipType::class.java, errorBuilder) + val relationshipTypeFiles = normalizedFile("$modelTypePath", "relationship_type").listFiles() + val deferred = relationshipTypeFiles.map { + async { + loadModelType(it, RelationshipType::class.java, errorBuilder) + } } - - deferredResults.awaitAll() + deferred.awaitAll() } coroutineScope { - val nodeTypeFiles = File("$modelTypePath/node_type").listFiles() - - val deferredResults = mutableListOf<Deferred<Unit>>() - - for (file in nodeTypeFiles) deferredResults += async { - loadModelType(file, - NodeType::class.java, errorBuilder) + val nodeTypeFiles = normalizedFile("$modelTypePath", "node_type").listFiles() + val deferred = nodeTypeFiles.map { + async { + loadModelType(it, NodeType::class.java, errorBuilder) + } } - deferredResults.awaitAll() + deferred.awaitAll() } if (!errorBuilder.isEmpty) { @@ -106,11 +102,11 @@ open class ModelTypeLoadService(private val modelTypeHandler: ModelTypeHandler) } } - private inline fun <reified T> loadModelType(file: File, classType: Class<T>, errorBuilder: StrBuilder) { + private suspend inline fun <reified T> loadModelType(file: File, classType: Class<T>, errorBuilder: StrBuilder) { try { log.trace("Loading ${classType.name} (${file.name})") val dataKey = FilenameUtils.getBaseName(file.name) - val definitionContent = file.readText(Charset.defaultCharset()) + val definitionContent = file.readNBText() val definition = JacksonUtils.readValue(definitionContent, classType) as EntityType //checkNotNull(definition) { "failed to get data type from file : ${file.name}" } diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt index e07552592..69b7c643c 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt @@ -1,5 +1,6 @@ /* * 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. @@ -17,57 +18,56 @@ package org.onap.ccsdk.cds.controllerblueprints.service.load import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.text.StrBuilder import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile +import org.onap.ccsdk.cds.controllerblueprints.core.readNBText import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary import org.onap.ccsdk.cds.controllerblueprints.service.handler.ResourceDictionaryHandler import org.springframework.stereotype.Service import java.io.File -import java.nio.charset.Charset @Service open class ResourceDictionaryLoadService(private val resourceDictionaryHandler: ResourceDictionaryHandler) { private val log = EELFManager.getInstance().getLogger(ResourceDictionaryLoadService::class.java) - open fun loadPathsResourceDictionary(paths: List<String>) { - paths.forEach { loadPathResourceDictionary(it) } + open suspend fun loadPathsResourceDictionary(paths: List<String>) { + paths.forEach { + loadPathResourceDictionary(it) + } } - open fun loadPathResourceDictionary(path: String) { + open suspend fun loadPathResourceDictionary(path: String) { log.info(" *************************** loadResourceDictionary **********************") - val files = File(path).listFiles() - - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf<Deferred<Unit>>() + val files = normalizedFile(path).listFiles() + val errorBuilder = StrBuilder() - for (file in files) { - deferredResults += async { - loadResourceDictionary(errorBuilder, file) + coroutineScope() { + val deferred = files.map { + async { + loadResourceDictionary(errorBuilder, it) } } + deferred.awaitAll() + } - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) } + } - private fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { + private suspend fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { try { - log.trace("Loading NodeType(${file.name}") - val definitionContent = file.readText(Charset.defaultCharset()) + log.trace("Loading NodeType(${file.name}}") + val definitionContent = file.readNBText() val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java) if (resourceDefinition != null) { diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt new file mode 100644 index 000000000..bf77af66c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.kt @@ -0,0 +1,63 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.service.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import java.util.* + +/** + * ControllerBlueprintModelSearchRepository.java Purpose: Provide Configuration Generator AsdcArtifactsRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ControllerBlueprintModelSearchRepository : JpaRepository<BlueprintModelSearch, Long> { + + /** + * This is a findById method + * + * @param id id + * @return Optional<BlueprintModelSearch> + </BlueprintModelSearch> */ + fun findById(id: String): Optional<BlueprintModelSearch> + + /** + * This is a findAll method + * @return List<BlueprintModelSearch> + </BlueprintModelSearch> */ + override fun findAll(): List<BlueprintModelSearch> + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional<AsdcArtifacts> + </AsdcArtifacts> */ + fun findByArtifactNameAndArtifactVersion(artifactName: String, artifactVersion: String): Optional<BlueprintModelSearch> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional<BlueprintModelSearch> + </BlueprintModelSearch> */ + fun findByTagsContainingIgnoreCase(tags: String): List<BlueprintModelSearch> +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt deleted file mode 100644 index 5758fb7fb..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.service.repository - -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary -import org.springframework.stereotype.Service -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import reactor.core.scheduler.Schedulers - -/** - * ResourceDictionaryReactRepository. - * - * @author Brinda Santh - */ -@Service -open class ResourceDictionaryReactRepository(private val resourceDictionaryRepository: ResourceDictionaryRepository) { - - fun save(resourceDictionary: ResourceDictionary): Mono<ResourceDictionary> { - return Mono.justOrEmpty(resourceDictionaryRepository.save(resourceDictionary)) - } - - fun findByName(name: String): Mono<ResourceDictionary> { - return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) - } - - fun findByNameIn(names: List<String>): Flux<ResourceDictionary> { - return Flux.fromIterable(resourceDictionaryRepository.findByNameIn(names)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByTagsContainingIgnoreCase(tags: String): Flux<ResourceDictionary> { - return Flux.fromIterable(resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags)) - .subscribeOn(Schedulers.elastic()) - } - - fun deleteByName(name: String): Mono<Void> { - resourceDictionaryRepository.deleteByName(name) - return Mono.empty() - } - -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt new file mode 100644 index 000000000..b1b633a10 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.kt @@ -0,0 +1,66 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.service.repository + +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository + + +/** + * ResourceMappingRepository.java Purpose: Provide Configuration Generator ResourceMappingRepository + * + * @author Brinda Santh + * @version 1.0 + */ +@Repository +interface ResourceDictionaryRepository : JpaRepository<ResourceDictionary, String> { + + + /** + * This is a findByName method + * + * @param name name + * @return Optional<ResourceMapping> + </ResourceMapping> */ + fun findByName(name: String): ResourceDictionary? + + /** + * This is a findByNameIn method + * + * @param names names + * @return Optional<ResourceMapping> + </ResourceMapping> */ + fun findByNameIn(names: List<String>): List<ResourceDictionary> + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional<ModelType> + </ModelType> */ + fun findByTagsContainingIgnoreCase(tags: String): List<ResourceDictionary> + + /** + * This is a deleteByName method + * + * @param name name + */ + fun deleteByName(name: String) + + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java deleted file mode 100644 index 12652c916..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2018 IBM. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.service; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.cds.controllerblueprints.TestApplication; -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@RunWith(SpringRunner.class) -@DataJpaTest -@Transactional(propagation = Propagation.NOT_SUPPORTED) -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ModelTypeServiceTest { - private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeServiceTest.class); - @Autowired - private ModelTypeHandler modelTypeHandler; - - String modelName = "test-datatype"; - - @Test - @Commit - public void test01SaveModelType() throws Exception { - log.info("**************** test01SaveModelType ********************"); - - String content = JacksonUtils.Companion.getClassPathFileContent("model_type/data_type/datatype-property.json"); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); - modelType.setDescription("Definition for Sample Datatype "); - modelType.setDefinition(JacksonUtils.Companion.jsonNode(content)); - modelType.setModelName(modelName); - modelType.setVersion("1.0.0"); - modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setUpdatedBy("xxxxxx@xxx.com"); - modelType = modelTypeHandler.saveModel(modelType); - log.info("Saved Mode {}", modelType.toString()); - Assert.assertNotNull("Failed to get Saved ModelType", modelType); - Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName()); - - ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelType.getModelName()); - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", - dbModelType); - - // Model Update - modelType.setUpdatedBy("bs2796@xxx.com"); - modelType = modelTypeHandler.saveModel(modelType); - Assert.assertNotNull("Failed to get Saved ModelType", modelType); - Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy()); - - } - - @Test - public void test02SearchModelTypes() throws Exception { - log.info("*********************** test02SearchModelTypes ***************************"); - - String tags = "test-datatype"; - - List<ModelType> dbModelTypes = modelTypeHandler.searchModelTypes(tags); - Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); - Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0); - - } - - @Test - public void test03GetModelType() throws Exception { - log.info("************************* test03GetModelType *********************************"); - ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelName); - Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType); - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName()); - - List<ModelType> dbDatatypeModelTypes = - modelTypeHandler.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); - Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0); - - List<ModelType> dbModelTypeByDerivedFroms = - modelTypeHandler.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); - Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms); - Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size() > 0); - - } - - @Test - public void test04DeleteModelType() throws Exception { - log.info( - "************************ test03DeleteModelType ***********************"); - ModelType dbResourceMapping = modelTypeHandler.getModelTypeByName(modelName); - Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping); - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName()); - - modelTypeHandler.deleteByModelName(dbResourceMapping.getModelName()); - } -}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java deleted file mode 100644 index 37e0549fa..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.controllerblueprints.service.repository; - -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.cds.controllerblueprints.TestApplication; -import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Arrays; -import java.util.List; - -/** - * ResourceDictionaryReactRepositoryTest. - * - * @author Brinda Santh - */ - -@RunWith(SpringRunner.class) -@DataJpaTest -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ResourceDictionaryReactRepositoryTest { - - private String sourceName = "test-source"; - - @Autowired - protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; - - @Test - @Commit - public void test01Save() { - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-primary-db-source.json", ResourceDefinition.class); - Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition); - resourceDefinition.setName(sourceName); - - ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block(); - Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary); - } - - @Test - public void test02FindByNameReact() { - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); - } - - @Test - public void test03FindByNameInReact() { - List<ResourceDictionary> dbResourceDictionaries = - resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); - } - - @Test - public void test04FindByTagsContainingIgnoreCaseReact() { - List<ResourceDictionary> dbTagsResourceDictionaries = - resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); - } - - @Test - @Commit - public void test05Delete() { - resourceDictionaryReactRepository.deleteByName(sourceName).block(); - } - - private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { - ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setName(resourceDefinition.getName()); - resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); - resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); - resourceDictionary.setTags(resourceDefinition.getTags()); - resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); - resourceDictionary.setDefinition(resourceDefinition); - return resourceDictionary; - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.kt new file mode 100644 index 000000000..741431840 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.kt @@ -0,0 +1,138 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.service + +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.transaction.annotation.Propagation +import org.springframework.transaction.annotation.Transactional + + +@RunWith(SpringRunner::class) +@DataJpaTest +@Transactional(propagation = Propagation.NOT_SUPPORTED) +@ContextConfiguration(classes = [TestApplication::class]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ModelTypeServiceTest { + @Autowired + private val modelTypeHandler: ModelTypeHandler? = null + + internal var modelName = "test-datatype" + + private val log = EELFManager.getInstance().getLogger(ModelTypeServiceTest::class.java) + + @Test + @Commit + @Throws(Exception::class) + fun test01SaveModelType() { + runBlocking { + log.info("**************** test01SaveModelType ********************") + + val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json") + var modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + modelType.description = "Definition for Sample Datatype " + modelType.definition = JacksonUtils.jsonNode(content) + modelType.modelName = modelName + modelType.version = "1.0.0" + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.updatedBy = "xxxxxx@xxx.com" + modelType = modelTypeHandler!!.saveModel(modelType) + log.info("Saved Mode {}", modelType.toString()) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) + + val dbModelType = modelTypeHandler.getModelTypeByName(modelType.modelName) + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType) + + // Model Update + modelType.updatedBy = "bs2796@xxx.com" + modelType = modelTypeHandler.saveModel(modelType) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) + } + + } + + @Test + @Throws(Exception::class) + fun test02SearchModelTypes() { + runBlocking { + log.info("*********************** test02SearchModelTypes ***************************") + + val tags = "test-datatype" + + val dbModelTypes = modelTypeHandler!!.searchModelTypes(tags) + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size > 0) + } + + } + + @Test + @Throws(Exception::class) + fun test03GetModelType() { + runBlocking { + log.info("************************* test03GetModelType *********************************") + val dbModelType = modelTypeHandler!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) + + val dbDatatypeModelTypes = modelTypeHandler.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes) + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size > 0) + + val dbModelTypeByDerivedFroms = modelTypeHandler.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT) + Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms) + Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size > 0) + } + + } + + @Test + @Throws(Exception::class) + fun test04DeleteModelType() { + runBlocking { + log.info( + "************************ test03DeleteModelType ***********************") + val dbResourceMapping = modelTypeHandler!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) + + modelTypeHandler.deleteByModelName(dbResourceMapping.modelName) + } + } + +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepositoryTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepositoryTest.kt new file mode 100644 index 000000000..b35a86b37 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepositoryTest.kt @@ -0,0 +1,94 @@ +/* + * 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.controllerblueprints.service.repository + +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@DataJpaTest +@ContextConfiguration(classes = [TestApplication::class]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ResourceDictionaryReactRepositoryTest { + + private val sourceName = "test-source" + + @Autowired + lateinit var resourceDictionaryRepository: ResourceDictionaryRepository + + @Test + @Commit + fun test01Save() { + val resourceDefinition = JacksonUtils.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-primary-db-source.json", ResourceDefinition::class.java) + Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition) + resourceDefinition!!.name = sourceName + + val resourceDictionary = transformResourceDictionary(resourceDefinition) + val dbResourceDictionary = resourceDictionaryRepository.save(resourceDictionary) + Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary) + } + + @Test + fun test02FindByNameReact() { + val dbResourceDictionary = resourceDictionaryRepository.findByName(sourceName) + Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary) + } + + @Test + fun test03FindByNameInReact() { + val dbResourceDictionaries = resourceDictionaryRepository.findByNameIn(arrayListOf(sourceName)) + Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries) + } + + @Test + fun test04FindByTagsContainingIgnoreCaseReact() { + val dbTagsResourceDictionaries = resourceDictionaryRepository.findByTagsContainingIgnoreCase(sourceName) + Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries) + } + + @Test + @Commit + fun test05Delete() { + runBlocking { + resourceDictionaryRepository.deleteByName(sourceName) + } + } + + private fun transformResourceDictionary(resourceDefinition: ResourceDefinition): ResourceDictionary { + val resourceDictionary = ResourceDictionary() + resourceDictionary.name = resourceDefinition.name + resourceDictionary.dataType = resourceDefinition.property.type + resourceDictionary.description = resourceDefinition.property.description + resourceDictionary.tags = resourceDefinition.tags + resourceDictionary.updatedBy = resourceDefinition.updatedBy + resourceDictionary.definition = resourceDefinition + return resourceDictionary + } +}
\ No newline at end of file |