blob: 7b93470de36af7e62eb69c648325ff91e70e5902 [file] [log] [blame]
Michael Landodd603392017-07-12 00:54:52 +03001/*-
2 * ============LICENSE_START=======================================================
3 * SDC
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
Piotr Darosz2c25cba2019-03-27 15:25:50 +01006 * Modifications Copyright (C) 2019 Nokia. All rights reserved.
Michael Landodd603392017-07-12 00:54:52 +03007 * ================================================================================
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
Michael Landoed64b5e2017-06-09 03:19:04 +030022'use strict';
23
Michael Landoa5445102018-03-04 14:53:33 +020024import * as _ from "lodash";
Michael Landoed64b5e2017-06-09 03:19:04 +030025import {ArtifactType} from './../utils';
26import {HeatParameterModel} from "./heat-parameters";
27
28//this object contains keys, each key contain ArtifactModel
29export 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
48export 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;
ys969316a9fce2020-01-19 13:50:02 +020072 isFromCsar: boolean;
Michael Landoed64b5e2017-06-09 03:19:04 +030073
74 //custom properties
75 selected:boolean;
76 originalDescription:string;
77 envArtifact:ArtifactModel;
ys969316a9fce2020-01-19 13:50:02 +020078 allowDeleteAndUpdate: boolean;
Michael Landoed64b5e2017-06-09 03:19:04 +030079
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;
ys969316a9fce2020-01-19 13:50:02 +0200102 this.heatParameters = _.sortBy(_.cloneDeep(artifact.heatParameters), 'name');
Michael Landoed64b5e2017-06-09 03:19:04 +0300103 this.generatedFromId = artifact.generatedFromId;
104 this.selected = artifact.selected ? artifact.selected : false;
105 this.originalDescription = artifact.description;
ys969316a9fce2020-01-19 13:50:02 +0200106 this.isFromCsar = artifact.isFromCsar;
Michael Landoed64b5e2017-06-09 03:19:04 +0300107 }
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
Piotr Darosz2c25cba2019-03-27 15:25:50 +0100118 public isGenericBrowseable = ():boolean => {
119 return this.artifactType == ArtifactType.VES_EVENTS;
120 };
121
Michael Landoed64b5e2017-06-09 03:19:04 +0300122 public toJSON = ():any => {
123 this.selected = undefined;
124 this.originalDescription = undefined;
125 this.envArtifact = undefined;
ys969316a9fce2020-01-19 13:50:02 +0200126 this.allowDeleteAndUpdate = undefined;
Michael Landoed64b5e2017-06-09 03:19:04 +0300127 return this;
128 };
129}
130
131