2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.sdc.be.model.jsonjanusgraph.datamodel;
22 import java.util.HashMap;
23 import java.util.List;
25 import java.util.UUID;
28 import org.openecomp.sdc.be.datatypes.elements.AdditionalInfoParameterDataDefinition;
29 import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.AttributeDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
36 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
37 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
38 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
39 import org.openecomp.sdc.be.model.LifecycleStateEnum;
40 import org.openecomp.sdc.be.model.category.CategoryDefinition;
41 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
42 import org.openecomp.sdc.common.log.api.ILogConfiguration;
47 public abstract class ToscaElement {
49 protected Map<String, Object> metadata;
50 protected List<CategoryDefinition> categories;
51 protected Map<String, ArtifactDataDefinition> toscaArtifacts;
52 protected ToscaElementTypeEnum toscaType;
53 private Map<String, ArtifactDataDefinition> artifacts;
54 private Map<String, ArtifactDataDefinition> deploymentArtifacts;
55 private Map<String, AdditionalInfoParameterDataDefinition> additionalInformation;
56 private Map<String, PropertyDataDefinition> properties;
57 private Map<String, AttributeDataDefinition> attributes;
58 private Map<String, ListCapabilityDataDefinition> capabilities;
59 private Map<String, MapPropertiesDataDefinition> capabilitiesProperties;
60 private Map<String, ListRequirementDataDefinition> requirements;
61 private Map<String, DataTypeDataDefinition> dataTypes;
63 private String creatorUserId;
64 private String creatorFullName;
65 private String lastUpdaterUserId;
66 private String lastUpdaterFullName;
67 private Map<String, String> allVersions;
68 private String toscaVersion;
70 protected ToscaElement(ToscaElementTypeEnum toscaType) {
71 this.toscaType = toscaType;
73 // metadata properties
75 // ----------------------------
76 public Object getMetadataValue(JsonPresentationFields name) {
77 return getMetadataValueOrDefault(name, null);
80 public Object getMetadataValueOrDefault(JsonPresentationFields name, Object defaultVal) {
81 if (metadata != null) {
82 return metadata.getOrDefault(name.getPresentation(), defaultVal);
87 public void setMetadataValue(JsonPresentationFields name, Object value) {
88 setMetadataValue(name.getPresentation(), value);
91 public void setMetadataValue(String name, Object value) {
92 if (metadata == null) {
93 metadata = new HashMap<>();
95 metadata.put(name, value);
98 // --------------------
99 public String getUUID() {
100 return (String) getMetadataValue(JsonPresentationFields.UUID);
103 public void setUUID(String uuid) {
104 setMetadataValue(JsonPresentationFields.UUID, uuid);
107 public String getVersion() {
108 return (String) getMetadataValue(JsonPresentationFields.VERSION);
111 public String getNormalizedName() {
112 return (String) getMetadataValue(JsonPresentationFields.NORMALIZED_NAME);
115 public void setNormalizedName(String normaliseComponentName) {
116 setMetadataValue(JsonPresentationFields.NORMALIZED_NAME, normaliseComponentName);
119 public String getName() {
120 return (String) getMetadataValue(JsonPresentationFields.NAME);
123 public String getSystemName() {
124 return (String) getMetadataValue(JsonPresentationFields.SYSTEM_NAME);
127 public void setSystemName(String systemName) {
128 setMetadataValue(JsonPresentationFields.SYSTEM_NAME, systemName);
131 public LifecycleStateEnum getLifecycleState() {
132 return LifecycleStateEnum.findState((String) getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
135 public void setLifecycleState(LifecycleStateEnum state) {
137 setMetadataValue(JsonPresentationFields.LIFECYCLE_STATE, state.name());
141 public Long getCreationDate() {
142 return (Long) getMetadataValue(JsonPresentationFields.CREATION_DATE);
145 public void setCreationDate(Long currentDate) {
146 setMetadataValue(JsonPresentationFields.CREATION_DATE, currentDate);
149 public Long getLastUpdateDate() {
150 return (Long) getMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE);
153 public void setLastUpdateDate(Long currentDate) {
154 setMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE, currentDate);
157 public String getUniqueId() {
158 return (String) getMetadataValue(JsonPresentationFields.UNIQUE_ID);
161 public void setUniqueId(String uniqueId) {
162 setMetadataValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
165 public void setHighestVersion(Boolean isHighest) {
166 setMetadataValue(JsonPresentationFields.HIGHEST_VERSION, isHighest);
169 public Boolean isHighestVersion() {
170 return (Boolean) getMetadataValue(JsonPresentationFields.HIGHEST_VERSION);
173 public ResourceTypeEnum getResourceType() {
174 String resourceType = (String) getMetadataValue(JsonPresentationFields.RESOURCE_TYPE);
175 return resourceType != null ? ResourceTypeEnum.valueOf(resourceType) : null;
178 public void setResourceType(ResourceTypeEnum resourceType) {
179 if (resourceType != null) {
180 setMetadataValue(JsonPresentationFields.RESOURCE_TYPE, resourceType.name());
184 public ComponentTypeEnum getComponentType() {
185 return ComponentTypeEnum.valueOf((String) getMetadataValue(JsonPresentationFields.COMPONENT_TYPE));
188 public void setComponentType(ComponentTypeEnum componentType) {
189 if (componentType != null) {
190 setMetadataValue(JsonPresentationFields.COMPONENT_TYPE, componentType.name());
194 public String getDerivedFromGenericType() {
195 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE);
198 public void setDerivedFromGenericType(String derivedFromGenericType) {
199 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE, derivedFromGenericType);
202 public String getDerivedFromGenericVersion() {
203 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION);
206 public void setDerivedFromGenericVersion(String derivedFromGenericVersion) {
207 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION, derivedFromGenericVersion);
210 public Boolean isArchived() {
211 return (Boolean) getMetadataValue(JsonPresentationFields.IS_ARCHIVED);
214 public void setArchived(Boolean archived) {
215 setMetadataValue(JsonPresentationFields.IS_ARCHIVED, archived);
218 public Long getArchiveTime() {
219 Object archiveTime = getMetadataValue(JsonPresentationFields.ARCHIVE_TIME);
220 if (archiveTime instanceof Integer) {
221 return Long.valueOf((Integer) getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
223 return (Long) archiveTime;
226 public void setArchiveTime(Long archiveTime) {
227 setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime);
230 public Boolean isVspArchived() {
231 return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED);
234 public void setVspArchived(Boolean vspArchived) {
235 setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived);
238 public void generateUUID() {
239 String prevUUID = getUUID();
240 String version = getVersion();
241 if ((prevUUID == null && NodeTypeOperation.uuidNormativeNewVersion.matcher(version).matches()) || NodeTypeOperation.uuidNewVersion
242 .matcher(version).matches()) {
243 UUID uuid = UUID.randomUUID();
244 setUUID(uuid.toString());
245 MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, uuid.toString());