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.operations.impl;
22 import java.util.HashMap;
24 import java.util.UUID;
25 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
26 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
28 import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
29 import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
30 import org.openecomp.sdc.be.resources.data.TagData;
31 import org.openecomp.sdc.be.resources.data.UserData;
32 import org.openecomp.sdc.common.api.Constants;
33 import org.openecomp.sdc.common.util.ValidationUtils;
35 public class UniqueIdBuilder {
37 private static final String HEAT_PARAM_PREFIX = "heat_";
38 private static String DOT = ".";
39 private static UserData userData = new UserData();
40 private static TagData tagData = new TagData();
41 private static ResourceCategoryData resCategoryData = new ResourceCategoryData();
42 private static ServiceCategoryData serCategoryData = new ServiceCategoryData();
43 private static Map<NodeTypeEnum, String> nodeTypeToUniqueKeyMapper = new HashMap<>();
46 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.User, userData.getUniqueIdKey());
47 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.Tag, tagData.getUniqueIdKey());
48 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ResourceCategory, resCategoryData.getUniqueIdKey());
49 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ServiceCategory, serCategoryData.getUniqueIdKey());
52 public static String buildPropertyUniqueId(String resourceId, String propertyName) {
53 return resourceId + DOT + propertyName;
56 static String buildHeatParameterUniqueId(String resourceId, String propertyName) {
57 return resourceId + DOT + HEAT_PARAM_PREFIX + propertyName;
60 static String buildHeatParameterValueUniqueId(String resourceId, String artifactLabel, String propertyName) {
61 return buildTypeUid(resourceId, artifactLabel, propertyName);
65 * find the unique id key of a node on the graph
70 public static String getKeyByNodeType(NodeTypeEnum nodeTypeEnum) {
71 String uniqueID = nodeTypeToUniqueKeyMapper.get(nodeTypeEnum);
72 if (uniqueID == null) {
73 uniqueID = GraphPropertiesDictionary.UNIQUE_ID.getProperty();
78 public static String buildResourceUniqueId() {
79 return generateUUID();
82 public static String generateUUID() {
83 UUID uuid = UUID.randomUUID();
84 return uuid.toString();
87 public static String buildComponentUniqueId() {
88 return generateUUID();
91 static String buildCapabilityTypeUid(String type) {
95 static String buildRelationshipTypeUid(String type) {
99 public static String buildAttributeUid(String resourceId, String attName) {
100 return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName);
103 public static String buildRequirementUid(String resourceId, String reqName) {
104 return resourceId + DOT + reqName;
107 public static String buildCapabilityUid(String resourceId, String capabilityName) {
108 return buildTypeUid(NodeTypeEnum.Capability.getName(), resourceId, capabilityName);
111 public static String buildArtifactByInterfaceUniqueId(String resourceId, String interfaceName, String operation, String artifactLabel) {
112 return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
115 public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
116 return buildTypeUid(parentId, instanceId, artifactLabel);
119 public static String buildResourceInstanceUniuqeId(String serviceId, String resourceId, String logicalName) {
120 return buildTypeUid(serviceId, resourceId, logicalName);
123 public static String buildRelationsipInstInstanceUid(String resourceInstUid, String requirement) {
124 return generateUUID();
128 * TODO Pavel To be removed when new category logic comes in
130 static String buildResourceCategoryUid(String categoryName, String subcategoryName, NodeTypeEnum type) {
131 return buildTypeUid(type.getName(), categoryName, subcategoryName);
135 * TODO Pavel To be removed when new category logic comes in
137 static String buildServiceCategoryUid(String categoryName, NodeTypeEnum type) {
138 return type.getName() + DOT + categoryName;
142 public static String buildCategoryUid(String categoryName, NodeTypeEnum type) {
143 return type.getName() + DOT + categoryName;
146 public static String buildComponentCategoryUid(String categoryName, VertexTypeEnum type) {
147 return type.getName() + DOT + ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
150 public static String buildSubCategoryUid(String categoryUid, String subCategoryName) {
151 return categoryUid + DOT + subCategoryName;
154 public static String buildGroupingUid(String subCategoryUid, String groupingName) {
155 return subCategoryUid + DOT + groupingName;
158 static String buildResourceInstancePropertyValueUid(String resourceInstanceUniqueId, Integer index) {
159 return resourceInstanceUniqueId + DOT + "property" + DOT + index;
162 public static String buildComponentPropertyUniqueId(String resourceId, String propertyName) {
163 return buildTypeUid(NodeTypeEnum.Property.getName(), resourceId, propertyName);
166 static String buildResourceInstanceAttributeValueUid(String resourceInstanceUniqueId, Integer index) {
167 return resourceInstanceUniqueId + DOT + "attribute" + DOT + index;
170 static String buildResourceInstanceInputValueUid(String resourceInstanceUniqueId, Integer index) {
171 return resourceInstanceUniqueId + DOT + "input" + DOT + index;
174 static String buildAdditionalInformationUniqueId(String resourceUniqueId) {
175 return resourceUniqueId + DOT + "additionalinformation";
178 static String buildDataTypeUid(String name) {
179 return name + DOT + "datatype";
182 public static String buildInvariantUUID() {
183 return generateUUID();
186 static String buildGroupTypeUid(String type, String version, String resourceName) {
187 return buildTypeUid(type, version, resourceName);
190 static String buildPolicyTypeUid(String type, String version, String resourceName) {
191 return buildTypeUid(type, version, resourceName);
194 static String buildTypeUid(String type, String version, String resourceName) {
195 return type + DOT + version + DOT + resourceName;
198 public static String buildPolicyUniqueId(String componentId, String name) {
199 return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
202 public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
203 return groupUniqueId + DOT + "property" + DOT + index;