Implement Attributes/Outputs BE (part 1)
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / jsonjanusgraph / datamodel / ToscaElement.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.model.jsonjanusgraph.datamodel;
22
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.UUID;
27 import lombok.Getter;
28 import lombok.Setter;
29 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
36 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
37 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
38 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
39 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
40 import org.openecomp.sdc.be.model.LifecycleStateEnum;
41 import org.openecomp.sdc.be.model.category.CategoryDefinition;
42 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
43 import org.openecomp.sdc.common.log.api.ILogConfiguration;
44 import org.slf4j.MDC;
45
46 @Getter
47 @Setter
48 public abstract class ToscaElement {
49
50     protected Map<String, Object> metadata;
51     protected List<CategoryDefinition> categories;
52     protected Map<String, ArtifactDataDefinition> toscaArtifacts;
53     protected ToscaElementTypeEnum toscaType;
54     private Map<String, ArtifactDataDefinition> artifacts;
55     private Map<String, ArtifactDataDefinition> deploymentArtifacts;
56     private Map<String, AdditionalInfoParameterDataDefinition> additionalInformation;
57     private Map<String, PropertyDataDefinition> properties;
58     private Map<String, AttributeDataDefinition> attributes;
59     private Map<String, ListCapabilityDataDefinition> capabilities;
60     private Map<String, MapPropertiesDataDefinition> capabilitiesProperties;
61     private Map<String, ListRequirementDataDefinition> requirements;
62     private Map<String, DataTypeDataDefinition> dataTypes;
63     // User
64     private String creatorUserId;
65     private String creatorFullName;
66     private String lastUpdaterUserId;
67     private String lastUpdaterFullName;
68
69     private Map<String, String> allVersions;
70     private String toscaVersion;
71
72     protected ToscaElement(ToscaElementTypeEnum toscaType){
73         this.toscaType = toscaType;
74     }
75
76     // metadata properties
77     // ----------------------------
78     public Object getMetadataValue(JsonPresentationFields name) {
79         return getMetadataValueOrDefault(name, null);
80     }
81
82     public Object getMetadataValueOrDefault(JsonPresentationFields name, Object defaultVal) {
83         if (metadata != null) {
84             return metadata.getOrDefault(name.getPresentation(), defaultVal);
85         }
86         return null;
87     }
88
89     public void setMetadataValue(JsonPresentationFields name, Object value) {
90         setMetadataValue(name.getPresentation(), value);
91     }
92     
93     public void setMetadataValue(String name, Object value) {
94         if (metadata == null) {
95             metadata = new HashMap<>();
96         }
97         metadata.put(name, value);
98     }
99     // --------------------
100     public String getUUID() {
101         return (String) getMetadataValue(JsonPresentationFields.UUID);
102     }
103
104     public void setUUID(String uuid) {
105         setMetadataValue(JsonPresentationFields.UUID, uuid);
106     }
107
108     public String getVersion() {
109         return (String) getMetadataValue(JsonPresentationFields.VERSION);
110     }
111
112     public String getNormalizedName() {
113         return (String) getMetadataValue(JsonPresentationFields.NORMALIZED_NAME);
114     }
115
116     public void setNormalizedName(String normaliseComponentName) {
117         setMetadataValue(JsonPresentationFields.NORMALIZED_NAME, normaliseComponentName);
118     }
119
120     public String getName() {
121         return (String) getMetadataValue(JsonPresentationFields.NAME);
122     }
123
124     public String getSystemName() {
125         return (String) getMetadataValue(JsonPresentationFields.SYSTEM_NAME);
126     }
127     public void setSystemName(String systemName) {
128         setMetadataValue(JsonPresentationFields.SYSTEM_NAME, systemName);
129     }
130
131     public void setLifecycleState(LifecycleStateEnum state) {
132         if(state != null)
133             setMetadataValue(JsonPresentationFields.LIFECYCLE_STATE, state.name());
134     }
135
136     public LifecycleStateEnum getLifecycleState() {
137         return LifecycleStateEnum.findState( (String) getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
138     }
139
140     public Long getCreationDate() {
141         return (Long) getMetadataValue(JsonPresentationFields.CREATION_DATE);
142     }
143
144     public void setCreationDate(Long currentDate) {
145         setMetadataValue(JsonPresentationFields.CREATION_DATE, currentDate);
146     }
147
148     public void setLastUpdateDate(Long currentDate) {
149         setMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE, currentDate);
150     }
151     public Long getLastUpdateDate() {
152         return (Long) getMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE);
153     }
154
155     public String getUniqueId() {
156         return (String) getMetadataValue(JsonPresentationFields.UNIQUE_ID);
157     }
158     public void setUniqueId(String uniqueId) {
159          setMetadataValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
160     }
161
162     public void setHighestVersion(Boolean isHighest) {
163          setMetadataValue(JsonPresentationFields.HIGHEST_VERSION, isHighest);
164
165     }
166     public Boolean isHighestVersion() {
167         return (Boolean) getMetadataValue(JsonPresentationFields.HIGHEST_VERSION);
168
169     }
170     public ResourceTypeEnum getResourceType() {
171         String resourceType = (String) getMetadataValue(JsonPresentationFields.RESOURCE_TYPE);
172         return resourceType != null ? ResourceTypeEnum.valueOf(resourceType) : null;
173     }
174
175     public void setResourceType(ResourceTypeEnum resourceType) {
176         if(resourceType != null)
177             setMetadataValue(JsonPresentationFields.RESOURCE_TYPE, resourceType.name());
178     }
179
180     public ComponentTypeEnum getComponentType() {
181         return ComponentTypeEnum.valueOf((String) getMetadataValue(JsonPresentationFields.COMPONENT_TYPE));
182     }
183
184     public void setComponentType(ComponentTypeEnum componentType) {
185         if(componentType != null)
186             setMetadataValue(JsonPresentationFields.COMPONENT_TYPE, componentType.name());
187     }
188
189     public String getDerivedFromGenericType(){
190         return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE);
191     }
192
193     public void setDerivedFromGenericType(String derivedFromGenericType){
194         setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE, derivedFromGenericType);
195     }
196
197     public String getDerivedFromGenericVersion(){
198         return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION);
199     }
200
201     public void setDerivedFromGenericVersion(String derivedFromGenericVersion){
202         setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION, derivedFromGenericVersion);
203     }
204
205     public Boolean isArchived() { return (Boolean) getMetadataValue(JsonPresentationFields.IS_ARCHIVED); }
206
207     public void setArchived(Boolean archived) { setMetadataValue(JsonPresentationFields.IS_ARCHIVED, archived); }
208
209     public Long getArchiveTime() {
210         Object archiveTime = getMetadataValue(JsonPresentationFields.ARCHIVE_TIME);
211         if (archiveTime instanceof Integer){
212             return Long.valueOf((Integer)getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
213         }
214         return (Long)archiveTime;
215     }
216
217     public void setArchiveTime(Long archiveTime) {
218         setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime);
219     }
220
221     public Boolean isVspArchived() {
222         return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED);
223     }
224
225     public void setVspArchived(Boolean vspArchived) {
226         setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived);
227     }
228
229     public void generateUUID() {
230         String prevUUID = getUUID();
231         String version = getVersion();
232         if ((prevUUID == null && NodeTypeOperation.uuidNormativeNewVersion.matcher(version).matches()) || NodeTypeOperation.uuidNewVersion.matcher(version).matches()) {
233             UUID uuid = UUID.randomUUID();
234             setUUID(uuid.toString());
235             MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, uuid.toString());
236         }
237     }
238
239 }