diff options
6 files changed, 133 insertions, 6 deletions
diff --git a/cds-ui/client/src/app/common/core/store/models/blueprintState.model.ts b/cds-ui/client/src/app/common/core/store/models/blueprintState.model.ts index 6d2659248..6d3aa8c93 100644 --- a/cds-ui/client/src/app/common/core/store/models/blueprintState.model.ts +++ b/cds-ui/client/src/app/common/core/store/models/blueprintState.model.ts @@ -28,6 +28,8 @@ export interface IBlueprintState { name?: string; files?: any; filesData?: any; + uploadedFileName?: string; + entryDefinition?: string; isLoadSuccess?: boolean; isUpdateSuccess?: boolean; isSaveSuccess?: boolean; diff --git a/cds-ui/client/src/app/common/core/store/reducers/blueprint.reducer.ts b/cds-ui/client/src/app/common/core/store/reducers/blueprint.reducer.ts index 37a659da6..da933ab5e 100644 --- a/cds-ui/client/src/app/common/core/store/reducers/blueprint.reducer.ts +++ b/cds-ui/client/src/app/common/core/store/reducers/blueprint.reducer.ts @@ -55,7 +55,9 @@ export function blueprintReducer(state: IBlueprintState = initialBlueprintState, blueprint: action.payload.blueprint, name: action.payload.name, files: action.payload.files, - filesData: action.payload.filesData + filesData: action.payload.filesData, + uploadedFileName: action.payload.uploadedFileName, + entryDefinition: action.payload.entryDefinition } default: return state; diff --git a/cds-ui/client/src/app/feature-modules/blueprint/select-template/metadata/metadata.component.ts b/cds-ui/client/src/app/feature-modules/blueprint/select-template/metadata/metadata.component.ts index 2327a5839..609aacae7 100644 --- a/cds-ui/client/src/app/feature-modules/blueprint/select-template/metadata/metadata.component.ts +++ b/cds-ui/client/src/app/feature-modules/blueprint/select-template/metadata/metadata.component.ts @@ -23,13 +23,12 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Observable } from 'rxjs'; import { Store } from '@ngrx/store'; -import { A11yModule } from '@angular/cdk/a11y'; import { IAppState } from '../../../../common/core/store/state/app.state'; import { IBlueprintState } from 'src/app/common/core/store/models/blueprintState.model'; import { IBlueprint } from 'src/app/common/core/store/models/blueprint.model'; import { IMetaData } from '../../../../common/core/store/models/metadata.model'; -import { LoadBlueprintSuccess } from 'src/app/common/core/store/actions/blueprint.action'; +import { SetBlueprintState } from 'src/app/common/core/store/actions/blueprint.action'; @Component({ selector: 'app-metadata', @@ -41,6 +40,13 @@ export class MetadataComponent implements OnInit { metadata: IMetaData; bpState: Observable<IBlueprintState>; blueprint: IBlueprint; + filesTree: any = []; + filesData: any = []; + selectedFile: string; + zipFolder: any; + blueprintName: string; + uploadedFileName: string; + entryDefinition: string; constructor(private formBuilder: FormBuilder, private store: Store<IAppState>) { this.bpState = this.store.select('blueprint'); @@ -58,6 +64,16 @@ export class MetadataComponent implements OnInit { this.bpState.subscribe( blueprintdata => { var blueprintState: IBlueprintState = { blueprint: blueprintdata.blueprint, isLoadSuccess: blueprintdata.isLoadSuccess, isSaveSuccess: blueprintdata.isSaveSuccess, isUpdateSuccess: blueprintdata.isUpdateSuccess }; + this.blueprint = blueprintState.blueprint; + this.filesTree = blueprintdata.files; + this.filesData = blueprintdata.filesData; + this.blueprintName = blueprintdata.name; + this.uploadedFileName = blueprintdata.uploadedFileName; + this.entryDefinition = blueprintdata.entryDefinition; + + + + var blueprintState: IBlueprintState = { blueprint: blueprintdata.blueprint, isLoadSuccess: blueprintdata.isLoadSuccess, isSaveSuccess: blueprintdata.isSaveSuccess, isUpdateSuccess: blueprintdata.isUpdateSuccess }; this.metadata = blueprintState.blueprint.metadata; this.blueprint = blueprintState.blueprint; let metadatavalues = []; @@ -82,7 +98,21 @@ export class MetadataComponent implements OnInit { UploadMetadata() { this.metadata = Object.assign({}, this.CBAMetadataForm.value); this.blueprint.metadata = this.metadata; - this.store.dispatch(new LoadBlueprintSuccess(this.blueprint)); + + this.filesData.forEach((fileNode) => { + if (fileNode.name.includes(this.blueprintName) && fileNode.name == this.entryDefinition) { + fileNode.data = JSON.stringify(this.blueprint, null, "\t"); + } + }); + let blueprintState = { + blueprint: this.blueprint, + name: this.blueprintName, + files: this.filesTree, + filesData: this.filesData, + uploadedFileName: this.uploadedFileName, + entryDefinition: this.entryDefinition + } + this.store.dispatch(new SetBlueprintState(blueprintState)); } }
\ No newline at end of file diff --git a/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.ts b/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.ts index 9c11f7684..25f85de77 100644 --- a/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.ts +++ b/cds-ui/client/src/app/feature-modules/blueprint/select-template/search-template/search-template.component.ts @@ -53,6 +53,7 @@ export class SearchTemplateComponent implements OnInit { private activationBlueprint: any; private tocsaMetadaData: any; private blueprintName: string; + private entryDefinition: string; constructor(private store: Store<IAppState>) { } @@ -78,7 +79,9 @@ export class SearchTemplateComponent implements OnInit { blueprint: data, name: this.blueprintName, files: this.tree, - filesData: this.paths + filesData: this.paths, + uploadedFileName: this.uploadedFileName, + entryDefinition: this.entryDefinition } this.store.dispatch(new SetBlueprintState(blueprintState)) // this.store.dispatch(new LoadBlueprintSuccess(data)); @@ -142,6 +145,7 @@ export class SearchTemplateComponent implements OnInit { this.activationBlueprint = path.data; newPart.data = JSON.parse(this.activationBlueprint.toString()); console.log('newpart', newPart); + this.entryDefinition = path.name.trim(); } if(newPart.name !== '') { currentLevel.push(newPart); diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt index 656e86169..1a943d110 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.NullNode import com.fasterxml.jackson.databind.node.ObjectNode +import com.fasterxml.jackson.databind.node.TextNode import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants import org.onap.ccsdk.cds.controllerblueprints.core.* @@ -122,7 +123,7 @@ class ResourceAssignmentUtils { if (isNotEmpty(it.name) && it.property != null) { val rName = it.name val type = nullToEmpty(it.property?.type).toLowerCase() - val value = it.property?.value + val value = useDefaultValueIfNull(it, rName) logger.info("Generating Resource name ($rName), type ($type), value ($value)") root.set(rName, value) } @@ -136,6 +137,15 @@ class ResourceAssignmentUtils { return result } + private fun useDefaultValueIfNull(resourceAssignment: ResourceAssignment, resourceAssignmentName: String): JsonNode { + if (resourceAssignment.property?.value == null) { + val defaultValue = "\${$resourceAssignmentName}" + return TextNode(defaultValue) + } else { + return resourceAssignment.property!!.value!! + } + } + fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt new file mode 100644 index 000000000..9b87c12eb --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils + +import com.fasterxml.jackson.databind.node.TextNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import kotlin.test.assertEquals + +class ResourceAssignmentUtilsTest { + + @Test + fun `generateResourceDataForAssignments - positive test`() { + //given a valid resource assignment + val validResourceAssignment = createResourceAssignmentForTest("valid_value") + + //and a list containing that resource assignment + val resourceAssignmentList = listOf<ResourceAssignment>(validResourceAssignment) + + //when the values of the resources are evaluated + val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList) + + //then the assignment should produce a valid result + val expected = "{\n" + " \"pnf-id\" : \"valid_value\"\n" + "}" + assertEquals(expected, outcome, "unexpected outcome generated") + + } + + @Test + fun `generateResourceDataForAssignments - resource without value is not resolved as null`() { + //given a valid resource assignment + val resourceAssignmentWithNullValue = createResourceAssignmentForTest(null) + + //and a list containing that resource assignment + val resourceAssignmentList = listOf<ResourceAssignment>(resourceAssignmentWithNullValue) + + //when the values of the resources are evaluated + val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList) + + //then the assignment should produce a valid result + val expected = "{\n" + " \"pnf-id\" : \"\${pnf-id}\"\n" + "}" + assertEquals(expected, outcome, "unexpected outcome generated") + + } + + private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment { + val valueForTest = if (resourceValue == null) null else TextNode(resourceValue) + val resourceAssignmentForTest = ResourceAssignment().apply { + name = "pnf-id" + dictionaryName = "pnf-id" + dictionarySource = "input" + property = PropertyDefinition().apply { + type = "string" + value = valueForTest + } + } + return resourceAssignmentForTest + } +}
\ No newline at end of file |