Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / blueprint-validation / src / main / kotlin / org / onap / ccsdk / apps / controllerblueprints / validation / extension / ArtifactMappingResourceValidator.kt
1 /*
2  *  Copyright © 2018 IBM.
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.validation.extension
18
19 import com.att.eelf.configuration.EELFLogger
20 import com.att.eelf.configuration.EELFManager
21 import org.onap.ccsdk.apps.controllerblueprints.core.data.ArtifactDefinition
22 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintArtifactDefinitionValidator
23 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintTypeValidatorService
24 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService
25 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
26 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
27 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.service.ResourceAssignmentValidationServiceImpl
28 import org.springframework.stereotype.Service
29 import java.io.File
30
31 @Service("artifact-mapping-resource-artifact-definition-validator")
32 open class ArtifactMappingResourceValidator(private val bluePrintTypeValidatorService: BluePrintTypeValidatorService)
33     : BluePrintArtifactDefinitionValidator {
34
35     private val log: EELFLogger = EELFManager.getInstance().getLogger(ArtifactMappingResourceValidator::class.toString())
36
37     override fun validate(bluePrintRuntimeService: BluePrintRuntimeService<*>, name: String,
38                           artifactDefinition: ArtifactDefinition) {
39
40         val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
41         val file: String = artifactDefinition.file
42         val completePath = bluePrintContext.rootPath.plus(File.separator).plus(file)
43         log.trace("Validation artifact-mapping-resource($completePath)")
44         val resourceAssignment = JacksonUtils.getListFromFile(completePath, ResourceAssignment::class.java)
45         val resourceAssignmentValidationService = ResourceAssignmentValidationServiceImpl()
46         resourceAssignmentValidationService.validate(resourceAssignment)
47     }
48 }