blob: e6e76e0f61ff78f9f4d9ba48c6cdd146f98ab885 [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";
aribeiro1de16922021-10-01 11:30:49 +010027import {PropertyBEModel} from "./properties-inputs/property-be-model";
Michael Landoed64b5e2017-06-09 03:19:04 +030028
29//this object contains keys, each key contain ArtifactModel
30export 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
49export 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;
ys969316a9fce2020-01-19 13:50:02 +020073 isFromCsar: boolean;
Michael Landoed64b5e2017-06-09 03:19:04 +030074
75 //custom properties
76 selected:boolean;
77 originalDescription:string;
78 envArtifact:ArtifactModel;
ys969316a9fce2020-01-19 13:50:02 +020079 allowDeleteAndUpdate: boolean;
aribeiro1de16922021-10-01 11:30:49 +010080 properties:Array<PropertyBEModel>;
Michael Landoed64b5e2017-06-09 03:19:04 +030081
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;
ys969316a9fce2020-01-19 13:50:02 +0200104 this.heatParameters = _.sortBy(_.cloneDeep(artifact.heatParameters), 'name');
Michael Landoed64b5e2017-06-09 03:19:04 +0300105 this.generatedFromId = artifact.generatedFromId;
106 this.selected = artifact.selected ? artifact.selected : false;
107 this.originalDescription = artifact.description;
ys969316a9fce2020-01-19 13:50:02 +0200108 this.isFromCsar = artifact.isFromCsar;
aribeiro1de16922021-10-01 11:30:49 +0100109 this.properties = _.sortBy(_.cloneDeep(artifact.properties), 'name');
Michael Landoed64b5e2017-06-09 03:19:04 +0300110 }
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
Piotr Darosz2c25cba2019-03-27 15:25:50 +0100121 public isGenericBrowseable = ():boolean => {
Tomasz Golabekc5ef9802020-02-19 16:46:44 +0100122 return this.artifactType === ArtifactType.VES_EVENTS || this.artifactType === ArtifactType.PM_DICTIONARY;
Piotr Darosz2c25cba2019-03-27 15:25:50 +0100123 };
124
Michael Landoed64b5e2017-06-09 03:19:04 +0300125 public toJSON = ():any => {
126 this.selected = undefined;
127 this.originalDescription = undefined;
128 this.envArtifact = undefined;
ys969316a9fce2020-01-19 13:50:02 +0200129 this.allowDeleteAndUpdate = undefined;
Michael Landoed64b5e2017-06-09 03:19:04 +0300130 return this;
131 };
132}
133
134