2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.controllerblueprints.service.load
19 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintCatalogService
20 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService
21 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils
22 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
23 import org.springframework.stereotype.Service
28 class BluePrintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
29 private val bluePrintValidatorService: BluePrintValidatorService) : BluePrintCatalogService {
31 override fun uploadToDataBase(file: String): String {
32 val id = UUID.randomUUID().toString()
33 val blueprintFile = File(file)
34 // If the file is directory
35 if (blueprintFile.isDirectory) {
36 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(id, blueprintFile.absolutePath)
37 val valid = bluePrintValidatorService.validateBluePrints(bluePrintRuntimeService)
39 val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/${id}.zip")
41 BluePrintArchiveUtils.compress(blueprintFile, zipFile, true)
43 // TODO(Upload to the Data Base)
45 // After Upload to Database delete the zip file
46 zipFile.deleteOnExit()
50 // TODO(Upload to the Data Base)
55 override fun downloadFromDataBase(name: String, version: String, path: String): String {
56 // If path ends with zip, then compress otherwise download as extracted folder
58 TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
61 override fun prepareBluePrint(name: String, version: String): String {
62 val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version"
63 downloadFromDataBase(name, version, preparedPath)