diff options
author | Wojciech Sliwka <wojciech.sliwka@nokia.com> | 2019-03-21 14:01:50 +0100 |
---|---|---|
committer | Wojciech Sliwka <wojciech.sliwka@nokia.com> | 2019-04-08 13:03:31 +0200 |
commit | 8e3b16a64b98b1774c4e2c2159e71668de2883c4 (patch) | |
tree | 87932d6e8d3162c28000c30af723dfd6cfcbb2cd /vid-app-common/src/main/webapp | |
parent | 56d27d6651babd9223ee8e3a3deddda9d702dcd1 (diff) |
align logic to new so api
Change-Id: Ic1a975eb6d3d9487fc2e006d2f171fa044806ef3
Issue-ID: VID-400
Signed-off-by: Wojciech Sliwka <wojciech.sliwka@nokia.com>
Diffstat (limited to 'vid-app-common/src/main/webapp')
3 files changed, 140 insertions, 57 deletions
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js index f8202fbf2..246834cdd 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js @@ -390,11 +390,9 @@ workflowParameters.requestDetails.cloudConfiguration = vm.changeManagement.vnfNames[0].cloudConfiguration; let parameters = vm.getRemoteWorkFlowParameters(vm.changeManagement.workflow); - let i = 1; parameters.forEach((parameter)=>{ - let inputField = document.getElementById('so-workflow-parameter-'+i); - i++; - workflowParameters.requestDetails.requestParameters.userParams[0][parameter.name]=inputField.value; + let inputField = document.getElementById('so-workflow-parameter-'+parameter.soFieldName); + workflowParameters.requestDetails.requestParameters.userParams[0][parameter.soFieldName]=inputField.value; }); return workflowParameters; @@ -402,40 +400,60 @@ vm.openModal = function () { if(vm.hasScheduler) { //scheduling supported - $scope.widgetParameter = ""; // needed by the scheduler? - - // properties needed by the scheduler so it knows whether to show - // policy or sniro related features on the scheduler UI or not. - vm.changeManagement.policyYN = "Y"; - vm.changeManagement.sniroYN = "Y"; - - if (featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_ADD_MSO_TESTAPI_FIELD)) { - vm.changeManagement.testApi = DataService.getMsoRequestParametersTestApi(); - } - var data = { - widgetName: 'Portal-Common-Scheduler', - widgetData: vm.changeManagement, - widgetParameter: $scope.widgetParameter - }; - - window.parent.postMessage(data, VIDCONFIGURATION.SCHEDULER_PORTAL_URL); + vm.scheduleWorkflow(); } else { - //no scheduling support - var dataToSo = extractChangeManagementCallbackDataStr(vm.changeManagement); - if(dataToSo) { - var vnfName = vm.changeManagement.vnfNames[0].name; - changeManagementService.postChangeManagementNow(dataToSo, vnfName); - } + //no scheduling support + vm.executeWorkflow(); + } + }; + + vm.scheduleWorkflow = function () { + $scope.widgetParameter = ""; // needed by the scheduler? + + // properties needed by the scheduler so it knows whether to show + // policy or sniro related features on the scheduler UI or not. + vm.changeManagement.policyYN = "Y"; + vm.changeManagement.sniroYN = "Y"; + + if (featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_ADD_MSO_TESTAPI_FIELD)) { + vm.changeManagement.testApi = DataService.getMsoRequestParametersTestApi(); + } + var data = { + widgetName: 'Portal-Common-Scheduler', + widgetData: vm.changeManagement, + widgetParameter: $scope.widgetParameter + }; + + window.parent.postMessage(data, VIDCONFIGURATION.SCHEDULER_PORTAL_URL); + }; + vm.executeWorkflow = function () { + if (vm.localWorkflows && vm.localWorkflows.length > 0) { + vm.triggerLocalWorkflow(); + } else { + vm.triggerRemoteWorkflow(); + } + }; + + vm.triggerLocalWorkflow = function () { + var dataToSo = extractChangeManagementCallbackDataStr(vm.changeManagement); + if (dataToSo) { + var vnfName = vm.changeManagement.vnfNames[0].name; + changeManagementService.postChangeManagementNow(dataToSo, vnfName); + } + }; + + vm.triggerRemoteWorkflow = function () { + let cachedWorkflowDetails = vm.getCachedWorkflowDetails(vm.changeManagement.workflow); + if (cachedWorkflowDetails.length > 0) { let workflowParameters = getWorkflowParametersFromForm(); - if(workflowParameters){ + if (workflowParameters) { let servieInstanceId = vm.changeManagement.vnfNames[0]['service-instance-node'][0].properties['service-instance-id']; let vnfInstanceId = vm.changeManagement.vnfNames[0].id; - let workflow_UUID = vm.changeManagement.fromVNFVersion; - - changeManagementService.postWorkflowsParametersNow(servieInstanceId,vnfInstanceId,workflow_UUID,workflowParameters); + let workflow_UUID = cachedWorkflowDetails[0].id; + changeManagementService.postWorkflowsParametersNow(servieInstanceId, vnfInstanceId, workflow_UUID, workflowParameters); } - } + } }; vm.loadSubscribers = function () { @@ -728,13 +746,37 @@ }; vm.loadRemoteWorkFlowParameters = function (workflow) { - changeManagementService.getSOWorkflowParameter(workflow.id) - .then(function (response) { - vm.remoteWorkflowsParameters.set(workflow.name, response.data.parameterDefinitions); - }) - .catch(function (error) { - $log.error(error); - }); + let parameters = []; + workflow.workflowInputParameters + .filter( function (param) { + return param.soPayloadLocation === "userParams" + }) + .forEach(function (param) { + let workflowParams = vm.repackAttributes(param); + if (param.validation.length > 0) { + let validation = param.validation[0]; + if ('maxLength' in validation) { + workflowParams.maxLength = validation.maxLength; + } + if ('allowableChars' in validation) { + workflowParams.pattern = validation.allowableChars; + } + } + parameters.push(workflowParams); + } + ); + vm.remoteWorkflowsParameters.set(workflow.name, parameters); + }; + + vm.repackAttributes = function (workflowParam){ + return { + name: workflowParam.label, + required: workflowParam.required, + id: workflowParam.soFieldName, + soFieldName: workflowParam.soFieldName, + maxLength: '500', + pattern: '.*' + } }; vm.getRemoteWorkFlowParameters = function (workflow) { @@ -757,6 +799,13 @@ } }; + vm.getCachedWorkflowDetails = function (workflow) { + return vm.remoteWorkflows.filter( function (remoteWorkflow) { + return remoteWorkflow.name === workflow; + }); + + }; + //Must be $scope because we bind to the onchange of the html (cannot attached to vm variable). $scope.selectFileForVNFName = function (fileInput) { if (fileInput && fileInput.id) { diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js index 9810c0013..5989ffdd6 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js @@ -100,32 +100,59 @@ describe('Testing workFlows from SO', () => { } ], }}); - let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]}); - let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": []}}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{ - $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}]; + "id": "ab6478e4-ea33-3346-ac12-ab121484a333", + "workflowName": "inPlaceSoftwareUpdate", + "name": "inPlaceSoftwareUpdate", + "source": "sdc", + "workflowInputParameters": [ + { + "label": "New Software Version", + "inputType": "text", + "required": true, + "soFieldName": "new_software_version", + "soPayloadLocation": "userParams", + "validation":[] + } + ] + }] + }); + + $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}]; $changeManagementService.getWorkflows = () => getWorkflowsStub; $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; - $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; // when return $controller.loadWorkFlows().then(() => { - expect($controller.workflows).toContain('workflow 1'); - expect($controller.workflows).toContain('workflow 2'); + expect($controller.workflows).toContain('inPlaceSoftwareUpdate'); + expect($controller.localWorkflowsParameters).toBeUndefined(); }); }); - test('Verify load workflows will call load workflows parameters from SO', () => { + test('Verify load workflows will set workflows and parameters', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}}); - let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]}); - let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [ - {"id": 1, "name": "parameter 1", "required": true, "type": "STRING", "pattern": "[0-9]*"}, - {"id": 2, "name": "parameter 2", "required": true, "type": "STRING", "pattern": ".*"}, - {"id": 3, "name": "parameter 3", "required": false, "type": "STRING", "pattern": "[0-9]*"}]}}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data":[{ - $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}]; + "id": "ab6478e4-ea33-3346-ac12-ab121484a333", + "workflowName": "inPlaceSoftwareUpdate", + "name": "inPlaceSoftwareUpdate", + "source": "sdc", + "workflowInputParameters": [ + { + "label": "New Software Version", + "inputType": "text", + "required": true, + "soFieldName": "new_software_version", + "soPayloadLocation": "userParams", + "validation":[] + } + ] + }] + }); + $controller.changeManagement.vnfNames = [{modelVersionId: 'test1', name:'test'}]; $changeManagementService.getWorkflows = () => getWorkflowsStub; $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; @@ -133,10 +160,17 @@ describe('Testing workFlows from SO', () => { // when return $controller.loadWorkFlows() .then(() => { - expect($controller.remoteWorkflowsParameters).toEqual(new Map([["workflow 0", - [{"id": 1, "name": "parameter 1", "pattern": "[0-9]*", "required": true, "type": "STRING"}, - {"id": 2, "name": "parameter 2", "pattern": ".*", "required": true, "type": "STRING"}, - {"id": 3, "name": "parameter 3", "pattern": "[0-9]*", "required": false, "type": "STRING"}]]])); + expect($controller.workflows).toEqual(["inPlaceSoftwareUpdate"]); + expect($controller.remoteWorkflowsParameters).toEqual(new Map([["inPlaceSoftwareUpdate", + [{ + "name": "New Software Version", + "required": true, + "id": "new_software_version", + "soFieldName": "new_software_version", + "maxLength": '500', + "pattern": '.*' + }]] + ])); }); }); diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html index 9fb978c42..a5a6d1610 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html @@ -97,7 +97,7 @@ <div class="form-group" ng-if="vm.changeManagement.workflow" ng-repeat="item in vm.getRemoteWorkFlowParameters(vm.changeManagement.workflow)"> <label for="so-workflow-parameter-{{item.id}}" class="control-label">{{item.name}}</label> - <input ng-model="item.value" type="text" id="so-workflow-parameter-{{item.id}}" pattern="{{item.pattern}}" ng-required="{{item.required}}"> + <input ng-model="item.value" type="text" id="so-workflow-parameter-{{item.id}}" pattern="{{item.pattern}}" maxlength="{{item.maxLength}}" ng-required="{{item.required}}" soFieldName="{{item.soFieldName}}"> </div> </div> |