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.operations.impl;
23 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
26 import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
27 import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
28 import org.openecomp.sdc.be.resources.data.TagData;
29 import org.openecomp.sdc.be.resources.data.UserData;
30 import org.openecomp.sdc.common.api.Constants;
31 import org.openecomp.sdc.common.util.ValidationUtils;
33 import java.util.HashMap;
35 import java.util.UUID;
37 public class UniqueIdBuilder {
39 private static String DOT = ".";
40 private static final String HEAT_PARAM_PREFIX = "heat_";
42 public static String buildPropertyUniqueId(String resourceId, String propertyName) {
43 return resourceId + DOT + propertyName;
46 static String buildHeatParameterUniqueId(String resourceId, String propertyName) {
47 return resourceId + DOT + HEAT_PARAM_PREFIX + propertyName;
50 static String buildHeatParameterValueUniqueId(String resourceId, String artifactLabel, String propertyName) {
51 return buildTypeUid(resourceId, artifactLabel, propertyName);
54 private static UserData userData = new UserData();
55 private static TagData tagData = new TagData();
56 private static ResourceCategoryData resCategoryData = new ResourceCategoryData();
57 private static ServiceCategoryData serCategoryData = new ServiceCategoryData();
59 private static Map<NodeTypeEnum, String> nodeTypeToUniqueKeyMapper = new HashMap<>();
63 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.User, userData.getUniqueIdKey());
64 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.Tag, tagData.getUniqueIdKey());
65 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ResourceCategory, resCategoryData.getUniqueIdKey());
66 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ServiceCategory, serCategoryData.getUniqueIdKey());
70 * find the unique id key of a node on the graph
75 public static String getKeyByNodeType(NodeTypeEnum nodeTypeEnum) {
77 String key = nodeTypeToUniqueKeyMapper.get(nodeTypeEnum);
79 key = GraphPropertiesDictionary.UNIQUE_ID.getProperty();
85 public static String buildResourceUniqueId() {
86 return generateUUID();
89 public static String generateUUID() {
90 UUID uuid = UUID.randomUUID();
91 return uuid.toString();
94 public static String buildComponentUniqueId() {
95 return generateUUID();
98 static String buildCapabilityTypeUid(String type) {
102 public static String buildAttributeUid(String resourceId, String attName) {
103 return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName);
105 public static String buildRequirementUid(String resourceId, String reqName) {
106 return resourceId + DOT + reqName;
109 public static String buildCapabilityUid(String resourceId, String capabilityName) {
110 return buildTypeUid(NodeTypeEnum.Capability.getName(), resourceId, capabilityName);
113 public static String buildArtifactByInterfaceUniqueId(String resourceId, String interfaceName, String operation, String artifactLabel) {
115 return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
118 public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
120 return buildTypeUid(parentId, instanceId, artifactLabel);
123 public static String buildResourceInstanceUniuqeId(String serviceId, String resourceId, String logicalName) {
125 return buildTypeUid(serviceId, resourceId, logicalName);
128 public static String buildRelationsipInstInstanceUid(String resourceInstUid, String requirement) {
130 return generateUUID();
134 * TODO Pavel To be removed when new category logic comes in
136 static String buildResourceCategoryUid(String categoryName, String subcategoryName, NodeTypeEnum type) {
137 return buildTypeUid(type.getName(), categoryName, subcategoryName);
141 * TODO Pavel To be removed when new category logic comes in
143 static String buildServiceCategoryUid(String categoryName, NodeTypeEnum type) {
144 return type.getName() + DOT + categoryName;
148 public static String buildCategoryUid(String categoryName, NodeTypeEnum type) {
149 return type.getName() + DOT + categoryName;
151 public static String buildComponentCategoryUid(String categoryName, VertexTypeEnum type) {
152 return type.getName() + DOT + ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
155 public static String buildSubCategoryUid(String categoryUid, String subCategoryName) {
156 return categoryUid + DOT + subCategoryName;
159 public static String buildGroupingUid(String subCategoryUid, String groupingName) {
160 return subCategoryUid + DOT + groupingName;
163 static String buildResourceInstancePropertyValueUid(String resourceInstanceUniqueId, Integer index) {
164 return resourceInstanceUniqueId + DOT + "property" + DOT + index;
167 public static String buildComponentPropertyUniqueId(String resourceId, String propertyName) {
168 return buildTypeUid(NodeTypeEnum.Property.getName(), resourceId, propertyName);
171 static String buildResourceInstanceAttributeValueUid(String resourceInstanceUniqueId, Integer index) {
172 return resourceInstanceUniqueId + DOT + "attribute" + DOT + index;
175 static String buildResourceInstanceInputValueUid(String resourceInstanceUniqueId, Integer index) {
176 return resourceInstanceUniqueId + DOT + "input" + DOT + index;
179 static String buildAdditionalInformationUniqueId(String resourceUniqueId) {
180 return resourceUniqueId + DOT + "additionalinformation";
183 static String buildDataTypeUid(String name) {
184 return name + DOT + "datatype";
187 public static String buildInvariantUUID() {
188 return generateUUID();
191 static String buildGroupTypeUid(String type, String version, String resourceName) {
192 return buildTypeUid(type, version, resourceName);
195 static String buildPolicyTypeUid(String type, String version, String resourceName) {
196 return buildTypeUid(type, version, resourceName);
199 static String buildTypeUid(String type, String version, String resourceName) {
200 return type + DOT + version + DOT + resourceName;
203 public static String buildPolicyUniqueId(String componentId, String name) {
204 return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
207 public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
208 return groupUniqueId + DOT + "property" + DOT + index;