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