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