Edit op crashes for existing WF 91/77791/2
authorArielk <Ariel.Kenan@amdocs.com>
Mon, 4 Feb 2019 15:22:02 +0000 (17:22 +0200)
committerAvi Gaffa <avi.gaffa@amdocs.com>
Tue, 5 Feb 2019 09:30:23 +0000 (09:30 +0000)
Change-Id: I2901820a46d8360daa76b46600c67134c63f079a
Issue-ID: SDC-2084
Signed-off-by: Arielk <Ariel.Kenan@amdocs.com>
catalog-ui/src/app/ng2/pages/interface-operation/interface-operation.page.component.ts
catalog-ui/src/app/ng2/pages/interface-operation/operation-creator/operation-creator.component.ts

index 70a0e95..b22a4bd 100644 (file)
@@ -111,6 +111,7 @@ export class InterfaceOperationComponent {
     isLoading: boolean;
     interfaceTypes:{ [interfaceType: string]: Array<string> };
     modalTranslation: ModalTranslation;
+    workflows: Array<any>;
 
     @Input() component: IComponent;
     @Input() readonly: boolean;
@@ -132,16 +133,19 @@ export class InterfaceOperationComponent {
 
     ngOnInit(): void {
         this.isLoading = true;
+        const workflowSubscription = this.enableWorkflowAssociation ? this.WorkflowServiceNg2.getWorkflows() : Promise.resolve();
         Observable.forkJoin(
             this.ComponentServiceNg2.getInterfaces(this.component),
             this.ComponentServiceNg2.getComponentInputs(this.component),
-            this.ComponentServiceNg2.getInterfaceTypes(this.component)
+            this.ComponentServiceNg2.getInterfaceTypes(this.component),
+            workflowSubscription
         ).subscribe((response: Array<any>) => {
             this.isLoading = false;
             this.initInterfaces(response[0].interfaces);
             this.sortInterfaces();
             this.inputs = response[1].inputs;
             this.interfaceTypes = response[2];
+            this.workflows = response[3];
         });
     }
 
@@ -239,6 +243,7 @@ export class InterfaceOperationComponent {
         };
 
         const input: OperationCreatorInput = {
+            allWorkflows: this.workflows,
             inputOperation: operation,
             interfaces: this.interfaces,
             inputProperties: this.inputs,
@@ -246,7 +251,7 @@ export class InterfaceOperationComponent {
             readonly: this.readonly,
             isService: this.component.isService(),
             interfaceTypes: this.interfaceTypes,
-            validityChangedCallback: this.enableOrDisableSaveButton
+            validityChangedCallback: this.enableOrDisableSaveButton,
         };
 
         const modalConfig: IModalConfig = {
index fd9e1cf..329ce70 100644 (file)
@@ -31,6 +31,7 @@ class TypedDropDownOption extends DropDownOption {
 }
 
 export interface OperationCreatorInput {
+    allWorkflows: Array<any>,
     inputOperation: OperationModel,
     interfaces: Array<InterfaceModel>,
     inputProperties: Array<InputBEModel>,
@@ -38,7 +39,7 @@ export interface OperationCreatorInput {
     readonly: boolean,
     isService: boolean,
     interfaceTypes: { [interfaceType: string]: Array<string> },
-    validityChangedCallback: Function
+    validityChangedCallback: Function,
 }
 
 @Component({
@@ -59,6 +60,7 @@ export class OperationCreatorComponent {
     operationNames: Array<TypedDropDownOption> = [];
     validityChangedCallback: Function;
 
+    allWorkflows: Array<any>;
     workflows: Array<DropdownValue> = [];
     workflowVersions: Array<DropdownValue> = [];
     inputProperties: Array<InputBEModel> = [];
@@ -132,8 +134,6 @@ export class OperationCreatorComponent {
 
         const inputOperation = this.inputOperation;
         this.operation = new OperationModel(inputOperation || {});
-        this.onSelectInterface(new DropDownOption(this.operation.interfaceType));
-        this.validityChanged();
 
         this.operationOutputs = _.reduce(
             this.interfaces,
@@ -147,42 +147,45 @@ export class OperationCreatorComponent {
         []);
 
         if (this.enableWorkflowAssociation) {
-            this.isLoading = true;
-            this.workflowServiceNg2.getWorkflows().subscribe(workflows => {
-                this.isLoading = false;
-                this.workflows = _.map(
-                    _.filter(
-                        workflows,
-                        (workflow: any) => {
-                            if (workflow.archiving === this.workflowServiceNg2.WF_STATE_ACTIVE) {
-                                return true;
-                            }
-                            if (workflow.archiving === this.workflowServiceNg2.WF_STATE_ARCHIVED &&
-                                workflow.id === this.operation.workflowId) {
-                                this.archivedWorkflowId = workflow.id;
-                                return true;
-                            }
-                            return false;
+            this.workflows = _.map(
+                _.filter(
+                    this.allWorkflows,
+                    (workflow: any) => {
+                        if (workflow.archiving === this.workflowServiceNg2.WF_STATE_ACTIVE) {
+                            return true;
                         }
-                    ),
-                    (workflow: any) => new DropdownValue(workflow.id, workflow.name)
-                );
-                this.reconstructOperation();
-            });
-        } else {
-            this.reconstructOperation();
+                        if (workflow.archiving === this.workflowServiceNg2.WF_STATE_ARCHIVED &&
+                            workflow.id === this.operation.workflowId) {
+                            this.archivedWorkflowId = workflow.id;
+                            return true;
+                        }
+                        return false;
+                    }
+                ),
+                (workflow: any) => new DropdownValue(workflow.id, workflow.name)
+            );
         }
+        this.reconstructOperation();
+        this.validityChanged();
+        this.updateTable();
     }
 
     reconstructOperation = () => {
         const inputOperation = this.inputOperation;
         if (inputOperation) {
+            this.onSelectInterface(new DropDownOption(this.operation.interfaceType));
             if (this.enableWorkflowAssociation && inputOperation.workflowVersionId && this.isUsingExistingWF(inputOperation)) {
+                this.assignInputParameters[this.operation.workflowId] = {[inputOperation.workflowVersionId]: []};
+                this.assignOutputParameters[this.operation.workflowId] = {[inputOperation.workflowVersionId]: []};
+                this.inputParameters = this.assignInputParameters[this.operation.workflowId][this.operation.workflowVersionId];
+                this.outputParameters = this.assignOutputParameters[this.operation.workflowId][this.operation.workflowVersionId];
                 const sub = this.onSelectWorkflow(new DropDownOption(inputOperation.workflowId), inputOperation.workflowVersionId);
                 if (sub) {
                     sub.add(() => {
                         this.buildParams();
                         this.updateTable();
+                        this.operation.workflowVersionId = '-1';
+                        setTimeout(() => this.operation.workflowVersionId = this.inputOperation.workflowVersionId, 0);
                     });
                 }
             } else {
@@ -196,8 +199,6 @@ export class OperationCreatorComponent {
                 this.isEditMode = true;
             }
         }
-        this.updateTable();
-        this.validityChanged();
     }
 
     buildParams = () => {
@@ -274,7 +275,7 @@ export class OperationCreatorComponent {
 
     onSelectWorkflow(workflowId: DropDownOption, selectedVersionId?: string): Subscription {
 
-        if (_.isUndefined(workflowId) || workflowId.value === this.operation.workflowId) {
+        if (_.isUndefined(workflowId)) {
             return;
         }
         this.operation.workflowId = workflowId.value;
@@ -307,11 +308,6 @@ export class OperationCreatorComponent {
                     return new DropdownValue(version.id, `V ${version.name}`);
                 }
             );
-
-            if (selectedVersionId) {
-                this.assignInputParameters[this.operation.workflowId][selectedVersionId] = [];
-                this.assignOutputParameters[this.operation.workflowId][selectedVersionId] = [];
-            }
             if (!selectedVersionId && this.workflowVersions.length) {
                 this.operation.workflowVersionId = _.last(this.workflowVersions).value;
             }