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.ListCapabilityDataDefinition;
32 import org.openecomp.sdc.be.datatypes.elements.ListRequirementDataDefinition;
33 import org.openecomp.sdc.be.datatypes.elements.MapPropertiesDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
35 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
36 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
37 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
38 import org.openecomp.sdc.be.model.LifecycleStateEnum;
39 import org.openecomp.sdc.be.model.category.CategoryDefinition;
40 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.NodeTypeOperation;
41 import org.openecomp.sdc.common.log.api.ILogConfiguration;
46 public abstract class ToscaElement {
48 protected Map<String, Object> metadata;
49 protected List<CategoryDefinition> categories;
50 protected Map<String, ArtifactDataDefinition> toscaArtifacts;
51 protected ToscaElementTypeEnum toscaType;
52 private Map<String, ArtifactDataDefinition> artifacts;
53 private Map<String, ArtifactDataDefinition> deploymentArtifacts;
54 private Map<String, AdditionalInfoParameterDataDefinition> additionalInformation;
55 private Map<String, PropertyDataDefinition> properties;
56 private Map<String, ListCapabilityDataDefinition> capabilities;
57 private Map<String, MapPropertiesDataDefinition> capabilitiesProperties;
58 private Map<String, ListRequirementDataDefinition> requirements;
60 private String creatorUserId;
61 private String creatorFullName;
62 private String lastUpdaterUserId;
63 private String lastUpdaterFullName;
65 private Map<String, String> allVersions;
66 private String toscaVersion;
68 public ToscaElement(ToscaElementTypeEnum toscaType){
69 this.toscaType = toscaType;
72 // metadata properties
73 // ----------------------------
74 public Object getMetadataValue(JsonPresentationFields name) {
75 return getMetadataValueOrDefault(name, null);
78 public Object getMetadataValueOrDefault(JsonPresentationFields name, Object defaultVal) {
79 if (metadata != null) {
80 return metadata.getOrDefault(name.getPresentation(), defaultVal);
85 public void setMetadataValue(JsonPresentationFields name, Object value) {
86 if (metadata == null) {
87 metadata = new HashMap<>();
89 metadata.put(name.getPresentation(), value);
92 // --------------------
93 public String getUUID() {
94 return (String) getMetadataValue(JsonPresentationFields.UUID);
97 public void setUUID(String uuid) {
98 setMetadataValue(JsonPresentationFields.UUID, uuid);
101 public String getVersion() {
102 return (String) getMetadataValue(JsonPresentationFields.VERSION);
105 public String getNormalizedName() {
106 return (String) getMetadataValue(JsonPresentationFields.NORMALIZED_NAME);
109 public void setNormalizedName(String normaliseComponentName) {
110 setMetadataValue(JsonPresentationFields.NORMALIZED_NAME, normaliseComponentName);
113 public String getName() {
114 return (String) getMetadataValue(JsonPresentationFields.NAME);
117 public String getSystemName() {
118 return (String) getMetadataValue(JsonPresentationFields.SYSTEM_NAME);
120 public void setSystemName(String systemName) {
121 setMetadataValue(JsonPresentationFields.SYSTEM_NAME, systemName);
124 public void setLifecycleState(LifecycleStateEnum state) {
126 setMetadataValue(JsonPresentationFields.LIFECYCLE_STATE, state.name());
129 public LifecycleStateEnum getLifecycleState() {
130 return LifecycleStateEnum.findState( (String) getMetadataValue(JsonPresentationFields.LIFECYCLE_STATE));
133 public Long getCreationDate() {
134 return (Long) getMetadataValue(JsonPresentationFields.CREATION_DATE);
137 public void setCreationDate(Long currentDate) {
138 setMetadataValue(JsonPresentationFields.CREATION_DATE, currentDate);
141 public void setLastUpdateDate(Long currentDate) {
142 setMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE, currentDate);
144 public Long getLastUpdateDate() {
145 return (Long) getMetadataValue(JsonPresentationFields.LAST_UPDATE_DATE);
148 public String getUniqueId() {
149 return (String) getMetadataValue(JsonPresentationFields.UNIQUE_ID);
151 public void setUniqueId(String uniqueId) {
152 setMetadataValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
155 public void setHighestVersion(Boolean isHighest) {
156 setMetadataValue(JsonPresentationFields.HIGHEST_VERSION, isHighest);
159 public Boolean isHighestVersion() {
160 return (Boolean) getMetadataValue(JsonPresentationFields.HIGHEST_VERSION);
163 public ResourceTypeEnum getResourceType() {
164 String resourceType = (String) getMetadataValue(JsonPresentationFields.RESOURCE_TYPE);
165 return resourceType != null ? ResourceTypeEnum.valueOf(resourceType) : null;
168 public void setResourceType(ResourceTypeEnum resourceType) {
169 if(resourceType != null)
170 setMetadataValue(JsonPresentationFields.RESOURCE_TYPE, resourceType.name());
173 public ComponentTypeEnum getComponentType() {
174 return ComponentTypeEnum.valueOf((String) getMetadataValue(JsonPresentationFields.COMPONENT_TYPE));
177 public void setComponentType(ComponentTypeEnum componentType) {
178 if(componentType != null)
179 setMetadataValue(JsonPresentationFields.COMPONENT_TYPE, componentType.name());
182 public String getDerivedFromGenericType(){
183 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE);
186 public void setDerivedFromGenericType(String derivedFromGenericType){
187 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_TYPE, derivedFromGenericType);
190 public String getDerivedFromGenericVersion(){
191 return (String) getMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION);
194 public void setDerivedFromGenericVersion(String derivedFromGenericVersion){
195 setMetadataValue(JsonPresentationFields.DERIVED_FROM_GENERIC_VERSION, derivedFromGenericVersion);
198 public Boolean isArchived() { return (Boolean) getMetadataValue(JsonPresentationFields.IS_ARCHIVED); }
200 public void setArchived(Boolean archived) { setMetadataValue(JsonPresentationFields.IS_ARCHIVED, archived); }
202 public Long getArchiveTime() {
203 Object archiveTime = getMetadataValue(JsonPresentationFields.ARCHIVE_TIME);
204 if (archiveTime instanceof Integer){
205 return new Long((Integer)getMetadataValue(JsonPresentationFields.ARCHIVE_TIME));
207 return (Long)archiveTime;
210 public void setArchiveTime(Long archiveTime) {
211 setMetadataValue(JsonPresentationFields.ARCHIVE_TIME, archiveTime);
214 public Boolean isVspArchived() {
215 return (Boolean) getMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED);
218 public void setVspArchived(Boolean vspArchived) {
219 setMetadataValue(JsonPresentationFields.IS_VSP_ARCHIVED, vspArchived);
222 public void generateUUID() {
223 String prevUUID = getUUID();
224 String version = getVersion();
225 if ((prevUUID == null && NodeTypeOperation.uuidNormativeNewVersion.matcher(version).matches()) || NodeTypeOperation.uuidNewVersion.matcher(version).matches()) {
226 UUID uuid = UUID.randomUUID();
227 setUUID(uuid.toString());
228 MDC.put(ILogConfiguration.MDC_SERVICE_INSTANCE_ID, uuid.toString());