d6588e96e196449194afa53f6e5fd405ff332e4b
[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 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 @Getter
41 @Setter
42 public abstract class ComponentMetadataDataDefinition extends ToscaDataDefinition {
43
44     private static final Logger LOGGER = Logger.getLogger(ComponentMetadataDataDefinition.class.getName());
45     private String uniqueId;
46     private String name; // archiveName
47     private String version; // archiveVersion
48     private Boolean highestVersion;
49     private Long creationDate;
50     private Long lastUpdateDate;
51     private String description;
52     private String state;
53     private List<String> tags;
54     private String conformanceLevel;
55     private String icon;
56     private String UUID;
57     private String normalizedName;
58     private String systemName;
59     private String contactId;
60     private Map<String, String> allVersions;
61     private Boolean isDeleted;
62     private String projectCode;
63     private String csarUUID;
64     private String csarVersion;
65     private String importedToscaChecksum;
66     private String invariantUUID;
67     protected ComponentTypeEnum componentType;
68     private String creatorUserId;
69     private String creatorFullName;
70     private String lastUpdaterUserId;
71     private String lastUpdaterFullName;
72     private Boolean isArchived = false;
73     private Long archiveTime;
74     private Boolean isVspArchived = false;
75     private Map<String, String> categorySpecificMetadata;
76     private String model;
77
78     protected ComponentMetadataDataDefinition(ComponentMetadataDataDefinition other) {
79         this.uniqueId = other.getUniqueId();
80         this.name = other.getName();
81         this.version = other.getVersion();
82         this.highestVersion = other.isHighestVersion();
83         this.creationDate = other.getCreationDate();
84         this.lastUpdateDate = other.getLastUpdateDate();
85         this.description = other.getDescription();
86         this.state = other.getState();
87         this.tags = new ArrayList<>(other.getTags() != null ? other.getTags() : new LinkedList<>());
88         this.icon = other.getIcon();
89         this.contactId = other.getContactId();
90         this.UUID = other.getUUID();
91         this.normalizedName = other.getNormalizedName();
92         this.systemName = other.getSystemName();
93         this.allVersions = new HashMap<>(other.getAllVersions() != null ? other.getAllVersions() : new HashMap<>());
94         this.isDeleted = other.getIsDeleted();
95         this.projectCode = other.getProjectCode();
96         this.csarUUID = other.getCsarUUID();
97         this.csarVersion = other.csarVersion;
98         this.importedToscaChecksum = other.getImportedToscaChecksum();
99         this.invariantUUID = other.getInvariantUUID();
100         this.isArchived = other.isArchived;
101         this.isVspArchived = other.isVspArchived;
102         this.archiveTime = other.getArchiveTime();
103         this.categorySpecificMetadata = other.getCategorySpecificMetadata();
104         this.model = other.getModel();
105     }
106
107     protected ComponentMetadataDataDefinition(JsonPresentationFieldsExtractor extractor) {
108         this.uniqueId = extractor.getUniqueId();
109         this.name = extractor.getName();
110         this.version = extractor.getVersion();
111         this.highestVersion = extractor.isHighestVersion();
112         this.creationDate = extractor.getCreationDate();
113         this.lastUpdateDate = extractor.getLastUpdateDate();
114         this.description = extractor.getDescription();
115         this.state = extractor.getState();
116         this.tags = extractor.getTags();
117         this.icon = extractor.getIcon();
118         this.contactId = extractor.getContactId();
119         this.UUID = extractor.getUUID();
120         this.normalizedName = extractor.getNormalizedName();
121         this.systemName = extractor.getSystemName();
122         this.isDeleted = extractor.isDeleted();
123         this.projectCode = extractor.getProjectCode();
124         this.csarUUID = extractor.getCsarUuid();
125         this.csarVersion = extractor.getCsarVersion();
126         this.importedToscaChecksum = extractor.getImportedToscaChecksum();
127         this.invariantUUID = extractor.getInvariantUuid();
128         this.isArchived = extractor.isArchived();
129         this.isVspArchived = extractor.isVspArchived();
130         this.archiveTime = extractor.getArchiveTime();
131         this.model = extractor.getModel();
132     }
133
134     public void setUniqueId(String uniqueId) {
135         if (this.uniqueId != null && !this.uniqueId.equals(uniqueId)) {
136             LOGGER.warn("uniqueId changed more then once -> OLD : {} , NEW: {} ", this.uniqueId, uniqueId);
137         }
138         this.uniqueId = uniqueId;
139     }
140
141     public void setUUID(String UUID) {
142         if (this.UUID != null && !this.UUID.equals(UUID)) {
143             LOGGER.warn("UUID changed more then once -> OLD : {} , NEW: {} ", this.UUID, UUID);
144         }
145         this.UUID = UUID;
146     }
147
148     public void setInvariantUUID(String invariantUUID) {
149         if (this.invariantUUID != null && !this.invariantUUID.equals(invariantUUID)) {
150             LOGGER.warn("InvariantUUID changed more then once -> OLD : {} , NEW: {} ", this.invariantUUID, invariantUUID);
151         }
152         this.invariantUUID = invariantUUID;
153     }
154
155     public Boolean isHighestVersion() {
156         return highestVersion;
157     }
158
159     public String getLifecycleState() {
160         return state;
161     }
162
163     public void setLifecycleState(String state) {
164         this.state = state;
165     }
166
167     public Boolean isDeleted() {
168         return getIsDeleted();
169     }
170
171     public Boolean isArchived() {
172         return getIsArchived();
173     }
174
175     public void setArchived(Boolean archived) {
176         setIsArchived(archived);
177     }
178
179     public Boolean isVspArchived() {
180         return getIsVspArchived();
181     }
182
183     public void setVspArchived(Boolean vspArchived) {
184         setIsVspArchived(vspArchived);
185     }
186
187     /**
188      * Return the type of the actual component - e.g. for a Resource, return the actual VF/CR
189      *
190      * @return
191      */
192     public abstract String getActualComponentType();
193 }