Sync Integ to Master
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / operations / impl / UniqueIdBuilder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations.impl;
22
23 import java.util.HashMap;
24 import java.util.Map;
25 import java.util.UUID;
26
27 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
28 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
29 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
30 import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
31 import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
32 import org.openecomp.sdc.be.resources.data.TagData;
33 import org.openecomp.sdc.be.resources.data.UserData;
34 import org.openecomp.sdc.common.api.Constants;
35 import org.openecomp.sdc.common.util.ValidationUtils;
36
37 public class UniqueIdBuilder {
38
39         private static String DOT = ".";
40         private static final String HEAT_PARAM_PREFIX = "heat_";
41         
42         public static String buildPropertyUniqueId(String resourceId, String propertyName) {
43                 return resourceId + DOT + propertyName;
44         }
45         
46         public static String buildHeatParameterUniqueId(String resourceId, String propertyName) {
47                 return resourceId + DOT + HEAT_PARAM_PREFIX + propertyName;
48         }
49
50         public static String buildHeatParameterValueUniqueId(String resourceId, String artifactLabel, String propertyName) {
51                 return resourceId + DOT + artifactLabel + DOT + propertyName;
52         }
53
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();
58
59         private static Map<NodeTypeEnum, String> nodeTypeToUniqueKeyMapper = new HashMap<NodeTypeEnum, String>();
60
61         static {
62
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());
67         }
68
69         /**
70          * find the unique id key of a node on the graph
71          * 
72          * @param nodeTypeEnum
73          * @return
74          */
75         public static String getKeyByNodeType(NodeTypeEnum nodeTypeEnum) {
76
77                 String key = nodeTypeToUniqueKeyMapper.get(nodeTypeEnum);
78                 if (key == null) {
79                         key = GraphPropertiesDictionary.UNIQUE_ID.getProperty();
80                 }
81
82                 return key;
83         }
84
85         public static String buildResourceUniqueId() {
86                 return generateUUID();
87         }
88
89         public static String generateUUID() {
90                 UUID uuid = UUID.randomUUID();
91                 return uuid.toString();
92         }
93
94         public static String buildComponentUniqueId() {
95                 return generateUUID();
96         }
97
98         public static String buildConstantProductId() {
99                 return generateUUID();
100         }
101
102         public static String buildCapabilityTypeUid(String type) {
103                 return type;
104         }
105
106         public static String buildAttributeUid(String resourceId, String attName) {
107                 return NodeTypeEnum.Attribute.getName() + DOT + resourceId + DOT + attName;
108         }
109         public static String buildArtifactUid(String parentId, String label) {
110                 return parentId + DOT + label;
111         }
112         public static String buildRequirementUid(String resourceId, String reqName) {
113                 return resourceId + DOT + reqName;
114         }
115
116         public static String buildRequirementImplUid(String resourceId, String reqName) {
117
118                 return NodeTypeEnum.RequirementImpl.getName() + DOT + resourceId + DOT + reqName;
119
120         }
121
122         public static String buildCapabilityUid(String resourceId, String capabilityName) {
123                 return NodeTypeEnum.Capability.getName() + DOT + resourceId + DOT + capabilityName;
124         }
125
126         public static String buildCapabilityInstanceUid(String parentId, String capabilityName) {
127                 return NodeTypeEnum.CapabilityInst.getName() + DOT + parentId + DOT + capabilityName;
128         }
129
130         public static String buildPropertyValueUniqueId(String parentId, String paramName) {
131                 return NodeTypeEnum.PropertyValue.getName() + DOT + parentId + DOT + paramName;
132         }
133         
134         public static String buildArtifactByInterfaceUniqueId(String resourceId, String interfaceName, String operation, String artifactLabel) {
135
136                 return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
137         }
138         
139         public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
140
141                 return parentId + DOT + instanceId + DOT + artifactLabel;
142         }
143
144         // public static String
145         // buildArtifactByInterfaceUniqueIdAndRsrcNameVersion(String
146         // resourceName,String resourceVersion,String interfaceName,String
147         // operation,String artifactLabel) {
148         // String resourceId = UniqueIdBuilder.buildResourceUniqueId(resourceName,
149         // resourceVersion);
150         // return resourceId + DOT + interfaceName + DOT +operation + DOT +
151         // artifactLabel;
152         // }
153         public static String buildArtifactByInterfaceUniqueIdAndRsrcId(String resourceId, String interfaceName, String operation, String artifactLabel) {
154                 return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
155         }
156
157         public static String buildOperationByInterfaceUniqueId(String resourceId, String interfaceName, String operation) {
158
159                 return resourceId + DOT + interfaceName + DOT + operation;
160         }
161
162         public static String buildInterfaceUniqueId(String resourceId, String interfaceName) {
163                 return resourceId + DOT + interfaceName;
164         }
165
166         public static String buildResourceInstanceUniuqeId(String serviceId, String resourceId, String logicalName) {
167
168                 return serviceId + DOT + resourceId + DOT + logicalName;
169         }
170
171         public static String buildRelationsipInstInstanceUid(String resourceInstUid, String requirement) {
172
173                 return generateUUID();
174         }
175
176         /*
177          * TODO Pavel To be removed when new category logic comes in
178          */
179         public static String buildResourceCategoryUid(String categoryName, String subcategoryName, NodeTypeEnum type) {
180                 return type.getName() + DOT + categoryName + DOT + subcategoryName;
181         }
182
183         /*
184          * TODO Pavel To be removed when new category logic comes in
185          */
186         public static String buildServiceCategoryUid(String categoryName, NodeTypeEnum type) {
187                 return type.getName() + DOT + categoryName;
188         }
189
190         // New logic
191         public static String buildCategoryUid(String categoryName, NodeTypeEnum type) {
192                 return type.getName() + DOT + categoryName;
193         }
194         public static String buildComponentCategoryUid(String categoryName, VertexTypeEnum type) {
195                 return type.getName() + DOT + ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
196         }
197
198         public static String buildSubCategoryUid(String categoryUid, String subCategoryName) {
199                 return categoryUid + DOT + subCategoryName;
200         }
201
202         public static String buildGroupingUid(String subCategoryUid, String groupingName) {
203                 return subCategoryUid + DOT + groupingName;
204         }
205
206         public static String buildResourceInstancePropertyValueUid(String resourceInstanceUniqueId, Integer index) {
207                 return resourceInstanceUniqueId + DOT + "property" + DOT + index;
208         }
209         
210         public static String buildComponentPropertyUniqueId(String resourceId, String propertyName) {
211                 return NodeTypeEnum.Property.getName() + DOT + resourceId + DOT + propertyName;
212         }
213
214         public static String buildResourceInstanceAttributeValueUid(String resourceInstanceUniqueId, Integer index) {
215                 return resourceInstanceUniqueId + DOT + "attribute" + DOT + index;
216         }
217
218         public static String buildResourceInstanceInputValueUid(String resourceInstanceUniqueId, Integer index) {
219                 return resourceInstanceUniqueId + DOT + "input" + DOT + index;
220         }
221
222         public static String buildAdditionalInformationUniqueId(String resourceUniqueId) {
223                 return resourceUniqueId + DOT + "additionalinformation";
224         }
225
226         public static String buildHeatParamValueUid(String heatEnvArtifactId, String parameterName) {
227                 return heatEnvArtifactId + DOT + parameterName;
228         }
229
230         public static String buildDataTypeUid(String name) {
231                 return name + DOT + "datatype";
232         }
233
234         public static String buildInvariantUUID() {
235                 return generateUUID();
236         }
237
238         public static String buildGroupTypeUid(String type, String version) {
239                 return type + DOT + version + DOT + "grouptype";
240         }
241
242         public static String buildPolicyTypeUid(String type, String version) {
243                 return type + DOT + version + DOT + "policytype";
244         }
245
246         public static String buildGroupUniqueId(String componentId, String name) {
247                 return componentId + DOT + name + DOT + "group";
248         }
249         
250         public static String buildPolicyUniqueId(String componentId, String name) {
251                 return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
252         }
253
254         public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
255                 return groupUniqueId + DOT + "property" + DOT + index;
256
257         }
258         
259         public static String buildUserFunctionalMenuUid(String userId) {
260                 return userId + DOT + "functionalmenu";
261
262         }
263 }