2 * Copyright (C) 2019 Bell Canada.
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.
16 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db
18 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
19 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
22 import org.springframework.dao.DataIntegrityViolationException
23 import org.springframework.stereotype.Service
27 class ResourceResolutionResultService(private val resourceResolutionRepository: ResourceResolutionRepository) {
29 fun write(properties: Map<String, Any>, result: String, bluePrintRuntimeService: BluePrintRuntimeService<*>,
30 artifactPrefix: String) {
32 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
34 val resourceResolutionResult = ResourceResolutionResult()
35 resourceResolutionResult.id = UUID.randomUUID().toString()
36 resourceResolutionResult.artifactName = artifactPrefix
37 resourceResolutionResult.blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
38 resourceResolutionResult.blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
39 resourceResolutionResult.resolutionKey =
40 properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_KEY].toString()
41 resourceResolutionResult.result = result
44 resourceResolutionRepository.saveAndFlush(resourceResolutionResult)
45 } catch (ex: DataIntegrityViolationException) {
46 throw BluePrintException("Failed to store resource resolution result.", ex)
50 fun read(bluePrintRuntimeService: BluePrintRuntimeService<*>, artifactPrefix: String,
51 resolutionKey: String): String {
53 val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
55 val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]
56 val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]
58 return resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
62 artifactPrefix).result!!