1fb34d789998d4e7072115079fb21f8939c13e6d
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2018-2019 Bell Canada 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.cds.blueprintsprocessor.resolutionresults.api
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
20 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResult
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResultService
22 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintCatalogService
23 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
24 import org.springframework.stereotype.Service
25 import java.util.*
26
27 /**
28  * Process Resolution Results API request to store and retrieve resource resolution results using database acess layer
29  * ResourceResolutionResultService and corresponding entities
30  *
31  * @author Serge Simard
32  * @version 1.0
33  */
34 @Service
35 class ResolutionResultsServiceHandler(private val bluePrintCatalogService: BluePrintCatalogService,
36                                       private var resolutionResultService: ResourceResolutionResultService) {
37
38     suspend fun loadStoredResultById(resolutionResultId: String): String {
39
40         return resolutionResultService.readByKey(resolutionResultId)
41     }
42
43     suspend fun loadStoredResult(blueprintName : String, blueprintVersion : String, artifactTemplate: String,
44                                      resolutionKey: String): String {
45
46         val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion)
47         val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(),
48                 basePath.toString())
49
50         return resolutionResultService.read(blueprintRuntimeService, artifactTemplate, resolutionKey)
51     }
52
53     suspend fun saveNewStoredResult(blueprintName : String, blueprintVersion : String, artifactTemplate: String,
54                                     resolutionKey: String, result: String): ResourceResolutionResult {
55
56         val basePath = bluePrintCatalogService.getFromDatabase(blueprintName, blueprintVersion)
57         val blueprintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(UUID.randomUUID().toString(),
58                 basePath.toString())
59
60         val properties = mapOf(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY to resolutionKey)
61
62         val resultStored = resolutionResultService.write(properties, result, blueprintRuntimeService, artifactTemplate)
63
64         return resultStored
65     }
66
67     suspend fun removeStoredResultById(resolutionResultId: String): Unit {
68
69         return resolutionResultService.deleteByKey(resolutionResultId)
70     }
71 }