4feb026fd6d195ef6c84c050cbbd8e01794f279c
[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 org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
24 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFieldsExtractor;
25 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
26 import org.openecomp.sdc.common.log.wrappers.Logger;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.LinkedList;
31 import java.util.List;
32 import java.util.Map;
33
34 public abstract class ComponentMetadataDataDefinition extends ToscaDataDefinition {
35
36     private static final Logger LOGGER = Logger.getLogger(ComponentMetadataDataDefinition.class.getName());
37
38     private String uniqueId;
39
40     private String name; // archiveName
41
42     private String version; // archiveVersion
43
44     private Boolean isHighestVersion;
45
46     private Long creationDate;
47
48     private Long lastUpdateDate;
49
50     private String description;
51
52     private String state;
53
54     private List<String> tags;
55
56     private String conformanceLevel;
57
58     private String icon;
59
60     private String UUID;
61
62     private String normalizedName;
63
64     private String systemName;
65
66     private String contactId;
67
68     private Map<String, String> allVersions;
69
70     private Boolean isDeleted;
71
72     private String projectCode;
73
74     private String csarUUID;
75
76     private String csarVersion;
77
78     private String importedToscaChecksum;
79
80     private String invariantUUID;
81
82     protected ComponentTypeEnum componentType;
83
84     // USER
85     private String creatorUserId;
86
87     private String creatorFullName;
88
89     private String lastUpdaterUserId;
90
91     private String lastUpdaterFullName;
92
93     //Archive/Restore
94     private Boolean isArchived = false;
95
96     private Long archiveTime;
97
98     private Boolean isVspArchived = false;
99
100     public Boolean getIsHighestVersion() {
101         return isHighestVersion;
102     }
103
104     public void setIsHighestVersion(Boolean isHighestVersion) {
105         this.isHighestVersion = isHighestVersion;
106     }
107
108     public ComponentTypeEnum getComponentType() {
109         return componentType;
110     }
111
112     public void setComponentType(ComponentTypeEnum componentType) {
113         this.componentType = componentType;
114     }
115
116     public String getCreatorUserId() {
117         return creatorUserId;
118     }
119
120     public void setCreatorUserId(String creatorUserId) {
121         this.creatorUserId = creatorUserId;
122     }
123
124     public String getCreatorFullName() {
125         return creatorFullName;
126     }
127
128     public void setCreatorFullName(String creatorFullName) {
129         this.creatorFullName = creatorFullName;
130     }
131
132     public String getLastUpdaterUserId() {
133         return lastUpdaterUserId;
134     }
135
136     public void setLastUpdaterUserId(String lastUpdaterUserId) {
137         this.lastUpdaterUserId = lastUpdaterUserId;
138     }
139
140     public String getLastUpdaterFullName() {
141         return lastUpdaterFullName;
142     }
143
144     public void setLastUpdaterFullName(String lastUpdaterFullName) {
145         this.lastUpdaterFullName = lastUpdaterFullName;
146     }
147
148     public Boolean getIsDeleted() {
149         return isDeleted;
150     }
151
152     public Boolean isArchived() {
153         return isArchived;
154     }
155
156     public void setArchived(Boolean archived) {
157         isArchived = archived;
158     }
159
160     public Long getArchiveTime() {
161         return archiveTime;
162     }
163
164     public void setArchiveTime(Long archiveTime) {
165         this.archiveTime = archiveTime;
166     }
167
168     public Boolean isVspArchived() {
169         return isVspArchived;
170     }
171
172     public void setVspArchived(Boolean vspArchived) {
173         isVspArchived = vspArchived;
174     }
175
176     public ComponentMetadataDataDefinition() {
177
178     }
179
180     public ComponentMetadataDataDefinition(ComponentMetadataDataDefinition other) {
181         this.uniqueId = other.getUniqueId();
182         this.name = other.getName();
183         this.version = other.getVersion();
184         this.isHighestVersion = other.isHighestVersion();
185         this.creationDate = other.getCreationDate();
186         this.lastUpdateDate = other.getLastUpdateDate();
187         this.description = other.getDescription();
188         this.state = other.getState();
189         this.tags = new ArrayList<>(other.getTags() != null ? other.getTags() : new LinkedList<>());
190         this.icon = other.getIcon();
191         this.contactId = other.getContactId();
192         this.UUID = other.getUUID();
193         this.normalizedName = other.getNormalizedName();
194         this.systemName = other.getSystemName();
195         this.allVersions = new HashMap<>(other.getAllVersions() != null ? other.getAllVersions() : new HashMap<>());
196         this.isDeleted = other.isDeleted();
197         this.projectCode = other.getProjectCode();
198         this.csarUUID = other.getCsarUUID();
199         this.csarVersion = other.csarVersion;
200         this.importedToscaChecksum = other.getImportedToscaChecksum();
201         this.invariantUUID = other.getInvariantUUID();
202         this.isArchived = other.isArchived;
203         this.isVspArchived = other.isVspArchived;
204         this.archiveTime = other.getArchiveTime();
205     }
206
207         public ComponentMetadataDataDefinition(JsonPresentationFieldsExtractor extractor){
208                 this.uniqueId = extractor.getUniqueId();
209                 this.name = extractor.getName();
210                 this.version = extractor.getVersion();
211                 this.isHighestVersion = extractor.isHighestVersion();
212                 this.creationDate = extractor.getCreationDate();
213                 this.lastUpdateDate = extractor.getLastUpdateDate();
214                 this.description = extractor.getDescription();
215                 this.state = extractor.getState();
216                 this.tags = extractor.getTags();
217                 this.icon = extractor.getIcon();
218                 this.contactId = extractor.getContactId();
219                 this.UUID = extractor.getUUID();
220                 this.normalizedName = extractor.getNormalizedName();
221                 this.systemName = extractor.getSystemName();
222                 this.isDeleted = extractor.isDeleted();
223                 this.projectCode = extractor.getProjectCode();
224                 this.csarUUID = extractor.getCsarUuid();
225                 this.csarVersion = extractor.getCsarVersion();
226                 this.importedToscaChecksum = extractor.getImportedToscaChecksum();
227                 this.invariantUUID = extractor.getInvariantUuid();
228                 this.isArchived =  extractor.isArchived();
229                 this.isVspArchived =  extractor.isVspArchived();
230                 this.archiveTime =  extractor.getArchiveTime();
231         }
232
233
234     public String getUniqueId() {
235         return uniqueId;
236     }
237
238     public void setUniqueId(String uniqueId) {
239         if (this.uniqueId != null && !this.uniqueId.equals(uniqueId)) {
240             LOGGER.warn("uniqueId changed more then once -> OLD : {} , NEW: {} ", this.uniqueId, uniqueId);
241         }
242         this.uniqueId = uniqueId;
243     }
244
245     public String getName() {
246         return name;
247     }
248
249     public void setName(String name) {
250         this.name = name;
251     }
252
253     public String getVersion() {
254         return version;
255     }
256
257     public void setVersion(String version) {
258         this.version = version;
259     }
260
261     public Boolean isHighestVersion() {
262         return isHighestVersion;
263     }
264
265     public void setHighestVersion(Boolean isHighestVersion) {
266         this.isHighestVersion = isHighestVersion;
267     }
268
269     public Long getCreationDate() {
270         return creationDate;
271     }
272
273     public void setCreationDate(Long creationDate) {
274         this.creationDate = creationDate;
275     }
276
277     public Long getLastUpdateDate() {
278         return lastUpdateDate;
279     }
280
281     public void setLastUpdateDate(Long lastUpdateDate) {
282         this.lastUpdateDate = lastUpdateDate;
283     }
284
285     public String getDescription() {
286         return description;
287     }
288
289     public void setDescription(String description) {
290         this.description = description;
291     }
292
293     public String getState() {
294         return state;
295     }
296
297     public void setState(String state) {
298         this.state = state;
299     }
300
301     public List<String> getTags() {
302         return tags;
303     }
304
305     public void setTags(List<String> tags) {
306         this.tags = tags;
307     }
308
309     public String getIcon() {
310         return icon;
311     }
312
313     public void setIcon(String icon) {
314         this.icon = icon;
315     }
316
317     public String getContactId() {
318         return contactId;
319     }
320
321     public void setContactId(String contactId) {
322         this.contactId = contactId;
323     }
324
325     public String getUUID() {
326         return UUID;
327     }
328
329     public void setUUID(String UUID) {
330         if (this.UUID != null && !this.UUID.equals(UUID)) {
331             LOGGER.warn("UUID changed more then once -> OLD : {} , NEW: {} ", this.UUID, UUID);
332         }
333         this.UUID = UUID;
334     }
335
336     public String getNormalizedName() {
337         return normalizedName;
338     }
339
340     public void setNormalizedName(String normalizedName) {
341         this.normalizedName = normalizedName;
342     }
343
344     public String getSystemName() {
345         return systemName;
346     }
347
348     public void setSystemName(String systemName) {
349         this.systemName = systemName;
350     }
351
352     public Map<String, String> getAllVersions() {
353         return allVersions;
354     }
355
356     public void setAllVersions(Map<String, String> allVersions) {
357         this.allVersions = allVersions;
358     }
359
360     public String getInvariantUUID() {
361         return invariantUUID;
362     }
363
364     public void setInvariantUUID(String invariantUUID) {
365         if (this.invariantUUID != null && !this.invariantUUID.equals(invariantUUID)) {
366             LOGGER.warn("InvariantUUID changed more then once -> OLD : {} , NEW: {} ", this.invariantUUID, invariantUUID);
367         }
368         this.invariantUUID = invariantUUID;
369     }
370
371     public Boolean isDeleted() {
372         return isDeleted;
373     }
374
375     public void setIsDeleted(Boolean isDeleted) {
376         this.isDeleted = isDeleted;
377     }
378
379     public String getProjectCode() {
380         return projectCode;
381     }
382
383     public void setProjectCode(String projectCode) {
384         this.projectCode = projectCode;
385     }
386
387     public String getCsarUUID() {
388         return csarUUID;
389     }
390
391     public void setCsarUUID(String csarUUID) {
392         this.csarUUID = csarUUID;
393     }
394
395     public String getCsarVersion() {
396         return csarVersion;
397     }
398
399     public void setCsarVersion(String csarVersion) {
400         this.csarVersion = csarVersion;
401     }
402
403     public String getImportedToscaChecksum() {
404         return importedToscaChecksum;
405     }
406
407     public void setImportedToscaChecksum(String importedToscaChecksum) {
408         this.importedToscaChecksum = importedToscaChecksum;
409     }
410
411     public String getConformanceLevel() {
412         return conformanceLevel;
413     }
414
415     public void setConformanceLevel(String conformanceLevel) {
416         this.conformanceLevel = conformanceLevel;
417     }
418
419     public String getLifecycleState() {
420         return state;
421     }
422
423     public void setLifecycleState(String state) {
424         this.state = state;
425     }
426
427     @Override
428     public String toString() {
429         return "ComponentMetadataDataDefinition [uniqueId=" + uniqueId + ", name=" + name + ", version=" + version
430                 + ", isHighestVersion=" + isHighestVersion + ", creationDate=" + creationDate + ", lastUpdateDate="
431                 + lastUpdateDate + ", description=" + description + ", state=" + state + ", tags=" + tags
432                 + ", conformanceLevel=" + conformanceLevel + ", icon=" + icon + ", UUID=" + UUID + ", normalizedName="
433                 + normalizedName + ", systemName=" + systemName + ", contactId=" + contactId + ", allVersions="
434                 + allVersions + ", isDeleted=" + isDeleted + ", projectCode=" + projectCode + ", csarUUID=" + csarUUID
435                 + ", csarVersion=" + csarVersion + ", importedToscaChecksum=" + importedToscaChecksum
436                 + ", invariantUUID=" + invariantUUID + ", componentType=" + componentType + ", creatorUserId="
437                 + creatorUserId + ", creatorFullName=" + creatorFullName + ", lastUpdaterUserId=" + lastUpdaterUserId
438                 + ", lastUpdaterFullName=" + lastUpdaterFullName + "]";
439     }
440
441     @Override
442     public int hashCode() {
443         final int prime = 31;
444         int result = 1;
445         result = prime * result + ((UUID == null) ? 0 : UUID.hashCode());
446         result = prime * result + ((allVersions == null) ? 0 : allVersions.hashCode());
447         result = prime * result + ((componentType == null) ? 0 : componentType.hashCode());
448         result = prime * result + ((conformanceLevel == null) ? 0 : conformanceLevel.hashCode());
449         result = prime * result + ((contactId == null) ? 0 : contactId.hashCode());
450         result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode());
451         result = prime * result + ((creatorFullName == null) ? 0 : creatorFullName.hashCode());
452         result = prime * result + ((creatorUserId == null) ? 0 : creatorUserId.hashCode());
453         result = prime * result + ((csarUUID == null) ? 0 : csarUUID.hashCode());
454         result = prime * result + ((csarVersion == null) ? 0 : csarVersion.hashCode());
455         result = prime * result + ((description == null) ? 0 : description.hashCode());
456         result = prime * result + ((icon == null) ? 0 : icon.hashCode());
457         result = prime * result + ((importedToscaChecksum == null) ? 0 : importedToscaChecksum.hashCode());
458         result = prime * result + ((invariantUUID == null) ? 0 : invariantUUID.hashCode());
459         result = prime * result + ((isDeleted == null) ? 0 : isDeleted.hashCode());
460         result = prime * result + ((isHighestVersion == null) ? 0 : isHighestVersion.hashCode());
461         result = prime * result + ((lastUpdateDate == null) ? 0 : lastUpdateDate.hashCode());
462         result = prime * result + ((lastUpdaterFullName == null) ? 0 : lastUpdaterFullName.hashCode());
463         result = prime * result + ((lastUpdaterUserId == null) ? 0 : lastUpdaterUserId.hashCode());
464         result = prime * result + ((name == null) ? 0 : name.hashCode());
465         result = prime * result + ((normalizedName == null) ? 0 : normalizedName.hashCode());
466         result = prime * result + ((projectCode == null) ? 0 : projectCode.hashCode());
467         result = prime * result + ((state == null) ? 0 : state.hashCode());
468         result = prime * result + ((systemName == null) ? 0 : systemName.hashCode());
469         result = prime * result + ((tags == null) ? 0 : tags.hashCode());
470         result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
471         result = prime * result + ((version == null) ? 0 : version.hashCode());
472         return result;
473     }
474
475     @Override
476     public boolean equals(Object obj) {
477         if (this == obj) {
478             return true;
479         }
480         if (obj == null) {
481             return false;
482         }
483         if (getClass() != obj.getClass()) {
484             return false;
485         }
486         ComponentMetadataDataDefinition other = (ComponentMetadataDataDefinition) obj;
487         if (UUID == null) {
488             if (other.UUID != null) {
489                 return false;
490             }
491         } else if (!UUID.equals(other.UUID)) {
492             return false;
493         }
494         if (allVersions == null) {
495             if (other.allVersions != null) {
496                 return false;
497             }
498         } else if (!allVersions.equals(other.allVersions)) {
499             return false;
500         }
501         if (componentType != other.componentType) {
502             return false;
503         }
504         if (conformanceLevel == null) {
505             if (other.conformanceLevel != null) {
506                 return false;
507             }
508         } else if (!conformanceLevel.equals(other.conformanceLevel)) {
509             return false;
510         }
511         if (contactId == null) {
512             if (other.contactId != null) {
513                 return false;
514             }
515         } else if (!contactId.equals(other.contactId)) {
516             return false;
517         }
518         if (creationDate == null) {
519             if (other.creationDate != null) {
520                 return false;
521             }
522         } else if (!creationDate.equals(other.creationDate)) {
523             return false;
524         }
525         if (creatorFullName == null) {
526             if (other.creatorFullName != null) {
527                 return false;
528             }
529         } else if (!creatorFullName.equals(other.creatorFullName)) {
530             return false;
531         }
532         if (creatorUserId == null) {
533             if (other.creatorUserId != null) {
534                 return false;
535             }
536         } else if (!creatorUserId.equals(other.creatorUserId)) {
537             return false;
538         }
539         if (csarUUID == null) {
540             if (other.csarUUID != null) {
541                 return false;
542             }
543         } else if (!csarUUID.equals(other.csarUUID)) {
544             return false;
545         }
546         if (csarVersion == null) {
547             if (other.csarVersion != null) {
548                 return false;
549             }
550         } else if (!csarVersion.equals(other.csarVersion)) {
551             return false;
552         }
553         if (description == null) {
554             if (other.description != null) {
555                 return false;
556             }
557         } else if (!description.equals(other.description)) {
558             return false;
559         }
560         if (icon == null) {
561             if (other.icon != null) {
562                 return false;
563             }
564         } else if (!icon.equals(other.icon)) {
565             return false;
566         }
567         if (importedToscaChecksum == null) {
568             if (other.importedToscaChecksum != null) {
569                 return false;
570             }
571         } else if (!importedToscaChecksum.equals(other.importedToscaChecksum)) {
572             return false;
573         }
574         if (invariantUUID == null) {
575             if (other.invariantUUID != null) {
576                 return false;
577             }
578         } else if (!invariantUUID.equals(other.invariantUUID)) {
579             return false;
580         }
581         if (isDeleted == null) {
582             if (other.isDeleted != null) {
583                 return false;
584             }
585         } else if (!isDeleted.equals(other.isDeleted)) {
586             return false;
587         }
588         if (isHighestVersion == null) {
589             if (other.isHighestVersion != null) {
590                 return false;
591             }
592         } else if (!isHighestVersion.equals(other.isHighestVersion)) {
593             return false;
594         }
595         if (lastUpdateDate == null) {
596             if (other.lastUpdateDate != null) {
597                 return false;
598             }
599         } else if (!lastUpdateDate.equals(other.lastUpdateDate)) {
600             return false;
601         }
602         if (lastUpdaterFullName == null) {
603             if (other.lastUpdaterFullName != null) {
604                 return false;
605             }
606         } else if (!lastUpdaterFullName.equals(other.lastUpdaterFullName)) {
607             return false;
608         }
609         if (lastUpdaterUserId == null) {
610             if (other.lastUpdaterUserId != null) {
611                 return false;
612             }
613         } else if (!lastUpdaterUserId.equals(other.lastUpdaterUserId)) {
614             return false;
615         }
616         if (name == null) {
617             if (other.name != null) {
618                 return false;
619             }
620         } else if (!name.equals(other.name)) {
621             return false;
622         }
623         if (normalizedName == null) {
624             if (other.normalizedName != null) {
625                 return false;
626             }
627         } else if (!normalizedName.equals(other.normalizedName)) {
628             return false;
629         }
630         if (projectCode == null) {
631             if (other.projectCode != null) {
632                 return false;
633             }
634         } else if (!projectCode.equals(other.projectCode)) {
635             return false;
636         }
637         if (state == null) {
638             if (other.state != null) {
639                 return false;
640             }
641         } else if (!state.equals(other.state)) {
642             return false;
643         }
644         if (systemName == null) {
645             if (other.systemName != null) {
646                 return false;
647             }
648         } else if (!systemName.equals(other.systemName)) {
649             return false;
650         }
651         if (tags == null) {
652             if (other.tags != null) {
653                 return false;
654             }
655         } else if (!tags.equals(other.tags)) {
656             return false;
657         }
658         if (uniqueId == null) {
659             if (other.uniqueId != null) {
660                 return false;
661             }
662         } else if (!uniqueId.equals(other.uniqueId)) {
663             return false;
664         }
665         if (version == null) {
666             return other.version == null;
667         } else {
668             return version.equals(other.version);
669         }
670     }
671
672     /**
673      * Return the type of the actual component - e.g. for a Resource, return the actual VF/CR
674      *
675      * @return
676      */
677     public abstract String getActualComponentType();
678 }