Add UI support for adding tosca artifact types
[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 import {PropertyBEModel} from "./properties-inputs/property-be-model";
28
29 //this object contains keys, each key contain ArtifactModel
30 export class ArtifactGroupModel {
31     
32     constructor(artifacts?:ArtifactGroupModel) {
33         _.forEach(artifacts, (artifact:ArtifactModel, key) => {
34             this[key] = new ArtifactModel(artifact);
35         });
36     }
37
38     public filteredByType(type:string):ArtifactGroupModel {
39         let tmpArtifactGroupModel = new ArtifactGroupModel();
40         _.each(Object.keys(this), (key)=>{
41             if (this[key].artifactType === type) {
42                 tmpArtifactGroupModel[key] = this[key];
43             }
44         });
45         return tmpArtifactGroupModel;
46     };
47 }
48
49 export class ArtifactModel {
50
51     artifactDisplayName:string;
52     artifactGroupType:string;
53     uniqueId:string;
54     artifactName:string;
55     artifactLabel:string;
56     artifactType:string;
57     artifactUUID:string;
58     artifactVersion:string;
59     creatorFullName:string;
60     creationDate:number;
61     lastUpdateDate:number;
62     description:string;
63     mandatory:boolean;
64     serviceApi:boolean;
65     payloadData:string;
66     timeout:number;
67     esId:string;
68     "Content-MD5":string;
69     artifactChecksum:string;
70     apiUrl:string;
71     heatParameters:Array<HeatParameterModel>;
72     generatedFromId:string;
73     isFromCsar: boolean;
74
75     //custom properties
76     selected:boolean;
77     originalDescription:string;
78     envArtifact:ArtifactModel;
79     allowDeleteAndUpdate: boolean;
80     properties:Array<PropertyBEModel>;
81
82     constructor(artifact?:ArtifactModel) {
83         if (artifact) {
84             this.artifactDisplayName = artifact.artifactDisplayName;
85             this.artifactGroupType = artifact.artifactGroupType;
86             this.uniqueId = artifact.uniqueId;
87             this.artifactName = artifact.artifactName;
88             this.artifactLabel = artifact.artifactLabel;
89             this.artifactType = artifact.artifactType;
90             this.artifactUUID = artifact.artifactUUID;
91             this.artifactVersion = artifact.artifactVersion;
92             this.creatorFullName = artifact.creatorFullName;
93             this.creationDate = artifact.creationDate;
94             this.lastUpdateDate = artifact.lastUpdateDate;
95             this.description = artifact.description;
96             this.mandatory = artifact.mandatory;
97             this.serviceApi = artifact.serviceApi;
98             this.payloadData = artifact.payloadData;
99             this.timeout = artifact.timeout;
100             this.esId = artifact.esId;
101             this["Content-MD5"] = artifact["Content-MD5"];
102             this.artifactChecksum = artifact.artifactChecksum;
103             this.apiUrl = artifact.apiUrl;
104             this.heatParameters = _.sortBy(_.cloneDeep(artifact.heatParameters), 'name');
105             this.generatedFromId = artifact.generatedFromId;
106             this.selected = artifact.selected ? artifact.selected : false;
107             this.originalDescription = artifact.description;
108             this.isFromCsar = artifact.isFromCsar;
109             this.properties = _.sortBy(_.cloneDeep(artifact.properties), 'name');
110         }
111     }
112
113     public isHEAT = ():boolean => {
114         return ArtifactType.HEAT === this.artifactType || ArtifactType.HEAT_VOL === this.artifactType || ArtifactType.HEAT_NET === this.artifactType;
115     };
116
117     public isThirdParty = ():boolean => {
118         return _.has(ArtifactType.THIRD_PARTY_RESERVED_TYPES, this.artifactType);
119     };
120
121     public isGenericBrowseable = ():boolean => {
122         return this.artifactType === ArtifactType.VES_EVENTS || this.artifactType === ArtifactType.PM_DICTIONARY;
123     };
124
125     public toJSON = ():any => {
126         this.selected = undefined;
127         this.originalDescription = undefined;
128         this.envArtifact = undefined;
129         this.allowDeleteAndUpdate = undefined;
130         return this;
131     };
132 }
133
134