08982cc678373249c34fc2978ed8928365fe3635
[vid.git] /
1 import * as moment from 'moment';
2 import * as _ from 'lodash';
3
4 export class InstantiationTemplatesRowModel {
5   readonly jobId: string;
6   readonly userId ?: string;
7   readonly createDate ?: string;
8   readonly instanceName ?: string;
9   readonly instantiationStatus?: string;
10   readonly summary?: string;
11   readonly region?: string;
12   readonly tenant?: string;
13   readonly aicZone?: string;
14
15   constructor(data) {
16     this.jobId = data.jobId;
17     this.userId = !_.isNil(data.created) ? data.userId : null;
18     this.createDate = !_.isNil(data.created) ? moment(data.created).format("YYYY-MM-DD HH:mm:ss") : null;
19     this.instanceName = this.getInstanceName(data.serviceInstanceName);
20     this.instantiationStatus = !_.isNil(data.jobStatus) ? data.jobStatus : null;
21     this.summary = null;
22     this.region = this.getRegion(data.regionId, data.owningEntityName);
23     this.tenant = !_.isNil(data.tenantName) ? data.tenantName : null;
24     this.aicZone = !_.isNil(data.aicZoneName) ? data.aicZoneName : null;
25
26   }
27
28
29   /**************************************************************************************************
30    return the LCP region and in brackets the cloud owner removing the “att-“ with capital letters.
31    **************************************************************************************************/
32   getCloudOwner = (owningEntityName: string): string => {
33     const splitByAtt: string[] = owningEntityName.split('att-');
34     let owning: string = splitByAtt[splitByAtt.length - 1];
35     return owning.toUpperCase();
36   };
37
38   getRegion = (regionId: string, owningEntityName: string): string => {
39     const convertOwning = !_.isNil(owningEntityName) ? `(${this.getCloudOwner(owningEntityName)})` : '';
40     return `${regionId} ${convertOwning}`.trim();
41   };
42
43
44   getInstanceName = (instanceName?: string): string => {
45     if (_.isNil(instanceName)) {
46       return '<Automatically generated>';
47     }
48     return instanceName;
49   }
50 }
51