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