From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- ms/controllerblueprints/modules/service/pom.xml | 8 +- .../service/ApplicationRegistrationService.java | 56 ---- .../service/AutoResourceMappingService.java | 210 ------------- .../service/SchemaGeneratorService.java | 116 -------- .../service/common/ErrorMessage.java | 75 ----- .../service/common/SwaggerGenerator.java | 185 ------------ .../service/domain/BlueprintModel.java | 284 ------------------ .../service/domain/BlueprintModelContent.java | 170 ----------- .../service/domain/BlueprintModelSearch.java | 166 ----------- .../service/domain/JpaJsonNodeConverter.java | 40 --- .../domain/JpaResourceDefinitionConverter.java | 39 --- .../service/domain/ModelType.java | 171 ----------- .../service/domain/ResourceDictionary.java | 158 ---------- .../service/model/AutoMapResponse.java | 53 ---- .../ControllerBlueprintModelSearchRepository.java | 69 ----- .../repository/ResourceDictionaryRepository.java | 69 ----- .../service/ApplicationRegistrationService.java | 56 ++++ .../service/AutoResourceMappingService.java | 210 +++++++++++++ .../service/SchemaGeneratorService.java | 116 ++++++++ .../service/common/ErrorMessage.java | 75 +++++ .../service/common/SwaggerGenerator.java | 185 ++++++++++++ .../service/domain/BlueprintModel.java | 285 ++++++++++++++++++ .../service/domain/BlueprintModelContent.java | 170 +++++++++++ .../service/domain/BlueprintModelSearch.java | 166 +++++++++++ .../service/domain/JpaJsonNodeConverter.java | 40 +++ .../domain/JpaResourceDefinitionConverter.java | 39 +++ .../service/domain/ModelType.java | 171 +++++++++++ .../service/domain/ResourceDictionary.java | 158 ++++++++++ .../service/model/AutoMapResponse.java | 53 ++++ .../ControllerBlueprintModelSearchRepository.java | 69 +++++ .../repository/ResourceDictionaryRepository.java | 69 +++++ .../service/BluePrintRepoServiceImpl.kt | 105 ------- .../ControllerBluePrintCoreConfiguration.kt | 60 ---- .../service/controller/BlueprintModelController.kt | 110 ------- .../ControllerBlueprintExeptionHandler.kt | 50 ---- .../service/controller/ModelTypeController.kt | 56 ---- .../controller/ResourceDictionaryController.kt | 68 ----- .../BluePrintArtifactDefinitionEnhancerImpl.kt | 93 ------ .../BluePrintAttributeDefinitionEnhancerImpl.kt | 55 ---- .../enhancer/BluePrintEnhancerServiceImpl.kt | 80 ----- .../enhancer/BluePrintNodeTemplateEnhancerImpl.kt | 70 ----- .../enhancer/BluePrintNodeTypeEnhancerImpl.kt | 154 ---------- .../enhancer/BluePrintPolicyTypeEnhancerImpl.kt | 43 --- .../BluePrintPropertyDefinitionEnhancerImpl.kt | 62 ---- .../BluePrintServiceTemplateEnhancerImpl.kt | 69 ----- .../BluePrintTopologyTemplateEnhancerImpl.kt | 61 ---- .../enhancer/BluePrintTypeEnhancerServiceImpl.kt | 65 ---- .../enhancer/BluePrintWorkflowEnhancerImpl.kt | 214 ------------- .../enhancer/ResourceAssignmentEnhancerService.kt | 111 ------- .../enhancer/ResourceDefinitionEnhancerService.kt | 145 --------- .../service/handler/BluePrintModelHandler.kt | 330 --------------------- .../service/handler/ModelTypeHandler.kt | 116 -------- .../service/handler/ResourceDictionaryHandler.kt | 148 --------- .../service/load/BluePrintCatalogLoadService.kt | 68 ----- .../service/load/BluePrintDatabaseLoadService.kt | 83 ------ .../load/ControllerBlueprintCatalogServiceImpl.kt | 112 ------- .../service/load/ModelTypeLoadService.kt | 150 ---------- .../service/load/ResourceDictionaryLoadService.kt | 106 ------- .../repository/BluePrintsReactRepository.kt | 76 ----- .../ControllerBlueprintModelContentRepository.kt | 22 -- .../ControllerBlueprintModelRepository.kt | 21 -- .../service/repository/ModelTypeRepository.kt | 85 ------ .../ResourceDictionaryReactRepository.kt | 56 ---- .../service/utils/BluePrintEnhancerUtils.kt | 163 ---------- .../service/validator/ModelTypeValidator.kt | 83 ------ .../service/BluePrintRepoServiceImpl.kt | 105 +++++++ .../ControllerBluePrintCoreConfiguration.kt | 60 ++++ .../service/controller/BlueprintModelController.kt | 110 +++++++ .../ControllerBlueprintExeptionHandler.kt | 50 ++++ .../service/controller/ModelTypeController.kt | 56 ++++ .../controller/ResourceDictionaryController.kt | 68 +++++ .../BluePrintArtifactDefinitionEnhancerImpl.kt | 93 ++++++ .../BluePrintAttributeDefinitionEnhancerImpl.kt | 55 ++++ .../enhancer/BluePrintEnhancerServiceImpl.kt | 80 +++++ .../enhancer/BluePrintNodeTemplateEnhancerImpl.kt | 70 +++++ .../enhancer/BluePrintNodeTypeEnhancerImpl.kt | 154 ++++++++++ .../enhancer/BluePrintPolicyTypeEnhancerImpl.kt | 43 +++ .../BluePrintPropertyDefinitionEnhancerImpl.kt | 62 ++++ .../BluePrintServiceTemplateEnhancerImpl.kt | 69 +++++ .../BluePrintTopologyTemplateEnhancerImpl.kt | 61 ++++ .../enhancer/BluePrintTypeEnhancerServiceImpl.kt | 65 ++++ .../enhancer/BluePrintWorkflowEnhancerImpl.kt | 214 +++++++++++++ .../enhancer/ResourceAssignmentEnhancerService.kt | 111 +++++++ .../enhancer/ResourceDefinitionEnhancerService.kt | 145 +++++++++ .../service/handler/BluePrintModelHandler.kt | 330 +++++++++++++++++++++ .../service/handler/ModelTypeHandler.kt | 116 ++++++++ .../service/handler/ResourceDictionaryHandler.kt | 148 +++++++++ .../service/load/BluePrintCatalogLoadService.kt | 68 +++++ .../service/load/BluePrintDatabaseLoadService.kt | 83 ++++++ .../load/ControllerBlueprintCatalogServiceImpl.kt | 112 +++++++ .../service/load/ModelTypeLoadService.kt | 150 ++++++++++ .../service/load/ResourceDictionaryLoadService.kt | 106 +++++++ .../repository/BluePrintsReactRepository.kt | 76 +++++ .../ControllerBlueprintModelContentRepository.kt | 22 ++ .../ControllerBlueprintModelRepository.kt | 21 ++ .../service/repository/ModelTypeRepository.kt | 85 ++++++ .../ResourceDictionaryReactRepository.kt | 56 ++++ .../service/utils/BluePrintEnhancerUtils.kt | 163 ++++++++++ .../service/validator/ModelTypeValidator.kt | 83 ++++++ .../apps/controllerblueprints/DatabaseConfig.java | 61 ---- .../apps/controllerblueprints/TestApplication.java | 34 --- .../service/ModelTypeServiceTest.java | 127 -------- .../service/common/SchemaGeneratorServiceTest.java | 50 ---- .../repository/ModelTypeReactRepositoryTest.java | 110 ------- .../ResourceDictionaryReactRepositoryTest.java | 103 ------- .../cds/controllerblueprints/DatabaseConfig.java | 61 ++++ .../cds/controllerblueprints/TestApplication.java | 34 +++ .../service/ModelTypeServiceTest.java | 127 ++++++++ .../service/common/SchemaGeneratorServiceTest.java | 50 ++++ .../repository/ModelTypeReactRepositoryTest.java | 110 +++++++ .../ResourceDictionaryReactRepositoryTest.java | 103 +++++++ .../controller/BlueprintModelControllerTest.kt | 193 ------------ .../service/controller/ModelTypeControllerTest.kt | 120 -------- .../controller/ResourceDictionaryControllerTest.kt | 43 --- .../service/controller/mock/MockFilePart.kt | 53 ---- .../enhancer/BluePrintEnhancerServiceImplTest.kt | 111 ------- .../service/utils/BluePrintEnhancerUtilsTest.kt | 66 ----- .../service/validator/ModelTypeValidatorTest.kt | 40 --- .../controller/BlueprintModelControllerTest.kt | 193 ++++++++++++ .../service/controller/ModelTypeControllerTest.kt | 120 ++++++++ .../controller/ResourceDictionaryControllerTest.kt | 43 +++ .../service/controller/mock/MockFilePart.kt | 53 ++++ .../enhancer/BluePrintEnhancerServiceImplTest.kt | 111 +++++++ .../service/utils/BluePrintEnhancerUtilsTest.kt | 66 +++++ .../service/validator/ModelTypeValidatorTest.kt | 40 +++ .../modules/service/src/test/resources/logback.xml | 2 +- 126 files changed, 6268 insertions(+), 6267 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java delete mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/ApplicationRegistrationService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/AutoResourceMappingService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/SchemaGeneratorService.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/ErrorMessage.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java create mode 100755 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaJsonNodeConverter.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ModelType.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ResourceDictionary.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/model/AutoMapResponse.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java create mode 100644 ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeController.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ModelTypeHandler.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt delete mode 100755 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt delete mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelController.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/BluePrintModelHandler.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt create mode 100755 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/BluePrintsReactRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidator.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt (limited to 'ms/controllerblueprints/modules/service') diff --git a/ms/controllerblueprints/modules/service/pom.xml b/ms/controllerblueprints/modules/service/pom.xml index cb2cf6ab2..f47a5b467 100644 --- a/ms/controllerblueprints/modules/service/pom.xml +++ b/ms/controllerblueprints/modules/service/pom.xml @@ -20,7 +20,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints modules 0.4.2-SNAPSHOT @@ -36,15 +36,15 @@ kotlinx-coroutines-reactor - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints db-resources - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-validation - org.onap.ccsdk.apps.controllerblueprints + org.onap.ccsdk.cds.controllerblueprints blueprint-scripts diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java deleted file mode 100644 index fc7410f96..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ApplicationRegistrationService.java +++ /dev/null @@ -1,56 +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.apps.controllerblueprints.service; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.collections.CollectionUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import java.util.List; - -@Component -@SuppressWarnings("unused") -public class ApplicationRegistrationService { - private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class); - - @Value("#{'${resourceSourceMappings}'.split(',')}") - private List resourceSourceMappings; - - @PostConstruct - public void register() { - registerDictionarySources(); - } - - public void registerDictionarySources() { - log.info("Registering Dictionary Sources : {}", resourceSourceMappings); - if (CollectionUtils.isNotEmpty(resourceSourceMappings)) { - resourceSourceMappings.forEach(resourceSourceMapping -> { - String[] mappingKeyValue = resourceSourceMapping.split("="); - if (mappingKeyValue != null && mappingKeyValue.length == 2) { - ResourceSourceMappingFactory.INSTANCE.registerSourceMapping(mappingKeyValue[0].trim(), mappingKeyValue[1].trim()); - } else { - log.warn("failed to get resource source mapping {}", resourceSourceMapping); - } - }); - } - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java deleted file mode 100644 index 1965ac901..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/AutoResourceMappingService.java +++ /dev/null @@ -1,210 +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.apps.controllerblueprints.service; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.base.Preconditions; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * AutoResourceMappingService.java Purpose: Provide Automapping of Resource Assignments AutoResourceMappingService - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -@SuppressWarnings("unused") -public class AutoResourceMappingService { - - private static EELFLogger log = EELFManager.getInstance().getLogger(AutoResourceMappingService.class); - - private ResourceDictionaryRepository dataDictionaryRepository; - - /** - * This is a AutoResourceMappingService constructor - * - * @param dataDictionaryRepository dataDictionaryRepository - */ - public AutoResourceMappingService(ResourceDictionaryRepository dataDictionaryRepository) { - this.dataDictionaryRepository = dataDictionaryRepository; - } - - /** - * This is a autoMap service to map the template keys automatically to Dictionary fields. - * - * @param resourceAssignments resourceAssignments - * @return AutoMapResponse - */ - public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { - AutoMapResponse autoMapResponse = new AutoMapResponse(); - try { - if (CollectionUtils.isNotEmpty(resourceAssignments)) { - - // Create the Dictionary definitions for the ResourceAssignment Names - Map dictionaryMap = getDictionaryDefinitions(resourceAssignments); - - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) - && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { - - populateDictionaryMapping(dictionaryMap, resourceAssignment); - - log.info("Mapped Resource : {}", resourceAssignment); - - } - } - } - List dictionaries = getDictionaryDefinitionsList(resourceAssignments); - List resourceAssignmentsFinal = getAllAutomapResourceAssignments(resourceAssignments); - autoMapResponse.setDataDictionaries(dictionaries); - autoMapResponse.setResourceAssignments(resourceAssignmentsFinal); - } catch (Exception e) { - log.error(String.format("Failed in auto process %s", e.getMessage())); - throw new BluePrintException(e.getMessage(), e); - } - return autoMapResponse; - } - - private void populateDictionaryMapping(Map dictionaryMap, ResourceAssignment resourceAssignment) { - ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); - if (dbDataDictionary != null && dbDataDictionary.getDefinition() != null) { - - ResourceDefinition dictionaryDefinition = dbDataDictionary.getDefinition(); - - if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) - && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { - - resourceAssignment.setDictionaryName(dbDataDictionary.getName()); - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - } - } - } - - private Map getDictionaryDefinitions(List resourceAssignments) { - Map dictionaryMap = new HashMap<>(); - List names = new ArrayList<>(); - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName())) { - names.add(resourceAssignment.getName()); - } - } - if (CollectionUtils.isNotEmpty(names)) { - - List dictionaries = dataDictionaryRepository.findByNameIn(names); - if (CollectionUtils.isNotEmpty(dictionaries)) { - for (ResourceDictionary dataDictionary : dictionaries) { - if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName())) { - dictionaryMap.put(dataDictionary.getName(), dataDictionary); - } - } - } - } - return dictionaryMap; - - } - - private List getDictionaryDefinitionsList(List resourceAssignments) { - List dictionaries = null; - List names = new ArrayList<>(); - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { - - if (!names.contains(resourceAssignment.getDictionaryName())) { - names.add(resourceAssignment.getDictionaryName()); - } - - if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { - List dependencyNames = resourceAssignment.getDependencies(); - for (String dependencyName : dependencyNames) { - if (StringUtils.isNotBlank(dependencyName) && !names.contains(dependencyName)) { - names.add(dependencyName); - } - } - } - } - } - if (CollectionUtils.isNotEmpty(names)) { - dictionaries = dataDictionaryRepository.findByNameIn(names); - } - return dictionaries; - - } - - private List getAllAutomapResourceAssignments(List resourceAssignments) { - List dictionaries = null; - List names = new ArrayList<>(); - for (ResourceAssignment resourceAssignment : resourceAssignments) { - if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { - if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { - List dependencieNames = resourceAssignment.getDependencies(); - for (String dependencieName : dependencieNames) { - if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName) - && !checkAssignmentsExists(resourceAssignments, dependencieName)) { - names.add(dependencieName); - } - } - } - } - } - - if (!names.isEmpty()) { - dictionaries = dataDictionaryRepository.findByNameIn(names); - } - if (dictionaries != null) { - for (ResourceDictionary resourcedictionary : dictionaries) { - ResourceDefinition dictionaryDefinition = resourcedictionary.getDefinition(); - Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition"); - PropertyDefinition property = new PropertyDefinition(); - property.setRequired(true); - ResourceAssignment resourceAssignment = new ResourceAssignment(); - resourceAssignment.setName(resourcedictionary.getName()); - resourceAssignment.setDictionaryName(resourcedictionary - .getName()); - resourceAssignment.setVersion(0); - resourceAssignment.setProperty(property); - ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); - resourceAssignments.add(resourceAssignment); - } - } - return resourceAssignments; - - } - - - private boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { - return resourceAssignmentsWithDepencies.stream().anyMatch(names -> names.getName().equalsIgnoreCase(resourceName)); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java deleted file mode 100644 index 3a1535ac0..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/SchemaGeneratorService.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.apps.controllerblueprints.service; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.google.common.base.Preconditions; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; -import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.common.SwaggerGenerator; - -import java.util.HashMap; -import java.util.Map; - -/** - * SchemaGeneratorService.java Purpose: Provide Service to generate service template input schema definition and Sample - * Json generation. - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -public class SchemaGeneratorService { - private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorService.class); - - private Map dataTypes; - - /** - * This is a SchemaGeneratorService constructor - */ - public SchemaGeneratorService() { - dataTypes = new HashMap<>(); - } - - /** - * This is a generateSchema - * - * @param serviceTemplateContent service template content - * @return String - * @throws BluePrintException Blueprint Exception - */ - public String generateSchema(String serviceTemplateContent) throws BluePrintException { - if (StringUtils.isNotBlank(serviceTemplateContent)) { - ServiceTemplate serviceTemplate = JacksonUtils.Companion.readValue(serviceTemplateContent, - ServiceTemplate.class); - return generateSchema(serviceTemplate); - } else { - throw new BluePrintException( - "Service Template Content is (" + serviceTemplateContent + ") not Defined."); - } - } - - /** - * This is a generateSchema - * - * @param serviceTemplate service template content - * @return String - * @throws BluePrintException Blueprint Exception - */ - public String generateSchema(ServiceTemplate serviceTemplate) throws BluePrintException { - String schemaContent = null; - Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined."); - try { - if (serviceTemplate.getTopologyTemplate() != null - && serviceTemplate.getTopologyTemplate().getInputs() != null) { - SwaggerGenerator swaggerGenerator = new SwaggerGenerator(serviceTemplate); - schemaContent = swaggerGenerator.generateSwagger(); - } - } catch (Exception e) { - throw new BluePrintException(e.getMessage(), e); - } - - return schemaContent; - } - - private void manageServiceTemplateActions(ServiceTemplate serviceTemplate, String actionName) { - if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null - && StringUtils.isNotBlank(actionName)) { - - if (MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs())) { - - serviceTemplate.getTopologyTemplate().getInputs().entrySet().removeIf(entity -> { - String keyName = entity.getKey(); - String replacedAction = actionName.replace("-action", "-request"); - log.debug("Key name : " + keyName + ", actionName " - + actionName + ", replacedAction :" + replacedAction); - if (keyName.endsWith("-request") && !keyName.equals(replacedAction)) { - log.info("deleting input property {} ", keyName); - return true; - } - return false; - }); - } - - } - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java deleted file mode 100644 index 5486262f6..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ErrorMessage.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.common; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; - -import java.io.Serializable; -import java.util.Date; - -@JsonInclude(Include.NON_NULL) -@JsonTypeName("errorMessage") -@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) -public class ErrorMessage implements Serializable { - private String message; - private Integer code; - private String debugMessage; - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - private Date timestamp = new Date(); - - public ErrorMessage(String message, Integer code, String debugMessage){ - this.message = message; - this.code = code; - this.debugMessage = debugMessage; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public Integer getCode() { - return code; - } - - public void setCode(Integer code) { - this.code = code; - } - - public String getDebugMessage() { - return debugMessage; - } - - public void setDebugMessage(String developerMessage) { - this.debugMessage = developerMessage; - } - - public Date getTimestamp() { - return timestamp; - } - - public void setTimestamp(Date timestamp) { - this.timestamp = timestamp; - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java deleted file mode 100644 index 77de8e7cf..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SwaggerGenerator.java +++ /dev/null @@ -1,185 +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.apps.controllerblueprints.service.common; - -import io.swagger.models.*; -import io.swagger.models.parameters.BodyParameter; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.properties.*; -import org.apache.commons.collections.MapUtils; -import org.apache.commons.lang3.BooleanUtils; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes; -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition; -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; - -import java.util.*; - -/** - * SwaggerGenerator.java Purpose: Provide Service to generate service template input schema definition and Sample Json - * generation. - * - * @author Brinda Santh - * @version 1.0 - */ -@Deprecated -public class SwaggerGenerator { - - private ServiceTemplate serviceTemplate; - public static final String INPUTS="inputs"; - - /** - * This is a SwaggerGenerator constructor - */ - public SwaggerGenerator(ServiceTemplate serviceTemplate) { - this.serviceTemplate = serviceTemplate; - } - - /** - * This is a generateSwagger - * - * @return String - */ - public String generateSwagger() { - - Swagger swagger = new Swagger().info(getInfo()); - - swagger.setPaths(getPaths()); - swagger.setDefinitions(getDefinition()); - - - return swagger.toString(); - } - - private Info getInfo() { - Info info = new Info(); - Contact contact = new Contact(); - contact.setName(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR)); - info.setContact(contact); - info.setTitle(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME)); - info.setDescription(serviceTemplate.getDescription()); - info.setVersion(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION)); - return info; - } - - private Map getPaths() { - Map paths = new HashMap<>(); - Path path = new Path(); - Operation post = new Operation(); - post.setOperationId("configure"); - post.setConsumes(Arrays.asList("application/json", "application/xml")); - post.setProduces(Arrays.asList("application/json", "application/xml")); - List parameters = new ArrayList<>(); - Parameter in = new BodyParameter().schema(new RefModel("#/definitions/inputs")); - in.setRequired(true); - in.setName(INPUTS); - parameters.add(in); - post.setParameters(parameters); - - Map responses = new HashMap<>(); - Response response = new Response().description("Success"); - responses.put("200", response); - - Response failureResponse = new Response().description("Failure"); - responses.put("400", failureResponse); - post.setResponses(responses); - - path.setPost(post); - paths.put("/operations/config-selfservice-api:configure", path); - return paths; - } - - private Map getDefinition() { - Map models = new HashMap<>(); - - ModelImpl inputmodel = new ModelImpl(); - inputmodel.setTitle(INPUTS); - serviceTemplate.getTopologyTemplate().getInputs().forEach((propertyName, property) -> { - Property defProperty = getPropery(propertyName, property); - inputmodel.property(propertyName, defProperty); - }); - models.put(INPUTS, inputmodel); - - if (MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { - serviceTemplate.getDataTypes().forEach((name, dataType) -> { - ModelImpl model = new ModelImpl(); - model.setDescription(dataType.getDescription()); - if (dataType != null && MapUtils.isNotEmpty(dataType.getProperties())) { - - dataType.getProperties().forEach((propertyName, property) -> { - Property defProperty = getPropery(propertyName, property); - model.addProperty(propertyName, defProperty); - }); - } - models.put(name, model); - }); - } - return models; - - } - - private Property getPropery(String name, PropertyDefinition propertyDefinition) { - Property defProperty = null; - - if (BluePrintTypes.validPrimitiveTypes().contains(propertyDefinition.getType())) { - if (BluePrintConstants.DATA_TYPE_BOOLEAN.equals(propertyDefinition.getType())) { - defProperty = new BooleanProperty(); - } else if (BluePrintConstants.DATA_TYPE_INTEGER.equals(propertyDefinition.getType())) { - StringProperty stringProperty = new StringProperty(); - stringProperty.setType("integer"); - defProperty = stringProperty; - } else if (BluePrintConstants.DATA_TYPE_FLOAT.equals(propertyDefinition.getType())) { - StringProperty stringProperty = new StringProperty(); - stringProperty.setFormat("float"); - defProperty = stringProperty; - } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP.equals(propertyDefinition.getType())) { - DateTimeProperty dateTimeProperty = new DateTimeProperty(); - dateTimeProperty.setFormat("date-time"); - defProperty = dateTimeProperty; - } else { - defProperty = new StringProperty(); - } - } else if (BluePrintTypes.validCollectionTypes().contains(propertyDefinition.getType())) { - ArrayProperty arrayProperty = new ArrayProperty(); - if (propertyDefinition.getEntrySchema() != null) { - String entrySchema = propertyDefinition.getEntrySchema().getType(); - if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema)) { - Property innerType = new RefProperty("#/definitions/" + entrySchema); - arrayProperty.setItems(innerType); - } else { - Property innerType = new StringProperty(); - arrayProperty.setItems(innerType); - } - defProperty = arrayProperty; - } - - } else { - defProperty = new RefProperty("#/definitions/" + propertyDefinition.getType()); - } - defProperty.setName(name); - if (propertyDefinition.getDefaultValue() != null) { - defProperty.setDefault(String.valueOf(propertyDefinition.getDefaultValue())); - } - - defProperty.setRequired(BooleanUtils.isTrue(propertyDefinition.getRequired())); - defProperty.setDescription(propertyDefinition.getDescription()); - return defProperty; - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java deleted file mode 100755 index 245e4a80a..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModel.java +++ /dev/null @@ -1,284 +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.apps.controllerblueprints.service.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import org.hibernate.annotations.Proxy; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - -/** - * BlueprintModel.java Purpose: Provide Configuration Generator BlueprintModel Entity - * - * @author Brinda Santh - * @version 1.0 - */ - -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CONFIG_MODEL", uniqueConstraints=@UniqueConstraint(columnNames={"artifact_name","artifact_version"})) -@Proxy(lazy=false) -public class BlueprintModel implements Serializable { - private static final long serialVersionUID = 1L; - @Id - @Column(name = "config_model_id") - private String id; - - @Column(name = "service_uuid") - private String serviceUUID; - - @Column(name = "distribution_id") - private String distributionId; - - @Column(name = "service_name") - private String serviceName; - - @Column(name = "service_description") - private String serviceDescription; - - @Column(name = "resource_uuid") - private String resourceUUID; - - @Column(name = "resource_instance_name") - private String resourceInstanceName; - - @Column(name = "resource_name") - private String resourceName; - - @Column(name = "resource_version") - private String resourceVersion; - - @Column(name = "resource_type") - private String resourceType; - - @Column(name = "artifact_uuid") - private String artifactUUId; - - @Column(name = "artifact_type") - private String artifactType; - - @Column(name = "artifact_version", nullable = false) - @ApiModelProperty(required=true) - private String artifactVersion; - - @Lob - @Column(name = "artifact_description") - private String artifactDescription; - - @Column(name = "internal_version") - private Integer internalVersion; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date createdDate = new Date(); - - @Column(name = "artifact_name", nullable = false) - @ApiModelProperty(required=true) - private String artifactName; - - @Column(name = "published", nullable = false) - @ApiModelProperty(required=true) - private String published; - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required=true) - private String updatedBy; - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required=true) - private String tags; - - @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) - private BlueprintModelContent blueprintModelContent; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getServiceUUID() { - return serviceUUID; - } - - public void setServiceUUID(String serviceUUID) { - this.serviceUUID = serviceUUID; - } - - public String getDistributionId() { - return distributionId; - } - - public void setDistributionId(String distributionId) { - this.distributionId = distributionId; - } - - public String getServiceName() { - return serviceName; - } - - public void setServiceName(String serviceName) { - this.serviceName = serviceName; - } - - public String getServiceDescription() { - return serviceDescription; - } - - public void setServiceDescription(String serviceDescription) { - this.serviceDescription = serviceDescription; - } - - public String getResourceUUID() { - return resourceUUID; - } - - public void setResourceUUID(String resourceUUID) { - this.resourceUUID = resourceUUID; - } - - public String getResourceInstanceName() { - return resourceInstanceName; - } - - public void setResourceInstanceName(String resourceInstanceName) { - this.resourceInstanceName = resourceInstanceName; - } - - public String getResourceName() { - return resourceName; - } - - public void setResourceName(String resourceName) { - this.resourceName = resourceName; - } - - public String getResourceVersion() { - return resourceVersion; - } - - public void setResourceVersion(String resourceVersion) { - this.resourceVersion = resourceVersion; - } - - public String getResourceType() { - return resourceType; - } - - public void setResourceType(String resourceType) { - this.resourceType = resourceType; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public BlueprintModelContent getBlueprintModelContent() { - return blueprintModelContent; - } - - public void setBlueprintModelContent(BlueprintModelContent blueprintModelContent) { - this.blueprintModelContent = blueprintModelContent; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java deleted file mode 100644 index 0bfa0f124..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelContent.java +++ /dev/null @@ -1,170 +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.apps.controllerblueprints.service.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; -import java.util.Objects; - -/** - * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity - * - * @author Brinda Santh - * @version 1.0 - */ -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "CONFIG_MODEL_CONTENT") -public class BlueprintModelContent implements Serializable { - - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "config_model_content_id") - private String id; - - @Column(name = "name", nullable = false) - @ApiModelProperty(required=true) - private String name; - - @Column(name = "content_type", nullable = false) - @ApiModelProperty(required=true) - private String contentType; - - @OneToOne - @JoinColumn(name = "config_model_id") - private BlueprintModel blueprintModel; - - @Lob - @Column(name = "description") - private String description; - - @Lob - @Column(name = "content", nullable = false) - @ApiModelProperty(required=true) - private byte[] content; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "updated_date") - private Date creationDate = new Date(); - - @Override - public String toString() { - return "[" + "id = " + id + - ", name = " + name + - ", contentType = " + contentType + - "]"; - } - - @Override - public boolean equals(Object o) { - - if (o == this) { - return true; - } - if (!(o instanceof BlueprintModelContent)) { - return false; - } - BlueprintModelContent blueprintModelContent = (BlueprintModelContent) o; - return Objects.equals(id, blueprintModelContent.id) && Objects.equals(name, blueprintModelContent.name) - && Objects.equals(contentType, blueprintModelContent.contentType); - } - - @Override - public int hashCode() { - return Objects.hash(id, name, contentType); - } - - public String getId() { - return id; - } - - - public void setId(String id) { - this.id = id; - } - - - public String getName() { - return name; - } - - - public void setName(String name) { - this.name = name; - } - - - public String getContentType() { - return contentType; - } - - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - - public BlueprintModel getBlueprintModel() { - return blueprintModel; - } - - - public void setBlueprintModel(BlueprintModel blueprintModel) { - this.blueprintModel = blueprintModel; - } - - - public String getDescription() { - return description; - } - - - public void setDescription(String description) { - this.description = description; - } - - - public byte[] getContent() { - return content; - } - - - public void setContent(byte[] content) { - this.content = content; - } - - - public Date getCreationDate() { - return creationDate; - } - - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java deleted file mode 100644 index 33753b2f2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/BlueprintModelSearch.java +++ /dev/null @@ -1,166 +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.apps.controllerblueprints.service.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.annotation.JsonTypeName; -import org.springframework.data.annotation.LastModifiedDate; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - -@Entity -@Table(name = "CONFIG_MODEL") -@JsonTypeName("blueprintModel") -@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) -public class BlueprintModelSearch implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "config_model_id") - private String id; - - @Column(name = "artifact_uuid") - private String artifactUUId; - - @Column(name = "artifact_type") - private String artifactType; - - @Column(name = "artifact_version", nullable = false) - private String artifactVersion; - - @Lob - @Column(name = "artifact_description") - private String artifactDescription; - - @Column(name = "internal_version") - private Integer internalVersion; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date createdDate = new Date(); - - @Column(name = "artifact_name", nullable = false) - private String artifactName; - - @Column(name = "published", nullable = false) - private String published; - - @Column(name = "updated_by", nullable = false) - private String updatedBy; - - @Lob - @Column(name = "tags", nullable = false) - private String tags; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getArtifactUUId() { - return artifactUUId; - } - - public void setArtifactUUId(String artifactUUId) { - this.artifactUUId = artifactUUId; - } - - public String getArtifactType() { - return artifactType; - } - - public void setArtifactType(String artifactType) { - this.artifactType = artifactType; - } - - public String getArtifactVersion() { - return artifactVersion; - } - - public void setArtifactVersion(String artifactVersion) { - this.artifactVersion = artifactVersion; - } - - public String getArtifactDescription() { - return artifactDescription; - } - - public void setArtifactDescription(String artifactDescription) { - this.artifactDescription = artifactDescription; - } - - public Integer getInternalVersion() { - return internalVersion; - } - - public void setInternalVersion(Integer internalVersion) { - this.internalVersion = internalVersion; - } - - public Date getCreatedDate() { - return createdDate; - } - - public void setCreatedDate(Date createdDate) { - this.createdDate = createdDate; - } - - public String getArtifactName() { - return artifactName; - } - - public void setArtifactName(String artifactName) { - this.artifactName = artifactName; - } - - public String getPublished() { - return published; - } - - public void setPublished(String published) { - this.published = published; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public static long getSerialversionuid() { - return serialVersionUID; - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java deleted file mode 100644 index 074483a7c..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaJsonNodeConverter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.domain; - -import com.fasterxml.jackson.databind.JsonNode; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; - -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; -/** - * @author Brinda Santh - */ -@Converter -public class JpaJsonNodeConverter implements - AttributeConverter { - - @Override - public String convertToDatabaseColumn(JsonNode node) { - return JacksonUtils.Companion.getJson(node, true); - } - - @Override - public JsonNode convertToEntityAttribute(String dbData) { - return JacksonUtils.Companion.jsonNode(dbData); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java deleted file mode 100644 index e28cdcd5b..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.domain; - -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; - -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; -/** - * @author Brinda Santh - */ -@Converter -public class JpaResourceDefinitionConverter implements - AttributeConverter { - @Override - public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) { - return JacksonUtils.Companion.getJson(resourceDefinition); - } - - @Override - public ResourceDefinition convertToEntityAttribute(String content) { - return JacksonUtils.Companion.readValue(content, ResourceDefinition.class); - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java deleted file mode 100644 index 65a135c19..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ModelType.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.databind.JsonNode; -import io.swagger.annotations.ApiModelProperty; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - - -/** - * AsdcReference.java Purpose: Provide Configuration Generator AsdcReference Entity - * - * @author Brinda Santh - * @version 1.0 - */ -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "MODEL_TYPE") -public class ModelType implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "model_name", nullable = false) - @ApiModelProperty(required=true) - private String modelName; - - @Column(name = "derived_from", nullable = false) - @ApiModelProperty(required=true) - private String derivedFrom; - - @Column(name = "definition_type", nullable = false) - @ApiModelProperty(required=true) - private String definitionType; - - @Lob - @Convert(converter = JpaJsonNodeConverter.class) - @Column(name = "definition", nullable = false) - @ApiModelProperty(required=true) - private JsonNode definition; - - @Lob - @Column(name = "description", nullable = false) - @ApiModelProperty(required=true) - private String description; - - @Column(name = "version", nullable = false) - @ApiModelProperty(required=true) - private String version; - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required=true) - private String tags; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date creationDate; - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required=true) - private String updatedBy; - - @Override - public String toString() { - return "[" + "modelName = " + modelName + - ", derivedFrom = " + derivedFrom + - ", definitionType = " + definitionType + - ", description = " + description + - ", creationDate = " + creationDate + - ", version = " + version + - ", updatedBy = " + updatedBy + - ", tags = " + tags + - "]"; - } - - public String getModelName() { - return modelName; - } - - public void setModelName(String modelName) { - this.modelName = modelName; - } - - public String getDerivedFrom() { - return derivedFrom; - } - - public void setDerivedFrom(String derivedFrom) { - this.derivedFrom = derivedFrom; - } - - public String getDefinitionType() { - return definitionType; - } - - public void setDefinitionType(String definitionType) { - this.definitionType = definitionType; - } - - public JsonNode getDefinition() { - return definition; - } - - public void setDefinition(JsonNode definition) { - this.definition = definition; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java deleted file mode 100644 index 5352d9c96..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/domain/ResourceDictionary.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.domain; - -import com.fasterxml.jackson.annotation.JsonFormat; -import io.swagger.annotations.ApiModelProperty; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.springframework.data.annotation.LastModifiedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import javax.persistence.*; -import java.io.Serializable; -import java.util.Date; - -/** - * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity - * - * @author Brinda Santh - * @version 1.0 - */ -@EntityListeners({AuditingEntityListener.class}) -@Entity -@Table(name = "RESOURCE_DICTIONARY") -public class ResourceDictionary implements Serializable { - private static final long serialVersionUID = 1L; - - @Id - @Column(name = "name", nullable = false) - @ApiModelProperty(required=true) - private String name; - - @Column(name = "data_type", nullable = false) - @ApiModelProperty(required=true) - private String dataType; - - @Column(name = "entry_schema") - private String entrySchema; - - @Lob - @Convert(converter = JpaResourceDefinitionConverter.class) - @Column(name = "definition", nullable = false) - @ApiModelProperty(required=true) - private ResourceDefinition definition; - - @Lob - @Column(name = "description", nullable = false) - @ApiModelProperty(required=true) - private String description; - - @Lob - @Column(name = "tags", nullable = false) - @ApiModelProperty(required=true) - private String tags; - - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") - @LastModifiedDate - @Temporal(TemporalType.TIMESTAMP) - @Column(name = "creation_date") - private Date creationDate; - - @Column(name = "updated_by", nullable = false) - @ApiModelProperty(required=true) - private String updatedBy; - - @Override - public String toString() { - return "[" + ", name = " + name + - ", dataType = " + dataType + - ", entrySchema = " + entrySchema + - ", definition =" + definition + - ", description = " + description + - ", updatedBy = " + updatedBy + - ", tags = " + tags + - ", creationDate = " + creationDate + - "]"; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDataType() { - return dataType; - } - - public void setDataType(String dataType) { - this.dataType = dataType; - } - - public String getEntrySchema() { - return entrySchema; - } - - public void setEntrySchema(String entrySchema) { - this.entrySchema = entrySchema; - } - - public ResourceDefinition getDefinition() { - return definition; - } - - public void setDefinition(ResourceDefinition definition) { - this.definition = definition; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public String getUpdatedBy() { - return updatedBy; - } - - public void setUpdatedBy(String updatedBy) { - this.updatedBy = updatedBy; - } - - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java deleted file mode 100644 index 2250828ac..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/model/AutoMapResponse.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.model; - -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; - -import java.util.List; - -/** - * ArtifactRequest.java Purpose: Provide Configuration Generator ArtifactRequest Model - * - * @author Brinda Santh - * @version 1.0 - */ -public class AutoMapResponse { - - private List resourceAssignments; - private List dataDictionaries; - - public List getResourceAssignments() { - return resourceAssignments; - } - - public void setResourceAssignments(List resourceAssignments) { - this.resourceAssignments = resourceAssignments; - } - - public List getDataDictionaries() { - return dataDictionaries; - } - - public void setDataDictionaries(List dataDictionaries) { - this.dataDictionaries = dataDictionaries; - } - - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java deleted file mode 100644 index 343f8c67b..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/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.apps.controllerblueprints.service.repository; - -import org.onap.ccsdk.apps.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 { - - /** - * This is a findById method - * - * @param id id - * @return Optional - */ - @NotNull - Optional findById(@NotNull String id); - - /** - * This is a findAll method - * @return List - */ - @Override - List findAll(); - - /** - * This is a findByArtifactNameAndArtifactVersion method - * - * @param artifactName artifactName - * @param artifactVersion artifactVersion - * @return Optional - */ - Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java deleted file mode 100644 index c53040e2b..000000000 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/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.apps.controllerblueprints.service.repository; - -import org.onap.ccsdk.apps.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 { - - - /** - * This is a findByName method - * - * @param name name - * @return Optional - */ - Optional findByName(String name); - - /** - * This is a findByNameIn method - * - * @param names names - * @return Optional - */ - List findByNameIn(List names); - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags tags - * @return Optional - */ - List findByTagsContainingIgnoreCase(String tags); - - /** - * This is a deleteByName method - * - * @param name name - */ - void deleteByName(String name); - - -} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/ApplicationRegistrationService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/ApplicationRegistrationService.java new file mode 100644 index 000000000..1e7109262 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/ApplicationRegistrationService.java @@ -0,0 +1,56 @@ +/* + * 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; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.collections.CollectionUtils; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.util.List; + +@Component +@SuppressWarnings("unused") +public class ApplicationRegistrationService { + private static EELFLogger log = EELFManager.getInstance().getLogger(ApplicationRegistrationService.class); + + @Value("#{'${resourceSourceMappings}'.split(',')}") + private List resourceSourceMappings; + + @PostConstruct + public void register() { + registerDictionarySources(); + } + + public void registerDictionarySources() { + log.info("Registering Dictionary Sources : {}", resourceSourceMappings); + if (CollectionUtils.isNotEmpty(resourceSourceMappings)) { + resourceSourceMappings.forEach(resourceSourceMapping -> { + String[] mappingKeyValue = resourceSourceMapping.split("="); + if (mappingKeyValue != null && mappingKeyValue.length == 2) { + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping(mappingKeyValue[0].trim(), mappingKeyValue[1].trim()); + } else { + log.warn("failed to get resource source mapping {}", resourceSourceMapping); + } + }); + } + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/AutoResourceMappingService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/AutoResourceMappingService.java new file mode 100644 index 000000000..c04c0dcf4 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/AutoResourceMappingService.java @@ -0,0 +1,210 @@ +/* + * 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; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.Preconditions; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils; +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; +import org.onap.ccsdk.cds.controllerblueprints.service.model.AutoMapResponse; +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ResourceDictionaryRepository; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * AutoResourceMappingService.java Purpose: Provide Automapping of Resource Assignments AutoResourceMappingService + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +@SuppressWarnings("unused") +public class AutoResourceMappingService { + + private static EELFLogger log = EELFManager.getInstance().getLogger(AutoResourceMappingService.class); + + private ResourceDictionaryRepository dataDictionaryRepository; + + /** + * This is a AutoResourceMappingService constructor + * + * @param dataDictionaryRepository dataDictionaryRepository + */ + public AutoResourceMappingService(ResourceDictionaryRepository dataDictionaryRepository) { + this.dataDictionaryRepository = dataDictionaryRepository; + } + + /** + * This is a autoMap service to map the template keys automatically to Dictionary fields. + * + * @param resourceAssignments resourceAssignments + * @return AutoMapResponse + */ + public AutoMapResponse autoMap(List resourceAssignments) throws BluePrintException { + AutoMapResponse autoMapResponse = new AutoMapResponse(); + try { + if (CollectionUtils.isNotEmpty(resourceAssignments)) { + + // Create the Dictionary definitions for the ResourceAssignment Names + Map dictionaryMap = getDictionaryDefinitions(resourceAssignments); + + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName()) + && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { + + populateDictionaryMapping(dictionaryMap, resourceAssignment); + + log.info("Mapped Resource : {}", resourceAssignment); + + } + } + } + List dictionaries = getDictionaryDefinitionsList(resourceAssignments); + List resourceAssignmentsFinal = getAllAutomapResourceAssignments(resourceAssignments); + autoMapResponse.setDataDictionaries(dictionaries); + autoMapResponse.setResourceAssignments(resourceAssignmentsFinal); + } catch (Exception e) { + log.error(String.format("Failed in auto process %s", e.getMessage())); + throw new BluePrintException(e.getMessage(), e); + } + return autoMapResponse; + } + + private void populateDictionaryMapping(Map dictionaryMap, ResourceAssignment resourceAssignment) { + ResourceDictionary dbDataDictionary = dictionaryMap.get(resourceAssignment.getName()); + if (dbDataDictionary != null && dbDataDictionary.getDefinition() != null) { + + ResourceDefinition dictionaryDefinition = dbDataDictionary.getDefinition(); + + if (dictionaryDefinition != null && StringUtils.isNotBlank(dictionaryDefinition.getName()) + && StringUtils.isBlank(resourceAssignment.getDictionaryName())) { + + resourceAssignment.setDictionaryName(dbDataDictionary.getName()); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + } + } + } + + private Map getDictionaryDefinitions(List resourceAssignments) { + Map dictionaryMap = new HashMap<>(); + List names = new ArrayList<>(); + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getName())) { + names.add(resourceAssignment.getName()); + } + } + if (CollectionUtils.isNotEmpty(names)) { + + List dictionaries = dataDictionaryRepository.findByNameIn(names); + if (CollectionUtils.isNotEmpty(dictionaries)) { + for (ResourceDictionary dataDictionary : dictionaries) { + if (dataDictionary != null && StringUtils.isNotBlank(dataDictionary.getName())) { + dictionaryMap.put(dataDictionary.getName(), dataDictionary); + } + } + } + } + return dictionaryMap; + + } + + private List getDictionaryDefinitionsList(List resourceAssignments) { + List dictionaries = null; + List names = new ArrayList<>(); + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { + + if (!names.contains(resourceAssignment.getDictionaryName())) { + names.add(resourceAssignment.getDictionaryName()); + } + + if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { + List dependencyNames = resourceAssignment.getDependencies(); + for (String dependencyName : dependencyNames) { + if (StringUtils.isNotBlank(dependencyName) && !names.contains(dependencyName)) { + names.add(dependencyName); + } + } + } + } + } + if (CollectionUtils.isNotEmpty(names)) { + dictionaries = dataDictionaryRepository.findByNameIn(names); + } + return dictionaries; + + } + + private List getAllAutomapResourceAssignments(List resourceAssignments) { + List dictionaries = null; + List names = new ArrayList<>(); + for (ResourceAssignment resourceAssignment : resourceAssignments) { + if (resourceAssignment != null && StringUtils.isNotBlank(resourceAssignment.getDictionaryName())) { + if (resourceAssignment.getDependencies() != null && !resourceAssignment.getDependencies().isEmpty()) { + List dependencieNames = resourceAssignment.getDependencies(); + for (String dependencieName : dependencieNames) { + if (StringUtils.isNotBlank(dependencieName) && !names.contains(dependencieName) + && !checkAssignmentsExists(resourceAssignments, dependencieName)) { + names.add(dependencieName); + } + } + } + } + } + + if (!names.isEmpty()) { + dictionaries = dataDictionaryRepository.findByNameIn(names); + } + if (dictionaries != null) { + for (ResourceDictionary resourcedictionary : dictionaries) { + ResourceDefinition dictionaryDefinition = resourcedictionary.getDefinition(); + Preconditions.checkNotNull(dictionaryDefinition, "failed to get Resource Definition from dictionary definition"); + PropertyDefinition property = new PropertyDefinition(); + property.setRequired(true); + ResourceAssignment resourceAssignment = new ResourceAssignment(); + resourceAssignment.setName(resourcedictionary.getName()); + resourceAssignment.setDictionaryName(resourcedictionary + .getName()); + resourceAssignment.setVersion(0); + resourceAssignment.setProperty(property); + ResourceDictionaryUtils.populateSourceMapping(resourceAssignment, dictionaryDefinition); + resourceAssignments.add(resourceAssignment); + } + } + return resourceAssignments; + + } + + + private boolean checkAssignmentsExists(List resourceAssignmentsWithDepencies, String resourceName) { + return resourceAssignmentsWithDepencies.stream().anyMatch(names -> names.getName().equalsIgnoreCase(resourceName)); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/SchemaGeneratorService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/SchemaGeneratorService.java new file mode 100644 index 000000000..6c09ef8cd --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/SchemaGeneratorService.java @@ -0,0 +1,116 @@ +/* + * 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; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.Preconditions; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException; +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType; +import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.service.common.SwaggerGenerator; + +import java.util.HashMap; +import java.util.Map; + +/** + * SchemaGeneratorService.java Purpose: Provide Service to generate service template input schema definition and Sample + * Json generation. + * + * @author Brinda Santh + * @version 1.0 + */ +@Deprecated +public class SchemaGeneratorService { + private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorService.class); + + private Map dataTypes; + + /** + * This is a SchemaGeneratorService constructor + */ + public SchemaGeneratorService() { + dataTypes = new HashMap<>(); + } + + /** + * This is a generateSchema + * + * @param serviceTemplateContent service template content + * @return String + * @throws BluePrintException Blueprint Exception + */ + public String generateSchema(String serviceTemplateContent) throws BluePrintException { + if (StringUtils.isNotBlank(serviceTemplateContent)) { + ServiceTemplate serviceTemplate = JacksonUtils.Companion.readValue(serviceTemplateContent, + ServiceTemplate.class); + return generateSchema(serviceTemplate); + } else { + throw new BluePrintException( + "Service Template Content is (" + serviceTemplateContent + ") not Defined."); + } + } + + /** + * This is a generateSchema + * + * @param serviceTemplate service template content + * @return String + * @throws BluePrintException Blueprint Exception + */ + public String generateSchema(ServiceTemplate serviceTemplate) throws BluePrintException { + String schemaContent = null; + Preconditions.checkNotNull(serviceTemplate, "Service Template is not defined."); + try { + if (serviceTemplate.getTopologyTemplate() != null + && serviceTemplate.getTopologyTemplate().getInputs() != null) { + SwaggerGenerator swaggerGenerator = new SwaggerGenerator(serviceTemplate); + schemaContent = swaggerGenerator.generateSwagger(); + } + } catch (Exception e) { + throw new BluePrintException(e.getMessage(), e); + } + + return schemaContent; + } + + private void manageServiceTemplateActions(ServiceTemplate serviceTemplate, String actionName) { + if (serviceTemplate != null && serviceTemplate.getTopologyTemplate() != null + && StringUtils.isNotBlank(actionName)) { + + if (MapUtils.isNotEmpty(serviceTemplate.getTopologyTemplate().getInputs())) { + + serviceTemplate.getTopologyTemplate().getInputs().entrySet().removeIf(entity -> { + String keyName = entity.getKey(); + String replacedAction = actionName.replace("-action", "-request"); + log.debug("Key name : " + keyName + ", actionName " + + actionName + ", replacedAction :" + replacedAction); + if (keyName.endsWith("-request") && !keyName.equals(replacedAction)) { + log.info("deleting input property {} ", keyName); + return true; + } + return false; + }); + } + + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/ErrorMessage.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/ErrorMessage.java new file mode 100644 index 000000000..155a162b6 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/ErrorMessage.java @@ -0,0 +1,75 @@ +/* + * 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.common; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; + +import java.io.Serializable; +import java.util.Date; + +@JsonInclude(Include.NON_NULL) +@JsonTypeName("errorMessage") +@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) +public class ErrorMessage implements Serializable { + private String message; + private Integer code; + private String debugMessage; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + private Date timestamp = new Date(); + + public ErrorMessage(String message, Integer code, String debugMessage){ + this.message = message; + this.code = code; + this.debugMessage = debugMessage; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getDebugMessage() { + return debugMessage; + } + + public void setDebugMessage(String developerMessage) { + this.debugMessage = developerMessage; + } + + public Date getTimestamp() { + return timestamp; + } + + public void setTimestamp(Date timestamp) { + this.timestamp = timestamp; + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java new file mode 100644 index 000000000..abf774981 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SwaggerGenerator.java @@ -0,0 +1,185 @@ +/* + * 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.common; + +import io.swagger.models.*; +import io.swagger.models.parameters.BodyParameter; +import io.swagger.models.parameters.Parameter; +import io.swagger.models.properties.*; +import org.apache.commons.collections.MapUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes; +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition; +import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate; + +import java.util.*; + +/** + * SwaggerGenerator.java Purpose: Provide Service to generate service template input schema definition and Sample Json + * generation. + * + * @author Brinda Santh + * @version 1.0 + */ +@Deprecated +public class SwaggerGenerator { + + private ServiceTemplate serviceTemplate; + public static final String INPUTS="inputs"; + + /** + * This is a SwaggerGenerator constructor + */ + public SwaggerGenerator(ServiceTemplate serviceTemplate) { + this.serviceTemplate = serviceTemplate; + } + + /** + * This is a generateSwagger + * + * @return String + */ + public String generateSwagger() { + + Swagger swagger = new Swagger().info(getInfo()); + + swagger.setPaths(getPaths()); + swagger.setDefinitions(getDefinition()); + + + return swagger.toString(); + } + + private Info getInfo() { + Info info = new Info(); + Contact contact = new Contact(); + contact.setName(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_AUTHOR)); + info.setContact(contact); + info.setTitle(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_NAME)); + info.setDescription(serviceTemplate.getDescription()); + info.setVersion(serviceTemplate.getMetadata().get(BluePrintConstants.METADATA_TEMPLATE_VERSION)); + return info; + } + + private Map getPaths() { + Map paths = new HashMap<>(); + Path path = new Path(); + Operation post = new Operation(); + post.setOperationId("configure"); + post.setConsumes(Arrays.asList("application/json", "application/xml")); + post.setProduces(Arrays.asList("application/json", "application/xml")); + List parameters = new ArrayList<>(); + Parameter in = new BodyParameter().schema(new RefModel("#/definitions/inputs")); + in.setRequired(true); + in.setName(INPUTS); + parameters.add(in); + post.setParameters(parameters); + + Map responses = new HashMap<>(); + Response response = new Response().description("Success"); + responses.put("200", response); + + Response failureResponse = new Response().description("Failure"); + responses.put("400", failureResponse); + post.setResponses(responses); + + path.setPost(post); + paths.put("/operations/config-selfservice-api:configure", path); + return paths; + } + + private Map getDefinition() { + Map models = new HashMap<>(); + + ModelImpl inputmodel = new ModelImpl(); + inputmodel.setTitle(INPUTS); + serviceTemplate.getTopologyTemplate().getInputs().forEach((propertyName, property) -> { + Property defProperty = getPropery(propertyName, property); + inputmodel.property(propertyName, defProperty); + }); + models.put(INPUTS, inputmodel); + + if (MapUtils.isNotEmpty(serviceTemplate.getDataTypes())) { + serviceTemplate.getDataTypes().forEach((name, dataType) -> { + ModelImpl model = new ModelImpl(); + model.setDescription(dataType.getDescription()); + if (dataType != null && MapUtils.isNotEmpty(dataType.getProperties())) { + + dataType.getProperties().forEach((propertyName, property) -> { + Property defProperty = getPropery(propertyName, property); + model.addProperty(propertyName, defProperty); + }); + } + models.put(name, model); + }); + } + return models; + + } + + private Property getPropery(String name, PropertyDefinition propertyDefinition) { + Property defProperty = null; + + if (BluePrintTypes.validPrimitiveTypes().contains(propertyDefinition.getType())) { + if (BluePrintConstants.DATA_TYPE_BOOLEAN.equals(propertyDefinition.getType())) { + defProperty = new BooleanProperty(); + } else if (BluePrintConstants.DATA_TYPE_INTEGER.equals(propertyDefinition.getType())) { + StringProperty stringProperty = new StringProperty(); + stringProperty.setType("integer"); + defProperty = stringProperty; + } else if (BluePrintConstants.DATA_TYPE_FLOAT.equals(propertyDefinition.getType())) { + StringProperty stringProperty = new StringProperty(); + stringProperty.setFormat("float"); + defProperty = stringProperty; + } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP.equals(propertyDefinition.getType())) { + DateTimeProperty dateTimeProperty = new DateTimeProperty(); + dateTimeProperty.setFormat("date-time"); + defProperty = dateTimeProperty; + } else { + defProperty = new StringProperty(); + } + } else if (BluePrintTypes.validCollectionTypes().contains(propertyDefinition.getType())) { + ArrayProperty arrayProperty = new ArrayProperty(); + if (propertyDefinition.getEntrySchema() != null) { + String entrySchema = propertyDefinition.getEntrySchema().getType(); + if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema)) { + Property innerType = new RefProperty("#/definitions/" + entrySchema); + arrayProperty.setItems(innerType); + } else { + Property innerType = new StringProperty(); + arrayProperty.setItems(innerType); + } + defProperty = arrayProperty; + } + + } else { + defProperty = new RefProperty("#/definitions/" + propertyDefinition.getType()); + } + defProperty.setName(name); + if (propertyDefinition.getDefaultValue() != null) { + defProperty.setDefault(String.valueOf(propertyDefinition.getDefaultValue())); + } + + defProperty.setRequired(BooleanUtils.isTrue(propertyDefinition.getRequired())); + defProperty.setDescription(propertyDefinition.getDescription()); + return defProperty; + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java new file mode 100755 index 000000000..916e94b4e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModel.java @@ -0,0 +1,285 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.hibernate.annotations.Proxy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * BlueprintModel.java Purpose: Provide Configuration Generator BlueprintModel Entity + * + * @author Brinda Santh + * @version 1.0 + */ + +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL", uniqueConstraints=@UniqueConstraint(columnNames={"artifact_name","artifact_version"})) +@Proxy(lazy=false) +public class BlueprintModel implements Serializable { + private static final long serialVersionUID = 1L; + @Id + @Column(name = "config_model_id") + private String id; + + @Column(name = "service_uuid") + private String serviceUUID; + + @Column(name = "distribution_id") + private String distributionId; + + @Column(name = "service_name") + private String serviceName; + + @Column(name = "service_description") + private String serviceDescription; + + @Column(name = "resource_uuid") + private String resourceUUID; + + @Column(name = "resource_instance_name") + private String resourceInstanceName; + + @Column(name = "resource_name") + private String resourceName; + + @Column(name = "resource_version") + private String resourceVersion; + + @Column(name = "resource_type") + private String resourceType; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @Column(name = "artifact_version", nullable = false) + @ApiModelProperty(required=true) + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @Column(name = "artifact_name", nullable = false) + @ApiModelProperty(required=true) + private String artifactName; + + @Column(name = "published", nullable = false) + @ApiModelProperty(required=true) + private String published; + + @Column(name = "updated_by", nullable = false) + @ApiModelProperty(required=true) + private String updatedBy; + + @Lob + @Column(name = "tags", nullable = false) + @ApiModelProperty(required=true) + private String tags; + + @OneToOne(mappedBy = "blueprintModel", fetch = FetchType.EAGER, orphanRemoval = true, cascade = CascadeType.ALL) + private org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent blueprintModelContent; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getServiceUUID() { + return serviceUUID; + } + + public void setServiceUUID(String serviceUUID) { + this.serviceUUID = serviceUUID; + } + + public String getDistributionId() { + return distributionId; + } + + public void setDistributionId(String distributionId) { + this.distributionId = distributionId; + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getServiceDescription() { + return serviceDescription; + } + + public void setServiceDescription(String serviceDescription) { + this.serviceDescription = serviceDescription; + } + + public String getResourceUUID() { + return resourceUUID; + } + + public void setResourceUUID(String resourceUUID) { + this.resourceUUID = resourceUUID; + } + + public String getResourceInstanceName() { + return resourceInstanceName; + } + + public void setResourceInstanceName(String resourceInstanceName) { + this.resourceInstanceName = resourceInstanceName; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + + public String getResourceVersion() { + return resourceVersion; + } + + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + public String getResourceType() { + return resourceType; + } + + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent getBlueprintModelContent() { + return blueprintModelContent; + } + + public void setBlueprintModelContent( + org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent blueprintModelContent) { + this.blueprintModelContent = blueprintModelContent; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java new file mode 100644 index 000000000..20a1fdcdf --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelContent.java @@ -0,0 +1,170 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.Objects; + +/** + * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "CONFIG_MODEL_CONTENT") +public class BlueprintModelContent implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "config_model_content_id") + private String id; + + @Column(name = "name", nullable = false) + @ApiModelProperty(required=true) + private String name; + + @Column(name = "content_type", nullable = false) + @ApiModelProperty(required=true) + private String contentType; + + @OneToOne + @JoinColumn(name = "config_model_id") + private BlueprintModel blueprintModel; + + @Lob + @Column(name = "description") + private String description; + + @Lob + @Column(name = "content", nullable = false) + @ApiModelProperty(required=true) + private byte[] content; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "updated_date") + private Date creationDate = new Date(); + + @Override + public String toString() { + return "[" + "id = " + id + + ", name = " + name + + ", contentType = " + contentType + + "]"; + } + + @Override + public boolean equals(Object o) { + + if (o == this) { + return true; + } + if (!(o instanceof BlueprintModelContent)) { + return false; + } + BlueprintModelContent blueprintModelContent = (BlueprintModelContent) o; + return Objects.equals(id, blueprintModelContent.id) && Objects.equals(name, blueprintModelContent.name) + && Objects.equals(contentType, blueprintModelContent.contentType); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, contentType); + } + + public String getId() { + return id; + } + + + public void setId(String id) { + this.id = id; + } + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public String getContentType() { + return contentType; + } + + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + + public BlueprintModel getBlueprintModel() { + return blueprintModel; + } + + + public void setBlueprintModel(BlueprintModel blueprintModel) { + this.blueprintModel = blueprintModel; + } + + + public String getDescription() { + return description; + } + + + public void setDescription(String description) { + this.description = description; + } + + + public byte[] getContent() { + return content; + } + + + public void setContent(byte[] content) { + this.content = content; + } + + + public Date getCreationDate() { + return creationDate; + } + + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java new file mode 100644 index 000000000..5c351bc63 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/BlueprintModelSearch.java @@ -0,0 +1,166 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import org.springframework.data.annotation.LastModifiedDate; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +@Entity +@Table(name = "CONFIG_MODEL") +@JsonTypeName("blueprintModel") +@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME) +public class BlueprintModelSearch implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "config_model_id") + private String id; + + @Column(name = "artifact_uuid") + private String artifactUUId; + + @Column(name = "artifact_type") + private String artifactType; + + @Column(name = "artifact_version", nullable = false) + private String artifactVersion; + + @Lob + @Column(name = "artifact_description") + private String artifactDescription; + + @Column(name = "internal_version") + private Integer internalVersion; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date createdDate = new Date(); + + @Column(name = "artifact_name", nullable = false) + private String artifactName; + + @Column(name = "published", nullable = false) + private String published; + + @Column(name = "updated_by", nullable = false) + private String updatedBy; + + @Lob + @Column(name = "tags", nullable = false) + private String tags; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getArtifactUUId() { + return artifactUUId; + } + + public void setArtifactUUId(String artifactUUId) { + this.artifactUUId = artifactUUId; + } + + public String getArtifactType() { + return artifactType; + } + + public void setArtifactType(String artifactType) { + this.artifactType = artifactType; + } + + public String getArtifactVersion() { + return artifactVersion; + } + + public void setArtifactVersion(String artifactVersion) { + this.artifactVersion = artifactVersion; + } + + public String getArtifactDescription() { + return artifactDescription; + } + + public void setArtifactDescription(String artifactDescription) { + this.artifactDescription = artifactDescription; + } + + public Integer getInternalVersion() { + return internalVersion; + } + + public void setInternalVersion(Integer internalVersion) { + this.internalVersion = internalVersion; + } + + public Date getCreatedDate() { + return createdDate; + } + + public void setCreatedDate(Date createdDate) { + this.createdDate = createdDate; + } + + public String getArtifactName() { + return artifactName; + } + + public void setArtifactName(String artifactName) { + this.artifactName = artifactName; + } + + public String getPublished() { + return published; + } + + public void setPublished(String published) { + this.published = published; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaJsonNodeConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaJsonNodeConverter.java new file mode 100644 index 000000000..f45c30fc6 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaJsonNodeConverter.java @@ -0,0 +1,40 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.databind.JsonNode; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +/** + * @author Brinda Santh + */ +@Converter +public class JpaJsonNodeConverter implements + AttributeConverter { + + @Override + public String convertToDatabaseColumn(JsonNode node) { + return JacksonUtils.Companion.getJson(node, true); + } + + @Override + public JsonNode convertToEntityAttribute(String dbData) { + return JacksonUtils.Companion.jsonNode(dbData); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java new file mode 100644 index 000000000..60c069428 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/JpaResourceDefinitionConverter.java @@ -0,0 +1,39 @@ +/* + * 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.domain; + +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; +/** + * @author Brinda Santh + */ +@Converter +public class JpaResourceDefinitionConverter implements + AttributeConverter { + @Override + public String convertToDatabaseColumn(ResourceDefinition resourceDefinition) { + return JacksonUtils.Companion.getJson(resourceDefinition); + } + + @Override + public ResourceDefinition convertToEntityAttribute(String content) { + return JacksonUtils.Companion.readValue(content, ResourceDefinition.class); + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ModelType.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ModelType.java new file mode 100644 index 000000000..31b792407 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ModelType.java @@ -0,0 +1,171 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.databind.JsonNode; +import io.swagger.annotations.ApiModelProperty; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + + +/** + * AsdcReference.java Purpose: Provide Configuration Generator AsdcReference Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "MODEL_TYPE") +public class ModelType implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "model_name", nullable = false) + @ApiModelProperty(required=true) + private String modelName; + + @Column(name = "derived_from", nullable = false) + @ApiModelProperty(required=true) + private String derivedFrom; + + @Column(name = "definition_type", nullable = false) + @ApiModelProperty(required=true) + private String definitionType; + + @Lob + @Convert(converter = JpaJsonNodeConverter.class) + @Column(name = "definition", nullable = false) + @ApiModelProperty(required=true) + private JsonNode definition; + + @Lob + @Column(name = "description", nullable = false) + @ApiModelProperty(required=true) + private String description; + + @Column(name = "version", nullable = false) + @ApiModelProperty(required=true) + private String version; + + @Lob + @Column(name = "tags", nullable = false) + @ApiModelProperty(required=true) + private String tags; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date creationDate; + + @Column(name = "updated_by", nullable = false) + @ApiModelProperty(required=true) + private String updatedBy; + + @Override + public String toString() { + return "[" + "modelName = " + modelName + + ", derivedFrom = " + derivedFrom + + ", definitionType = " + definitionType + + ", description = " + description + + ", creationDate = " + creationDate + + ", version = " + version + + ", updatedBy = " + updatedBy + + ", tags = " + tags + + "]"; + } + + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDerivedFrom() { + return derivedFrom; + } + + public void setDerivedFrom(String derivedFrom) { + this.derivedFrom = derivedFrom; + } + + public String getDefinitionType() { + return definitionType; + } + + public void setDefinitionType(String definitionType) { + this.definitionType = definitionType; + } + + public JsonNode getDefinition() { + return definition; + } + + public void setDefinition(JsonNode definition) { + this.definition = definition; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ResourceDictionary.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ResourceDictionary.java new file mode 100644 index 000000000..2a6ab459b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/domain/ResourceDictionary.java @@ -0,0 +1,158 @@ +/* + * 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.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; + +/** + * DataDictionary.java Purpose: Provide Configuration Generator DataDictionary Entity + * + * @author Brinda Santh + * @version 1.0 + */ +@EntityListeners({AuditingEntityListener.class}) +@Entity +@Table(name = "RESOURCE_DICTIONARY") +public class ResourceDictionary implements Serializable { + private static final long serialVersionUID = 1L; + + @Id + @Column(name = "name", nullable = false) + @ApiModelProperty(required=true) + private String name; + + @Column(name = "data_type", nullable = false) + @ApiModelProperty(required=true) + private String dataType; + + @Column(name = "entry_schema") + private String entrySchema; + + @Lob + @Convert(converter = JpaResourceDefinitionConverter.class) + @Column(name = "definition", nullable = false) + @ApiModelProperty(required=true) + private ResourceDefinition definition; + + @Lob + @Column(name = "description", nullable = false) + @ApiModelProperty(required=true) + private String description; + + @Lob + @Column(name = "tags", nullable = false) + @ApiModelProperty(required=true) + private String tags; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + @LastModifiedDate + @Temporal(TemporalType.TIMESTAMP) + @Column(name = "creation_date") + private Date creationDate; + + @Column(name = "updated_by", nullable = false) + @ApiModelProperty(required=true) + private String updatedBy; + + @Override + public String toString() { + return "[" + ", name = " + name + + ", dataType = " + dataType + + ", entrySchema = " + entrySchema + + ", definition =" + definition + + ", description = " + description + + ", updatedBy = " + updatedBy + + ", tags = " + tags + + ", creationDate = " + creationDate + + "]"; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } + + public String getEntrySchema() { + return entrySchema; + } + + public void setEntrySchema(String entrySchema) { + this.entrySchema = entrySchema; + } + + public ResourceDefinition getDefinition() { + return definition; + } + + public void setDefinition(ResourceDefinition definition) { + this.definition = definition; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = tags; + } + + public Date getCreationDate() { + return creationDate; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public String getUpdatedBy() { + return updatedBy; + } + + public void setUpdatedBy(String updatedBy) { + this.updatedBy = updatedBy; + } + + + +} diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/model/AutoMapResponse.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/model/AutoMapResponse.java new file mode 100644 index 000000000..0fa337762 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/model/AutoMapResponse.java @@ -0,0 +1,53 @@ +/* + * 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.model; + +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; + +import java.util.List; + +/** + * ArtifactRequest.java Purpose: Provide Configuration Generator ArtifactRequest Model + * + * @author Brinda Santh + * @version 1.0 + */ +public class AutoMapResponse { + + private List resourceAssignments; + private List dataDictionaries; + + public List getResourceAssignments() { + return resourceAssignments; + } + + public void setResourceAssignments(List resourceAssignments) { + this.resourceAssignments = resourceAssignments; + } + + public List getDataDictionaries() { + return dataDictionaries; + } + + public void setDataDictionaries(List dataDictionaries) { + this.dataDictionaries = dataDictionaries; + } + + + +} 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 new file mode 100644 index 000000000..9aeee1771 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelSearchRepository.java @@ -0,0 +1,69 @@ +/* + * 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 { + + /** + * This is a findById method + * + * @param id id + * @return Optional + */ + @NotNull + Optional findById(@NotNull String id); + + /** + * This is a findAll method + * @return List + */ + @Override + List findAll(); + + /** + * This is a findByArtifactNameAndArtifactVersion method + * + * @param artifactName artifactName + * @param artifactVersion artifactVersion + * @return Optional + */ + Optional findByArtifactNameAndArtifactVersion(String artifactName, String artifactVersion); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags + * @return Optional + */ + List 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 new file mode 100644 index 000000000..314ac6a4e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryRepository.java @@ -0,0 +1,69 @@ +/* + * 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 { + + + /** + * This is a findByName method + * + * @param name name + * @return Optional + */ + Optional findByName(String name); + + /** + * This is a findByNameIn method + * + * @param names names + * @return Optional + */ + List findByNameIn(List names); + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags tags + * @return Optional + */ + List 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/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt deleted file mode 100644 index 88589eb7d..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/BluePrintRepoServiceImpl.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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. - * 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.apps.controllerblueprints.service - -import com.fasterxml.jackson.databind.JsonNode -import com.google.common.base.Preconditions -import org.apache.commons.lang3.StringUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository -import org.springframework.stereotype.Service - -interface ResourceDefinitionRepoService : BluePrintRepoService { - - @Throws(BluePrintException::class) - fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition -} - -@Service -open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRepository, - private val resourceDictionaryRepository: ResourceDictionaryRepository) : ResourceDefinitionRepoService { - - @Throws(BluePrintException::class) - override fun getNodeType(nodeTypeName: String): NodeType { - return getModelType(nodeTypeName, NodeType::class.java) - ?: throw BluePrintException("couldn't get NodeType($nodeTypeName)") - } - - @Throws(BluePrintException::class) - override fun getDataType(dataTypeName: String): DataType { - return getModelType(dataTypeName, DataType::class.java) - ?: throw BluePrintException("couldn't get DataType($dataTypeName)") - } - - @Throws(BluePrintException::class) - override fun getArtifactType(artifactTypeName: String): ArtifactType { - return getModelType(artifactTypeName, ArtifactType::class.java) - ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName)") - } - - @Throws(BluePrintException::class) - override fun getRelationshipType(relationshipTypeName: String): RelationshipType { - return getModelType(relationshipTypeName, RelationshipType::class.java) - ?: throw BluePrintException("couldn't get RelationshipType($relationshipTypeName)") - } - - @Throws(BluePrintException::class) - override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition { - return getModelType(capabilityDefinitionName, CapabilityDefinition::class.java) - ?: throw BluePrintException("couldn't get CapabilityDefinition($capabilityDefinitionName)") - } - - @Throws(BluePrintException::class) - override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { - val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) - return if (dbResourceDictionary.isPresent) { - dbResourceDictionary.get().definition - } else { - throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) - } - } - - @Throws(BluePrintException::class) - private fun getModelType(modelName: String, valueClass: Class): T? { - Preconditions.checkArgument(StringUtils.isNotBlank(modelName), - "Failed to get model from repo, model name is missing") - - val modelDefinition = getModelDefinition(modelName) - Preconditions.checkNotNull(modelDefinition, - String.format("Failed to get model content for model name (%s)", modelName)) - - return JacksonUtils.readValue(modelDefinition, valueClass) - } - - @Throws(BluePrintException::class) - private fun getModelDefinition(modelName: String): JsonNode { - val modelDefinition: JsonNode - val modelTypeDb = modelTypeRepository.findByModelName(modelName) - if (modelTypeDb != null) { - modelDefinition = modelTypeDb.definition - } else { - throw BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)) - } - return modelDefinition - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt deleted file mode 100644 index 2c4ee746a..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.apps.controllerblueprints.service - -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -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.annotation.Bean -import org.springframework.context.annotation.Configuration -import org.springframework.core.env.Environment -import org.springframework.stereotype.Service - -@Configuration -open class ControllerBluePrintCoreConfiguration(private val bluePrintProperties: ControllerBlueprintProperties) { - - companion object { - const val PREFIX_BLUEPRINT_LOAD_CONFIGURATION = "controllerblueprints" - } - - @Bean - open fun controlelrBlueprintLoadConfiguration(): BluePrintLoadConfiguration { - return bluePrintProperties - .propertyBeanType(PREFIX_BLUEPRINT_LOAD_CONFIGURATION, BluePrintLoadConfiguration::class.java) - } -} - -@Configuration -open class ControllerBlueprintPropertyConfiguration { - @Autowired - lateinit var environment: Environment - - @Bean - open fun controllerBluePrintPropertyBinder(): Binder { - val configurationPropertySource = ConfigurationPropertySources.get(environment) - return Binder(configurationPropertySource) - } -} - -@Service -open class ControllerBlueprintProperties(var bluePrintPropertyBinder: Binder) { - fun propertyBeanType(prefix: String, type: Class): T { - return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get() - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt deleted file mode 100644 index 4974bcd12..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelController.kt +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2019 Bell Canada 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. - * 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.apps.controllerblueprints.service.controller - -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch -import org.onap.ccsdk.apps.controllerblueprints.service.handler.BluePrintModelHandler -import org.springframework.core.io.Resource -import org.springframework.http.MediaType -import org.springframework.http.ResponseEntity -import org.springframework.http.codec.multipart.FilePart -import org.springframework.web.bind.annotation.* -import reactor.core.publisher.Mono - -/** - * BlueprintModelController Purpose: Handle controllerBlueprint API request - * - * @author Vinal Patel - * @version 1.0 - */ -@RestController -@RequestMapping("/api/v1/blueprint-model") -open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) { - - @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun saveBlueprint(@RequestPart("file") file: FilePart): Mono { - return bluePrintModelHandler.saveBlueprintModel(file) - } - - @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun allBlueprintModel(): List { - return this.bluePrintModelHandler.allBlueprintModel() - } - - @DeleteMapping("/{id}") - @Throws(BluePrintException::class) - fun deleteBlueprint(@PathVariable(value = "id") id: String) { - this.bluePrintModelHandler.deleteBlueprintModel(id) - } - - @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String): BlueprintModelSearch { - return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) - } - - @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, - @PathVariable(value = "version") version: String): ResponseEntity { - return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) - } - - @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { - return this.bluePrintModelHandler.getBlueprintModelSearch(id) - } - - @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity { - return this.bluePrintModelHandler.downloadBlueprintModelFile(id) - } - - @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType - .MULTIPART_FORM_DATA_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity = runBlocking { - bluePrintModelHandler.enrichBlueprint(file) - } - - @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking { - bluePrintModelHandler.publishBlueprint(file) - } - - @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List { - return this.bluePrintModelHandler.searchBlueprintModels(tags) - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt deleted file mode 100644 index 04753391f..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2018-2019 Bell Canada 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.apps.controllerblueprints.service.controller - -import org.springframework.web.bind.annotation.RestControllerAdvice -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode -import org.onap.ccsdk.apps.controllerblueprints.service.common.ErrorMessage -import org.springframework.http.HttpStatus -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.ExceptionHandler - -/** - * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right - * HTTP code status - * - * @author Vinal Patel - * @version 1.0 - */ -@RestControllerAdvice("org.onap.ccsdk.apps.controllerblueprints") -open class ControllerBlueprintExeptionHandler { - - @ExceptionHandler - fun ControllerBlueprintException(e: BluePrintException): ResponseEntity { - var errorCode = ErrorCode.valueOf(e.code) - val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message") - return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode)) - } - - @ExceptionHandler - fun ControllerBlueprintException(e: Exception): ResponseEntity { - var errorCode = ErrorCode.GENERIC_FAILURE - val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message") - return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode)) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeController.kt deleted file mode 100644 index db82849e8..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeController.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.controller - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ModelTypeHandler -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.* - -@RestController -@RequestMapping(value = arrayOf("/api/v1/model-type")) -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) - } - - @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) - fun searchModelTypes(@PathVariable(value = "tags") tags: String): List { - return modelTypeHandler.searchModelTypes(tags) - } - - @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) - @ResponseBody - fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List { - return 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) - } - - @DeleteMapping(path = arrayOf("/{name}")) - fun deleteModelTypeByName(@PathVariable(value = "name") name: String) { - modelTypeHandler.deleteByModelName(name) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt deleted file mode 100644 index 38397faa0..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryController.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.controller - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ResourceDictionaryHandler -import org.springframework.http.MediaType -import org.springframework.web.bind.annotation.* - -@RestController -@RequestMapping(value = ["/api/v1/dictionary"]) -open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) { - - @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - @Throws(BluePrintException::class) - fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary { - return 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) - } - - @DeleteMapping(path = ["/{name}"]) - fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) { - resourceDictionaryHandler.deleteResourceDictionary(name) - } - - @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun searchResourceDictionaryByNames(@RequestBody names: List): List { - return resourceDictionaryHandler.searchResourceDictionaryByNames(names) - } - - @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List { - return resourceDictionaryHandler.searchResourceDictionaryByTags(tags) - - } - - @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) - @ResponseBody - fun getResourceSourceMapping(): ResourceSourceMapping { - return resourceDictionaryHandler.getResourceSourceMapping() - } - -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt deleted file mode 100644 index 3b14d82ff..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils -import org.springframework.stereotype.Service - -@Service -open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) - : BluePrintArtifactDefinitionEnhancer { - - companion object { - const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" - } - - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintArtifactDefinitionEnhancerImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) { - log.info("enhancing ArtifactDefinition($name)") - - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val artifactTypeName = artifactDefinition.type - ?: throw BluePrintException("artifact type is missing for ArtifactDefinition($name)") - - // Populate Artifact Type - BluePrintEnhancerUtils.populateArtifactType(bluePrintContext, bluePrintRepoService, artifactTypeName) - - when (artifactTypeName) { - ARTIFACT_TYPE_MAPPING_SOURCE -> { - enhanceMappingType(name, artifactDefinition) - } - } - } - - // Enhance Resource Mapping - open fun enhanceMappingType(name: String, artifactDefinition: ArtifactDefinition) { - - val artifactFilePath = "${bluePrintContext.rootPath}/${artifactDefinition.file}" - - val alreadyEnhancedKey = "enhanced-${artifactDefinition.file}" - val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) - - log.info("enhancing resource mapping file(${artifactDefinition.file}) already enhanced($alreadyEnhanced)") - - if (!alreadyEnhanced) { - val resourceAssignments: MutableList = JacksonUtils.getListFromFile(artifactFilePath, ResourceAssignment::class.java) - as? MutableList - ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($artifactFilePath)") - - // Call Resource Assignment Enhancer - resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) - - bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt deleted file mode 100644 index f69e344f8..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.AttributeDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils - -class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintAttributeDefinitionEnhancer { - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) { - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val propertyType = attributeDefinition.type - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { - - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - val entrySchema = attributeDefinition.entrySchema - ?: throw BluePrintException("Entry Schema is missing for collection property($name)") - - if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { - BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type) - } - } else { - BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType) - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt deleted file mode 100644 index da755d166..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt +++ /dev/null @@ -1,80 +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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils -import org.springframework.stereotype.Service -import java.util.* - -@Service -open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) - - override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { - - // Copy the Blueprint Content to Target Location - BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) - - // Enhance the Blueprint - return enhance(enrichedBasePath) - } - - @Throws(BluePrintException::class) - override suspend fun enhance(basePath: String): BluePrintContext { - - log.info("Enhancing blueprint($basePath)") - val blueprintRuntimeService = BluePrintMetadataUtils - .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath) - - try { - - bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template", - blueprintRuntimeService.bluePrintContext().serviceTemplate) - - log.info("##### Enhancing blueprint Resource Definitions") - val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService, - blueprintRuntimeService) - - // Write the Enhanced Blueprint Definitions - BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext()) - - // Write the Enhanced Blueprint Resource Definitions - ResourceDictionaryUtils.writeResourceDefinitionTypes(basePath, resourceDefinitions) - - if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) { - throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString()) - } - - } catch (e: Exception) { - throw e - } - return blueprintRuntimeService.bluePrintContext() - } - -} - diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt deleted file mode 100644 index 0765f9035..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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. - * 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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintNodeTemplateEnhancer { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { - log.info("***** Enhancing NodeTemplate($name)") - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - - val nodeTypeName = nodeTemplate.type - // Get NodeType from Repo and Update Service Template - val nodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, nodeTypeName) - - // Enrich NodeType - bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) - - //Enrich Node Template Artifacts - enhanceNodeTemplateArtifactDefinition(name, nodeTemplate) - } - - open fun enhanceNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { - - nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> - // Enhance Artifacct Definitions - bluePrintTypeEnhancerService.enhanceArtifactDefinition(bluePrintRuntimeService, artifactDefinitionName, artifactDefinition) - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt deleted file mode 100644 index 6ff0b39be..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt +++ /dev/null @@ -1,154 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.InterfaceDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.data.NodeType -import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTypeEnhancer { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTypeEnhancerImpl::class.toString()) - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) { - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - - val derivedFrom = nodeType.derivedFrom - - if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { - val derivedFromNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, name) - // Enrich NodeType - enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType) - } - - // NodeType Attribute Definitions - enrichNodeTypeAttributes(name, nodeType) - - // NodeType Property Definitions - enrichNodeTypeProperties(name, nodeType) - - //NodeType Requirement - enrichNodeTypeRequirements(name, nodeType) - - //NodeType Capability - enrichNodeTypeCapabilityProperties(name, nodeType) - - //NodeType Interface - enrichNodeTypeInterfaces(name, nodeType) - - } - - open fun enrichNodeTypeAttributes(nodeTypeName: String, nodeType: NodeType) { - nodeType.attributes?.let { - bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!) - } - } - - open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) { - nodeType.properties?.let { - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) - } - } - - open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) { - - nodeType.requirements?.forEach { requirementName, requirementDefinition -> - // Populate Requirement Node - requirementDefinition.node?.let { requirementNodeTypeName -> - // Get Requirement NodeType from Repo and Update Service Template - val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, - bluePrintRepoService, requirementNodeTypeName) - // Enhance Node Type - enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType) - - // Enhance Relationship Type - val relationShipTypeName = requirementDefinition.relationship - ?: throw BluePrintException("couldn't get relationship name for the NodeType($nodeTypeName) " + - "Requirement($requirementName)") - enrichRelationShipType(relationShipTypeName) - } - } - } - - open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) { - nodeType.capabilities?.forEach { _, capabilityDefinition -> - capabilityDefinition.properties?.let { properties -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties) - } - } - } - - open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) { - nodeType.interfaces?.forEach { interfaceName, interfaceObj -> - // Populate Node type Interface Operation - log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName) - populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj) - - } - } - - open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) { - - interfaceObj.operations?.forEach { operationName, operation -> - enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation) - enrichNodeTypeInterfaceOperationOutputs(nodeTypeName, operationName, operation) - } - } - - open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { - operation.inputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) - } - } - - open fun enrichNodeTypeInterfaceOperationOutputs(nodeTypeName: String, operationName: String, - operation: OperationDefinition) { - operation.outputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) - } - } - - /** - * Get the Relationship Type from database and add to Blueprint Context - */ - open fun enrichRelationShipType(relationshipName: String) { - BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, relationshipName) - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt deleted file mode 100644 index 80a84fcde..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import org.onap.ccsdk.apps.controllerblueprints.core.data.PolicyType -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPolicyTypeEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -class BluePrintPolicyTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintPolicyTypeEnhancer { - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: PolicyType) { - - this.bluePrintRuntimeService = bluePrintRuntimeService - - // TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt deleted file mode 100644 index 1675e8cd2..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - * 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.apps.controllerblueprints.service.enhancer - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintPropertyDefinitionEnhancer { - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val propertyType = propertyDefinition.type - if (BluePrintTypes.validPrimitiveTypes().contains(propertyType) - || BluePrintTypes.validComplexTypes().contains(propertyType)) { - // Do Nothing, - } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { - val entrySchema = propertyDefinition.entrySchema - ?: throw BluePrintException("Entry Schema is missing for collection property($name)") - - if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { - BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type) - } - } else { - BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType) - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt deleted file mode 100644 index 8c269e546..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) - : BluePrintServiceTemplateEnhancer { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateEnhancerImpl::class.toString()) - - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: ServiceTemplate) { - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - initialCleanUp() - enhanceTopologyTemplate() - } - - open fun initialCleanUp() { - bluePrintContext.serviceTemplate.artifactTypes?.clear() - bluePrintContext.serviceTemplate.nodeTypes?.clear() - bluePrintContext.serviceTemplate.dataTypes?.clear() - bluePrintContext.serviceTemplate.policyTypes?.clear() - bluePrintContext.serviceTemplate.relationshipTypes?.clear() - - bluePrintContext.serviceTemplate.artifactTypes = mutableMapOf() - bluePrintContext.serviceTemplate.nodeTypes = mutableMapOf() - bluePrintContext.serviceTemplate.dataTypes = mutableMapOf() - bluePrintContext.serviceTemplate.policyTypes = mutableMapOf() - bluePrintContext.serviceTemplate.relationshipTypes = mutableMapOf() - log.info("reinitialized all type definitions") - - } - - open fun enhanceTopologyTemplate() { - bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate -> - bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "topology_template", topologyTemplate) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt deleted file mode 100644 index 428d490b5..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import org.onap.ccsdk.apps.controllerblueprints.core.data.TopologyTemplate -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTopologyTemplateEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintTopologyTemplateEnhancer { - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: TopologyTemplate) { - this.bluePrintRuntimeService = bluePrintRuntimeService - - enhanceTopologyTemplateInputs(type) - enhanceTopologyTemplateNodeTemplates(type) - enhanceTopologyTemplateWorkflows(type) - } - - open fun enhanceTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { - topologyTemplate.inputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) - } - } - - open fun enhanceTopologyTemplateNodeTemplates(topologyTemplate: TopologyTemplate) { - topologyTemplate.nodeTemplates?.forEach { nodeTemplateName, nodeTemplate -> - bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, nodeTemplateName, nodeTemplate) - } - } - - open fun enhanceTopologyTemplateWorkflows(topologyTemplate: TopologyTemplate) { - topologyTemplate.workflows?.forEach { workflowName, workflow -> - bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintRuntimeService, workflowName, workflow) - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt deleted file mode 100644 index 02a19c3fc..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.* -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.ApplicationContext -import org.springframework.stereotype.Service - -@Service -open class BluePrintTypeEnhancerServiceImpl : BluePrintTypeEnhancerService { - - @Autowired - private lateinit var context: ApplicationContext - - override fun getServiceTemplateEnhancers(): List { - return context.getBeansOfType(BluePrintServiceTemplateEnhancer::class.java).map { it.value } - } - - override fun getTopologyTemplateEnhancers(): List { - return context.getBeansOfType(BluePrintTopologyTemplateEnhancer::class.java).map { it.value } - } - - override fun getWorkflowEnhancers(): List { - return context.getBeansOfType(BluePrintWorkflowEnhancer::class.java).map { it.value } - } - - override fun getNodeTemplateEnhancers(): List { - return context.getBeansOfType(BluePrintNodeTemplateEnhancer::class.java).map { it.value } - } - - override fun getNodeTypeEnhancers(): List { - return context.getBeansOfType(BluePrintNodeTypeEnhancer::class.java).map { it.value } - } - - override fun getArtifactDefinitionEnhancers(): List { - return context.getBeansOfType(BluePrintArtifactDefinitionEnhancer::class.java).map { it.value } - } - - override fun getPolicyTypeEnhancers(): List { - return context.getBeansOfType(BluePrintPolicyTypeEnhancer::class.java).map { it.value } - } - - override fun getPropertyDefinitionEnhancers(): List { - return context.getBeansOfType(BluePrintPropertyDefinitionEnhancer::class.java).map { it.value } - } - - override fun getAttributeDefinitionEnhancers(): List { - return context.getBeansOfType(BluePrintAttributeDefinitionEnhancer::class.java).map { it.value } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt deleted file mode 100644 index fc9ee5045..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive -import org.onap.ccsdk.apps.controllerblueprints.core.data.DataType -import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition -import org.onap.ccsdk.apps.controllerblueprints.core.data.Workflow -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, - private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) - : BluePrintWorkflowEnhancer { - private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintWorkflowEnhancerImpl::class.toString()) - - companion object { - const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" - const val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" - } - - lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> - lateinit var bluePrintContext: BluePrintContext - - private val workflowDataTypes: MutableMap = hashMapOf() - - override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) { - log.info("##### Enhancing Workflow($name)") - this.bluePrintRuntimeService = bluePrintRuntimeService - this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() - - val dynamicPropertyName = "$name-properties" - if (workflow.inputs == null) { - workflow.inputs = hashMapOf() - } - // Clean Dynamic Property Field, If present - workflow.inputs?.remove(dynamicPropertyName) - - // Enrich Only for Resource Assignment and Dynamic Input Properties if any - enhanceStepTargets(name, workflow) - - // Enrich Workflow Inputs - enhanceWorkflowInputs(name, workflow) - } - - open fun enhanceWorkflowInputs(name: String, workflow: Workflow) { - - workflow.inputs?.let { inputs -> - bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) - } - } - - private fun enhanceStepTargets(name: String, workflow: Workflow) { - - // Get the first Step Target NodeTemplate name( It may be Component or DG Node Template) - val firstNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) - - val derivedFrom = bluePrintContext.nodeTemplateNodeType(firstNodeTemplateName).derivedFrom - - when { - derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { - // DO Nothing - } - derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { - enhanceDGStepTargets(name, workflow, firstNodeTemplateName) - } - else -> { - throw BluePrintProcessorException("couldn't execute workflow($name) step mapped " + - "to node template($firstNodeTemplateName) derived from($derivedFrom)") - } - } - - } - - private fun enhanceDGStepTargets(name: String, workflow: Workflow, dgNodeTemplateName: String) { - - val dgNodeTemplate = bluePrintContext.nodeTemplateByName(dgNodeTemplateName) - - // Get the Dependent Component Node Template Names - val dependencyNodeTemplateNodes = dgNodeTemplate.properties?.get(PROPERTY_DEPENDENCY_NODE_TEMPLATES) - ?: throw BluePrintException("couldn't get property($PROPERTY_DEPENDENCY_NODE_TEMPLATES) ") - - val dependencyNodeTemplates = JacksonUtils.getListFromJsonNode(dependencyNodeTemplateNodes, String::class.java) - - log.info("workflow($name) dependent component NodeTemplates($dependencyNodeTemplates)") - - // Check and Get Resource Assignment File - val resourceAssignmentArtifacts = dependencyNodeTemplates?.mapNotNull { componentNodeTemplateName -> - log.info("identified workflow($name) targets($componentNodeTemplateName)") - - val resourceAssignmentArtifacts = bluePrintContext.nodeTemplateByName(componentNodeTemplateName) - .artifacts?.filter { - it.value.type == ARTIFACT_TYPE_MAPPING_SOURCE - }?.map { - log.info("resource assignment artifacts(${it.key}) for NodeType(${componentNodeTemplateName})") - it.value.file - } - resourceAssignmentArtifacts - }?.flatten() - - log.info("workflow($name) resource assignment files($resourceAssignmentArtifacts") - - if (resourceAssignmentArtifacts != null && resourceAssignmentArtifacts.isNotEmpty()) { - - // Add Workflow Dynamic Property - addWorkFlowDynamicPropertyDefinitions(name, workflow) - - resourceAssignmentArtifacts.forEach { fileName -> - // Enhance Resource Assignment File - val resourceAssignmentProperties = enhanceResourceAssignmentFile(fileName!!) - // Add Workflow Dynamic DataType - addWorkFlowDynamicDataType(name, resourceAssignmentProperties) - } - } - } - - // Enhancement for Dynamic Properties, Resource Assignment Properties, Resource Sources - private fun enhanceResourceAssignmentFile(fileName: String): MutableMap { - - val filePath = "${bluePrintContext.rootPath}/$fileName" - - log.info("enriching artifacts file(${filePath}") - - val resourceAssignmentProperties: MutableMap = hashMapOf() - - val resourceAssignments: MutableList = JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) - as? MutableList - ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") - - val alreadyEnhancedKey = "enhanced-$fileName" - val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) - - log.info("enhancing workflow resource mapping file($fileName) already enhanced($alreadyEnhanced)") - - if (!alreadyEnhanced) { - // Call Resource Assignment Enhancer - resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) - bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) - } - - resourceAssignments.forEach { resourceAssignment -> - resourceAssignmentProperties[resourceAssignment.name] = resourceAssignment.property!! - } - return resourceAssignmentProperties - } - - private fun addWorkFlowDynamicPropertyDefinitions(name: String, workflow: Workflow) { - val dynamicPropertyName = "$name-properties" - val propertyDefinition = PropertyDefinition() - propertyDefinition.description = "Dynamic PropertyDefinition for workflow($name)." - propertyDefinition.type = "dt-$dynamicPropertyName" - propertyDefinition.required = true - // Add to Workflow Inputs - workflow.inputs?.put(dynamicPropertyName, propertyDefinition) - } - - private fun addWorkFlowDynamicDataType(workflowName: String, mappingProperties: MutableMap) { - - val dataTypeName = "dt-$workflowName-properties" - - var dynamicDataType: DataType? = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) - - if (dynamicDataType == null) { - log.info("dataType not present for the recipe({})", dataTypeName) - dynamicDataType = DataType() - dynamicDataType.version = "1.0.0" - dynamicDataType.description = "Dynamic DataType definition for workflow($workflowName)." - dynamicDataType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC - - val dataTypeProperties: MutableMap = hashMapOf() - dynamicDataType.properties = dataTypeProperties - - // Overwrite WorkFlow DataType - bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dynamicDataType) - - } else { - log.info("dynamic dataType($dataTypeName) already present for workflow($workflowName).") - } - // Merge all the Recipe Properties - mappingProperties.forEach { propertyName, propertyDefinition -> - dynamicDataType.properties?.put(propertyName, propertyDefinition) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt deleted file mode 100644 index 4d1f44a6a..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService -import org.springframework.beans.factory.config.ConfigurableBeanFactory -import org.springframework.context.annotation.Scope -import org.springframework.stereotype.Service - -/** - * ResourceAssignmentEnhancerService. - * - * @author Brinda Santh - */ -interface ResourceAssignmentEnhancerService { - - @Throws(BluePrintException::class) - fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>, - resourceAssignments: List) -} - -/** - * ResourceAssignmentEnhancerDefaultService. - * - * @author Brinda Santh - */ -@Service -@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) - : ResourceAssignmentEnhancerService { - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceImpl::class.java) - - /** - * Get the defined source instance from the ResourceAssignment, - * then get the NodeType of the Sources assigned - */ - override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>, - resourceAssignments: List) { - - val uniqueSourceNodeTypeNames = hashSetOf() - - // Iterate the Resource Assignment and - resourceAssignments.map { resourceAssignment -> - val dictionaryName = resourceAssignment.dictionaryName!! - val dictionarySource = resourceAssignment.dictionarySource!! - log.debug("Enriching assignment name(${resourceAssignment.name}), dictionary name($dictionaryName), source($dictionarySource)") - val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource) - - // Add Unique Node Types - uniqueSourceNodeTypeNames.add(sourceNodeTypeName) - - // TODO("Candidate for Optimisation") - if (checkResourceDefinitionNeeded(resourceAssignment)) { - - bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintRuntimeService, resourceAssignment.name, - resourceAssignment.property!!); - - // Get the Resource Definition from Repo - val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) - - val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) - ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)") - - // Enrich as NodeTemplate - bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate) - } - } - // Enrich the ResourceSource NodeTypes - uniqueSourceNodeTypeNames.map { nodeTypeName -> - val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName) - bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) - } - - } - - private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean { - return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) - || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)) - && BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!)) - } - - private fun getResourceDefinition(name: String): ResourceDefinition { - return resourceDefinitionRepoService.getResourceDefinition(name) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt deleted file mode 100644 index 816b35664..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt +++ /dev/null @@ -1,145 +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.apps.controllerblueprints.service.enhancer - -import com.att.eelf.configuration.EELFLogger -import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.Deferred -import kotlinx.coroutines.async -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils -import org.onap.ccsdk.apps.controllerblueprints.service.ResourceDefinitionRepoService -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils -import org.springframework.stereotype.Service - -interface ResourceDefinitionEnhancerService { - - @Throws(BluePrintException::class) - fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>): List -} - -@Service -class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : - ResourceDefinitionEnhancerService { - - private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionEnhancerService::class.toString()) - - companion object { - const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" - } - - // Enhance the Resource Definition - // 1. Get the Resource Mapping files from all NodeTemplates. - // 2. Get all the Unique Resource assignments from all mapping files - // 3. Collect the Resource Definition for Resource Assignment names from database. - // 4. Create the Resource Definition under blueprint base path. - override fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, - bluePrintRuntimeService: BluePrintRuntimeService<*>): List { - - var resourceDefinitions: List = mutableListOf() - - val blueprintContext = bluePrintRuntimeService.bluePrintContext() - - val mappingFiles = getAllResourceMappingFiles(blueprintContext) - log.info("resources assignment files ($mappingFiles)") - if (mappingFiles != null) { - resourceDefinitions = getResourceDefinition(blueprintContext, mappingFiles) - // Enriching Resource Definition Sources - enrichResourceDefinitionSources(bluePrintRuntimeService.bluePrintContext(), resourceDefinitions) - } - return resourceDefinitions - } - - // Get all the Mapping files from all node templates. - private fun getAllResourceMappingFiles(blueprintContext: BluePrintContext): List? { - - return blueprintContext.nodeTemplates()?.mapNotNull { nodeTemplateMap -> - - // Return only Mapping Artifact File Names - nodeTemplateMap.value.artifacts?.filter { artifactDefinitionMap -> - artifactDefinitionMap.value.type == ARTIFACT_TYPE_MAPPING_SOURCE - }?.mapNotNull { artifactDefinitionMap -> - artifactDefinitionMap.value.file - } - - }?.flatten()?.distinct() - } - - // Convert file content to ResourceAssignments asynchronously - private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List) = runBlocking { - val blueprintBasePath = blueprintContext.rootPath - val deferredResourceAssignments = mutableListOf>>() - for (file in files) { - log.info("processing file ($file)") - deferredResourceAssignments += async { - ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") - } - } - - val resourceAssignments = mutableListOf() - for (deferredResourceAssignment in deferredResourceAssignments) { - resourceAssignments.addAll(deferredResourceAssignment.await()) - } - - val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } - generateResourceDictionary(blueprintBasePath, distinctResourceAssignments) - //log.info("distinct Resource assignment ($distinctResourceAssignments)") - } - - - // Read the Resource Definitions from the Database and write to type file. - private fun generateResourceDictionary(blueprintBasePath: String, resourceAssignments: List) - : List { - val resourceKeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct().sorted() - log.info("distinct resource keys ($resourceKeys)") - - //TODO("Optimise DB single Query to multiple Query") - return resourceKeys.map { resourceKey -> - getResourceDefinition(resourceKey) - } - } - - private fun enrichResourceDefinitionSources(bluePrintContext: BluePrintContext, - resourceDefinitions: List) { - val sources = resourceDefinitions - .map { it.sources } - .map { - it.values - .map { nodeTemplate -> - nodeTemplate.type - } - } - .flatten().distinct() - log.info("Enriching Resource Definition sources Node Template: $sources") - sources.forEach { - BluePrintEnhancerUtils.populateNodeType(bluePrintContext, resourceDefinitionRepoService, it) - } - } - - // Get the Resource Definition from Database - private fun getResourceDefinition(name: String): ResourceDefinition { - return resourceDefinitionRepoService.getResourceDefinition(name) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt deleted file mode 100644 index 11087bc52..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/BluePrintModelHandler.kt +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * 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. - * 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.apps.controllerblueprints.service.handler - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository -import org.onap.ccsdk.apps.controllerblueprints.service.utils.BluePrintEnhancerUtils -import org.springframework.core.io.ByteArrayResource -import org.springframework.core.io.Resource -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType -import org.springframework.http.ResponseEntity -import org.springframework.http.codec.multipart.FilePart -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional -import reactor.core.publisher.Mono -import java.io.File -import java.io.IOException -import java.util.* - -/** - * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest - * - * @author Brinda Santh - * @version 1.0 - */ - -@Service -open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintCatalogService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintModelSearchRepository: ControllerBlueprintModelSearchRepository, - private val blueprintModelRepository: ControllerBlueprintModelRepository, - private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository, - private val bluePrintEnhancerService: BluePrintEnhancerService) { - - /** - * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database - * - * @return List list of the controller blueprint archives - */ - open fun allBlueprintModel(): List { - return blueprintModelSearchRepository.findAll() - } - - /** - * This is a saveBlueprintModel method - * - * @param filePart filePart - * @return Mono - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun saveBlueprintModel(filePart: FilePart): Mono { - try { - val cbaLocation = BluePrintFileUtils.getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath) - return BluePrintEnhancerUtils.saveCBAFile(filePart, cbaLocation).map { fileName -> - var blueprintId: String? = null - try { - blueprintId = bluePrintCatalogService.saveToDatabase(cbaLocation.resolve(fileName).toFile(), false) - } catch (e: BluePrintException) { - // FIXME handle expection - } - blueprintModelSearchRepository.findById(blueprintId!!).get() - } - } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - String.format("I/O Error while uploading the CBA file: %s", e.message), e) - } - - } - - - /** - * This is a searchBlueprintModels method - * - * @param tags tags - * @return List - */ - open fun searchBlueprintModels(tags: String): List { - return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags) - } - - /** - * This is a getBlueprintModelSearchByNameAndVersion method - * - * @param name name - * @param version version - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch { - val blueprintModelSearch: BlueprintModelSearch - val dbBlueprintModel = blueprintModelSearchRepository - .findByArtifactNameAndArtifactVersion(name, version) - if (dbBlueprintModel.isPresent) { - blueprintModelSearch = dbBlueprintModel.get() - } else { - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, - String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)) - } - return blueprintModelSearch - } - - /** - * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version - * - * @param name name - * @param version version - * @return ResponseEntity - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun downloadBlueprintModelFileByNameAndVersion(name: String, - version: String): ResponseEntity { - val blueprintModel: BlueprintModel - try { - blueprintModel = getBlueprintModelByNameAndVersion(name, version) - } catch (e: BluePrintException) { - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e) - } - - val fileName = blueprintModel.id + ".zip" - val file = blueprintModel.blueprintModelContent.content - return prepareResourceEntity(fileName, file) - } - - /** - * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource - * - * @return ResponseEntity - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun downloadBlueprintModelFile(id: String): ResponseEntity { - val blueprintModel: BlueprintModel - try { - blueprintModel = getBlueprintModel(id) - } catch (e: BluePrintException) { - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e) - } - - val fileName = blueprintModel.id + ".zip" - val file = blueprintModel.blueprintModelContent.content - return prepareResourceEntity(fileName, file) - } - - /** - * @return ResponseEntity - */ - private fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity { - return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") - .body(ByteArrayResource(file)) - } - - /** - * This is a getBlueprintModel method - * - * @param id id - * @return BlueprintModel - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun getBlueprintModel(id: String): BlueprintModel { - val blueprintModel: BlueprintModel - val dbBlueprintModel = blueprintModelRepository.findById(id) - if (dbBlueprintModel.isPresent) { - blueprintModel = dbBlueprintModel.get() - } else { - val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) - } - return blueprintModel - } - - /** - * This is a getBlueprintModelByNameAndVersion method - * - * @param name name - * @param version version - * @return BlueprintModel - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun getBlueprintModelByNameAndVersion(name: String, version: String): BlueprintModel { - val blueprintModel = blueprintModelRepository - .findByArtifactNameAndArtifactVersion(name, version) - if (blueprintModel != null) { - return blueprintModel - } else { - val msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version) - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) - } - } - - /** - * This is a getBlueprintModelSearch method - * - * @param id id - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun getBlueprintModelSearch(id: String): BlueprintModelSearch { - val blueprintModelSearch: BlueprintModelSearch - val dbBlueprintModel = blueprintModelSearchRepository.findById(id) - if (dbBlueprintModel.isPresent) { - blueprintModelSearch = dbBlueprintModel.get() - } else { - val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) - } - - return blueprintModelSearch - } - - /** - * This is a deleteBlueprintModel method - * - * @param id id - * @throws BluePrintException BluePrintException - */ - @Transactional - @Throws(BluePrintException::class) - open fun deleteBlueprintModel(id: String) { - val dbBlueprintModel = blueprintModelRepository.findById(id) - if (dbBlueprintModel.isPresent) { - blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get()) - blueprintModelRepository.delete(dbBlueprintModel.get()) - } else { - val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) - throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) - } - } - - /** - * This is a CBA enrichBlueprint method - * Save the Zip File in archive location and extract the cba content. - * Populate the Enhancement Location - * Enhance the CBA content - * Compress the Enhanced Content - * Return back the the compressed content back to the caller. - * - * @param filePart filePart - * @return ResponseEntity - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity { - val enhanceId = UUID.randomUUID().toString() - val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, enhanceId) - val blueprintEnrichmentDir = normalizedPathName(bluePrintLoadConfiguration.blueprintEnrichmentPath, enhanceId) - try { - BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) - - // Enhance the Blue Prints - bluePrintEnhancerService.enhance(blueprintEnrichmentDir) - - return BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentDir, blueprintArchive) - - } catch (e: IOException) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Enriching CBA: ${e.message}", e) - } finally { - BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) - } - } - - /** - * This is a publishBlueprintModel method to change the status published to YES - * - * @param filePart filePart - * @return BlueprintModelSearch - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch { - val publishId = UUID.randomUUID().toString() - val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(publishId) - val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(publishId) - try { - val compressedFilePart = BluePrintEnhancerUtils - .extractCompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) - - val blueprintId = bluePrintCatalogService.saveToDatabase(compressedFilePart, true) - - return blueprintModelSearchRepository.findById(blueprintId).get() - - } catch (e: Exception) { - throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, - "Error in Publishing CBA: ${e.message}", e) - } finally { - BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) - } - } - - companion object { - - private const val BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo" - private const val BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + " and version(%s) from repo" - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ModelTypeHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ModelTypeHandler.kt deleted file mode 100644 index 8099d07ff..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ModelTypeHandler.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.handler - -import com.att.eelf.configuration.EELFManager -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ModelTypeRepository -import org.onap.ccsdk.apps.controllerblueprints.service.validator.ModelTypeValidator -import org.springframework.stereotype.Service - -@Service -open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository) { - - private val log = EELFManager.getInstance().getLogger(ModelTypeHandler::class.java)!! - - /** - * This is a getModelTypeByName service - * - * @param modelTypeName modelTypeName - * @return ModelType - */ - fun getModelTypeByName(modelTypeName: String): ModelType? { - log.info("Searching : $modelTypeName") - check(modelTypeName.isNotBlank()) { "Model Name Information is missing." } - return modelTypeRepository.findByModelName(modelTypeName) - } - - - /** - * This is a searchModelTypes service - * - * @param tags tags - * @return List - */ - fun searchModelTypes(tags: String): List { - check(tags.isNotBlank()) { "No Search Information provide" } - return modelTypeRepository.findByTagsContainingIgnoreCase(tags) - } - - /** - * This is a saveModel service - * - * @param modelType modelType - * @return ModelType - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - open fun saveModel(modelType: ModelType): ModelType { - lateinit var dbModel: ModelType - ModelTypeValidator.validateModelType(modelType) - val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) - if (dbModelType != null) { - dbModel = dbModelType - dbModel.description = modelType.description - dbModel.definition = modelType.definition - dbModel.definitionType = modelType.definitionType - dbModel.derivedFrom = modelType.derivedFrom - dbModel.tags = modelType.tags - dbModel.version = modelType.version - dbModel.updatedBy = modelType.updatedBy - dbModel = modelTypeRepository.save(dbModel) - } else { - dbModel = modelTypeRepository.save(modelType) - } - return dbModel - } - - - /** - * This is a deleteByModelName service - * - * @param modelName modelName - */ - open fun deleteByModelName(modelName: String) { - check(modelName.isNotBlank()) { "Model Name Information is missing." } - modelTypeRepository.deleteByModelName(modelName) - - } - - /** - * This is a getModelTypeByDefinitionType service - * - * @param definitionType definitionType - * @return List - */ - fun getModelTypeByDefinitionType(definitionType: String): List { - check(definitionType.isNotBlank()) { "Model definitionType Information is missing." } - return modelTypeRepository.findByDefinitionType(definitionType) - } - - /** - * This is a getModelTypeByDerivedFrom service - * - * @param derivedFrom derivedFrom - * @return List - */ - fun getModelTypeByDerivedFrom(derivedFrom: String): List { - check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } - return modelTypeRepository.findByDerivedFrom(derivedFrom) - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt deleted file mode 100644 index ec7d8aebc..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/handler/ResourceDictionaryHandler.kt +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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. - * 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.apps.controllerblueprints.service.handler - -import com.google.common.base.Preconditions -import org.apache.commons.collections.CollectionUtils -import org.apache.commons.lang3.StringUtils -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ResourceDictionaryRepository -import org.springframework.stereotype.Service - -@Service -class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) { - - - /** - * This is a getDataDictionaryByName service - * - * @param name name - * @return DataDictionary - * @throws BluePrintException BluePrintException - */ - @Throws(BluePrintException::class) - 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() - } else { - throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)) - } - } - - /** - * This is a searchResourceDictionaryByNames service - * - * @param names names - * @return List - */ - fun searchResourceDictionaryByNames(names: List): List { - Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide") - return resourceDictionaryRepository.findByNameIn(names) - } - - /** - * This is a searchResourceDictionaryByTags service - * - * @param tags tags - * @return List - */ - fun searchResourceDictionaryByTags(tags: String): List { - Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide") - return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags) - } - - /** - * This is a saveDataDictionary service - * - * @param resourceDictionary resourceDictionary - * @return DataDictionary - */ - @Throws(BluePrintException::class) - fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { - var resourceDictionary = resourceDictionary - - val resourceDefinition = resourceDictionary.definition - Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content") - // Validate the Resource Definitions - //TODO( Save Validator) - //validate(resourceDefinition) - - resourceDictionary.tags = resourceDefinition.tags - resourceDefinition.updatedBy = resourceDictionary.updatedBy - // Set the Property Definitions - val propertyDefinition = resourceDefinition.property - resourceDictionary.description = propertyDefinition.description - resourceDictionary.dataType = propertyDefinition.type - if (propertyDefinition.entrySchema != null) { - resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type - } - - validateResourceDictionary(resourceDictionary) - - val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) - if (dbResourceDictionaryData.isPresent) { - val dbResourceDictionary = dbResourceDictionaryData.get() - - dbResourceDictionary.name = resourceDictionary.name - dbResourceDictionary.definition = resourceDictionary.definition - dbResourceDictionary.description = resourceDictionary.description - dbResourceDictionary.tags = resourceDictionary.tags - dbResourceDictionary.updatedBy = resourceDictionary.updatedBy - dbResourceDictionary.dataType = resourceDictionary.dataType - dbResourceDictionary.entrySchema = resourceDictionary.entrySchema - resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary) - } else { - resourceDictionary = resourceDictionaryRepository.save(resourceDictionary) - } - - return resourceDictionary - } - - /** - * This is a deleteResourceDictionary service - * - * @param name name - */ - fun deleteResourceDictionary(name: String) { - check(name.isNotBlank()) { "Resource dictionary name is missing." } - resourceDictionaryRepository.deleteByName(name) - } - - /** - * This is a getResourceSourceMapping service - */ - fun getResourceSourceMapping(): ResourceSourceMapping { - return ResourceSourceMappingFactory.getRegisterSourceMapping() - } - - private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean { - checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.") - checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." } - checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.") - checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.") - checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.") - return true - - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt deleted file mode 100644 index 948601cf4..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintCatalogLoadService.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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.apps.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.apps.controllerblueprints.core.interfaces.BluePrintCatalogService -import org.springframework.stereotype.Service -import java.io.File - -@Service -open class BluePrintCatalogLoadService(private val bluePrintCatalogService: BluePrintCatalogService) { - - private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java) - - open fun loadPathsBluePrintModelCatalog(paths: List) { - paths.forEach { loadPathBluePrintModelCatalog(it) } - } - - open fun loadPathBluePrintModelCatalog(path: String) { - - val files = File(path).listFiles() - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf>() - - for (file in files) { - deferredResults += async { - loadBluePrintModelCatalog(errorBuilder, file) - } - } - - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } - } - } - - open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) { - try { - bluePrintCatalogService.saveToDatabase(file) - } catch (e: Exception) { - errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}") - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt deleted file mode 100644 index 8144a1e79..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.load - -import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.runBlocking -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.springframework.boot.context.event.ApplicationReadyEvent -import org.springframework.context.event.EventListener -import org.springframework.stereotype.Service - -@Service -open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val modelTypeLoadService: ModelTypeLoadService, - private val resourceDictionaryLoadService: ResourceDictionaryLoadService, - private val bluePrintCatalogLoadService: BluePrintCatalogLoadService) { - - private val log = EELFManager.getInstance().getLogger(BluePrintDatabaseLoadService::class.java) - - - @EventListener(ApplicationReadyEvent::class) - open fun init() { - if (bluePrintLoadConfiguration.loadInitialData) { - initModelTypes() - initResourceDictionary() - initBluePrintCatalog() - } else { - log.info("Initial data load is disabled") - } - } - - open 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) - } - } - } - } - - open fun initResourceDictionary() { - log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " + - "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") - - if (bluePrintLoadConfiguration.loadResourceDictionary) { - val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",") - paths?.let { - resourceDictionaryLoadService.loadPathsResourceDictionary(paths) - } - } - } - - open fun initBluePrintCatalog() { - log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " + - "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") - - if (bluePrintLoadConfiguration.loadBluePrint) { - val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",") - paths?.let { - bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths) - } - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt deleted file mode 100755 index 17149e466..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * 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. - * 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.apps.controllerblueprints.service.load - -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants -import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration -import org.onap.ccsdk.apps.controllerblueprints.core.data.ErrorCode -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent -import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository -import org.slf4j.LoggerFactory -import org.springframework.dao.DataIntegrityViolationException -import org.springframework.stereotype.Service -import java.io.File -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -/** - * Similar implementation in [org.onap.ccsdk.apps.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl] - */ -@Service -class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService, - private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, - private val blueprintModelRepository: ControllerBlueprintModelRepository) - : BlueprintCatalogServiceImpl(bluePrintValidatorService) { - - - private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString()) - - init { - log.info("BlueprintProcessorCatalogServiceImpl initialized") - } - - override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) - - override fun get(name: String, version: String, extract: Boolean): Path? { - val path = if (extract) { - Paths.get("${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version") - } else { - Paths.get("${bluePrintLoadConfiguration.blueprintArchivePath}/$name/$version.zip") - } - blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { - it.blueprintModelContent.run { - path.toFile().writeBytes(this!!.content!!).let { - return path - } - } - } - return null - } - - override fun save(metadata: MutableMap, archiveFile: File) { - - val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] - val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] - - - blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { - log.info("Overwriting blueprint model :$artifactName::$artifactVersion") - blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) - } - - val blueprintModel = BlueprintModel() - blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL - blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] - ?: BluePrintConstants.FLAG_N - blueprintModel.artifactName = artifactName - blueprintModel.artifactVersion = artifactVersion - blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] - blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] - blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" - - val blueprintModelContent = BlueprintModelContent() - blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] - blueprintModelContent.contentType = "CBA_ZIP" - blueprintModelContent.name = "$artifactName:$artifactVersion" - blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" - blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) - blueprintModelContent.blueprintModel = blueprintModel - // Set the Blueprint Model Content into blueprintModel - blueprintModel.blueprintModelContent = blueprintModelContent - - try { - blueprintModelRepository.saveAndFlush(blueprintModel) - } catch (ex: DataIntegrityViolationException) { - throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + - "is already exist in database: ${ex.message}", ex) - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt deleted file mode 100644 index 061ef88ef..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ModelTypeLoadService.kt +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.load - -import com.att.eelf.configuration.EELFManager -import kotlinx.coroutines.* -import org.apache.commons.io.FilenameUtils -import org.apache.commons.lang3.text.StrBuilder -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -import org.onap.ccsdk.apps.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) { - - private val log = EELFManager.getInstance().getLogger(ModelTypeLoadService::class.java) - private val updateBySystem = "System" - - open suspend fun loadPathsModelType(modelTypePaths: List) { - modelTypePaths.forEach { runBlocking { 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 { - log.info(" *************************** loadModelType **********************") - try { - val errorBuilder = StrBuilder() - - coroutineScope { - val dataTypeFiles = File("$modelTypePath/data_type").listFiles() - - val deferredResults = mutableListOf>() - - for (file in dataTypeFiles) deferredResults += async { - loadModelType(file, DataType::class.java, errorBuilder) - } - - deferredResults.awaitAll() - } - - coroutineScope { - val artifactTypeFiles = File("$modelTypePath/artifact_type").listFiles() - - val deferredResults = mutableListOf>() - - for (file in artifactTypeFiles) deferredResults += async { - loadModelType(file, - ArtifactType::class.java, errorBuilder) - } - - deferredResults.awaitAll() - } - - coroutineScope { - val relationshipTypeFiles = File("$modelTypePath/relationship_type").listFiles() - - val deferredResults = mutableListOf>() - - for (file in relationshipTypeFiles) deferredResults += async { - loadModelType(file, - RelationshipType::class.java, errorBuilder) - } - - deferredResults.awaitAll() - } - - coroutineScope { - val nodeTypeFiles = File("$modelTypePath/node_type").listFiles() - - val deferredResults = mutableListOf>() - - for (file in nodeTypeFiles) deferredResults += async { - loadModelType(file, - NodeType::class.java, errorBuilder) - } - deferredResults.awaitAll() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } - } catch (e: Exception) { - log.error("Failed to loade ModelTypes under($modelTypePath)", e) - } - } - - private inline fun loadModelType(file: File, classType: Class, errorBuilder: StrBuilder) { - try { - log.trace("Loading ${classType.name} (${file.name})") - val dataKey = FilenameUtils.getBaseName(file.name) - val definitionContent = file.readText(Charset.defaultCharset()) - val definition = JacksonUtils.readValue(definitionContent, classType) as EntityType - //checkNotNull(definition) { "failed to get data type from file : ${file.name}" } - - val modelType = ModelType() - val definitionType: String? - when (T::class) { - DataType::class -> { - definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE - } - RelationshipType::class -> { - definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE - } - ArtifactType::class -> { - definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE - } - NodeType::class -> { - definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE - } - else -> { - throw BluePrintException("couldn't process model type($classType) definition") - } - } - modelType.definitionType = definitionType - modelType.derivedFrom = definition.derivedFrom - modelType.description = definition.description - modelType.definition = JacksonUtils.jsonNode(definitionContent) - modelType.modelName = dataKey - modelType.version = definition.version - modelType.updatedBy = updateBySystem - modelType.tags = (dataKey + "," + definition.derivedFrom + "," + definitionType) - modelTypeHandler.saveModel(modelType) - log.trace("${classType.name}(${file.name}) loaded successfully ") - } catch (e: Exception) { - errorBuilder.appendln("Couldn't load ${classType.name}(${file.name}: ${e.message}") - } - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt deleted file mode 100644 index 8100cac39..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/load/ResourceDictionaryLoadService.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.apps.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.StringUtils -import org.apache.commons.lang3.text.StrBuilder -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary -import org.onap.ccsdk.apps.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) { - paths.forEach { loadPathResourceDictionary(it) } - } - - open fun loadPathResourceDictionary(path: String) { - log.info(" *************************** loadResourceDictionary **********************") - val files = File(path).listFiles() - - runBlocking { - val errorBuilder = StrBuilder() - val deferredResults = mutableListOf>() - - for (file in files) { - deferredResults += async { - loadResourceDictionary(errorBuilder, file) - } - } - - for (deferredResult in deferredResults) { - deferredResult.await() - } - - if (!errorBuilder.isEmpty) { - log.error(errorBuilder.toString()) - } - } - } - - private fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { - try { - log.trace("Loading NodeType(${file.name}") - val definitionContent = file.readText(Charset.defaultCharset()) - val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java) - if (resourceDefinition != null) { - - checkNotNull(resourceDefinition.property) { "Failed to get Property Definition" } - val resourceDictionary = ResourceDictionary() - resourceDictionary.name = resourceDefinition.name - resourceDictionary.definition = resourceDefinition - - checkNotNull(resourceDefinition.property) { "Property field is missing" } - resourceDictionary.description = resourceDefinition.property.description - resourceDictionary.dataType = resourceDefinition.property.type - - if (resourceDefinition.property.entrySchema != null) { - resourceDictionary.entrySchema = resourceDefinition.property.entrySchema!!.type - } - resourceDictionary.updatedBy = resourceDefinition.updatedBy - - if (StringUtils.isBlank(resourceDefinition.tags)) { - resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy - + ", " + resourceDefinition.updatedBy) - - } else { - resourceDictionary.tags = resourceDefinition.tags - } - resourceDictionaryHandler.saveResourceDictionary(resourceDictionary) - - log.trace("Resource dictionary(${file.name}) loaded successfully ") - } else { - throw BluePrintException("couldn't get dictionary from content information") - } - } catch (e: Exception) { - errorBuilder.appendln("Couldn't load Resource dictionary (${file.name}: ${e.message}") - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt deleted file mode 100644 index 141ba92c6..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt +++ /dev/null @@ -1,76 +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.apps.controllerblueprints.service.repository - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -import org.springframework.stereotype.Service -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import reactor.core.scheduler.Schedulers - -/** - * ModelTypeReactRepository. - * - * @author Brinda Santh - */ -@Service -open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) { - - fun save(modelType: ModelType): Mono { - return Mono.justOrEmpty(modelTypeRepository.save(modelType)) - } - - fun findByModelName(modelName: String): Mono { - return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName)) - } - - fun findByModelNameIn(modelNames: List): Flux { - return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByDerivedFrom(derivedFrom: String): Flux { - return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByDerivedFromIn(derivedFroms: List): Flux { - return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByDefinitionType(definitionType: String): Flux { - return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByDefinitionTypeIn(definitionTypes: List): Flux { - return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByTagsContainingIgnoreCase(tags: String): Flux { - return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) - .subscribeOn(Schedulers.elastic()) - } - - fun deleteByModelName(modelName: String): Mono { - modelTypeRepository.deleteByModelName(modelName) - return Mono.empty() - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt deleted file mode 100644 index 7cda72763..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 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.apps.controllerblueprints.service.repository - -import org.onap.ccsdk.apps.controllerblueprints.db.resources.repository.ModelContentRepository -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent - -interface ControllerBlueprintModelContentRepository : ModelContentRepository diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt deleted file mode 100644 index ec1175072..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 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.apps.controllerblueprints.service.repository - -import org.onap.ccsdk.apps.controllerblueprints.db.resources.repository.ModelRepository -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel - -interface ControllerBlueprintModelRepository : ModelRepository diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.kt deleted file mode 100644 index 990cc6518..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeRepository.kt +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.repository - -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.stereotype.Repository -import javax.transaction.Transactional - -@Repository -interface ModelTypeRepository : JpaRepository { - /** - * This is a findByModelName method - * - * @param modelName Model Name - * @return Optional - */ - fun findByModelName(modelName: String): ModelType? - /** - * This is a findByModelNameIn method - * - * @param modelNames Model Names - * @return List - */ - fun findByModelNameIn(modelNames: List): List - /** - * This is a findByDerivedFrom method - * - * @param derivedFrom Derived From - * @return List - */ - fun findByDerivedFrom(derivedFrom: String): List - /** - * This is a findByDerivedFromIn method - * - * @param derivedFroms Derived Froms - * @return List - */ - fun findByDerivedFromIn(derivedFroms: List): List - - /** - * This is a findByDefinitionType method - * - * @param definitionType Definition Type - * @return List - */ - fun findByDefinitionType(definitionType: String): List - /** - * This is a findByDefinitionTypeIn method - * - * @param definitionTypes Definition Types - * @return List - */ - fun findByDefinitionTypeIn(definitionTypes: List): List - - /** - * This is a findByTagsContainingIgnoreCase method - * - * @param tags Tags - * @return Optional - */ - fun findByTagsContainingIgnoreCase(tags: String): List - - /** - * This is a deleteByModelName method - * - * @param modelName ModelName - */ - @Transactional - fun deleteByModelName(modelName: String) -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt deleted file mode 100644 index 0865b69da..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/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.apps.controllerblueprints.service.repository - -import org.onap.ccsdk.apps.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 { - return Mono.justOrEmpty(resourceDictionaryRepository.save(resourceDictionary)) - } - - fun findByName(name: String): Mono { - return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) - } - - fun findByNameIn(names: List): Flux { - return Flux.fromIterable(resourceDictionaryRepository.findByNameIn(names)) - .subscribeOn(Schedulers.elastic()) - } - - fun findByTagsContainingIgnoreCase(tags: String): Flux { - return Flux.fromIterable(resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags)) - .subscribeOn(Schedulers.elastic()) - } - - fun deleteByName(name: String): Mono { - 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/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt deleted file mode 100644 index 41a7bf8a5..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2019 Bell Canada. - * 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. - * 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.apps.controllerblueprints.service.utils - -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.reactive.awaitSingle -import kotlinx.coroutines.withContext -import org.onap.ccsdk.apps.controllerblueprints.core.* -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintRepoService -import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.springframework.core.io.ByteArrayResource -import org.springframework.core.io.Resource -import org.springframework.http.HttpHeaders -import org.springframework.http.MediaType -import org.springframework.http.ResponseEntity -import org.springframework.http.codec.multipart.FilePart -import org.springframework.util.StringUtils -import reactor.core.publisher.Mono -import java.io.File -import java.io.IOException -import java.nio.file.Path -import java.nio.file.Paths -import java.util.* - - -class BluePrintEnhancerUtils { - companion object { - - fun populateDataTypes(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - dataTypeName: String): DataType { - val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) - ?: bluePrintRepoService.getDataType(dataTypeName) - ?: throw BluePrintException("couldn't get DataType($dataTypeName) from repo.") - bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dataType) - return dataType - } - - fun populateRelationshipType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - relationshipName: String): RelationshipType { - - val relationshipType = bluePrintContext.serviceTemplate.relationshipTypes?.get(relationshipName) - ?: bluePrintRepoService.getRelationshipType(relationshipName) - ?: throw BluePrintException("couldn't get RelationshipType($relationshipName) from repo.") - bluePrintContext.serviceTemplate.relationshipTypes?.put(relationshipName, relationshipType) - return relationshipType - } - - - fun populateNodeType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - nodeTypeName: String): NodeType { - - val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName) - ?: bluePrintRepoService.getNodeType(nodeTypeName) - ?: throw BluePrintException("couldn't get NodeType($nodeTypeName) from repo.") - bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) - return nodeType - } - - fun populateArtifactType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, - artifactTypeName: String): ArtifactType { - - val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) - ?: bluePrintRepoService.getArtifactType(artifactTypeName) - ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.") - bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) - return artifactType - } - - private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { - // Delete the Directory - targetFile.deleteRecursively() - return filePart.transferTo(targetFile) - .thenReturn(targetFile) - .awaitSingle() - } - - suspend fun extractCompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { - //Recreate the Base Directories - normalizedFile(archiveDir).reCreateDirs() - normalizedFile(enhanceDir).reCreateDirs() - val filePartFile = normalizedFile(archiveDir, "cba.zip") - // Copy the File Part to ZIP - return copyFromFilePart(filePart, filePartFile) - } - - suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { - val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir) - val deCompressFileName = normalizedPathName(enhanceDir) - return filePartFile.deCompress(deCompressFileName) - } - - suspend fun compressToFilePart(enhanceDir: String, archiveDir: String): ResponseEntity { - val compressedFile = normalizedFile(archiveDir, "enhanced-cba.zip") - BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile, true) - return prepareResourceEntity(compressedFile.name, compressedFile.readBytes()) - } - - suspend fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity { - return ResponseEntity.ok() - .contentType(MediaType.parseMediaType("text/plain")) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") - .body(ByteArrayResource(file)) - } - - suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) { - deleteDir(archiveLocation) - deleteDir(enhancementLocation) - } - - /** - * This is a saveCBAFile method - * take a [FilePart], transfer it to disk using a Flux of FilePart and return a [Mono] representing the CBA file name - * - * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save - * @return a [Mono] String representing the result of the operation - * @throws (BluePrintException, IOException) BluePrintException, IOException - */ - @Throws(BluePrintException::class, IOException::class) - fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Mono { - - // Normalize file name - val fileName = StringUtils.cleanPath(filePart.filename()) - - // Check if the file's extension is "CBA" - if (StringUtils.getFilenameExtension(fileName) != "zip") { - throw BluePrintException(ErrorCode.INVALID_FILE_EXTENSION.value, "Invalid file extension required ZIP") - } - - // Change file name to match a pattern - val changedFileName = UUID.randomUUID().toString() + ".zip" - //String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); - - // Copy file to the target location (Replacing existing file with the same name) - val targetLocation = targetDirectory.resolve(changedFileName) - - // if a file with the same name already exists in a repository, delete and recreate it - val file = File(targetLocation.toString()) - if (file.exists()) - file.delete() - file.createNewFile() - - return filePart.transferTo(file).thenReturn(changedFileName) - } - } -} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.kt deleted file mode 100644 index 1428c81d6..000000000 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidator.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.validator - -import com.fasterxml.jackson.databind.JsonNode -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.data.* -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType - -class ModelTypeValidator { - companion object { - /** - * This is a validateModelTypeDefinition - * - * @param definitionType definitionType - * @param definitionContent definitionContent - * @return boolean - */ - fun validateModelTypeDefinition(definitionType: String, definitionContent: JsonNode): Boolean { - - when (definitionType) { - BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE -> { - JacksonUtils.readValue(definitionContent, DataType::class.java) - ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent") - } - BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE -> { - JacksonUtils.readValue(definitionContent, NodeType::class.java) - ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent") - } - BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE -> { - JacksonUtils.readValue(definitionContent, ArtifactType::class.java) - ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent") - } - BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE -> { - JacksonUtils.readValue(definitionContent, CapabilityDefinition::class.java) - ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent") - } - BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE -> { - JacksonUtils.readValue(definitionContent, RelationshipType::class.java) - ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent") - } - } - return true - } - - /** - * This is a validateModelType method - * - * @param modelType modelType - * @return boolean - */ - fun validateModelType(modelType: ModelType?): Boolean { - checkNotNull(modelType) { "Model Type Information is missing." } - - val validRootTypes = BluePrintTypes.validModelTypes() - - check(validRootTypes.contains(modelType.definitionType)) { - "Not Valid Model Root Type(${modelType.definitionType}), It should be $validRootTypes" - } - - validateModelTypeDefinition(modelType.definitionType, modelType.definition) - return true - } - } - -} 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 new file mode 100644 index 000000000..8ede9f208 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/BluePrintRepoServiceImpl.kt @@ -0,0 +1,105 @@ +/* + * 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. + * 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.fasterxml.jackson.databind.JsonNode +import com.google.common.base.Preconditions +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +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.repository.ModelTypeRepository +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ResourceDictionaryRepository +import org.springframework.stereotype.Service + +interface ResourceDefinitionRepoService : BluePrintRepoService { + + @Throws(BluePrintException::class) + fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition +} + +@Service +open class BluePrintRepoFileService(private val modelTypeRepository: ModelTypeRepository, + private val resourceDictionaryRepository: ResourceDictionaryRepository) : ResourceDefinitionRepoService { + + @Throws(BluePrintException::class) + override fun getNodeType(nodeTypeName: String): NodeType { + return getModelType(nodeTypeName, NodeType::class.java) + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName)") + } + + @Throws(BluePrintException::class) + override fun getDataType(dataTypeName: String): DataType { + return getModelType(dataTypeName, DataType::class.java) + ?: throw BluePrintException("couldn't get DataType($dataTypeName)") + } + + @Throws(BluePrintException::class) + override fun getArtifactType(artifactTypeName: String): ArtifactType { + return getModelType(artifactTypeName, ArtifactType::class.java) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName)") + } + + @Throws(BluePrintException::class) + override fun getRelationshipType(relationshipTypeName: String): RelationshipType { + return getModelType(relationshipTypeName, RelationshipType::class.java) + ?: throw BluePrintException("couldn't get RelationshipType($relationshipTypeName)") + } + + @Throws(BluePrintException::class) + override fun getCapabilityDefinition(capabilityDefinitionName: String): CapabilityDefinition { + return getModelType(capabilityDefinitionName, CapabilityDefinition::class.java) + ?: throw BluePrintException("couldn't get CapabilityDefinition($capabilityDefinitionName)") + } + + @Throws(BluePrintException::class) + override fun getResourceDefinition(resourceDefinitionName: String): ResourceDefinition { + val dbResourceDictionary = resourceDictionaryRepository.findByName(resourceDefinitionName) + return if (dbResourceDictionary.isPresent) { + dbResourceDictionary.get().definition + } else { + throw BluePrintException(String.format("failed to get resource dictionary (%s) from repo", resourceDefinitionName)) + } + } + + @Throws(BluePrintException::class) + private fun getModelType(modelName: String, valueClass: Class): T? { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), + "Failed to get model from repo, model name is missing") + + val modelDefinition = getModelDefinition(modelName) + Preconditions.checkNotNull(modelDefinition, + String.format("Failed to get model content for model name (%s)", modelName)) + + return JacksonUtils.readValue(modelDefinition, valueClass) + } + + @Throws(BluePrintException::class) + private fun getModelDefinition(modelName: String): JsonNode { + val modelDefinition: JsonNode + val modelTypeDb = modelTypeRepository.findByModelName(modelName) + if (modelTypeDb != null) { + modelDefinition = modelTypeDb.definition + } else { + throw BluePrintException(String.format("failed to get model definition (%s) from repo", modelName)) + } + return modelDefinition + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt new file mode 100644 index 000000000..8a7c01851 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/ControllerBluePrintCoreConfiguration.kt @@ -0,0 +1,60 @@ +/* + * 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 + +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +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.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.core.env.Environment +import org.springframework.stereotype.Service + +@Configuration +open class ControllerBluePrintCoreConfiguration(private val bluePrintProperties: ControllerBlueprintProperties) { + + companion object { + const val PREFIX_BLUEPRINT_LOAD_CONFIGURATION = "controllerblueprints" + } + + @Bean + open fun controlelrBlueprintLoadConfiguration(): BluePrintLoadConfiguration { + return bluePrintProperties + .propertyBeanType(PREFIX_BLUEPRINT_LOAD_CONFIGURATION, BluePrintLoadConfiguration::class.java) + } +} + +@Configuration +open class ControllerBlueprintPropertyConfiguration { + @Autowired + lateinit var environment: Environment + + @Bean + open fun controllerBluePrintPropertyBinder(): Binder { + val configurationPropertySource = ConfigurationPropertySources.get(environment) + return Binder(configurationPropertySource) + } +} + +@Service +open class ControllerBlueprintProperties(var bluePrintPropertyBinder: Binder) { + fun propertyBeanType(prefix: String, type: Class): T { + return bluePrintPropertyBinder.bind(prefix, Bindable.of(type)).get() + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelController.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelController.kt new file mode 100644 index 000000000..0ea753fd1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelController.kt @@ -0,0 +1,110 @@ +/* + * Copyright © 2019 Bell Canada 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. + * 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.controller + +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.onap.ccsdk.cds.controllerblueprints.service.handler.BluePrintModelHandler +import org.springframework.core.io.Resource +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.http.codec.multipart.FilePart +import org.springframework.web.bind.annotation.* +import reactor.core.publisher.Mono + +/** + * BlueprintModelController Purpose: Handle controllerBlueprint API request + * + * @author Vinal Patel + * @version 1.0 + */ +@RestController +@RequestMapping("/api/v1/blueprint-model") +open class BlueprintModelController(private val bluePrintModelHandler: BluePrintModelHandler) { + + @PostMapping("", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun saveBlueprint(@RequestPart("file") file: FilePart): Mono { + return bluePrintModelHandler.saveBlueprintModel(file) + } + + @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun allBlueprintModel(): List { + return this.bluePrintModelHandler.allBlueprintModel() + } + + @DeleteMapping("/{id}") + @Throws(BluePrintException::class) + fun deleteBlueprint(@PathVariable(value = "id") id: String) { + this.bluePrintModelHandler.deleteBlueprintModel(id) + } + + @GetMapping("/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String): BlueprintModelSearch { + return this.bluePrintModelHandler.getBlueprintModelSearchByNameAndVersion(name, version) + } + + @GetMapping("/download/by-name/{name}/version/{version}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun downloadBlueprintByNameAndVersion(@PathVariable(value = "name") name: String, + @PathVariable(value = "version") version: String): ResponseEntity { + return this.bluePrintModelHandler.downloadBlueprintModelFileByNameAndVersion(name, version) + } + + @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getBlueprintModel(@PathVariable(value = "id") id: String): BlueprintModelSearch { + return this.bluePrintModelHandler.getBlueprintModelSearch(id) + } + + @GetMapping("/download/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun downloadBluePrint(@PathVariable(value = "id") id: String): ResponseEntity { + return this.bluePrintModelHandler.downloadBlueprintModelFile(id) + } + + @PostMapping("/enrich", produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType + .MULTIPART_FORM_DATA_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun enrichBlueprint(@RequestPart("file") file: FilePart): ResponseEntity = runBlocking { + bluePrintModelHandler.enrichBlueprint(file) + } + + @PostMapping("/publish", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun publishBlueprint(@RequestPart("file") file: FilePart): BlueprintModelSearch = runBlocking { + bluePrintModelHandler.publishBlueprint(file) + } + + @GetMapping("/search/{tags}", produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchBlueprintModels(@PathVariable(value = "tags") tags: String): List { + return this.bluePrintModelHandler.searchBlueprintModels(tags) + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt new file mode 100644 index 000000000..de8ba93e3 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ControllerBlueprintExeptionHandler.kt @@ -0,0 +1,50 @@ +/* + * Copyright © 2018-2019 Bell Canada 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.controller + +import org.springframework.web.bind.annotation.RestControllerAdvice +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.service.common.ErrorMessage +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.ExceptionHandler + +/** + * ControllerBlueprintExceptionHandler Purpose: Handle exceptions in controllerBlueprint API and provide the right + * HTTP code status + * + * @author Vinal Patel + * @version 1.0 + */ +@RestControllerAdvice("org.onap.ccsdk.cds.controllerblueprints") +open class ControllerBlueprintExeptionHandler { + + @ExceptionHandler + fun ControllerBlueprintException(e: BluePrintException): ResponseEntity { + var errorCode = ErrorCode.valueOf(e.code) + val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message") + return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode)) + } + + @ExceptionHandler + fun ControllerBlueprintException(e: Exception): ResponseEntity { + var errorCode = ErrorCode.GENERIC_FAILURE + val errorMessage = ErrorMessage(errorCode?.message(e.message!!), errorCode?.value, "ControllerBluePrint_Error_Message") + return ResponseEntity(errorMessage, HttpStatus.resolve(errorCode!!.httpCode)) + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..0509e970e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeController.kt @@ -0,0 +1,56 @@ +/* + * 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.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 org.springframework.http.MediaType +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping(value = arrayOf("/api/v1/model-type")) +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) + } + + @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + fun searchModelTypes(@PathVariable(value = "tags") tags: String): List { + return modelTypeHandler.searchModelTypes(tags) + } + + @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE)) + @ResponseBody + fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List { + return 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) + } + + @DeleteMapping(path = arrayOf("/{name}")) + fun deleteModelTypeByName(@PathVariable(value = "name") name: String) { + 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 new file mode 100644 index 000000000..e21639715 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryController.kt @@ -0,0 +1,68 @@ +/* + * 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.controller + +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 org.springframework.http.MediaType +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping(value = ["/api/v1/dictionary"]) +open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) { + + @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + @Throws(BluePrintException::class) + fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary { + return 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) + } + + @DeleteMapping(path = ["/{name}"]) + fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) { + resourceDictionaryHandler.deleteResourceDictionary(name) + } + + @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchResourceDictionaryByNames(@RequestBody names: List): List { + return resourceDictionaryHandler.searchResourceDictionaryByNames(names) + } + + @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List { + return resourceDictionaryHandler.searchResourceDictionaryByTags(tags) + + } + + @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE]) + @ResponseBody + fun getResourceSourceMapping(): ResourceSourceMapping { + return resourceDictionaryHandler.getResourceSourceMapping() + } + +} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt new file mode 100644 index 000000000..b49fc46b5 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintArtifactDefinitionEnhancerImpl.kt @@ -0,0 +1,93 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.data.ArtifactDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.springframework.stereotype.Service + +@Service +open class BluePrintArtifactDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) + : BluePrintArtifactDefinitionEnhancer { + + companion object { + const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" + } + + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintArtifactDefinitionEnhancerImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, artifactDefinition: ArtifactDefinition) { + log.info("enhancing ArtifactDefinition($name)") + + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val artifactTypeName = artifactDefinition.type + ?: throw BluePrintException("artifact type is missing for ArtifactDefinition($name)") + + // Populate Artifact Type + BluePrintEnhancerUtils.populateArtifactType(bluePrintContext, bluePrintRepoService, artifactTypeName) + + when (artifactTypeName) { + ARTIFACT_TYPE_MAPPING_SOURCE -> { + enhanceMappingType(name, artifactDefinition) + } + } + } + + // Enhance Resource Mapping + open fun enhanceMappingType(name: String, artifactDefinition: ArtifactDefinition) { + + val artifactFilePath = "${bluePrintContext.rootPath}/${artifactDefinition.file}" + + val alreadyEnhancedKey = "enhanced-${artifactDefinition.file}" + val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) + + log.info("enhancing resource mapping file(${artifactDefinition.file}) already enhanced($alreadyEnhanced)") + + if (!alreadyEnhanced) { + val resourceAssignments: MutableList = JacksonUtils.getListFromFile(artifactFilePath, ResourceAssignment::class.java) + as? MutableList + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($artifactFilePath)") + + // Call Resource Assignment Enhancer + resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) + + bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt new file mode 100644 index 000000000..8713b4c6c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintAttributeDefinitionEnhancerImpl.kt @@ -0,0 +1,55 @@ +/* + * 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.enhancer + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.data.AttributeDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintAttributeDefinitionEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils + +class BluePrintAttributeDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) + : BluePrintAttributeDefinitionEnhancer { + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, attributeDefinition: AttributeDefinition) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val propertyType = attributeDefinition.type + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType)) { + + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + val entrySchema = attributeDefinition.entrySchema + ?: throw BluePrintException("Entry Schema is missing for collection property($name)") + + if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { + BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type) + } + } else { + BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt new file mode 100644 index 000000000..e4861e1fc --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImpl.kt @@ -0,0 +1,80 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils +import org.springframework.stereotype.Service +import java.util.* + +@Service +open class BluePrintEnhancerServiceImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceDefinitionEnhancerService: ResourceDefinitionEnhancerService) : BluePrintEnhancerService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintEnhancerServiceImpl::class.toString()) + + override suspend fun enhance(basePath: String, enrichedBasePath: String): BluePrintContext { + + // Copy the Blueprint Content to Target Location + BluePrintFileUtils.copyBluePrint(basePath, enrichedBasePath) + + // Enhance the Blueprint + return enhance(enrichedBasePath) + } + + @Throws(BluePrintException::class) + override suspend fun enhance(basePath: String): BluePrintContext { + + log.info("Enhancing blueprint($basePath)") + val blueprintRuntimeService = BluePrintMetadataUtils + .getBaseEnhancementBluePrintRuntime(UUID.randomUUID().toString(), basePath) + + try { + + bluePrintTypeEnhancerService.enhanceServiceTemplate(blueprintRuntimeService, "service_template", + blueprintRuntimeService.bluePrintContext().serviceTemplate) + + log.info("##### Enhancing blueprint Resource Definitions") + val resourceDefinitions = resourceDefinitionEnhancerService.enhance(bluePrintTypeEnhancerService, + blueprintRuntimeService) + + // Write the Enhanced Blueprint Definitions + BluePrintFileUtils.writeEnhancedBluePrint(blueprintRuntimeService.bluePrintContext()) + + // Write the Enhanced Blueprint Resource Definitions + ResourceDictionaryUtils.writeResourceDefinitionTypes(basePath, resourceDefinitions) + + if (blueprintRuntimeService.getBluePrintError().errors.isNotEmpty()) { + throw BluePrintException(blueprintRuntimeService.getBluePrintError().errors.toString()) + } + + } catch (e: Exception) { + throw e + } + return blueprintRuntimeService.bluePrintContext() + } + +} + diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt new file mode 100644 index 000000000..639b6ee1a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTemplateEnhancerImpl.kt @@ -0,0 +1,70 @@ +/* + * 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. + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTemplateEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintNodeTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) + : BluePrintNodeTemplateEnhancer { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTemplateEnhancerImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeTemplate: NodeTemplate) { + log.info("***** Enhancing NodeTemplate($name)") + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + + val nodeTypeName = nodeTemplate.type + // Get NodeType from Repo and Update Service Template + val nodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, nodeTypeName) + + // Enrich NodeType + bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) + + //Enrich Node Template Artifacts + enhanceNodeTemplateArtifactDefinition(name, nodeTemplate) + } + + open fun enhanceNodeTemplateArtifactDefinition(nodeTemplateName: String, nodeTemplate: NodeTemplate) { + + nodeTemplate.artifacts?.forEach { artifactDefinitionName, artifactDefinition -> + // Enhance Artifacct Definitions + bluePrintTypeEnhancerService.enhanceArtifactDefinition(bluePrintRuntimeService, artifactDefinitionName, artifactDefinition) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt new file mode 100644 index 000000000..f248c315a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintNodeTypeEnhancerImpl.kt @@ -0,0 +1,154 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.data.InterfaceDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeType +import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintNodeTypeEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintNodeTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintNodeTypeEnhancer { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintNodeTypeEnhancerImpl::class.toString()) + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, nodeType: NodeType) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + + val derivedFrom = nodeType.derivedFrom + + if (!BluePrintTypes.rootNodeTypes().contains(derivedFrom)) { + val derivedFromNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, bluePrintRepoService, name) + // Enrich NodeType + enhance(bluePrintRuntimeService, derivedFrom, derivedFromNodeType) + } + + // NodeType Attribute Definitions + enrichNodeTypeAttributes(name, nodeType) + + // NodeType Property Definitions + enrichNodeTypeProperties(name, nodeType) + + //NodeType Requirement + enrichNodeTypeRequirements(name, nodeType) + + //NodeType Capability + enrichNodeTypeCapabilityProperties(name, nodeType) + + //NodeType Interface + enrichNodeTypeInterfaces(name, nodeType) + + } + + open fun enrichNodeTypeAttributes(nodeTypeName: String, nodeType: NodeType) { + nodeType.attributes?.let { + bluePrintTypeEnhancerService.enhanceAttributeDefinitions(bluePrintRuntimeService, nodeType.attributes!!) + } + } + + open fun enrichNodeTypeProperties(nodeTypeName: String, nodeType: NodeType) { + nodeType.properties?.let { + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, nodeType.properties!!) + } + } + + open fun enrichNodeTypeRequirements(nodeTypeName: String, nodeType: NodeType) { + + nodeType.requirements?.forEach { requirementName, requirementDefinition -> + // Populate Requirement Node + requirementDefinition.node?.let { requirementNodeTypeName -> + // Get Requirement NodeType from Repo and Update Service Template + val requirementNodeType = BluePrintEnhancerUtils.populateNodeType(bluePrintContext, + bluePrintRepoService, requirementNodeTypeName) + // Enhance Node Type + enhance(bluePrintRuntimeService, requirementNodeTypeName, requirementNodeType) + + // Enhance Relationship Type + val relationShipTypeName = requirementDefinition.relationship + ?: throw BluePrintException("couldn't get relationship name for the NodeType($nodeTypeName) " + + "Requirement($requirementName)") + enrichRelationShipType(relationShipTypeName) + } + } + } + + open fun enrichNodeTypeCapabilityProperties(nodeTypeName: String, nodeType: NodeType) { + nodeType.capabilities?.forEach { _, capabilityDefinition -> + capabilityDefinition.properties?.let { properties -> + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, properties) + } + } + } + + open fun enrichNodeTypeInterfaces(nodeTypeName: String, nodeType: NodeType) { + nodeType.interfaces?.forEach { interfaceName, interfaceObj -> + // Populate Node type Interface Operation + log.debug("Enriching NodeType({}) Interface({})", nodeTypeName, interfaceName) + populateNodeTypeInterfaceOperation(nodeTypeName, interfaceName, interfaceObj) + + } + } + + open fun populateNodeTypeInterfaceOperation(nodeTypeName: String, interfaceName: String, interfaceObj: InterfaceDefinition) { + + interfaceObj.operations?.forEach { operationName, operation -> + enrichNodeTypeInterfaceOperationInputs(nodeTypeName, operationName, operation) + enrichNodeTypeInterfaceOperationOutputs(nodeTypeName, operationName, operation) + } + } + + open fun enrichNodeTypeInterfaceOperationInputs(nodeTypeName: String, operationName: String, operation: OperationDefinition) { + operation.inputs?.let { inputs -> + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) + } + } + + open fun enrichNodeTypeInterfaceOperationOutputs(nodeTypeName: String, operationName: String, + operation: OperationDefinition) { + operation.outputs?.let { inputs -> + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) + } + } + + /** + * Get the Relationship Type from database and add to Blueprint Context + */ + open fun enrichRelationShipType(relationshipName: String) { + BluePrintEnhancerUtils.populateRelationshipType(bluePrintContext, bluePrintRepoService, relationshipName) + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt new file mode 100644 index 000000000..b0adc398f --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPolicyTypeEnhancerImpl.kt @@ -0,0 +1,43 @@ +/* + * 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.enhancer + +import org.onap.ccsdk.cds.controllerblueprints.core.data.PolicyType +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintPolicyTypeEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class BluePrintPolicyTypeEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) + : BluePrintPolicyTypeEnhancer { + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: PolicyType) { + + this.bluePrintRuntimeService = bluePrintRuntimeService + + // TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt new file mode 100644 index 000000000..85de039de --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintPropertyDefinitionEnhancerImpl.kt @@ -0,0 +1,62 @@ +/* + * 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. + * 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.enhancer + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintPropertyDefinitionEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintPropertyDefinitionEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) + : BluePrintPropertyDefinitionEnhancer { + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, propertyDefinition: PropertyDefinition) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val propertyType = propertyDefinition.type + if (BluePrintTypes.validPrimitiveTypes().contains(propertyType) + || BluePrintTypes.validComplexTypes().contains(propertyType)) { + // Do Nothing, + } else if (BluePrintTypes.validCollectionTypes().contains(propertyType)) { + val entrySchema = propertyDefinition.entrySchema + ?: throw BluePrintException("Entry Schema is missing for collection property($name)") + + if (!BluePrintTypes.validPrimitiveTypes().contains(entrySchema.type)) { + BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, entrySchema.type) + } + } else { + BluePrintEnhancerUtils.populateDataTypes(bluePrintContext, bluePrintRepoService, propertyType) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt new file mode 100644 index 000000000..ef460ec9e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintServiceTemplateEnhancerImpl.kt @@ -0,0 +1,69 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintServiceTemplateEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintServiceTemplateEnhancerImpl(private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) + : BluePrintServiceTemplateEnhancer { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintServiceTemplateEnhancerImpl::class.toString()) + + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: ServiceTemplate) { + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + initialCleanUp() + enhanceTopologyTemplate() + } + + open fun initialCleanUp() { + bluePrintContext.serviceTemplate.artifactTypes?.clear() + bluePrintContext.serviceTemplate.nodeTypes?.clear() + bluePrintContext.serviceTemplate.dataTypes?.clear() + bluePrintContext.serviceTemplate.policyTypes?.clear() + bluePrintContext.serviceTemplate.relationshipTypes?.clear() + + bluePrintContext.serviceTemplate.artifactTypes = mutableMapOf() + bluePrintContext.serviceTemplate.nodeTypes = mutableMapOf() + bluePrintContext.serviceTemplate.dataTypes = mutableMapOf() + bluePrintContext.serviceTemplate.policyTypes = mutableMapOf() + bluePrintContext.serviceTemplate.relationshipTypes = mutableMapOf() + log.info("reinitialized all type definitions") + + } + + open fun enhanceTopologyTemplate() { + bluePrintContext.serviceTemplate.topologyTemplate?.let { topologyTemplate -> + bluePrintTypeEnhancerService.enhanceTopologyTemplate(bluePrintRuntimeService, "topology_template", topologyTemplate) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt new file mode 100644 index 000000000..e611a2224 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTopologyTemplateEnhancerImpl.kt @@ -0,0 +1,61 @@ +/* + * 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.enhancer + +import org.onap.ccsdk.cds.controllerblueprints.core.data.TopologyTemplate +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTopologyTemplateEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintTopologyTemplateEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService) : BluePrintTopologyTemplateEnhancer { + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, type: TopologyTemplate) { + this.bluePrintRuntimeService = bluePrintRuntimeService + + enhanceTopologyTemplateInputs(type) + enhanceTopologyTemplateNodeTemplates(type) + enhanceTopologyTemplateWorkflows(type) + } + + open fun enhanceTopologyTemplateInputs(topologyTemplate: TopologyTemplate) { + topologyTemplate.inputs?.let { inputs -> + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) + } + } + + open fun enhanceTopologyTemplateNodeTemplates(topologyTemplate: TopologyTemplate) { + topologyTemplate.nodeTemplates?.forEach { nodeTemplateName, nodeTemplate -> + bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, nodeTemplateName, nodeTemplate) + } + } + + open fun enhanceTopologyTemplateWorkflows(topologyTemplate: TopologyTemplate) { + topologyTemplate.workflows?.forEach { workflowName, workflow -> + bluePrintTypeEnhancerService.enhanceWorkflow(bluePrintRuntimeService, workflowName, workflow) + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt new file mode 100644 index 000000000..4f7656c8c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintTypeEnhancerServiceImpl.kt @@ -0,0 +1,65 @@ +/* + * 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.enhancer + +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.* +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +@Service +open class BluePrintTypeEnhancerServiceImpl : BluePrintTypeEnhancerService { + + @Autowired + private lateinit var context: ApplicationContext + + override fun getServiceTemplateEnhancers(): List { + return context.getBeansOfType(BluePrintServiceTemplateEnhancer::class.java).map { it.value } + } + + override fun getTopologyTemplateEnhancers(): List { + return context.getBeansOfType(BluePrintTopologyTemplateEnhancer::class.java).map { it.value } + } + + override fun getWorkflowEnhancers(): List { + return context.getBeansOfType(BluePrintWorkflowEnhancer::class.java).map { it.value } + } + + override fun getNodeTemplateEnhancers(): List { + return context.getBeansOfType(BluePrintNodeTemplateEnhancer::class.java).map { it.value } + } + + override fun getNodeTypeEnhancers(): List { + return context.getBeansOfType(BluePrintNodeTypeEnhancer::class.java).map { it.value } + } + + override fun getArtifactDefinitionEnhancers(): List { + return context.getBeansOfType(BluePrintArtifactDefinitionEnhancer::class.java).map { it.value } + } + + override fun getPolicyTypeEnhancers(): List { + return context.getBeansOfType(BluePrintPolicyTypeEnhancer::class.java).map { it.value } + } + + override fun getPropertyDefinitionEnhancers(): List { + return context.getBeansOfType(BluePrintPropertyDefinitionEnhancer::class.java).map { it.value } + } + + override fun getAttributeDefinitionEnhancers(): List { + return context.getBeansOfType(BluePrintAttributeDefinitionEnhancer::class.java).map { it.value } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt new file mode 100644 index 000000000..091dfdafc --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintWorkflowEnhancerImpl.kt @@ -0,0 +1,214 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive +import org.onap.ccsdk.cds.controllerblueprints.core.data.DataType +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.core.data.Workflow +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowEnhancer +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class BluePrintWorkflowEnhancerImpl(private val bluePrintRepoService: BluePrintRepoService, + private val bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + private val resourceAssignmentEnhancerService: ResourceAssignmentEnhancerService) + : BluePrintWorkflowEnhancer { + private val log: EELFLogger = EELFManager.getInstance().getLogger(BluePrintWorkflowEnhancerImpl::class.toString()) + + companion object { + const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" + const val PROPERTY_DEPENDENCY_NODE_TEMPLATES = "dependency-node-templates" + } + + lateinit var bluePrintRuntimeService: BluePrintRuntimeService<*> + lateinit var bluePrintContext: BluePrintContext + + private val workflowDataTypes: MutableMap = hashMapOf() + + override fun enhance(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String, workflow: Workflow) { + log.info("##### Enhancing Workflow($name)") + this.bluePrintRuntimeService = bluePrintRuntimeService + this.bluePrintContext = bluePrintRuntimeService.bluePrintContext() + + val dynamicPropertyName = "$name-properties" + if (workflow.inputs == null) { + workflow.inputs = hashMapOf() + } + // Clean Dynamic Property Field, If present + workflow.inputs?.remove(dynamicPropertyName) + + // Enrich Only for Resource Assignment and Dynamic Input Properties if any + enhanceStepTargets(name, workflow) + + // Enrich Workflow Inputs + enhanceWorkflowInputs(name, workflow) + } + + open fun enhanceWorkflowInputs(name: String, workflow: Workflow) { + + workflow.inputs?.let { inputs -> + bluePrintTypeEnhancerService.enhancePropertyDefinitions(bluePrintRuntimeService, inputs) + } + } + + private fun enhanceStepTargets(name: String, workflow: Workflow) { + + // Get the first Step Target NodeTemplate name( It may be Component or DG Node Template) + val firstNodeTemplateName = bluePrintContext.workflowFirstStepNodeTemplate(name) + + val derivedFrom = bluePrintContext.nodeTemplateNodeType(firstNodeTemplateName).derivedFrom + + when { + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_COMPONENT, true) -> { + // DO Nothing + } + derivedFrom.startsWith(BluePrintConstants.MODEL_TYPE_NODE_DG, true) -> { + enhanceDGStepTargets(name, workflow, firstNodeTemplateName) + } + else -> { + throw BluePrintProcessorException("couldn't execute workflow($name) step mapped " + + "to node template($firstNodeTemplateName) derived from($derivedFrom)") + } + } + + } + + private fun enhanceDGStepTargets(name: String, workflow: Workflow, dgNodeTemplateName: String) { + + val dgNodeTemplate = bluePrintContext.nodeTemplateByName(dgNodeTemplateName) + + // Get the Dependent Component Node Template Names + val dependencyNodeTemplateNodes = dgNodeTemplate.properties?.get(PROPERTY_DEPENDENCY_NODE_TEMPLATES) + ?: throw BluePrintException("couldn't get property($PROPERTY_DEPENDENCY_NODE_TEMPLATES) ") + + val dependencyNodeTemplates = JacksonUtils.getListFromJsonNode(dependencyNodeTemplateNodes, String::class.java) + + log.info("workflow($name) dependent component NodeTemplates($dependencyNodeTemplates)") + + // Check and Get Resource Assignment File + val resourceAssignmentArtifacts = dependencyNodeTemplates?.mapNotNull { componentNodeTemplateName -> + log.info("identified workflow($name) targets($componentNodeTemplateName)") + + val resourceAssignmentArtifacts = bluePrintContext.nodeTemplateByName(componentNodeTemplateName) + .artifacts?.filter { + it.value.type == ARTIFACT_TYPE_MAPPING_SOURCE + }?.map { + log.info("resource assignment artifacts(${it.key}) for NodeType(${componentNodeTemplateName})") + it.value.file + } + resourceAssignmentArtifacts + }?.flatten() + + log.info("workflow($name) resource assignment files($resourceAssignmentArtifacts") + + if (resourceAssignmentArtifacts != null && resourceAssignmentArtifacts.isNotEmpty()) { + + // Add Workflow Dynamic Property + addWorkFlowDynamicPropertyDefinitions(name, workflow) + + resourceAssignmentArtifacts.forEach { fileName -> + // Enhance Resource Assignment File + val resourceAssignmentProperties = enhanceResourceAssignmentFile(fileName!!) + // Add Workflow Dynamic DataType + addWorkFlowDynamicDataType(name, resourceAssignmentProperties) + } + } + } + + // Enhancement for Dynamic Properties, Resource Assignment Properties, Resource Sources + private fun enhanceResourceAssignmentFile(fileName: String): MutableMap { + + val filePath = "${bluePrintContext.rootPath}/$fileName" + + log.info("enriching artifacts file(${filePath}") + + val resourceAssignmentProperties: MutableMap = hashMapOf() + + val resourceAssignments: MutableList = JacksonUtils.getListFromFile(filePath, ResourceAssignment::class.java) + as? MutableList + ?: throw BluePrintProcessorException("couldn't get ResourceAssignment definitions for the file($filePath)") + + val alreadyEnhancedKey = "enhanced-$fileName" + val alreadyEnhanced = bluePrintRuntimeService.check(alreadyEnhancedKey) + + log.info("enhancing workflow resource mapping file($fileName) already enhanced($alreadyEnhanced)") + + if (!alreadyEnhanced) { + // Call Resource Assignment Enhancer + resourceAssignmentEnhancerService.enhanceBluePrint(bluePrintTypeEnhancerService, bluePrintRuntimeService, resourceAssignments) + bluePrintRuntimeService.put(alreadyEnhancedKey, true.asJsonPrimitive()) + } + + resourceAssignments.forEach { resourceAssignment -> + resourceAssignmentProperties[resourceAssignment.name] = resourceAssignment.property!! + } + return resourceAssignmentProperties + } + + private fun addWorkFlowDynamicPropertyDefinitions(name: String, workflow: Workflow) { + val dynamicPropertyName = "$name-properties" + val propertyDefinition = PropertyDefinition() + propertyDefinition.description = "Dynamic PropertyDefinition for workflow($name)." + propertyDefinition.type = "dt-$dynamicPropertyName" + propertyDefinition.required = true + // Add to Workflow Inputs + workflow.inputs?.put(dynamicPropertyName, propertyDefinition) + } + + private fun addWorkFlowDynamicDataType(workflowName: String, mappingProperties: MutableMap) { + + val dataTypeName = "dt-$workflowName-properties" + + var dynamicDataType: DataType? = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) + + if (dynamicDataType == null) { + log.info("dataType not present for the recipe({})", dataTypeName) + dynamicDataType = DataType() + dynamicDataType.version = "1.0.0" + dynamicDataType.description = "Dynamic DataType definition for workflow($workflowName)." + dynamicDataType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATA_TYPE_DYNAMIC + + val dataTypeProperties: MutableMap = hashMapOf() + dynamicDataType.properties = dataTypeProperties + + // Overwrite WorkFlow DataType + bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dynamicDataType) + + } else { + log.info("dynamic dataType($dataTypeName) already present for workflow($workflowName).") + } + // Merge all the Recipe Properties + mappingProperties.forEach { propertyName, propertyDefinition -> + dynamicDataType.properties?.put(propertyName, propertyDefinition) + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt new file mode 100644 index 000000000..7d4244cda --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceAssignmentEnhancerService.kt @@ -0,0 +1,111 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory +import org.onap.ccsdk.cds.controllerblueprints.service.ResourceDefinitionRepoService +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.stereotype.Service + +/** + * ResourceAssignmentEnhancerService. + * + * @author Brinda Santh + */ +interface ResourceAssignmentEnhancerService { + + @Throws(BluePrintException::class) + fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>, + resourceAssignments: List) +} + +/** + * ResourceAssignmentEnhancerDefaultService. + * + * @author Brinda Santh + */ +@Service +@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) +open class ResourceAssignmentEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) + : ResourceAssignmentEnhancerService { + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentEnhancerServiceImpl::class.java) + + /** + * Get the defined source instance from the ResourceAssignment, + * then get the NodeType of the Sources assigned + */ + override fun enhanceBluePrint(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>, + resourceAssignments: List) { + + val uniqueSourceNodeTypeNames = hashSetOf() + + // Iterate the Resource Assignment and + resourceAssignments.map { resourceAssignment -> + val dictionaryName = resourceAssignment.dictionaryName!! + val dictionarySource = resourceAssignment.dictionarySource!! + log.debug("Enriching assignment name(${resourceAssignment.name}), dictionary name($dictionaryName), source($dictionarySource)") + val sourceNodeTypeName = ResourceSourceMappingFactory.getRegisterSourceMapping(dictionarySource) + + // Add Unique Node Types + uniqueSourceNodeTypeNames.add(sourceNodeTypeName) + + // TODO("Candidate for Optimisation") + if (checkResourceDefinitionNeeded(resourceAssignment)) { + + bluePrintTypeEnhancerService.enhancePropertyDefinition(bluePrintRuntimeService, resourceAssignment.name, + resourceAssignment.property!!); + + // Get the Resource Definition from Repo + val resourceDefinition: ResourceDefinition = getResourceDefinition(dictionaryName) + + val sourceNodeTemplate = resourceDefinition.sources.get(dictionarySource) + ?: throw BluePrintException("failed to get assigned dictionarySource($dictionarySource) from resourceDefinition($dictionaryName)") + + // Enrich as NodeTemplate + bluePrintTypeEnhancerService.enhanceNodeTemplate(bluePrintRuntimeService, dictionarySource, sourceNodeTemplate) + } + } + // Enrich the ResourceSource NodeTypes + uniqueSourceNodeTypeNames.map { nodeTypeName -> + val nodeType = resourceDefinitionRepoService.getNodeType(nodeTypeName) + bluePrintTypeEnhancerService.enhanceNodeType(bluePrintRuntimeService, nodeTypeName, nodeType) + } + + } + + private fun checkResourceDefinitionNeeded(resourceAssignment: ResourceAssignment): Boolean { + return !((resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_INPUT) + || resourceAssignment.dictionarySource.equals(ResourceDictionaryConstants.SOURCE_DEFAULT)) + && BluePrintTypes.validPrimitiveOrCollectionPrimitive(resourceAssignment.property!!)) + } + + private fun getResourceDefinition(name: String): ResourceDefinition { + return resourceDefinitionRepoService.getResourceDefinition(name) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt new file mode 100644 index 000000000..6f4527abc --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/ResourceDefinitionEnhancerService.kt @@ -0,0 +1,145 @@ +/* + * 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.enhancer + +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintTypeEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.ResourceDictionaryUtils +import org.onap.ccsdk.cds.controllerblueprints.service.ResourceDefinitionRepoService +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.springframework.stereotype.Service + +interface ResourceDefinitionEnhancerService { + + @Throws(BluePrintException::class) + fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>): List +} + +@Service +class ResourceDefinitionEnhancerServiceImpl(private val resourceDefinitionRepoService: ResourceDefinitionRepoService) : + ResourceDefinitionEnhancerService { + + private val log: EELFLogger = EELFManager.getInstance().getLogger(ResourceDefinitionEnhancerService::class.toString()) + + companion object { + const val ARTIFACT_TYPE_MAPPING_SOURCE: String = "artifact-mapping-resource" + } + + // Enhance the Resource Definition + // 1. Get the Resource Mapping files from all NodeTemplates. + // 2. Get all the Unique Resource assignments from all mapping files + // 3. Collect the Resource Definition for Resource Assignment names from database. + // 4. Create the Resource Definition under blueprint base path. + override fun enhance(bluePrintTypeEnhancerService: BluePrintTypeEnhancerService, + bluePrintRuntimeService: BluePrintRuntimeService<*>): List { + + var resourceDefinitions: List = mutableListOf() + + val blueprintContext = bluePrintRuntimeService.bluePrintContext() + + val mappingFiles = getAllResourceMappingFiles(blueprintContext) + log.info("resources assignment files ($mappingFiles)") + if (mappingFiles != null) { + resourceDefinitions = getResourceDefinition(blueprintContext, mappingFiles) + // Enriching Resource Definition Sources + enrichResourceDefinitionSources(bluePrintRuntimeService.bluePrintContext(), resourceDefinitions) + } + return resourceDefinitions + } + + // Get all the Mapping files from all node templates. + private fun getAllResourceMappingFiles(blueprintContext: BluePrintContext): List? { + + return blueprintContext.nodeTemplates()?.mapNotNull { nodeTemplateMap -> + + // Return only Mapping Artifact File Names + nodeTemplateMap.value.artifacts?.filter { artifactDefinitionMap -> + artifactDefinitionMap.value.type == ARTIFACT_TYPE_MAPPING_SOURCE + }?.mapNotNull { artifactDefinitionMap -> + artifactDefinitionMap.value.file + } + + }?.flatten()?.distinct() + } + + // Convert file content to ResourceAssignments asynchronously + private fun getResourceDefinition(blueprintContext: BluePrintContext, files: List) = runBlocking { + val blueprintBasePath = blueprintContext.rootPath + val deferredResourceAssignments = mutableListOf>>() + for (file in files) { + log.info("processing file ($file)") + deferredResourceAssignments += async { + ResourceDictionaryUtils.getResourceAssignmentFromFile("$blueprintBasePath/$file") + } + } + + val resourceAssignments = mutableListOf() + for (deferredResourceAssignment in deferredResourceAssignments) { + resourceAssignments.addAll(deferredResourceAssignment.await()) + } + + val distinctResourceAssignments = resourceAssignments.distinctBy { it.name } + generateResourceDictionary(blueprintBasePath, distinctResourceAssignments) + //log.info("distinct Resource assignment ($distinctResourceAssignments)") + } + + + // Read the Resource Definitions from the Database and write to type file. + private fun generateResourceDictionary(blueprintBasePath: String, resourceAssignments: List) + : List { + val resourceKeys = resourceAssignments.mapNotNull { it.dictionaryName }.distinct().sorted() + log.info("distinct resource keys ($resourceKeys)") + + //TODO("Optimise DB single Query to multiple Query") + return resourceKeys.map { resourceKey -> + getResourceDefinition(resourceKey) + } + } + + private fun enrichResourceDefinitionSources(bluePrintContext: BluePrintContext, + resourceDefinitions: List) { + val sources = resourceDefinitions + .map { it.sources } + .map { + it.values + .map { nodeTemplate -> + nodeTemplate.type + } + } + .flatten().distinct() + log.info("Enriching Resource Definition sources Node Template: $sources") + sources.forEach { + BluePrintEnhancerUtils.populateNodeType(bluePrintContext, resourceDefinitionRepoService, it) + } + } + + // Get the Resource Definition from Database + private fun getResourceDefinition(name: String): ResourceDefinition { + return resourceDefinitionRepoService.getResourceDefinition(name) + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/BluePrintModelHandler.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/BluePrintModelHandler.kt new file mode 100644 index 000000000..72c27adc1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/BluePrintModelHandler.kt @@ -0,0 +1,330 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * 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. + * 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.handler + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintFileUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelRepository +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelSearchRepository +import org.onap.ccsdk.cds.controllerblueprints.service.utils.BluePrintEnhancerUtils +import org.springframework.core.io.ByteArrayResource +import org.springframework.core.io.Resource +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.http.codec.multipart.FilePart +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import reactor.core.publisher.Mono +import java.io.File +import java.io.IOException +import java.util.* + +/** + * BlueprintModelHandler Purpose: Handler service to handle the request from BlurPrintModelRest + * + * @author Brinda Santh + * @version 1.0 + */ + +@Service +open class BluePrintModelHandler(private val bluePrintCatalogService: BluePrintCatalogService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelSearchRepository: ControllerBlueprintModelSearchRepository, + private val blueprintModelRepository: ControllerBlueprintModelRepository, + private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository, + private val bluePrintEnhancerService: BluePrintEnhancerService) { + + /** + * This is a getAllBlueprintModel method to retrieve all the BlueprintModel in Database + * + * @return List list of the controller blueprint archives + */ + open fun allBlueprintModel(): List { + return blueprintModelSearchRepository.findAll() + } + + /** + * This is a saveBlueprintModel method + * + * @param filePart filePart + * @return Mono + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun saveBlueprintModel(filePart: FilePart): Mono { + try { + val cbaLocation = BluePrintFileUtils.getCbaStorageDirectory(bluePrintLoadConfiguration.blueprintArchivePath) + return BluePrintEnhancerUtils.saveCBAFile(filePart, cbaLocation).map { fileName -> + var blueprintId: String? = null + try { + blueprintId = bluePrintCatalogService.saveToDatabase(cbaLocation.resolve(fileName).toFile(), false) + } catch (e: BluePrintException) { + // FIXME handle expection + } + blueprintModelSearchRepository.findById(blueprintId!!).get() + } + } catch (e: IOException) { + throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, + String.format("I/O Error while uploading the CBA file: %s", e.message), e) + } + + } + + + /** + * This is a searchBlueprintModels method + * + * @param tags tags + * @return List + */ + open fun searchBlueprintModels(tags: String): List { + return blueprintModelSearchRepository.findByTagsContainingIgnoreCase(tags) + } + + /** + * This is a getBlueprintModelSearchByNameAndVersion method + * + * @param name name + * @param version version + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun getBlueprintModelSearchByNameAndVersion(name: String, version: String): BlueprintModelSearch { + val blueprintModelSearch: BlueprintModelSearch + val dbBlueprintModel = blueprintModelSearchRepository + .findByArtifactNameAndArtifactVersion(name, version) + if (dbBlueprintModel.isPresent) { + blueprintModelSearch = dbBlueprintModel.get() + } else { + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, + String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version)) + } + return blueprintModelSearch + } + + /** + * This is a downloadBlueprintModelFileByNameAndVersion method to download a Blueprint by Name and Version + * + * @param name name + * @param version version + * @return ResponseEntity + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun downloadBlueprintModelFileByNameAndVersion(name: String, + version: String): ResponseEntity { + val blueprintModel: BlueprintModel + try { + blueprintModel = getBlueprintModelByNameAndVersion(name, version) + } catch (e: BluePrintException) { + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e) + } + + val fileName = blueprintModel.id + ".zip" + val file = blueprintModel.blueprintModelContent.content + return prepareResourceEntity(fileName, file) + } + + /** + * This is a downloadBlueprintModelFile method to find the target file to download and return a file resource + * + * @return ResponseEntity + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun downloadBlueprintModelFile(id: String): ResponseEntity { + val blueprintModel: BlueprintModel + try { + blueprintModel = getBlueprintModel(id) + } catch (e: BluePrintException) { + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, String.format("Error while " + "downloading the CBA file: %s", e.message), e) + } + + val fileName = blueprintModel.id + ".zip" + val file = blueprintModel.blueprintModelContent.content + return prepareResourceEntity(fileName, file) + } + + /** + * @return ResponseEntity + */ + private fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") + .body(ByteArrayResource(file)) + } + + /** + * This is a getBlueprintModel method + * + * @param id id + * @return BlueprintModel + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun getBlueprintModel(id: String): BlueprintModel { + val blueprintModel: BlueprintModel + val dbBlueprintModel = blueprintModelRepository.findById(id) + if (dbBlueprintModel.isPresent) { + blueprintModel = dbBlueprintModel.get() + } else { + val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) + } + return blueprintModel + } + + /** + * This is a getBlueprintModelByNameAndVersion method + * + * @param name name + * @param version version + * @return BlueprintModel + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun getBlueprintModelByNameAndVersion(name: String, version: String): BlueprintModel { + val blueprintModel = blueprintModelRepository + .findByArtifactNameAndArtifactVersion(name, version) + if (blueprintModel != null) { + return blueprintModel + } else { + val msg = String.format(BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG, name, version) + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) + } + } + + /** + * This is a getBlueprintModelSearch method + * + * @param id id + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun getBlueprintModelSearch(id: String): BlueprintModelSearch { + val blueprintModelSearch: BlueprintModelSearch + val dbBlueprintModel = blueprintModelSearchRepository.findById(id) + if (dbBlueprintModel.isPresent) { + blueprintModelSearch = dbBlueprintModel.get() + } else { + val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) + } + + return blueprintModelSearch + } + + /** + * This is a deleteBlueprintModel method + * + * @param id id + * @throws BluePrintException BluePrintException + */ + @Transactional + @Throws(BluePrintException::class) + open fun deleteBlueprintModel(id: String) { + val dbBlueprintModel = blueprintModelRepository.findById(id) + if (dbBlueprintModel.isPresent) { + blueprintModelContentRepository.deleteByBlueprintModel(dbBlueprintModel.get()) + blueprintModelRepository.delete(dbBlueprintModel.get()) + } else { + val msg = String.format(BLUEPRINT_MODEL_ID_FAILURE_MSG, id) + throw BluePrintException(ErrorCode.RESOURCE_NOT_FOUND.value, msg) + } + } + + /** + * This is a CBA enrichBlueprint method + * Save the Zip File in archive location and extract the cba content. + * Populate the Enhancement Location + * Enhance the CBA content + * Compress the Enhanced Content + * Return back the the compressed content back to the caller. + * + * @param filePart filePart + * @return ResponseEntity + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open suspend fun enrichBlueprint(filePart: FilePart): ResponseEntity { + val enhanceId = UUID.randomUUID().toString() + val blueprintArchive = normalizedPathName(bluePrintLoadConfiguration.blueprintArchivePath, enhanceId) + val blueprintEnrichmentDir = normalizedPathName(bluePrintLoadConfiguration.blueprintEnrichmentPath, enhanceId) + try { + BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) + + // Enhance the Blue Prints + bluePrintEnhancerService.enhance(blueprintEnrichmentDir) + + return BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentDir, blueprintArchive) + + } catch (e: IOException) { + throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Enriching CBA: ${e.message}", e) + } finally { + BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) + } + } + + /** + * This is a publishBlueprintModel method to change the status published to YES + * + * @param filePart filePart + * @return BlueprintModelSearch + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open suspend fun publishBlueprint(filePart: FilePart): BlueprintModelSearch { + val publishId = UUID.randomUUID().toString() + val blueprintArchive = bluePrintLoadConfiguration.blueprintArchivePath.plus(File.separator).plus(publishId) + val blueprintEnrichmentDir = bluePrintLoadConfiguration.blueprintEnrichmentPath.plus(File.separator).plus(publishId) + try { + val compressedFilePart = BluePrintEnhancerUtils + .extractCompressFilePart(filePart, blueprintArchive, blueprintEnrichmentDir) + + val blueprintId = bluePrintCatalogService.saveToDatabase(compressedFilePart, true) + + return blueprintModelSearchRepository.findById(blueprintId).get() + + } catch (e: Exception) { + throw BluePrintException(ErrorCode.IO_FILE_INTERRUPT.value, + "Error in Publishing CBA: ${e.message}", e) + } finally { + BluePrintEnhancerUtils.cleanEnhancer(blueprintArchive, blueprintEnrichmentDir) + } + } + + companion object { + + private const val BLUEPRINT_MODEL_ID_FAILURE_MSG = "failed to get blueprint model id(%s) from repo" + private const val BLUEPRINT_MODEL_NAME_VERSION_FAILURE_MSG = "failed to get blueprint model by name(%s)" + " and version(%s) from repo" + } +} 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 new file mode 100644 index 000000000..5c1a1652c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ModelTypeHandler.kt @@ -0,0 +1,116 @@ +/* + * 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.handler + +import com.att.eelf.configuration.EELFManager +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ModelTypeRepository +import org.onap.ccsdk.cds.controllerblueprints.service.validator.ModelTypeValidator +import org.springframework.stereotype.Service + +@Service +open class ModelTypeHandler(private val modelTypeRepository: ModelTypeRepository) { + + private val log = EELFManager.getInstance().getLogger(ModelTypeHandler::class.java)!! + + /** + * This is a getModelTypeByName service + * + * @param modelTypeName modelTypeName + * @return ModelType + */ + fun getModelTypeByName(modelTypeName: String): ModelType? { + log.info("Searching : $modelTypeName") + check(modelTypeName.isNotBlank()) { "Model Name Information is missing." } + return modelTypeRepository.findByModelName(modelTypeName) + } + + + /** + * This is a searchModelTypes service + * + * @param tags tags + * @return List + */ + fun searchModelTypes(tags: String): List { + check(tags.isNotBlank()) { "No Search Information provide" } + return modelTypeRepository.findByTagsContainingIgnoreCase(tags) + } + + /** + * This is a saveModel service + * + * @param modelType modelType + * @return ModelType + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + open fun saveModel(modelType: ModelType): ModelType { + lateinit var dbModel: ModelType + ModelTypeValidator.validateModelType(modelType) + val dbModelType: ModelType? = modelTypeRepository.findByModelName(modelType.modelName) + if (dbModelType != null) { + dbModel = dbModelType + dbModel.description = modelType.description + dbModel.definition = modelType.definition + dbModel.definitionType = modelType.definitionType + dbModel.derivedFrom = modelType.derivedFrom + dbModel.tags = modelType.tags + dbModel.version = modelType.version + dbModel.updatedBy = modelType.updatedBy + dbModel = modelTypeRepository.save(dbModel) + } else { + dbModel = modelTypeRepository.save(modelType) + } + return dbModel + } + + + /** + * This is a deleteByModelName service + * + * @param modelName modelName + */ + open fun deleteByModelName(modelName: String) { + check(modelName.isNotBlank()) { "Model Name Information is missing." } + modelTypeRepository.deleteByModelName(modelName) + + } + + /** + * This is a getModelTypeByDefinitionType service + * + * @param definitionType definitionType + * @return List + */ + fun getModelTypeByDefinitionType(definitionType: String): List { + check(definitionType.isNotBlank()) { "Model definitionType Information is missing." } + return modelTypeRepository.findByDefinitionType(definitionType) + } + + /** + * This is a getModelTypeByDerivedFrom service + * + * @param derivedFrom derivedFrom + * @return List + */ + fun getModelTypeByDerivedFrom(derivedFrom: String): List { + check(derivedFrom.isNotBlank()) { "Model derivedFrom Information is missing." } + return modelTypeRepository.findByDerivedFrom(derivedFrom) + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..f6e95de2d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/handler/ResourceDictionaryHandler.kt @@ -0,0 +1,148 @@ +/* + * 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. + * 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.handler + +import com.google.common.base.Preconditions +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.lang3.StringUtils +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ResourceDictionaryRepository +import org.springframework.stereotype.Service + +@Service +class ResourceDictionaryHandler(private val resourceDictionaryRepository: ResourceDictionaryRepository) { + + + /** + * This is a getDataDictionaryByName service + * + * @param name name + * @return DataDictionary + * @throws BluePrintException BluePrintException + */ + @Throws(BluePrintException::class) + 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() + } else { + throw BluePrintException(String.format("couldn't get resource dictionary for name (%s)", name)) + } + } + + /** + * This is a searchResourceDictionaryByNames service + * + * @param names names + * @return List + */ + fun searchResourceDictionaryByNames(names: List): List { + Preconditions.checkArgument(CollectionUtils.isNotEmpty(names), "No Search Information provide") + return resourceDictionaryRepository.findByNameIn(names) + } + + /** + * This is a searchResourceDictionaryByTags service + * + * @param tags tags + * @return List + */ + fun searchResourceDictionaryByTags(tags: String): List { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No search tag information provide") + return resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags) + } + + /** + * This is a saveDataDictionary service + * + * @param resourceDictionary resourceDictionary + * @return DataDictionary + */ + @Throws(BluePrintException::class) + fun saveResourceDictionary(resourceDictionary: ResourceDictionary): ResourceDictionary { + var resourceDictionary = resourceDictionary + + val resourceDefinition = resourceDictionary.definition + Preconditions.checkNotNull(resourceDefinition, "failed to get resource definition from content") + // Validate the Resource Definitions + //TODO( Save Validator) + //validate(resourceDefinition) + + resourceDictionary.tags = resourceDefinition.tags + resourceDefinition.updatedBy = resourceDictionary.updatedBy + // Set the Property Definitions + val propertyDefinition = resourceDefinition.property + resourceDictionary.description = propertyDefinition.description + resourceDictionary.dataType = propertyDefinition.type + if (propertyDefinition.entrySchema != null) { + resourceDictionary.entrySchema = propertyDefinition.entrySchema!!.type + } + + validateResourceDictionary(resourceDictionary) + + val dbResourceDictionaryData = resourceDictionaryRepository.findByName(resourceDictionary.name) + if (dbResourceDictionaryData.isPresent) { + val dbResourceDictionary = dbResourceDictionaryData.get() + + dbResourceDictionary.name = resourceDictionary.name + dbResourceDictionary.definition = resourceDictionary.definition + dbResourceDictionary.description = resourceDictionary.description + dbResourceDictionary.tags = resourceDictionary.tags + dbResourceDictionary.updatedBy = resourceDictionary.updatedBy + dbResourceDictionary.dataType = resourceDictionary.dataType + dbResourceDictionary.entrySchema = resourceDictionary.entrySchema + resourceDictionary = resourceDictionaryRepository.save(dbResourceDictionary) + } else { + resourceDictionary = resourceDictionaryRepository.save(resourceDictionary) + } + + return resourceDictionary + } + + /** + * This is a deleteResourceDictionary service + * + * @param name name + */ + fun deleteResourceDictionary(name: String) { + check(name.isNotBlank()) { "Resource dictionary name is missing." } + resourceDictionaryRepository.deleteByName(name) + } + + /** + * This is a getResourceSourceMapping service + */ + fun getResourceSourceMapping(): ResourceSourceMapping { + return ResourceSourceMappingFactory.getRegisterSourceMapping() + } + + private fun validateResourceDictionary(resourceDictionary: ResourceDictionary): Boolean { + checkNotEmptyOrThrow(resourceDictionary.name, "DataDictionary Definition name is missing.") + checkNotNull(resourceDictionary.definition) { "DataDictionary Definition Information is missing." } + checkNotEmptyOrThrow(resourceDictionary.description, "DataDictionary Definition Information is missing.") + checkNotEmptyOrThrow(resourceDictionary.tags, "DataDictionary Definition tags is missing.") + checkNotEmptyOrThrow(resourceDictionary.updatedBy, "DataDictionary Definition updatedBy is missing.") + return true + + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..bffdccda7 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintCatalogLoadService.kt @@ -0,0 +1,68 @@ +/* + * 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.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.springframework.stereotype.Service +import java.io.File + +@Service +open class BluePrintCatalogLoadService(private val bluePrintCatalogService: BluePrintCatalogService) { + + private val log = EELFManager.getInstance().getLogger(BluePrintCatalogLoadService::class.java) + + open fun loadPathsBluePrintModelCatalog(paths: List) { + paths.forEach { loadPathBluePrintModelCatalog(it) } + } + + open fun loadPathBluePrintModelCatalog(path: String) { + + val files = File(path).listFiles() + runBlocking { + val errorBuilder = StrBuilder() + val deferredResults = mutableListOf>() + + for (file in files) { + deferredResults += async { + loadBluePrintModelCatalog(errorBuilder, file) + } + } + + for (deferredResult in deferredResults) { + deferredResult.await() + } + + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) + } + } + } + + open fun loadBluePrintModelCatalog(errorBuilder: StrBuilder, file: File) { + try { + bluePrintCatalogService.saveToDatabase(file) + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load BlueprintModel(${file.name}: ${e.message}") + } + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..e6f6498df --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/BluePrintDatabaseLoadService.kt @@ -0,0 +1,83 @@ +/* + * 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.load + +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.springframework.boot.context.event.ApplicationReadyEvent +import org.springframework.context.event.EventListener +import org.springframework.stereotype.Service + +@Service +open class BluePrintDatabaseLoadService(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val modelTypeLoadService: ModelTypeLoadService, + private val resourceDictionaryLoadService: ResourceDictionaryLoadService, + private val bluePrintCatalogLoadService: BluePrintCatalogLoadService) { + + private val log = EELFManager.getInstance().getLogger(BluePrintDatabaseLoadService::class.java) + + + @EventListener(ApplicationReadyEvent::class) + open fun init() { + if (bluePrintLoadConfiguration.loadInitialData) { + initModelTypes() + initResourceDictionary() + initBluePrintCatalog() + } else { + log.info("Initial data load is disabled") + } + } + + open 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) + } + } + } + } + + open fun initResourceDictionary() { + log.info("resource dictionary load configuration(${bluePrintLoadConfiguration.loadResourceDictionary}) " + + "under paths(${bluePrintLoadConfiguration.loadResourceDictionaryPaths})") + + if (bluePrintLoadConfiguration.loadResourceDictionary) { + val paths = bluePrintLoadConfiguration.loadResourceDictionaryPaths?.split(",") + paths?.let { + resourceDictionaryLoadService.loadPathsResourceDictionary(paths) + } + } + } + + open fun initBluePrintCatalog() { + log.info("blueprint load configuration(${bluePrintLoadConfiguration.loadBluePrint}) " + + "under paths(${bluePrintLoadConfiguration.loadBluePrintPaths})") + + if (bluePrintLoadConfiguration.loadBluePrint) { + val paths = bluePrintLoadConfiguration.loadBluePrintPaths?.split(",") + paths?.let { + bluePrintCatalogLoadService.loadPathsBluePrintModelCatalog(paths) + } + } + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt new file mode 100755 index 000000000..358a4654a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ControllerBlueprintCatalogServiceImpl.kt @@ -0,0 +1,112 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * 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. + * 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.load + +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.common.ApplicationConstants +import org.onap.ccsdk.cds.controllerblueprints.core.config.BluePrintLoadConfiguration +import org.onap.ccsdk.cds.controllerblueprints.core.data.ErrorCode +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.db.resources.BlueprintCatalogServiceImpl +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent +import org.onap.ccsdk.cds.controllerblueprints.service.repository.ControllerBlueprintModelRepository +import org.slf4j.LoggerFactory +import org.springframework.dao.DataIntegrityViolationException +import org.springframework.stereotype.Service +import java.io.File +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths + +/** + * Similar implementation in [org.onap.ccsdk.cds.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl] + */ +@Service +class ControllerBlueprintCatalogServiceImpl(bluePrintValidatorService: BluePrintValidatorService, + private val bluePrintLoadConfiguration: BluePrintLoadConfiguration, + private val blueprintModelRepository: ControllerBlueprintModelRepository) + : BlueprintCatalogServiceImpl(bluePrintValidatorService) { + + + private val log = LoggerFactory.getLogger(ControllerBlueprintCatalogServiceImpl::class.toString()) + + init { + log.info("BlueprintProcessorCatalogServiceImpl initialized") + } + + override fun delete(name: String, version: String) = blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(name, version) + + override fun get(name: String, version: String, extract: Boolean): Path? { + val path = if (extract) { + Paths.get("${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version") + } else { + Paths.get("${bluePrintLoadConfiguration.blueprintArchivePath}/$name/$version.zip") + } + blueprintModelRepository.findByArtifactNameAndArtifactVersion(name, version)?.also { + it.blueprintModelContent.run { + path.toFile().writeBytes(this!!.content!!).let { + return path + } + } + } + return null + } + + override fun save(metadata: MutableMap, archiveFile: File) { + + val artifactName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME] + val artifactVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION] + + + blueprintModelRepository.findByArtifactNameAndArtifactVersion(artifactName!!, artifactVersion!!)?.let { + log.info("Overwriting blueprint model :$artifactName::$artifactVersion") + blueprintModelRepository.deleteByArtifactNameAndArtifactVersion(artifactName, artifactVersion) + } + + val blueprintModel = BlueprintModel() + blueprintModel.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL + blueprintModel.published = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_VALID] + ?: BluePrintConstants.FLAG_N + blueprintModel.artifactName = artifactName + blueprintModel.artifactVersion = artifactVersion + blueprintModel.updatedBy = metadata[BluePrintConstants.METADATA_TEMPLATE_AUTHOR] + blueprintModel.tags = metadata[BluePrintConstants.METADATA_TEMPLATE_TAGS] + blueprintModel.artifactDescription = "Controller Blueprint for $artifactName:$artifactVersion" + + val blueprintModelContent = BlueprintModelContent() + blueprintModelContent.id = metadata[BluePrintConstants.PROPERTY_BLUEPRINT_PROCESS_ID] + blueprintModelContent.contentType = "CBA_ZIP" + blueprintModelContent.name = "$artifactName:$artifactVersion" + blueprintModelContent.description = "$artifactName:$artifactVersion CBA Zip Content" + blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath()) + blueprintModelContent.blueprintModel = blueprintModel + // Set the Blueprint Model Content into blueprintModel + blueprintModel.blueprintModelContent = blueprintModelContent + + try { + blueprintModelRepository.saveAndFlush(blueprintModel) + } catch (ex: DataIntegrityViolationException) { + throw BluePrintException(ErrorCode.CONFLICT_ADDING_RESOURCE.value, "The blueprint entry " + + "is already exist in database: ${ex.message}", ex) + } + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..c3533979b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ModelTypeLoadService.kt @@ -0,0 +1,150 @@ +/* + * 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.load + +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.* +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.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) { + + private val log = EELFManager.getInstance().getLogger(ModelTypeLoadService::class.java) + private val updateBySystem = "System" + + open suspend fun loadPathsModelType(modelTypePaths: List) { + modelTypePaths.forEach { runBlocking { 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 { + log.info(" *************************** loadModelType **********************") + try { + val errorBuilder = StrBuilder() + + coroutineScope { + val dataTypeFiles = File("$modelTypePath/data_type").listFiles() + + val deferredResults = mutableListOf>() + + for (file in dataTypeFiles) deferredResults += async { + loadModelType(file, DataType::class.java, errorBuilder) + } + + deferredResults.awaitAll() + } + + coroutineScope { + val artifactTypeFiles = File("$modelTypePath/artifact_type").listFiles() + + val deferredResults = mutableListOf>() + + for (file in artifactTypeFiles) deferredResults += async { + loadModelType(file, + ArtifactType::class.java, errorBuilder) + } + + deferredResults.awaitAll() + } + + coroutineScope { + val relationshipTypeFiles = File("$modelTypePath/relationship_type").listFiles() + + val deferredResults = mutableListOf>() + + for (file in relationshipTypeFiles) deferredResults += async { + loadModelType(file, + RelationshipType::class.java, errorBuilder) + } + + deferredResults.awaitAll() + } + + coroutineScope { + val nodeTypeFiles = File("$modelTypePath/node_type").listFiles() + + val deferredResults = mutableListOf>() + + for (file in nodeTypeFiles) deferredResults += async { + loadModelType(file, + NodeType::class.java, errorBuilder) + } + deferredResults.awaitAll() + } + + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) + } + } catch (e: Exception) { + log.error("Failed to loade ModelTypes under($modelTypePath)", e) + } + } + + private inline fun loadModelType(file: File, classType: Class, errorBuilder: StrBuilder) { + try { + log.trace("Loading ${classType.name} (${file.name})") + val dataKey = FilenameUtils.getBaseName(file.name) + val definitionContent = file.readText(Charset.defaultCharset()) + val definition = JacksonUtils.readValue(definitionContent, classType) as EntityType + //checkNotNull(definition) { "failed to get data type from file : ${file.name}" } + + val modelType = ModelType() + val definitionType: String? + when (T::class) { + DataType::class -> { + definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + } + RelationshipType::class -> { + definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE + } + ArtifactType::class -> { + definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE + } + NodeType::class -> { + definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE + } + else -> { + throw BluePrintException("couldn't process model type($classType) definition") + } + } + modelType.definitionType = definitionType + modelType.derivedFrom = definition.derivedFrom + modelType.description = definition.description + modelType.definition = JacksonUtils.jsonNode(definitionContent) + modelType.modelName = dataKey + modelType.version = definition.version + modelType.updatedBy = updateBySystem + modelType.tags = (dataKey + "," + definition.derivedFrom + "," + definitionType) + modelTypeHandler.saveModel(modelType) + log.trace("${classType.name}(${file.name}) loaded successfully ") + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load ${classType.name}(${file.name}: ${e.message}") + } + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..e07552592 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/load/ResourceDictionaryLoadService.kt @@ -0,0 +1,106 @@ +/* + * 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.load + +import com.att.eelf.configuration.EELFManager +import kotlinx.coroutines.Deferred +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +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.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) { + paths.forEach { loadPathResourceDictionary(it) } + } + + open fun loadPathResourceDictionary(path: String) { + log.info(" *************************** loadResourceDictionary **********************") + val files = File(path).listFiles() + + runBlocking { + val errorBuilder = StrBuilder() + val deferredResults = mutableListOf>() + + for (file in files) { + deferredResults += async { + loadResourceDictionary(errorBuilder, file) + } + } + + for (deferredResult in deferredResults) { + deferredResult.await() + } + + if (!errorBuilder.isEmpty) { + log.error(errorBuilder.toString()) + } + } + } + + private fun loadResourceDictionary(errorBuilder: StrBuilder, file: File) { + try { + log.trace("Loading NodeType(${file.name}") + val definitionContent = file.readText(Charset.defaultCharset()) + val resourceDefinition = JacksonUtils.readValue(definitionContent, ResourceDefinition::class.java) + if (resourceDefinition != null) { + + checkNotNull(resourceDefinition.property) { "Failed to get Property Definition" } + val resourceDictionary = ResourceDictionary() + resourceDictionary.name = resourceDefinition.name + resourceDictionary.definition = resourceDefinition + + checkNotNull(resourceDefinition.property) { "Property field is missing" } + resourceDictionary.description = resourceDefinition.property.description + resourceDictionary.dataType = resourceDefinition.property.type + + if (resourceDefinition.property.entrySchema != null) { + resourceDictionary.entrySchema = resourceDefinition.property.entrySchema!!.type + } + resourceDictionary.updatedBy = resourceDefinition.updatedBy + + if (StringUtils.isBlank(resourceDefinition.tags)) { + resourceDictionary.tags = (resourceDefinition.name + ", " + resourceDefinition.updatedBy + + ", " + resourceDefinition.updatedBy) + + } else { + resourceDictionary.tags = resourceDefinition.tags + } + resourceDictionaryHandler.saveResourceDictionary(resourceDictionary) + + log.trace("Resource dictionary(${file.name}) loaded successfully ") + } else { + throw BluePrintException("couldn't get dictionary from content information") + } + } catch (e: Exception) { + errorBuilder.appendln("Couldn't load Resource dictionary (${file.name}: ${e.message}") + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/BluePrintsReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/BluePrintsReactRepository.kt new file mode 100644 index 000000000..0041fa7c8 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/BluePrintsReactRepository.kt @@ -0,0 +1,76 @@ +/* + * 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.ModelType +import org.springframework.stereotype.Service +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import reactor.core.scheduler.Schedulers + +/** + * ModelTypeReactRepository. + * + * @author Brinda Santh + */ +@Service +open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) { + + fun save(modelType: ModelType): Mono { + return Mono.justOrEmpty(modelTypeRepository.save(modelType)) + } + + fun findByModelName(modelName: String): Mono { + return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName)) + } + + fun findByModelNameIn(modelNames: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFrom(derivedFrom: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFromIn(derivedFroms: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionType(definitionType: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionTypeIn(definitionTypes: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByModelName(modelName: String): Mono { + modelTypeRepository.deleteByModelName(modelName) + 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/ControllerBlueprintModelContentRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt new file mode 100644 index 000000000..1a45d7f5c --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelContentRepository.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 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.db.resources.repository.ModelContentRepository +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelContent + +interface ControllerBlueprintModelContentRepository : ModelContentRepository diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt new file mode 100644 index 000000000..6e5792564 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ControllerBlueprintModelRepository.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 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.db.resources.repository.ModelRepository +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModel + +interface ControllerBlueprintModelRepository : ModelRepository diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeRepository.kt new file mode 100644 index 000000000..4fefc8144 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeRepository.kt @@ -0,0 +1,85 @@ +/* + * 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.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.stereotype.Repository +import javax.transaction.Transactional + +@Repository +interface ModelTypeRepository : JpaRepository { + /** + * This is a findByModelName method + * + * @param modelName Model Name + * @return Optional + */ + fun findByModelName(modelName: String): ModelType? + /** + * This is a findByModelNameIn method + * + * @param modelNames Model Names + * @return List + */ + fun findByModelNameIn(modelNames: List): List + /** + * This is a findByDerivedFrom method + * + * @param derivedFrom Derived From + * @return List + */ + fun findByDerivedFrom(derivedFrom: String): List + /** + * This is a findByDerivedFromIn method + * + * @param derivedFroms Derived Froms + * @return List + */ + fun findByDerivedFromIn(derivedFroms: List): List + + /** + * This is a findByDefinitionType method + * + * @param definitionType Definition Type + * @return List + */ + fun findByDefinitionType(definitionType: String): List + /** + * This is a findByDefinitionTypeIn method + * + * @param definitionTypes Definition Types + * @return List + */ + fun findByDefinitionTypeIn(definitionTypes: List): List + + /** + * This is a findByTagsContainingIgnoreCase method + * + * @param tags Tags + * @return Optional + */ + fun findByTagsContainingIgnoreCase(tags: String): List + + /** + * This is a deleteByModelName method + * + * @param modelName ModelName + */ + @Transactional + fun deleteByModelName(modelName: String) +} 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 new file mode 100644 index 000000000..5758fb7fb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt @@ -0,0 +1,56 @@ +/* + * 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 { + return Mono.justOrEmpty(resourceDictionaryRepository.save(resourceDictionary)) + } + + fun findByName(name: String): Mono { + return Mono.justOrEmpty(resourceDictionaryRepository.findByName(name)) + } + + fun findByNameIn(names: List): Flux { + return Flux.fromIterable(resourceDictionaryRepository.findByNameIn(names)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux { + return Flux.fromIterable(resourceDictionaryRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByName(name: String): Mono { + 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/utils/BluePrintEnhancerUtils.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt new file mode 100644 index 000000000..166a2b283 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtils.kt @@ -0,0 +1,163 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2019 Bell Canada. + * 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. + * 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.utils + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.reactive.awaitSingle +import kotlinx.coroutines.withContext +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintRepoService +import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.springframework.core.io.ByteArrayResource +import org.springframework.core.io.Resource +import org.springframework.http.HttpHeaders +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.StringUtils +import reactor.core.publisher.Mono +import java.io.File +import java.io.IOException +import java.nio.file.Path +import java.nio.file.Paths +import java.util.* + + +class BluePrintEnhancerUtils { + companion object { + + fun populateDataTypes(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + dataTypeName: String): DataType { + val dataType = bluePrintContext.serviceTemplate.dataTypes?.get(dataTypeName) + ?: bluePrintRepoService.getDataType(dataTypeName) + ?: throw BluePrintException("couldn't get DataType($dataTypeName) from repo.") + bluePrintContext.serviceTemplate.dataTypes?.put(dataTypeName, dataType) + return dataType + } + + fun populateRelationshipType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + relationshipName: String): RelationshipType { + + val relationshipType = bluePrintContext.serviceTemplate.relationshipTypes?.get(relationshipName) + ?: bluePrintRepoService.getRelationshipType(relationshipName) + ?: throw BluePrintException("couldn't get RelationshipType($relationshipName) from repo.") + bluePrintContext.serviceTemplate.relationshipTypes?.put(relationshipName, relationshipType) + return relationshipType + } + + + fun populateNodeType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + nodeTypeName: String): NodeType { + + val nodeType = bluePrintContext.serviceTemplate.nodeTypes?.get(nodeTypeName) + ?: bluePrintRepoService.getNodeType(nodeTypeName) + ?: throw BluePrintException("couldn't get NodeType($nodeTypeName) from repo.") + bluePrintContext.serviceTemplate.nodeTypes?.put(nodeTypeName, nodeType) + return nodeType + } + + fun populateArtifactType(bluePrintContext: BluePrintContext, bluePrintRepoService: BluePrintRepoService, + artifactTypeName: String): ArtifactType { + + val artifactType = bluePrintContext.serviceTemplate.artifactTypes?.get(artifactTypeName) + ?: bluePrintRepoService.getArtifactType(artifactTypeName) + ?: throw BluePrintException("couldn't get ArtifactType($artifactTypeName) from repo.") + bluePrintContext.serviceTemplate.artifactTypes?.put(artifactTypeName, artifactType) + return artifactType + } + + private suspend fun copyFromFilePart(filePart: FilePart, targetFile: File): File { + // Delete the Directory + targetFile.deleteRecursively() + return filePart.transferTo(targetFile) + .thenReturn(targetFile) + .awaitSingle() + } + + suspend fun extractCompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + //Recreate the Base Directories + normalizedFile(archiveDir).reCreateDirs() + normalizedFile(enhanceDir).reCreateDirs() + val filePartFile = normalizedFile(archiveDir, "cba.zip") + // Copy the File Part to ZIP + return copyFromFilePart(filePart, filePartFile) + } + + suspend fun decompressFilePart(filePart: FilePart, archiveDir: String, enhanceDir: String): File { + val filePartFile = extractCompressFilePart(filePart, archiveDir, enhanceDir) + val deCompressFileName = normalizedPathName(enhanceDir) + return filePartFile.deCompress(deCompressFileName) + } + + suspend fun compressToFilePart(enhanceDir: String, archiveDir: String): ResponseEntity { + val compressedFile = normalizedFile(archiveDir, "enhanced-cba.zip") + BluePrintArchiveUtils.compress(Paths.get(enhanceDir).toFile(), compressedFile, true) + return prepareResourceEntity(compressedFile.name, compressedFile.readBytes()) + } + + suspend fun prepareResourceEntity(fileName: String, file: ByteArray): ResponseEntity { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("text/plain")) + .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$fileName\"") + .body(ByteArrayResource(file)) + } + + suspend fun cleanEnhancer(archiveLocation: String, enhancementLocation: String) = withContext(Dispatchers.Default) { + deleteDir(archiveLocation) + deleteDir(enhancementLocation) + } + + /** + * This is a saveCBAFile method + * take a [FilePart], transfer it to disk using a Flux of FilePart and return a [Mono] representing the CBA file name + * + * @param (filePart, targetDirectory) - the request part containing the file to be saved and the default directory where to save + * @return a [Mono] String representing the result of the operation + * @throws (BluePrintException, IOException) BluePrintException, IOException + */ + @Throws(BluePrintException::class, IOException::class) + fun saveCBAFile(filePart: FilePart, targetDirectory: Path): Mono { + + // Normalize file name + val fileName = StringUtils.cleanPath(filePart.filename()) + + // Check if the file's extension is "CBA" + if (StringUtils.getFilenameExtension(fileName) != "zip") { + throw BluePrintException(ErrorCode.INVALID_FILE_EXTENSION.value, "Invalid file extension required ZIP") + } + + // Change file name to match a pattern + val changedFileName = UUID.randomUUID().toString() + ".zip" + //String changedFileName = BluePrintFileUtils.Companion.getCBAGeneratedFileName(fileName, this.CBA_FILE_NAME_PATTERN); + + // Copy file to the target location (Replacing existing file with the same name) + val targetLocation = targetDirectory.resolve(changedFileName) + + // if a file with the same name already exists in a repository, delete and recreate it + val file = File(targetLocation.toString()) + if (file.exists()) + file.delete() + file.createNewFile() + + return filePart.transferTo(file).thenReturn(changedFileName) + } + } +} diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidator.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidator.kt new file mode 100644 index 000000000..9bfb29c23 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidator.kt @@ -0,0 +1,83 @@ +/* + * 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.validator + +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.data.* +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType + +class ModelTypeValidator { + companion object { + /** + * This is a validateModelTypeDefinition + * + * @param definitionType definitionType + * @param definitionContent definitionContent + * @return boolean + */ + fun validateModelTypeDefinition(definitionType: String, definitionContent: JsonNode): Boolean { + + when (definitionType) { + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE -> { + JacksonUtils.readValue(definitionContent, DataType::class.java) + ?: throw BluePrintException("Model type definition is not DataType valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_NODE_TYPE -> { + JacksonUtils.readValue(definitionContent, NodeType::class.java) + ?: throw BluePrintException("Model type definition is not NodeType valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_ARTIFACT_TYPE -> { + JacksonUtils.readValue(definitionContent, ArtifactType::class.java) + ?: throw BluePrintException("Model type definition is not ArtifactType valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_CAPABILITY_TYPE -> { + JacksonUtils.readValue(definitionContent, CapabilityDefinition::class.java) + ?: throw BluePrintException("Model type definition is not CapabilityDefinition valid content $definitionContent") + } + BluePrintConstants.MODEL_DEFINITION_TYPE_RELATIONSHIP_TYPE -> { + JacksonUtils.readValue(definitionContent, RelationshipType::class.java) + ?: throw BluePrintException("Model type definition is not RelationshipType valid content $definitionContent") + } + } + return true + } + + /** + * This is a validateModelType method + * + * @param modelType modelType + * @return boolean + */ + fun validateModelType(modelType: ModelType?): Boolean { + checkNotNull(modelType) { "Model Type Information is missing." } + + val validRootTypes = BluePrintTypes.validModelTypes() + + check(validRootTypes.contains(modelType.definitionType)) { + "Not Valid Model Root Type(${modelType.definitionType}), It should be $validRootTypes" + } + + validateModelTypeDefinition(modelType.definitionType, modelType.definition) + return true + } + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java deleted file mode 100644 index db35fe661..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.apps.controllerblueprints; - -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.jpa.repository.config.EnableJpaAuditing; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; -import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; - -/** - * DatabaseConfig.java Purpose: Provide Configuration Generator DatabaseConfig Information - * - * @author Brinda Santh - * @version 1.0 - */ -@Configuration -@EntityScan("org.onap.ccsdk.apps.controllerblueprints.service.domain") -@EnableTransactionManagement -@EnableJpaRepositories("org.onap.ccsdk.apps.controllerblueprints.service.repository") -@EnableJpaAuditing -public class DatabaseConfig { - /** - * This is a entityManagerFactory method - * - * @param dataSource - * @return LocalContainerEntityManagerFactoryBean - */ - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { - HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - vendorAdapter.setGenerateDdl(true); - vendorAdapter.setShowSql(false); - LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); - factory.setJpaVendorAdapter(vendorAdapter); - factory.setPackagesToScan("org.onap.ccsdk.apps.controllerblueprints.service.domain"); - factory.setDataSource(dataSource); - return factory; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java deleted file mode 100644 index 537429f0b..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.apps.controllerblueprints; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - - -@SpringBootApplication -@ComponentScan(basePackages = {"org.onap.ccsdk.apps.controllerblueprints"}) -@EnableAutoConfiguration -public class TestApplication { - - public static void main(String[] args) { - SpringApplication.run(TestApplication.class, args); - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java deleted file mode 100644 index a94df6aec..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/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.apps.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.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.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 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 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 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/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java deleted file mode 100644 index ed208db97..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.common; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.service.SchemaGeneratorService; - -import java.io.File; -import java.nio.charset.Charset; - - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class SchemaGeneratorServiceTest { - - private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorServiceTest.class); - - @Test - public void test01GenerateSwaggerData() throws Exception { - log.info("******************* test01GenerateSwaggerData ******************************"); - - String file = "src/test/resources/enhance/enhanced-template.json"; - String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); - SchemaGeneratorService schemaGeneratorService = new SchemaGeneratorService(); - String schema = schemaGeneratorService.generateSchema(serviceTemplateContent); - log.trace("Generated Schema " + schema); - Assert.assertNotNull("failed to generate Sample Data", schema); - - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java deleted file mode 100644 index 739ce51bb..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java +++ /dev/null @@ -1,110 +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.apps.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.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -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; - -/** - * ModelTypeReactRepositoryTest. - * - * @author Brinda Santh - */ - -@RunWith(SpringRunner.class) -@DataJpaTest -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ModelTypeReactRepositoryTest { - - @Autowired - private ModelTypeReactRepository modelTypeReactRepository; - - String modelName = "test-datatype"; - - @Test - @Commit - public void test01Save() { - 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 dbModelType = modelTypeReactRepository.save(modelType).block(); - Assert.assertNotNull("Failed to get Saved ModelType", dbModelType); - } - - @Test - public void test02Finds() { - ModelType dbFindByModelName = modelTypeReactRepository.findByModelName(modelName).block(); - Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName); - - List dbFindByDefinitionType = - modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block(); - Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType); - Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType.size() > 0); - - List dbFindByDerivedFrom = - modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block(); - Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom); - Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom.size() > 0); - - List dbFindByModelNameIn = - modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block(); - Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn); - Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn.size() > 0); - - List dbFindByDefinitionTypeIn = - modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block(); - Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn); - Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn.size() > 0); - - List dbFindByDerivedFromIn = - modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block(); - Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn); - Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn.size() > 0); - } - - @Test - @Commit - public void test03Delete() { - modelTypeReactRepository.deleteByModelName(modelName).block(); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java deleted file mode 100644 index 330eaa844..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/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.apps.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.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.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 dbResourceDictionaries = - resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); - } - - @Test - public void test04FindByTagsContainingIgnoreCaseReact() { - List 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/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java new file mode 100644 index 000000000..658d3072f --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java @@ -0,0 +1,61 @@ +/* + * 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; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; + +/** + * DatabaseConfig.java Purpose: Provide Configuration Generator DatabaseConfig Information + * + * @author Brinda Santh + * @version 1.0 + */ +@Configuration +@EntityScan("org.onap.ccsdk.cds.controllerblueprints.service.domain") +@EnableTransactionManagement +@EnableJpaRepositories("org.onap.ccsdk.cds.controllerblueprints.service.repository") +@EnableJpaAuditing +public class DatabaseConfig { + /** + * This is a entityManagerFactory method + * + * @param dataSource + * @return LocalContainerEntityManagerFactoryBean + */ + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setGenerateDdl(true); + vendorAdapter.setShowSql(false); + LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); + factory.setJpaVendorAdapter(vendorAdapter); + factory.setPackagesToScan("org.onap.ccsdk.cds.controllerblueprints.service.domain"); + factory.setDataSource(dataSource); + return factory; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java new file mode 100644 index 000000000..d5ea7bc5d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java @@ -0,0 +1,34 @@ +/* + * 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; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + + +@SpringBootApplication +@ComponentScan(basePackages = {"org.onap.ccsdk.cds.controllerblueprints"}) +@EnableAutoConfiguration +public class TestApplication { + + public static void main(String[] args) { + SpringApplication.run(TestApplication.class, args); + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..12652c916 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java @@ -0,0 +1,127 @@ +/* + * 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 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 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 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/common/SchemaGeneratorServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java new file mode 100644 index 000000000..56a92fe0a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java @@ -0,0 +1,50 @@ +/* + * 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.common; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.cds.controllerblueprints.service.SchemaGeneratorService; + +import java.io.File; +import java.nio.charset.Charset; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SchemaGeneratorServiceTest { + + private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorServiceTest.class); + + @Test + public void test01GenerateSwaggerData() throws Exception { + log.info("******************* test01GenerateSwaggerData ******************************"); + + String file = "src/test/resources/enhance/enhanced-template.json"; + String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); + SchemaGeneratorService schemaGeneratorService = new SchemaGeneratorService(); + String schema = schemaGeneratorService.generateSchema(serviceTemplateContent); + log.trace("Generated Schema " + schema); + Assert.assertNotNull("failed to generate Sample Data", schema); + + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java new file mode 100644 index 000000000..26b162494 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java @@ -0,0 +1,110 @@ +/* + * 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.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.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; + +/** + * ModelTypeReactRepositoryTest. + * + * @author Brinda Santh + */ + +@RunWith(SpringRunner.class) +@DataJpaTest +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeReactRepositoryTest { + + @Autowired + private ModelTypeReactRepository modelTypeReactRepository; + + String modelName = "test-datatype"; + + @Test + @Commit + public void test01Save() { + 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 dbModelType = modelTypeReactRepository.save(modelType).block(); + Assert.assertNotNull("Failed to get Saved ModelType", dbModelType); + } + + @Test + public void test02Finds() { + ModelType dbFindByModelName = modelTypeReactRepository.findByModelName(modelName).block(); + Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName); + + List dbFindByDefinitionType = + modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block(); + Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType); + Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType.size() > 0); + + List dbFindByDerivedFrom = + modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block(); + Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom); + Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom.size() > 0); + + List dbFindByModelNameIn = + modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block(); + Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn); + Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn.size() > 0); + + List dbFindByDefinitionTypeIn = + modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block(); + Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn); + Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn.size() > 0); + + List dbFindByDerivedFromIn = + modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block(); + Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn); + Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn.size() > 0); + } + + @Test + @Commit + public void test03Delete() { + modelTypeReactRepository.deleteByModelName(modelName).block(); + } + +} 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 new file mode 100644 index 000000000..37e0549fa --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -0,0 +1,103 @@ +/* + * 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 dbResourceDictionaries = + resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); + } + + @Test + public void test04FindByTagsContainingIgnoreCaseReact() { + List 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/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt deleted file mode 100644 index d504c293e..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright © 2019 Bell Canada 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. - * 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.apps.controllerblueprints.service.controller - -import com.google.gson.Gson -import org.json.JSONException -import org.json.JSONObject -import org.junit.After -import org.junit.Before -import org.junit.FixMethodOrder -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.MethodSorters -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.context.annotation.ComponentScan -import org.springframework.core.io.ByteArrayResource -import org.springframework.http.HttpMethod -import org.springframework.http.HttpStatus -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.reactive.server.WebTestClient -import org.springframework.util.Base64Utils -import org.springframework.web.reactive.function.BodyInserters -import java.io.File -import java.io.IOException -import java.nio.charset.StandardCharsets.UTF_8 -import java.nio.file.Files -import java.nio.file.Paths - -/** - * BlueprintModelControllerTest Purpose: Integration test at API level - * - * @author Vinal Patel - * @version 1.0 - */ - -@RunWith(SpringRunner::class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = [TestApplication::class]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.controllerblueprints"]) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@EnableAutoConfiguration -class BlueprintModelControllerTest { - - companion object { - - private var id: String? = null - private var name: String? = null - private var version: String? = null - private var tag: String? = null - private var result: String? = null - } - - @Value("\${controllerblueprints.loadBluePrintPaths}") - private val loadBluePrintPaths: String? = null - - @Autowired - private val webTestClient: WebTestClient? = null - - @Value("\${controllerblueprints.loadBlueprintsExamplesPath}") - private val blueprintArchivePath: String? = null - - private val filename = "test.zip" - private var blueprintFile: File? = null - private var zipBlueprintFile: File? = null - - @Before - @Throws(Exception::class) - fun setUp() { - blueprintFile = File(loadBluePrintPaths+"/baseconfiguration") - if (blueprintFile!!.isDirectory) { - zipBlueprintFile = File(Paths.get(blueprintArchivePath).resolve(filename).toString()) - BluePrintArchiveUtils.compress(blueprintFile!!, zipBlueprintFile!!, true) - } - } - - @After - @Throws(Exception::class) - fun tearDown() { - zipBlueprintFile!!.delete() - } - - @Test - @Throws(IOException::class, JSONException::class) - fun test1_saveBluePrint() { - webTestClient(HttpMethod.POST, - BodyInserters.fromMultipartData("file", object : ByteArrayResource(Files.readAllBytes(zipBlueprintFile!!.toPath())) { - override fun getFilename(): String? { - return "test.zip" - } - }), - "/api/v1/blueprint-model", - HttpStatus.OK, true) - } - - @Test - @Throws(JSONException::class) - fun test2_getBluePrintByNameAndVersion() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/by-name/$name/version/$version", HttpStatus.OK, false) - } - - - @Test - @Throws(JSONException::class) - fun test3_getBlueprintModel() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/$id", HttpStatus.OK, false) - } - - @Test - @Throws(JSONException::class) - fun test4_getAllBlueprintModel() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model", HttpStatus.OK, false) - } - - @Test - @Throws(JSONException::class) - fun test5_downloadBluePrint() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/$id", HttpStatus.OK, false) - } - - @Test - fun test6_publishBlueprintModel() { - } - - @Test - @Throws(JSONException::class) - fun test7_searchBlueprintModels() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/search/$name", HttpStatus.OK, false) - } - - @Test - @Throws(JSONException::class) - fun test8_downloadBlueprintByNameAndVersion() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/by-name/$name/version/$version", HttpStatus.OK, false) - } - - @Test - fun test9_deleteBluePrint() { - //TODO: Use webTestClient function - //webTestClient(HttpMethod.DELETE, null, "/api/v1/blueprint-model/" + id, HttpStatus.OK, false); - webTestClient!!.delete().uri("/api/v1/blueprint-model/$id") - .header("Authorization", "Basic " + Base64Utils - .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) - .exchange() - .expectStatus().is2xxSuccessful - } - - @Throws(JSONException::class) - private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, expectedResponceStatus: HttpStatus, setParam: Boolean) { - - result = String(webTestClient!!.method(requestMethod).uri(uri) - .header("Authorization", "Basic " + Base64Utils - .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) - .body(body) - .exchange() - .expectStatus().isEqualTo(expectedResponceStatus) - .expectBody() - .returnResult().responseBody!!) - - if (setParam) { - val jsonResponse = JSONObject(result) - val blueprintModelSearchJSON = jsonResponse.getJSONObject("blueprintModel") - val gson = Gson() - val blueprintModelSearch = gson.fromJson(blueprintModelSearchJSON.toString(), BlueprintModelSearch::class.java) - id = blueprintModelSearch.id - name = blueprintModelSearch.artifactName - version = blueprintModelSearch.artifactVersion - tag = blueprintModelSearch.tags - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt deleted file mode 100644 index 6fd0d1f04..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.controller - -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.apps.controllerblueprints.TestApplication -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -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 ModelTypeControllerTest { - - private val log = EELFManager.getInstance().getLogger(ModelTypeControllerTest::class.java)!! - - @Autowired - internal var modelTypeController: ModelTypeController? = null - - private var modelName = "test-datatype" - - @Test - @Commit - @Throws(Exception::class) - fun test01SaveModelType() { - 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 = modelTypeController!!.saveModelType(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 = modelTypeController!!.getModelTypeByName(modelType.modelName) - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", - dbModelType) - - // Model Update - modelType.updatedBy = "bs2796@xxx.com" - modelType = modelTypeController!!.saveModelType(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() { - log.info("*********************** test02SearchModelTypes ***************************") - - val tags = "test-datatype" - - val dbModelTypes = modelTypeController!!.searchModelTypes(tags) - Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) - Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty()) - - } - - @Test - @Throws(Exception::class) - fun test03GetModelType() { - log.info("************************* test03GetModelType *********************************") - val dbModelType = modelTypeController!!.getModelTypeByName(modelName) - Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType) - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) - - val dbDatatypeModelTypes = modelTypeController!!.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.isNotEmpty()) - } - - @Test - @Commit - @Throws(Exception::class) - fun test04DeleteModelType() { - log.info( - "************************ test03DeleteModelType ***********************") - val dbResourceMapping = modelTypeController!!.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) - - modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName) - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt deleted file mode 100644 index 96c142613..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.controller - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [TestApplication::class]) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.controllerblueprints"]) -class ResourceDictionaryControllerTest { - - @Autowired - lateinit var resourceDictionaryController: ResourceDictionaryController - - @Test - fun testResourceDictionaryControllerPresence() { - assertNotNull(resourceDictionaryController, "failed to initialise ResourceDictionaryController") - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt deleted file mode 100644 index 60420aa64..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.controller.mock - -import org.apache.commons.io.FilenameUtils -import org.slf4j.LoggerFactory -import org.springframework.core.io.buffer.DataBuffer -import org.springframework.http.HttpHeaders -import org.springframework.http.codec.multipart.FilePart -import org.springframework.util.FileCopyUtils -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import java.io.File -import java.nio.file.Path - -class MockFilePart(private val fileName: String) : FilePart { - val log = LoggerFactory.getLogger(MockFilePart::class.java)!! - override fun content(): Flux { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun headers(): HttpHeaders { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun filename(): String { - return FilenameUtils.getName(fileName) - } - - override fun name(): String { - return FilenameUtils.getBaseName(fileName) - } - - override fun transferTo(path: Path): Mono { - log.info("Copying file($fileName to ${path}") - FileCopyUtils.copy(File(fileName), path.toFile()) - return Mono.empty() - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt deleted file mode 100644 index 62a37bef1..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ /dev/null @@ -1,111 +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.apps.controllerblueprints.service.enhancer - -import kotlinx.coroutines.runBlocking -import org.junit.Assert -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName -import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService -import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = arrayOf(TestApplication::class)) -@TestPropertySource(locations = arrayOf("classpath:application.properties")) -class BluePrintEnhancerServiceImplTest { - - @Autowired - lateinit var modelTypeLoadService: ModelTypeLoadService - - @Autowired - lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService - - @Autowired - lateinit var bluePrintEnhancerService: BluePrintEnhancerService - - @Autowired - lateinit var bluePrintValidatorService: BluePrintValidatorService - - @Before - fun init() { - runBlocking { - modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type") - resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary") - resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/test-dictionary") - } - } - - @Test - @Throws(Exception::class) - fun testEnhancementAndValidation() { - - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - testComponentInvokeEnhancementAndValidation(basePath, "base-enhance") - } - - @Test - @Throws(Exception::class) - fun testComponentInvokeEnhancementAndValidation() { - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke" - testComponentInvokeEnhancementAndValidation(basePath, "component-enhance") - } - - @Test - @Throws(Exception::class) - fun testGoldenEnhancementAndValidation() { - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden" - testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance") - } - - @Test - @Throws(Exception::class) - fun testCapabilityRestconfEnhancementAndValidation() { - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_restconf" - testComponentInvokeEnhancementAndValidation(basePath, "capability_restconf-enhance") - - } - - private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { - runBlocking { - val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName) - - deleteDir(targetPath) - - val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) - Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) - - // Validate the Generated BluePrints - val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint($basePath) validation failed ", valid) - - deleteDir(targetPath) - } - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt deleted file mode 100644 index 6bd10525e..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.utils - -import kotlinx.coroutines.runBlocking -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.* -import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart -import java.nio.file.Paths -import java.util.* -import kotlin.test.assertTrue - -class BluePrintEnhancerUtilsTest { - - private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - private val blueprintArchivePath: String = "./target/blueprints/archive" - private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" - private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") - - @Before - fun setUp() { - val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() - assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") - val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs() - assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}") - val blueprintFile = Paths.get(blueprintDir).toFile().normalize() - val testZipFile = blueprintFile.compress(zipBlueprintFileName) - assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}") - } - - @After - fun tearDown() { - deleteDir(blueprintArchivePath) - deleteDir(blueprintEnrichmentPath) - } - - @Test - fun testFilePartCompressionNDeCompression() { - val filePart = MockFilePart(zipBlueprintFileName) - - runBlocking { - val enhanceId = UUID.randomUUID().toString() - val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId) - val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId) - BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) - BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) - } - } -} - diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt deleted file mode 100644 index db4ee5c98..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.apps.controllerblueprints.service.validator - -import com.fasterxml.jackson.databind.JsonNode -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType - -class ModelTypeValidatorTest { - - @Test(expected = IllegalStateException::class) - @Throws(Exception::class) - fun testvalidateModelType() { - val modelType = ModelType() - modelType.definitionType = "" - modelType.derivedFrom = "" - modelType.description = "" - val definitionContent: JsonNode? = null - modelType.definition = definitionContent - modelType.modelName = "" - modelType.version = "" - modelType.tags = "" - modelType.updatedBy = "" - ModelTypeValidator.validateModelType(modelType) - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt new file mode 100644 index 000000000..d61e64251 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt @@ -0,0 +1,193 @@ +/* + * Copyright © 2019 Bell Canada 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. + * 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.controller + +import com.google.gson.Gson +import org.json.JSONException +import org.json.JSONObject +import org.junit.After +import org.junit.Before +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.BluePrintArchiveUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.core.io.ByteArrayResource +import org.springframework.http.HttpMethod +import org.springframework.http.HttpStatus +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.util.Base64Utils +import org.springframework.web.reactive.function.BodyInserters +import java.io.File +import java.io.IOException +import java.nio.charset.StandardCharsets.UTF_8 +import java.nio.file.Files +import java.nio.file.Paths + +/** + * BlueprintModelControllerTest Purpose: Integration test at API level + * + * @author Vinal Patel + * @version 1.0 + */ + +@RunWith(SpringRunner::class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = [TestApplication::class]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.controllerblueprints"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@EnableAutoConfiguration +class BlueprintModelControllerTest { + + companion object { + + private var id: String? = null + private var name: String? = null + private var version: String? = null + private var tag: String? = null + private var result: String? = null + } + + @Value("\${controllerblueprints.loadBluePrintPaths}") + private val loadBluePrintPaths: String? = null + + @Autowired + private val webTestClient: WebTestClient? = null + + @Value("\${controllerblueprints.loadBlueprintsExamplesPath}") + private val blueprintArchivePath: String? = null + + private val filename = "test.zip" + private var blueprintFile: File? = null + private var zipBlueprintFile: File? = null + + @Before + @Throws(Exception::class) + fun setUp() { + blueprintFile = File(loadBluePrintPaths+"/baseconfiguration") + if (blueprintFile!!.isDirectory) { + zipBlueprintFile = File(Paths.get(blueprintArchivePath).resolve(filename).toString()) + BluePrintArchiveUtils.compress(blueprintFile!!, zipBlueprintFile!!, true) + } + } + + @After + @Throws(Exception::class) + fun tearDown() { + zipBlueprintFile!!.delete() + } + + @Test + @Throws(IOException::class, JSONException::class) + fun test1_saveBluePrint() { + webTestClient(HttpMethod.POST, + BodyInserters.fromMultipartData("file", object : ByteArrayResource(Files.readAllBytes(zipBlueprintFile!!.toPath())) { + override fun getFilename(): String? { + return "test.zip" + } + }), + "/api/v1/blueprint-model", + HttpStatus.OK, true) + } + + @Test + @Throws(JSONException::class) + fun test2_getBluePrintByNameAndVersion() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/by-name/$name/version/$version", HttpStatus.OK, false) + } + + + @Test + @Throws(JSONException::class) + fun test3_getBlueprintModel() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/$id", HttpStatus.OK, false) + } + + @Test + @Throws(JSONException::class) + fun test4_getAllBlueprintModel() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model", HttpStatus.OK, false) + } + + @Test + @Throws(JSONException::class) + fun test5_downloadBluePrint() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/$id", HttpStatus.OK, false) + } + + @Test + fun test6_publishBlueprintModel() { + } + + @Test + @Throws(JSONException::class) + fun test7_searchBlueprintModels() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/search/$name", HttpStatus.OK, false) + } + + @Test + @Throws(JSONException::class) + fun test8_downloadBlueprintByNameAndVersion() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/by-name/$name/version/$version", HttpStatus.OK, false) + } + + @Test + fun test9_deleteBluePrint() { + //TODO: Use webTestClient function + //webTestClient(HttpMethod.DELETE, null, "/api/v1/blueprint-model/" + id, HttpStatus.OK, false); + webTestClient!!.delete().uri("/api/v1/blueprint-model/$id") + .header("Authorization", "Basic " + Base64Utils + .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) + .exchange() + .expectStatus().is2xxSuccessful + } + + @Throws(JSONException::class) + private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, expectedResponceStatus: HttpStatus, setParam: Boolean) { + + result = String(webTestClient!!.method(requestMethod).uri(uri) + .header("Authorization", "Basic " + Base64Utils + .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) + .body(body) + .exchange() + .expectStatus().isEqualTo(expectedResponceStatus) + .expectBody() + .returnResult().responseBody!!) + + if (setParam) { + val jsonResponse = JSONObject(result) + val blueprintModelSearchJSON = jsonResponse.getJSONObject("blueprintModel") + val gson = Gson() + val blueprintModelSearch = gson.fromJson(blueprintModelSearchJSON.toString(), BlueprintModelSearch::class.java) + id = blueprintModelSearch.id + name = blueprintModelSearch.artifactName + version = blueprintModelSearch.artifactVersion + tag = blueprintModelSearch.tags + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt new file mode 100644 index 000000000..610c9d033 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt @@ -0,0 +1,120 @@ +/* + * 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.controller + +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.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 ModelTypeControllerTest { + + private val log = EELFManager.getInstance().getLogger(ModelTypeControllerTest::class.java)!! + + @Autowired + internal var modelTypeController: ModelTypeController? = null + + private var modelName = "test-datatype" + + @Test + @Commit + @Throws(Exception::class) + fun test01SaveModelType() { + 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 = modelTypeController!!.saveModelType(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 = modelTypeController!!.getModelTypeByName(modelType.modelName) + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType) + + // Model Update + modelType.updatedBy = "bs2796@xxx.com" + modelType = modelTypeController!!.saveModelType(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() { + log.info("*********************** test02SearchModelTypes ***************************") + + val tags = "test-datatype" + + val dbModelTypes = modelTypeController!!.searchModelTypes(tags) + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty()) + + } + + @Test + @Throws(Exception::class) + fun test03GetModelType() { + log.info("************************* test03GetModelType *********************************") + val dbModelType = modelTypeController!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) + + val dbDatatypeModelTypes = modelTypeController!!.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.isNotEmpty()) + } + + @Test + @Commit + @Throws(Exception::class) + fun test04DeleteModelType() { + log.info( + "************************ test03DeleteModelType ***********************") + val dbResourceMapping = modelTypeController!!.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) + + modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName) + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt new file mode 100644 index 000000000..cf139ec00 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt @@ -0,0 +1,43 @@ +/* + * 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.controller + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [TestApplication::class]) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.controllerblueprints"]) +class ResourceDictionaryControllerTest { + + @Autowired + lateinit var resourceDictionaryController: ResourceDictionaryController + + @Test + fun testResourceDictionaryControllerPresence() { + assertNotNull(resourceDictionaryController, "failed to initialise ResourceDictionaryController") + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt new file mode 100644 index 000000000..2fb2129ae --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt @@ -0,0 +1,53 @@ +/* + * 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.controller.mock + +import org.apache.commons.io.FilenameUtils +import org.slf4j.LoggerFactory +import org.springframework.core.io.buffer.DataBuffer +import org.springframework.http.HttpHeaders +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.FileCopyUtils +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.io.File +import java.nio.file.Path + +class MockFilePart(private val fileName: String) : FilePart { + val log = LoggerFactory.getLogger(MockFilePart::class.java)!! + override fun content(): Flux { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun headers(): HttpHeaders { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun filename(): String { + return FilenameUtils.getName(fileName) + } + + override fun name(): String { + return FilenameUtils.getBaseName(fileName) + } + + override fun transferTo(path: Path): Mono { + log.info("Copying file($fileName to ${path}") + FileCopyUtils.copy(File(fileName), path.toFile()) + return Mono.empty() + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt new file mode 100644 index 000000000..677dd45ad --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -0,0 +1,111 @@ +/* + * 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.enhancer + +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.service.load.ModelTypeLoadService +import org.onap.ccsdk.cds.controllerblueprints.service.load.ResourceDictionaryLoadService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = arrayOf(TestApplication::class)) +@TestPropertySource(locations = arrayOf("classpath:application.properties")) +class BluePrintEnhancerServiceImplTest { + + @Autowired + lateinit var modelTypeLoadService: ModelTypeLoadService + + @Autowired + lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService + + @Autowired + lateinit var bluePrintEnhancerService: BluePrintEnhancerService + + @Autowired + lateinit var bluePrintValidatorService: BluePrintValidatorService + + @Before + fun init() { + runBlocking { + modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type") + resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary") + resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/test-dictionary") + } + } + + @Test + @Throws(Exception::class) + fun testEnhancementAndValidation() { + + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + testComponentInvokeEnhancementAndValidation(basePath, "base-enhance") + } + + @Test + @Throws(Exception::class) + fun testComponentInvokeEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke" + testComponentInvokeEnhancementAndValidation(basePath, "component-enhance") + } + + @Test + @Throws(Exception::class) + fun testGoldenEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden" + testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance") + } + + @Test + @Throws(Exception::class) + fun testCapabilityRestconfEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_restconf" + testComponentInvokeEnhancementAndValidation(basePath, "capability_restconf-enhance") + + } + + private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { + runBlocking { + val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName) + + deleteDir(targetPath) + + val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) + Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) + + // Validate the Generated BluePrints + val valid = bluePrintValidatorService.validateBluePrints(targetPath) + Assert.assertTrue("blueprint($basePath) validation failed ", valid) + + deleteDir(targetPath) + } + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt new file mode 100644 index 000000000..100c3adeb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.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.utils + +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.service.controller.mock.MockFilePart +import java.nio.file.Paths +import java.util.* +import kotlin.test.assertTrue + +class BluePrintEnhancerUtilsTest { + + private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + private val blueprintArchivePath: String = "./target/blueprints/archive" + private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" + private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") + + @Before + fun setUp() { + val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() + assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") + val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs() + assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}") + val blueprintFile = Paths.get(blueprintDir).toFile().normalize() + val testZipFile = blueprintFile.compress(zipBlueprintFileName) + assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}") + } + + @After + fun tearDown() { + deleteDir(blueprintArchivePath) + deleteDir(blueprintEnrichmentPath) + } + + @Test + fun testFilePartCompressionNDeCompression() { + val filePart = MockFilePart(zipBlueprintFileName) + + runBlocking { + val enhanceId = UUID.randomUUID().toString() + val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId) + val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId) + BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) + BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) + } + } +} + diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt new file mode 100644 index 000000000..728f431a7 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt @@ -0,0 +1,40 @@ +/* + * 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.validator + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType + +class ModelTypeValidatorTest { + + @Test(expected = IllegalStateException::class) + @Throws(Exception::class) + fun testvalidateModelType() { + val modelType = ModelType() + modelType.definitionType = "" + modelType.derivedFrom = "" + modelType.description = "" + val definitionContent: JsonNode? = null + modelType.definition = definitionContent + modelType.modelName = "" + modelType.version = "" + modelType.tags = "" + modelType.updatedBy = "" + ModelTypeValidator.validateModelType(modelType) + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml index 2546a8389..e66127977 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml +++ b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml @@ -31,7 +31,7 @@ - + -- cgit 1.2.3-korg