Increase code coverage
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / components / ComponentMetadataDataDefinition.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.datatypes.components;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28 import lombok.EqualsAndHashCode;
29 import lombok.Getter;
30 import lombok.NoArgsConstructor;
31 import lombok.Setter;
32 import lombok.ToString;
33 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
34 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFieldsExtractor;
35 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
36 import org.openecomp.sdc.common.log.wrappers.Logger;
37
38 @NoArgsConstructor
39 @EqualsAndHashCode
40 @ToString
41 public abstract class ComponentMetadataDataDefinition extends ToscaDataDefinition {
42
43     private static final Logger LOGGER = Logger.getLogger(ComponentMetadataDataDefinition.class.getName());
44
45     @Getter
46     private String uniqueId;
47     @Getter
48     @Setter
49     private String name; // archiveName
50     @Getter
51     @Setter
52     private String version; // archiveVersion
53     @Getter
54     @Setter
55     private Boolean highestVersion;
56     @Getter
57     @Setter
58     private Long creationDate;
59     @Getter
60     @Setter
61     private Long lastUpdateDate;
62     @Getter
63     @Setter
64     private String description;
65     @Getter
66     @Setter
67     private String state;
68     @Getter
69     @Setter
70     private List<String> tags;
71     @Getter
72     @Setter
73     private String conformanceLevel;
74     @Getter
75     @Setter
76     private String icon;
77     @Getter
78     private String UUID;
79     @Getter
80     @Setter
81     private String normalizedName;
82     @Getter
83     @Setter
84     private String systemName;
85     @Getter
86     @Setter
87     private String contactId;
88     @Getter
89     @Setter
90     private Map<String, String> allVersions;
91     @Getter
92     @Setter
93     private Boolean isDeleted;
94     @Getter
95     @Setter
96     private String projectCode;
97     @Getter
98     @Setter
99     private String csarUUID;
100     @Getter
101     @Setter
102     private String csarVersion;
103     @Getter
104     @Setter
105     private String importedToscaChecksum;
106     @Getter
107     private String invariantUUID;
108     @Getter
109     @Setter
110     protected ComponentTypeEnum componentType;
111     // USER
112     @Getter
113     @Setter
114     private String creatorUserId;
115     @Getter
116     @Setter
117     private String creatorFullName;
118     @Getter
119     @Setter
120     private String lastUpdaterUserId;
121     @Getter
122     @Setter
123     private String lastUpdaterFullName;
124     //Archive/Restore
125     @Getter
126     @Setter
127     private Boolean isArchived = false;
128     @Getter
129     @Setter
130     private Long archiveTime;
131     @Getter
132     @Setter
133     private Boolean isVspArchived = false;
134
135     public ComponentMetadataDataDefinition(ComponentMetadataDataDefinition other) {
136         this.uniqueId = other.getUniqueId();
137         this.name = other.getName();
138         this.version = other.getVersion();
139         this.highestVersion = other.isHighestVersion();
140         this.creationDate = other.getCreationDate();
141         this.lastUpdateDate = other.getLastUpdateDate();
142         this.description = other.getDescription();
143         this.state = other.getState();
144         this.tags = new ArrayList<>(other.getTags() != null ? other.getTags() : new LinkedList<>());
145         this.icon = other.getIcon();
146         this.contactId = other.getContactId();
147         this.UUID = other.getUUID();
148         this.normalizedName = other.getNormalizedName();
149         this.systemName = other.getSystemName();
150         this.allVersions = new HashMap<>(other.getAllVersions() != null ? other.getAllVersions() : new HashMap<>());
151         this.isDeleted = other.getIsDeleted();
152         this.projectCode = other.getProjectCode();
153         this.csarUUID = other.getCsarUUID();
154         this.csarVersion = other.csarVersion;
155         this.importedToscaChecksum = other.getImportedToscaChecksum();
156         this.invariantUUID = other.getInvariantUUID();
157         this.isArchived = other.isArchived;
158         this.isVspArchived = other.isVspArchived;
159         this.archiveTime = other.getArchiveTime();
160     }
161
162     public ComponentMetadataDataDefinition(JsonPresentationFieldsExtractor extractor) {
163         this.uniqueId = extractor.getUniqueId();
164         this.name = extractor.getName();
165         this.version = extractor.getVersion();
166         this.highestVersion = extractor.isHighestVersion();
167         this.creationDate = extractor.getCreationDate();
168         this.lastUpdateDate = extractor.getLastUpdateDate();
169         this.description = extractor.getDescription();
170         this.state = extractor.getState();
171         this.tags = extractor.getTags();
172         this.icon = extractor.getIcon();
173         this.contactId = extractor.getContactId();
174         this.UUID = extractor.getUUID();
175         this.normalizedName = extractor.getNormalizedName();
176         this.systemName = extractor.getSystemName();
177         this.isDeleted = extractor.isDeleted();
178         this.projectCode = extractor.getProjectCode();
179         this.csarUUID = extractor.getCsarUuid();
180         this.csarVersion = extractor.getCsarVersion();
181         this.importedToscaChecksum = extractor.getImportedToscaChecksum();
182         this.invariantUUID = extractor.getInvariantUuid();
183         this.isArchived = extractor.isArchived();
184         this.isVspArchived = extractor.isVspArchived();
185         this.archiveTime = extractor.getArchiveTime();
186     }
187
188     public void setUniqueId(String uniqueId) {
189         if (this.uniqueId != null && !this.uniqueId.equals(uniqueId)) {
190             LOGGER.warn("uniqueId changed more then once -> OLD : {} , NEW: {} ", this.uniqueId, uniqueId);
191         }
192         this.uniqueId = uniqueId;
193     }
194
195     public void setUUID(String UUID) {
196         if (this.UUID != null && !this.UUID.equals(UUID)) {
197             LOGGER.warn("UUID changed more then once -> OLD : {} , NEW: {} ", this.UUID, UUID);
198         }
199         this.UUID = UUID;
200     }
201
202     public void setInvariantUUID(String invariantUUID) {
203         if (this.invariantUUID != null && !this.invariantUUID.equals(invariantUUID)) {
204             LOGGER.warn("InvariantUUID changed more then once -> OLD : {} , NEW: {} ", this.invariantUUID,
205                     invariantUUID);
206         }
207         this.invariantUUID = invariantUUID;
208     }
209
210     public Boolean isHighestVersion() {
211         return highestVersion;
212     }
213
214     public String getLifecycleState() {
215         return state;
216     }
217
218     public void setLifecycleState(String state) {
219         this.state = state;
220     }
221
222     public Boolean isDeleted() {
223         return getIsDeleted();
224     }
225
226     public Boolean isArchived() {
227         return getIsArchived();
228     }
229
230     public void setArchived(Boolean archived) {
231         setIsArchived(archived);
232     }
233
234     public Boolean isVspArchived() {
235         return getIsVspArchived();
236     }
237
238     public void setVspArchived(Boolean vspArchived) {
239         setIsVspArchived(vspArchived);
240     }
241
242     /**
243      * Return the type of the actual component - e.g. for a Resource, return the actual VF/CR
244      *
245      * @return
246      */
247     public abstract String getActualComponentType();
248 }