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.apache.commons.lang.StringUtils;
26 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
27 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
30 import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
31 import org.openecomp.sdc.be.resources.data.TagData;
32 import org.openecomp.sdc.be.resources.data.UserData;
33 import org.openecomp.sdc.common.api.Constants;
34 import org.openecomp.sdc.common.util.ValidationUtils;
36 public class UniqueIdBuilder {
38 private static final String HEAT_PARAM_PREFIX = "heat_";
39 private static String DOT = ".";
40 private static UserData userData = new UserData();
41 private static TagData tagData = new TagData();
42 private static ResourceCategoryData resCategoryData = new ResourceCategoryData();
43 private static ServiceCategoryData serCategoryData = new ServiceCategoryData();
44 private static Map<NodeTypeEnum, String> nodeTypeToUniqueKeyMapper = new HashMap<>();
47 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.User, userData.getUniqueIdKey());
48 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.Tag, tagData.getUniqueIdKey());
49 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ResourceCategory, resCategoryData.getUniqueIdKey());
50 nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ServiceCategory, serCategoryData.getUniqueIdKey());
53 public static String buildPropertyUniqueId(String resourceId, String propertyName) {
54 return resourceId + DOT + propertyName;
57 static String buildHeatParameterUniqueId(String resourceId, String propertyName) {
58 return resourceId + DOT + HEAT_PARAM_PREFIX + propertyName;
61 static String buildHeatParameterValueUniqueId(String resourceId, String artifactLabel, String propertyName) {
62 return buildTypeUid(resourceId, artifactLabel, propertyName);
66 * find the unique id key of a node on the graph
71 public static String getKeyByNodeType(NodeTypeEnum nodeTypeEnum) {
72 String uniqueID = nodeTypeToUniqueKeyMapper.get(nodeTypeEnum);
73 if (uniqueID == null) {
74 uniqueID = GraphPropertiesDictionary.UNIQUE_ID.getProperty();
79 public static String buildResourceUniqueId() {
80 return generateUUID();
83 public static String generateUUID() {
84 UUID uuid = UUID.randomUUID();
85 return uuid.toString();
88 public static String buildComponentUniqueId() {
89 return generateUUID();
92 static String buildCapabilityTypeUid(String type) {
96 public static String buildRelationshipTypeUid(final String modelName, final String type) {
97 return StringUtils.isEmpty(modelName) ? type : modelName + DOT + type;
100 public static String buildAttributeUid(String resourceId, String attName) {
101 return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName);
104 public static String buildRequirementUid(String resourceId, String reqName) {
105 return resourceId + DOT + reqName;
108 public static String buildCapabilityUid(String resourceId, String capabilityName) {
109 return buildTypeUid(NodeTypeEnum.Capability.getName(), resourceId, capabilityName);
112 public static String buildArtifactByInterfaceUniqueId(String resourceId, String interfaceName, String operation, String artifactLabel) {
113 return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
116 public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
117 return buildTypeUid(parentId, instanceId, artifactLabel);
120 public static String buildResourceInstanceUniuqeId(String serviceId, String resourceId, String logicalName) {
121 return buildTypeUid(serviceId, resourceId, logicalName);
124 public static String buildRelationsipInstInstanceUid(String resourceInstUid, String requirement) {
125 return generateUUID();
129 * TODO Pavel To be removed when new category logic comes in
131 static String buildResourceCategoryUid(String categoryName, String subcategoryName, NodeTypeEnum type) {
132 return buildTypeUid(type.getName(), categoryName, subcategoryName);
136 * TODO Pavel To be removed when new category logic comes in
138 static String buildServiceCategoryUid(String categoryName, NodeTypeEnum type) {
139 return type.getName() + DOT + categoryName;
143 public static String buildCategoryUid(String categoryName, NodeTypeEnum type) {
144 return type.getName() + DOT + categoryName;
147 public static String buildComponentCategoryUid(String categoryName, VertexTypeEnum type) {
148 return type.getName() + DOT + ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
151 public static String buildSubCategoryUid(String categoryUid, String subCategoryName) {
152 return categoryUid + DOT + subCategoryName;
155 public static String buildGroupingUid(String subCategoryUid, String groupingName) {
156 return subCategoryUid + DOT + groupingName;
159 static String buildResourceInstancePropertyValueUid(String resourceInstanceUniqueId, Integer index) {
160 return resourceInstanceUniqueId + DOT + "property" + DOT + index;
163 public static String buildComponentPropertyUniqueId(String resourceId, String propertyName) {
164 return buildTypeUid(NodeTypeEnum.Property.getName(), resourceId, propertyName);
167 static String buildResourceInstanceAttributeValueUid(String resourceInstanceUniqueId, Integer index) {
168 return resourceInstanceUniqueId + DOT + "attribute" + DOT + index;
171 static String buildResourceInstanceInputValueUid(String resourceInstanceUniqueId, Integer index) {
172 return resourceInstanceUniqueId + DOT + "input" + DOT + index;
175 static String buildAdditionalInformationUniqueId(String resourceUniqueId) {
176 return resourceUniqueId + DOT + "additionalinformation";
179 public static String buildDataTypeUid(final String modelName, final String name) {
180 return StringUtils.isEmpty(modelName) ? name + DOT + "datatype" : modelName + DOT + name + DOT + "datatype";
183 public static String buildInvariantUUID() {
184 return generateUUID();
187 static String buildGroupTypeUid(String type, String version, String resourceName) {
188 return buildTypeUid(type, version, resourceName);
191 static String buildPolicyTypeUid(String type, String version, String resourceName) {
192 return buildTypeUid(type, version, resourceName);
195 static String buildTypeUid(String type, String version, String resourceName) {
196 return type + DOT + version + DOT + resourceName;
199 public static String buildPolicyUniqueId(String componentId, String name) {
200 return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
203 public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
204 return groupUniqueId + DOT + "property" + DOT + index;
207 public static String buildModelUid(final String modelName) {
208 return NodeTypeEnum.Model.getName() + DOT + modelName;