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.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, ListCapabilityDataDefinition> capabilities;
58 private Map<String, MapPropertiesDataDefinition> capabilitiesProperties;
59 private Map<String, ListRequirementDataDefinition> requirements;
60 private Map<String, DataTypeDataDefinition> dataTypes;
62 private String creatorUserId;
63 private String creatorFullName;
64 private String lastUpdaterUserId;
65 private String lastUpdaterFullName;
67 private Map<String, String> allVersions;
68 private String toscaVersion;
70 public ToscaElement(ToscaElementTypeEnum toscaType){
71 this.toscaType = toscaType;
74 // 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);
97 // --------------------
98 public String getUUID() {
99 return (String) getMetadataValue(JsonPresentationFields.UUID);
102 public void setUUID(String uuid) {
103 setMetadataValue(JsonPresentationFields.UUID, uuid);
106 public String getVersion() {
107 return (String) getMetadataValue(JsonPresentationFields.VERSION);
110 public String getNormalizedName() {
111 return (String) getMetadataValue(JsonPresentationFields.NORMALIZED_NAME);
114 public void setNormalizedName(String normaliseComponentName) {
115 setMetadataValue(JsonPresentationFields.NORMALIZED_NAME, normaliseComponentName);
118 public String getName() {
119 return (String) getMetadataValue(JsonPresentationFields.NAME);
122 public String getSystemName() {
123 return (String) getMetadataValue(JsonPresentationFields.SYSTEM_NAME);
125 public void setSystemName(String systemName) {
126 setMetadataValue(JsonPresentationFields.SYSTEM_NAME, systemName);
129 public void setLifecycleState(LifecycleStateEnum state) {
131 setMetadataValue(JsonPresentationFields.LIFECYCLE_STATE, state.name());
134 public LifecycleStateEnum getLifecycleState() {
135 return LifecycleStateEnum.findState( (String) getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
138 public Long getCreationDate() {
139 return (Long) getMetadataValue(JsonPresentationFields.CREATION_DATE);
142 public void setCreationDate(Long currentDate) {
143 setMetadataValue(JsonPresentationFields.CREATION_DATE, currentDate);
146 public void setLastUpdateDate(Long currentDate) {
147 setMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE, currentDate);
149 public Long getLastUpdateDate() {
150 return (Long) getMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE);
153 public String getUniqueId() {
154 return (String) getMetadataValue(JsonPresentationFields.UNIQUE_ID);
156 public void setUniqueId(String uniqueId) {
157 setMetadataValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
160 public void setHighestVersion(Boolean isHighest) {
161 setMetadataValue(JsonPresentationFields.HIGHEST_VERSION, isHighest);
164 public Boolean isHighestVersion() {
165 return (Boolean) getMetadataValue(JsonPresentationFields.HIGHEST_VERSION);
168 public ResourceTypeEnum getResourceType() {
169 String resourceType = (String) getMetadataValue(JsonPresentationFields.RESOURCE_TYPE);
170 return resourceType != null ? ResourceTypeEnum.valueOf(resourceType) : null;
173 public void setResourceType(ResourceTypeEnum resourceType) {
174 if(resourceType != null)
175 setMetadataValue(JsonPresentationFields.RESOURCE_TYPE, resourceType.name());
178 public ComponentTypeEnum getComponentType() {
179 return ComponentTypeEnum.valueOf((String) getMetadataValue(JsonPresentationFields.COMPONENT_TYPE));
182 public void setComponentType(ComponentTypeEnum componentType) {
183 if(componentType != null)
184 setMetadataValue(JsonPresentationFields.COMPONENT_TYPE, componentType.name());
187 public String getDerivedFromGenericType(){
188 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE);
191 public void setDerivedFromGenericType(String derivedFromGenericType){
192 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE, derivedFromGenericType);
195 public String getDerivedFromGenericVersion(){
196 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION);
199 public void setDerivedFromGenericVersion(String derivedFromGenericVersion){
200 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION, derivedFromGenericVersion);
203 public Boolean isArchived() { return (Boolean) getMetadataValue(JsonPresentationFields.IS_ARCHIVED); }
205 public void setArchived(Boolean archived) { setMetadataValue(JsonPresentationFields.IS_ARCHIVED, archived); }
207 public Long getArchiveTime() {
208 Object archiveTime = getMetadataValue(JsonPresentationFields.ARCHIVE_TIME);
209 if (archiveTime instanceof Integer){
210 return new Long((Integer)getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
212 return (Long)archiveTime;
215 public void setArchiveTime(Long archiveTime) {
216 setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime);
219 public Boolean isVspArchived() {
220 return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED);
223 public void setVspArchived(Boolean vspArchived) {
224 setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived);
227 public void generateUUID() {
228 String prevUUID = getUUID();
229 String version = getVersion();
230 if ((prevUUID == null && NodeTypeOperation.uuidNormativeNewVersion.matcher(version).matches()) || NodeTypeOperation.uuidNewVersion.matcher(version).matches()) {
231 UUID uuid = UUID.randomUUID();
232 setUUID(uuid.toString());
233 MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, uuid.toString());