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.db.resources
20 import org.onap.ccsdk.apps.controllerblueprints.core.config.BluePrintLoadConfiguration
21 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
22 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
23 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils
25 import javax.persistence.MappedSuperclass
28 abstract class BlueprintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration) : BluePrintCatalogService {
30 override fun uploadToDataBase(file: String, validate: Boolean): String {
31 // The file name provided here is unique as we transform to UUID before storing
32 val blueprintFile = File(file)
33 val fileName = blueprintFile.name
34 val id = BluePrintFileUtils.stripFileExtension(fileName)
35 // If the file is directory
36 if (blueprintFile.isDirectory) {
38 val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/$fileName")
40 BluePrintArchiveUtils.compress(blueprintFile, zipFile, true)
42 // Upload to the Data Base
43 saveToDataBase(blueprintFile, id, zipFile)
45 // After Upload to Database delete the zip file
50 // unzip the CBA file to validate before store in database
51 val targetDir = "${bluePrintLoadConfiguration.blueprintDeployPath}/$id/"
52 val extractedDirectory = BluePrintArchiveUtils.deCompress(blueprintFile, targetDir)
54 // Upload to the Data Base
55 saveToDataBase(extractedDirectory, id, blueprintFile)
57 // After Upload to Database delete the zip file
58 blueprintFile.delete()
59 extractedDirectory.delete()
65 override fun downloadFromDataBase(name: String, version: String, path: String): String {
66 // If path ends with zip, then compress otherwise download as extracted folder
68 TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
71 override fun downloadFromDataBase(uuid: String, path: String): String {
72 TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
75 override fun prepareBluePrint(name: String, version: String): String {
76 val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version"
77 downloadFromDataBase(name, version, preparedPath)
81 abstract fun saveToDataBase(extractedDirectory: File, id: String, archiveFile: File, checkValidity: Boolean? = false)