Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 1 | /*- |
| 2 | * ============LICENSE_START======================================================= |
| 3 | * SDC |
| 4 | * ================================================================================ |
| 5 | * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. |
Piotr Darosz | 2c25cba | 2019-03-27 15:25:50 +0100 | [diff] [blame] | 6 | * Modifications Copyright (C) 2019 Nokia. All rights reserved. |
Michael Lando | dd60339 | 2017-07-12 00:54:52 +0300 | [diff] [blame] | 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 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 22 | 'use strict'; |
| 23 | |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 24 | import * as _ from "lodash"; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 25 | import {ArtifactType} from './../utils'; |
| 26 | import {HeatParameterModel} from "./heat-parameters"; |
| 27 | |
| 28 | //this object contains keys, each key contain ArtifactModel |
| 29 | export 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 | |
| 48 | export 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; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 72 | isFromCsar: boolean; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 73 | |
| 74 | //custom properties |
| 75 | selected:boolean; |
| 76 | originalDescription:string; |
| 77 | envArtifact:ArtifactModel; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 78 | allowDeleteAndUpdate: boolean; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 79 | |
| 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; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 102 | this.heatParameters = _.sortBy(_.cloneDeep(artifact.heatParameters), 'name'); |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 103 | this.generatedFromId = artifact.generatedFromId; |
| 104 | this.selected = artifact.selected ? artifact.selected : false; |
| 105 | this.originalDescription = artifact.description; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 106 | this.isFromCsar = artifact.isFromCsar; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 107 | } |
| 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 Darosz | 2c25cba | 2019-03-27 15:25:50 +0100 | [diff] [blame] | 118 | public isGenericBrowseable = ():boolean => { |
| 119 | return this.artifactType == ArtifactType.VES_EVENTS; |
| 120 | }; |
| 121 | |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 122 | public toJSON = ():any => { |
| 123 | this.selected = undefined; |
| 124 | this.originalDescription = undefined; |
| 125 | this.envArtifact = undefined; |
ys9693 | 16a9fce | 2020-01-19 13:50:02 +0200 | [diff] [blame^] | 126 | this.allowDeleteAndUpdate = undefined; |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 127 | return this; |
| 128 | }; |
| 129 | } |
| 130 | |
| 131 | |