2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 Bell Canada.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.apps.controllerblueprints.service.load
20 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
21 import org.onap.ccsdk.apps.controllerblueprints.core.common.ApplicationConstants
22 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
24 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
26 import org.onap.ccsdk.apps.controllerblueprints.db.resources.BlueprintCatalogServiceImpl
27 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModel
28 import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelContent
29 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelContentRepository
30 import org.onap.ccsdk.apps.controllerblueprints.service.repository.ControllerBlueprintModelRepository
31 import org.springframework.stereotype.Service
33 import java.nio.file.Files
36 Similar implementation in [org.onap.ccsdk.apps.blueprintsprocessor.db.BlueprintProcessorCatalogServiceImpl]
39 class ControllerBlueprintCatalogServiceImpl(bluePrintLoadConfiguration: BluePrintLoadConfiguration,
40 private val bluePrintValidatorService: BluePrintValidatorService,
41 private val blueprintModelContentRepository: ControllerBlueprintModelContentRepository,
42 private val blueprintModelRepository: ControllerBlueprintModelRepository)
43 : BlueprintCatalogServiceImpl(bluePrintLoadConfiguration) {
45 override fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean?) {
47 val firstItem = BluePrintArchiveUtils.getFirstItemInDirectory(extractedDirectory)
48 val blueprintBaseDirectory = extractedDirectory.absolutePath + "/" + firstItem
50 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintBaseDirectory)
52 // Check Validity of blueprint
53 if (checkValidity!!) {
54 valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
57 if ((valid && checkValidity!!) || (!valid && !checkValidity!!)) {
58 val metaData = bluePrintRuntimeService.bluePrintContext().metadata!!
59 // FIXME("Check Duplicate for Artifact Name and Artifact Version")
60 val blueprintModel = BlueprintModel()
61 blueprintModel.id = id
62 blueprintModel.artifactType = ApplicationConstants.ASDC_ARTIFACT_TYPE_SDNC_MODEL
63 blueprintModel.published = ApplicationConstants.ACTIVE_N
64 blueprintModel.artifactName = metaData[BluePrintConstants.METADATA_TEMPLATE_NAME]
65 blueprintModel.artifactVersion = metaData[BluePrintConstants.METADATA_TEMPLATE_VERSION]
66 blueprintModel.updatedBy = metaData[BluePrintConstants.METADATA_TEMPLATE_AUTHOR]
67 blueprintModel.tags = metaData[BluePrintConstants.METADATA_TEMPLATE_TAGS]
68 blueprintModel.artifactDescription = "Controller Blueprint for ${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
70 val blueprintModelContent = BlueprintModelContent()
71 blueprintModelContent.id = id // For quick access both id's are same.always have one to one mapping.
72 blueprintModelContent.contentType = "CBA_ZIP"
73 blueprintModelContent.name = "${blueprintModel.artifactName}:${blueprintModel.artifactVersion}"
74 blueprintModelContent.description = "(${blueprintModel.artifactName}:${blueprintModel.artifactVersion} CBA Zip Content"
75 blueprintModelContent.content = Files.readAllBytes(archiveFile.toPath())
77 // Set the Blueprint Model into blueprintModelContent
78 blueprintModelContent.blueprintModel = blueprintModel
80 // Set the Blueprint Model Content into blueprintModel
81 blueprintModel.blueprintModelContent = blueprintModelContent
83 blueprintModelRepository.saveAndFlush(blueprintModel)