1 import * as moment from 'moment';
2 import * as _ from 'lodash';
3 import {InstantiationBase} from "../../../models/InstantiationBase";
5 export class InstantiationTemplatesRowModel extends InstantiationBase{
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;
16 this.userId = !_.isNil(data.userId) ? data.userId : null;
17 this.createDate = !_.isNil(data.created) ? moment(data.created).format("YYYY-MM-DD HH:mm:ss") : null;
18 this.instanceName = this.getInstanceName(data.serviceInstanceName);
19 this.instantiationStatus = !_.isNil(data.jobStatus) ? data.jobStatus : null;
20 this.summary = this.convertRequestSummaryFromMapToString(data.requestSummary);
21 this.region = this.getRegion(data.regionId, data.owningEntityName);
22 this.tenant = !_.isNil(data.tenantName) ? data.tenantName : null;
26 /**************************************************************************************************
27 return the LCP region and in brackets the cloud owner removing the “att-“ with capital letters.
28 **************************************************************************************************/
29 getCloudOwner = (owningEntityName: string): string => {
30 const splitByAtt: string[] = owningEntityName.split('att-');
31 let owning: string = splitByAtt[splitByAtt.length - 1];
32 return owning.toUpperCase();
35 getRegion = (regionId: string, owningEntityName: string): string => {
36 const convertOwning = !_.isNil(owningEntityName) ? `(${this.getCloudOwner(owningEntityName)})` : '';
37 const region = !_.isNil(regionId) ? regionId : '';
38 return `${region} ${convertOwning}`.trim();
42 getInstanceName = (instanceName?: string): string => {
43 if (_.isNil(instanceName)) {
44 return '<Automatically generated>';
49 convertRequestSummaryFromMapToString = (requestSummary: Map<string, number>): string => {
50 let values: string[] = _.map(requestSummary, (count: number, instanceType: string) => instanceType + ": " + count);
51 return _.join(values, ", ");