e290dc624e44c5f859b6883f1bbb6d5b0bbd393c
[sdc.git] / catalog-ui / src / app / models / artifacts.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nokia. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 'use strict';
23
24 import * as _ from "lodash";
25 import {ArtifactType} from './../utils';
26 import {HeatParameterModel} from "./heat-parameters";
27
28 //this object contains keys, each key contain ArtifactModel
29 export class ArtifactGroupModel {
30     
31     constructor(artifacts?:ArtifactGroupModel) {
32         _.forEach(artifacts, (artifact:ArtifactModel, key) => {
33             this[key] = new ArtifactModel(artifact);
34         });
35     }
36
37     public filteredByType(type:string):ArtifactGroupModel {
38         let tmpArtifactGroupModel = new ArtifactGroupModel();
39         _.each(Object.keys(this), (key)=>{
40             if (this[key].artifactType === type) {
41                 tmpArtifactGroupModel[key] = this[key];
42             }
43         });
44         return tmpArtifactGroupModel;
45     };
46 }
47
48 export class ArtifactModel {
49
50     artifactDisplayName:string;
51     artifactGroupType:string;
52     uniqueId:string;
53     artifactName:string;
54     artifactLabel:string;
55     artifactType:string;
56     artifactUUID:string;
57     artifactVersion:string;
58     creatorFullName:string;
59     creationDate:number;
60     lastUpdateDate:number;
61     description:string;
62     mandatory:boolean;
63     serviceApi:boolean;
64     payloadData:string;
65     timeout:number;
66     esId:string;
67     "Content-MD5":string;
68     artifactChecksum:string;
69     apiUrl:string;
70     heatParameters:Array<HeatParameterModel>;
71     generatedFromId:string;
72     isFromCsar: boolean;
73
74     //custom properties
75     selected:boolean;
76     originalDescription:string;
77     envArtifact:ArtifactModel;
78     allowDeleteAndUpdate: boolean;
79
80     constructor(artifact?:ArtifactModel) {
81         if (artifact) {
82             this.artifactDisplayName = artifact.artifactDisplayName;
83             this.artifactGroupType = artifact.artifactGroupType;
84             this.uniqueId = artifact.uniqueId;
85             this.artifactName = artifact.artifactName;
86             this.artifactLabel = artifact.artifactLabel;
87             this.artifactType = artifact.artifactType;
88             this.artifactUUID = artifact.artifactUUID;
89             this.artifactVersion = artifact.artifactVersion;
90             this.creatorFullName = artifact.creatorFullName;
91             this.creationDate = artifact.creationDate;
92             this.lastUpdateDate = artifact.lastUpdateDate;
93             this.description = artifact.description;
94             this.mandatory = artifact.mandatory;
95             this.serviceApi = artifact.serviceApi;
96             this.payloadData = artifact.payloadData;
97             this.timeout = artifact.timeout;
98             this.esId = artifact.esId;
99             this["Content-MD5"] = artifact["Content-MD5"];
100             this.artifactChecksum = artifact.artifactChecksum;
101             this.apiUrl = artifact.apiUrl;
102             this.heatParameters = _.sortBy(_.cloneDeep(artifact.heatParameters), 'name');
103             this.generatedFromId = artifact.generatedFromId;
104             this.selected = artifact.selected ? artifact.selected : false;
105             this.originalDescription = artifact.description;
106             this.isFromCsar = artifact.isFromCsar;
107         }
108     }
109
110     public isHEAT = ():boolean => {
111         return ArtifactType.HEAT === this.artifactType || ArtifactType.HEAT_VOL === this.artifactType || ArtifactType.HEAT_NET === this.artifactType;
112     };
113
114     public isThirdParty = ():boolean => {
115         return _.has(ArtifactType.THIRD_PARTY_RESERVED_TYPES, this.artifactType);
116     };
117
118     public isGenericBrowseable = ():boolean => {
119         return this.artifactType === ArtifactType.VES_EVENTS || this.artifactType === ArtifactType.PM_DICTIONARY;
120     };
121
122     public toJSON = ():any => {
123         this.selected = undefined;
124         this.originalDescription = undefined;
125         this.envArtifact = undefined;
126         this.allowDeleteAndUpdate = undefined;
127         return this;
128     };
129 }
130
131