re base code
[sdc.git] / catalog-ui / src / app / ng2 / pages / automated-upgrade / automated-upgrade-models / ui-component-to-upgrade.ts
1 import {ComponentState} from "../../../../utils/constants";
2 import {IDependenciesServerResponse} from "../../../services/responses/dependencies-server-response";
3 import {UiBaseObject} from "../../../../models/ui-models/ui-base-object";
4
5 /**
6  * Created by ob0695 on 5/1/2018.
7  */
8 export enum AutomatedUpgradeInstanceType {
9     VF, SERVICE_PROXY, ALLOTTED_RESOURCE
10 }
11 export class ServiceContainerToUpgradeUiObject extends UiBaseObject {
12
13     icon:string;
14     version:string;
15     isLock:boolean; // true if service is in check-out or ceritification-in-progress
16     vspInstances:Array<VspInstanceUiObject>; // list of instances of the vsp contain in the service - intances can be vf, proxy or allotted
17     isAlreadyUpgrade:boolean; // true if all instances is in latest version
18
19     constructor(componentToUpgrade:IDependenciesServerResponse) {
20         super(componentToUpgrade.uniqueId, componentToUpgrade.type, componentToUpgrade.name);
21         this.icon = componentToUpgrade.icon;
22         this.version = componentToUpgrade.version;
23         this.isAlreadyUpgrade = true;
24         this.isLock = componentToUpgrade.state === ComponentState.CERTIFICATION_IN_PROGRESS || componentToUpgrade.state === ComponentState.NOT_CERTIFIED_CHECKOUT;
25         this.vspInstances = [];
26     }
27
28     public addVfInstance = (vsp: IDependenciesServerResponse, latestVersion:string):void => {
29         let isNeededUpgrade = parseInt(vsp.version) < parseInt(latestVersion);
30         this.vspInstances.push(new VspInstanceUiObject(vsp.uniqueId, vsp.name, vsp.version, vsp.icon));
31         if (isNeededUpgrade) {
32             this.isAlreadyUpgrade = false;
33         }
34     }
35
36     public addProxyInstance = (vsp: IDependenciesServerResponse, isNeededUpgrade:boolean, instanceName:string):void => {
37         this.vspInstances.push(new ProxyVspInstanceUiObject(vsp.uniqueId, vsp.name, vsp.version, vsp.icon, instanceName));
38         if (isNeededUpgrade) {
39             this.isAlreadyUpgrade = false;
40         }
41     }
42
43     public addAllottedResourceInstance = (vsp: IDependenciesServerResponse, isNeededUpgrade:boolean, instanceName:string, vfName:string, vfId:string):void => {
44         this.vspInstances.push(new AllottedResourceInstanceUiObject(vsp.uniqueId, vsp.name, vsp.version, vsp.icon, instanceName, vfName, vfId));
45         if (isNeededUpgrade) {
46             this.isAlreadyUpgrade = false;
47         }
48     }
49
50     public addMultipleInstances = (vsp: IDependenciesServerResponse, vspLatestVersion:string, instancesNames:Array<string>, allottedOriginVf: IDependenciesServerResponse):void => {
51         _.forEach(instancesNames, (instanceName:string) => {
52             let isNeededUpgrade = parseInt(vsp.version) < parseInt(vspLatestVersion);
53             if (allottedOriginVf) {
54                 this.addAllottedResourceInstance(vsp, isNeededUpgrade, instanceName, allottedOriginVf.name, allottedOriginVf.uniqueId);
55             } else {
56                 this.addProxyInstance(vsp, isNeededUpgrade, instanceName);
57             }
58         })
59     }
60 }
61
62 export class VspInstanceUiObject {
63
64     vspName:string;
65     vspVersion:string;
66     vspId:string;
67     icon:string;
68     instanceType:AutomatedUpgradeInstanceType;
69
70     constructor(uniqueId:string, vspName:string, vspVersion:string, icon:string) {
71         this.vspId = uniqueId;
72         this.vspName = vspName;
73         this.vspVersion = vspVersion;
74         this.icon = icon;
75         this.instanceType = AutomatedUpgradeInstanceType.VF;
76     }
77 }
78
79 export class ProxyVspInstanceUiObject extends VspInstanceUiObject {
80
81     instanceName:string;
82
83     constructor(uniqueId:string, vspName:string, vspVersion:string, icon:string, instanceName: string) {
84         super(uniqueId, vspName, vspVersion, icon);
85         this.instanceName = instanceName;
86         this.instanceType = AutomatedUpgradeInstanceType.SERVICE_PROXY;
87     }
88 }
89
90 export class AllottedResourceInstanceUiObject extends VspInstanceUiObject {
91
92     instanceName:string;
93     originVfName:string;
94     originVfId:string;
95
96     constructor(uniqueId:string, vspName:string, vspVersion:string, icon:string, instanceName:string, originVfName:string, originVfId:string) {
97         super(uniqueId, vspName, vspVersion, icon)
98         this.instanceName = instanceName;
99         this.originVfId = originVfId;
100         this.originVfName = originVfName;
101         this.instanceType = AutomatedUpgradeInstanceType.ALLOTTED_RESOURCE;
102     }
103 }