blob: 959480b0f0b80975c15443977c9237f511518eb3 [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.
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
Michael Landoed64b5e2017-06-09 03:19:04 +030021'use strict';
22
Michael Landoa5445102018-03-04 14:53:33 +020023import * as _ from "lodash";
Michael Landoed64b5e2017-06-09 03:19:04 +030024import {ArtifactType} from './../utils';
25import {HeatParameterModel} from "./heat-parameters";
26
27//this object contains keys, each key contain ArtifactModel
28export class ArtifactGroupModel {
29
30 constructor(artifacts?:ArtifactGroupModel) {
31 _.forEach(artifacts, (artifact:ArtifactModel, key) => {
32 this[key] = new ArtifactModel(artifact);
33 });
34 }
35
36 public filteredByType(type:string):ArtifactGroupModel {
37 let tmpArtifactGroupModel = new ArtifactGroupModel();
38 _.each(Object.keys(this), (key)=>{
39 if (this[key].artifactType === type) {
40 tmpArtifactGroupModel[key] = this[key];
41 }
42 });
43 return tmpArtifactGroupModel;
44 };
45}
46
47export class ArtifactModel {
48
49 artifactDisplayName:string;
50 artifactGroupType:string;
51 uniqueId:string;
52 artifactName:string;
53 artifactLabel:string;
54 artifactType:string;
55 artifactUUID:string;
56 artifactVersion:string;
57 creatorFullName:string;
58 creationDate:number;
59 lastUpdateDate:number;
60 description:string;
61 mandatory:boolean;
62 serviceApi:boolean;
63 payloadData:string;
64 timeout:number;
65 esId:string;
66 "Content-MD5":string;
67 artifactChecksum:string;
68 apiUrl:string;
69 heatParameters:Array<HeatParameterModel>;
70 generatedFromId:string;
71
72 //custom properties
73 selected:boolean;
74 originalDescription:string;
75 envArtifact:ArtifactModel;
76
77 constructor(artifact?:ArtifactModel) {
78 if (artifact) {
79 this.artifactDisplayName = artifact.artifactDisplayName;
80 this.artifactGroupType = artifact.artifactGroupType;
81 this.uniqueId = artifact.uniqueId;
82 this.artifactName = artifact.artifactName;
83 this.artifactLabel = artifact.artifactLabel;
84 this.artifactType = artifact.artifactType;
85 this.artifactUUID = artifact.artifactUUID;
86 this.artifactVersion = artifact.artifactVersion;
87 this.creatorFullName = artifact.creatorFullName;
88 this.creationDate = artifact.creationDate;
89 this.lastUpdateDate = artifact.lastUpdateDate;
90 this.description = artifact.description;
91 this.mandatory = artifact.mandatory;
92 this.serviceApi = artifact.serviceApi;
93 this.payloadData = artifact.payloadData;
94 this.timeout = artifact.timeout;
95 this.esId = artifact.esId;
96 this["Content-MD5"] = artifact["Content-MD5"];
97 this.artifactChecksum = artifact.artifactChecksum;
98 this.apiUrl = artifact.apiUrl;
99 this.heatParameters = _.sortBy(artifact.heatParameters, 'name');
100 this.generatedFromId = artifact.generatedFromId;
101 this.selected = artifact.selected ? artifact.selected : false;
102 this.originalDescription = artifact.description;
103 }
104 }
105
106 public isHEAT = ():boolean => {
107 return ArtifactType.HEAT === this.artifactType || ArtifactType.HEAT_VOL === this.artifactType || ArtifactType.HEAT_NET === this.artifactType;
108 };
109
110 public isThirdParty = ():boolean => {
111 return _.has(ArtifactType.THIRD_PARTY_RESERVED_TYPES, this.artifactType);
112 };
113
114 public toJSON = ():any => {
115 this.selected = undefined;
116 this.originalDescription = undefined;
117 this.envArtifact = undefined;
118 return this;
119 };
120}
121
122