8cddbb4c9598bb5f553af575fe40043a5139ac5e
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.load
18
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
24 import java.io.File
25 import java.util.*
26
27 @Service
28 class BluePrintCatalogServiceImpl(private val bluePrintLoadConfiguration: BluePrintLoadConfiguration,
29                                   private val bluePrintValidatorService: BluePrintValidatorService) : BluePrintCatalogService {
30
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)
38             if (valid) {
39                 val zipFile = File("${bluePrintLoadConfiguration.blueprintArchivePath}/${id}.zip")
40                 // zip the directory
41                 BluePrintArchiveUtils.compress(blueprintFile, zipFile, true)
42
43                 // TODO(Upload to the Data Base)
44
45                 // After Upload to Database delete the zip file
46                 zipFile.deleteOnExit()
47             }
48         } else {
49             // If the file is ZIP
50             // TODO(Upload to the Data Base)
51         }
52         return id
53     }
54
55     override fun downloadFromDataBase(name: String, version: String, path: String): String {
56         // If path ends with zip, then compress otherwise download as extracted folder
57
58         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
59     }
60
61     override fun prepareBluePrint(name: String, version: String): String {
62         val preparedPath = "${bluePrintLoadConfiguration.blueprintDeployPath}/$name/$version"
63         downloadFromDataBase(name, version, preparedPath)
64         return preparedPath
65     }
66 }