Catalog alignment
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / ArtifactDefinition.java
1 /*-
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
21 package org.openecomp.sdc.be.model;
22
23 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
24 import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
25
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.stream.Collectors;
30
31 public class ArtifactDefinition extends ArtifactDataDefinition {
32
33     /**
34      * Base64 encoded Artifact file data
35      */
36     private byte[] payloadData;
37
38     private Boolean isHeatParamUpdated = false;
39
40     public Boolean getHeatParamUpdated() {
41         return isHeatParamUpdated;
42     }
43
44     public void setHeatParamUpdated(Boolean heatParamUpdated) {
45         isHeatParamUpdated = heatParamUpdated;
46     }
47
48     public ArtifactDefinition() {
49     }
50
51     public ArtifactDefinition(Map<String, Object> art) {
52         super(art);
53     }
54
55     public ArtifactDefinition(ArtifactDataDefinition a) {
56         super(a);
57     }
58
59     public ArtifactDefinition(ArtifactDefinition a) {
60         super(a);
61         this.payloadData = a.payloadData;
62     }
63
64     public ArtifactDefinition(ArtifactDataDefinition a, String payloadData) {
65         super(a);
66         setPayloadData(payloadData);
67     }
68
69     public byte[] getPayloadData() {
70         return payloadData;
71     }
72
73     public void setPayload(byte[] payloadData) {
74         this.payloadData = payloadData;
75     }
76
77     public void setPayloadData(String payloadData) {
78         if (payloadData != null) {
79             this.payloadData = payloadData.getBytes();
80         }
81     }
82
83     public List<HeatParameterDefinition> getListHeatParameters() {
84         List<HeatParameterDefinition> res = null;
85         List<HeatParameterDataDefinition> heatParameters = super.getHeatParameters();
86         if (heatParameters != null) {
87             res = heatParameters.stream().map(HeatParameterDefinition::new).collect(Collectors.toList());
88         }
89         return res;
90     }
91
92     public void setListHeatParameters(List<HeatParameterDefinition> properties) {
93         List<HeatParameterDataDefinition> res = null;
94
95         if (properties != null) {
96             res = properties.stream().map(HeatParameterDataDefinition::new).collect(Collectors.toList());
97         }
98         super.setHeatParameters(res);
99     }
100
101
102
103         public boolean checkEsIdExist() {
104                 return (getEsId() != null) && (!getEsId().trim().isEmpty());
105         }
106
107     @Override
108     public int hashCode() {
109         final int prime = 31;
110         int result = super.hashCode();
111
112         result = prime * result + Arrays.hashCode(payloadData);
113         return result;
114     }
115
116     @Override
117     public boolean equals(Object obj) {
118         if (this == obj) {
119             return true;
120         }
121         if (!super.equals(obj)) {
122             return false;
123         }
124         if (getClass() != obj.getClass()) {
125             return false;
126         }
127         ArtifactDefinition other = (ArtifactDefinition) obj;
128
129         if (payloadData == null) {
130             if (other.payloadData != null) {
131                 return false;
132             }
133         }
134         else if (!Arrays.equals(payloadData, other.payloadData)) {
135             return false;
136         }
137         return true;
138     }
139 }