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=========================================================
21 package org.openecomp.sdc.be.model.jsonjanusgraph.datamodel;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.UUID;
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;
48 public abstract class ToscaElement {
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;
64 private String creatorUserId;
65 private String creatorFullName;
66 private String lastUpdaterUserId;
67 private String lastUpdaterFullName;
69 private Map<String, String> allVersions;
70 private String toscaVersion;
72 protected ToscaElement(ToscaElementTypeEnum toscaType){
73 this.toscaType = toscaType;
76 // metadata properties
77 // ----------------------------
78 public Object getMetadataValue(JsonPresentationFields name) {
79 return getMetadataValueOrDefault(name, null);
82 public Object getMetadataValueOrDefault(JsonPresentationFields name, Object defaultVal) {
83 if (metadata != null) {
84 return metadata.getOrDefault(name.getPresentation(), defaultVal);
89 public void setMetadataValue(JsonPresentationFields name, Object value) {
90 setMetadataValue(name.getPresentation(), value);
93 public void setMetadataValue(String name, Object value) {
94 if (metadata == null) {
95 metadata = new HashMap<>();
97 metadata.put(name, value);
99 // --------------------
100 public String getUUID() {
101 return (String) getMetadataValue(JsonPresentationFields.UUID);
104 public void setUUID(String uuid) {
105 setMetadataValue(JsonPresentationFields.UUID, uuid);
108 public String getVersion() {
109 return (String) getMetadataValue(JsonPresentationFields.VERSION);
112 public String getNormalizedName() {
113 return (String) getMetadataValue(JsonPresentationFields.NORMALIZED_NAME);
116 public void setNormalizedName(String normaliseComponentName) {
117 setMetadataValue(JsonPresentationFields.NORMALIZED_NAME, normaliseComponentName);
120 public String getName() {
121 return (String) getMetadataValue(JsonPresentationFields.NAME);
124 public String getSystemName() {
125 return (String) getMetadataValue(JsonPresentationFields.SYSTEM_NAME);
127 public void setSystemName(String systemName) {
128 setMetadataValue(JsonPresentationFields.SYSTEM_NAME, systemName);
131 public void setLifecycleState(LifecycleStateEnum state) {
133 setMetadataValue(JsonPresentationFields.LIFECYCLE_STATE, state.name());
136 public LifecycleStateEnum getLifecycleState() {
137 return LifecycleStateEnum.findState( (String) getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
140 public Long getCreationDate() {
141 return (Long) getMetadataValue(JsonPresentationFields.CREATION_DATE);
144 public void setCreationDate(Long currentDate) {
145 setMetadataValue(JsonPresentationFields.CREATION_DATE, currentDate);
148 public void setLastUpdateDate(Long currentDate) {
149 setMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE, currentDate);
151 public Long getLastUpdateDate() {
152 return (Long) getMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE);
155 public String getUniqueId() {
156 return (String) getMetadataValue(JsonPresentationFields.UNIQUE_ID);
158 public void setUniqueId(String uniqueId) {
159 setMetadataValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
162 public void setHighestVersion(Boolean isHighest) {
163 setMetadataValue(JsonPresentationFields.HIGHEST_VERSION, isHighest);
166 public Boolean isHighestVersion() {
167 return (Boolean) getMetadataValue(JsonPresentationFields.HIGHEST_VERSION);
170 public ResourceTypeEnum getResourceType() {
171 String resourceType = (String) getMetadataValue(JsonPresentationFields.RESOURCE_TYPE);
172 return resourceType != null ? ResourceTypeEnum.valueOf(resourceType) : null;
175 public void setResourceType(ResourceTypeEnum resourceType) {
176 if(resourceType != null)
177 setMetadataValue(JsonPresentationFields.RESOURCE_TYPE, resourceType.name());
180 public ComponentTypeEnum getComponentType() {
181 return ComponentTypeEnum.valueOf((String) getMetadataValue(JsonPresentationFields.COMPONENT_TYPE));
184 public void setComponentType(ComponentTypeEnum componentType) {
185 if(componentType != null)
186 setMetadataValue(JsonPresentationFields.COMPONENT_TYPE, componentType.name());
189 public String getDerivedFromGenericType(){
190 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE);
193 public void setDerivedFromGenericType(String derivedFromGenericType){
194 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE, derivedFromGenericType);
197 public String getDerivedFromGenericVersion(){
198 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION);
201 public void setDerivedFromGenericVersion(String derivedFromGenericVersion){
202 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION, derivedFromGenericVersion);
205 public Boolean isArchived() { return (Boolean) getMetadataValue(JsonPresentationFields.IS_ARCHIVED); }
207 public void setArchived(Boolean archived) { setMetadataValue(JsonPresentationFields.IS_ARCHIVED, archived); }
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));
214 return (Long)archiveTime;
217 public void setArchiveTime(Long archiveTime) {
218 setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime);
221 public Boolean isVspArchived() {
222 return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED);
225 public void setVspArchived(Boolean vspArchived) {
226 setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived);
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());