Catalog alignment
[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 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;
32
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.UUID;
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     static String buildHeatParameterUniqueId(String resourceId, String propertyName) {
47         return resourceId + DOT + HEAT_PARAM_PREFIX + propertyName;
48     }
49
50     static String buildHeatParameterValueUniqueId(String resourceId, String artifactLabel, String propertyName) {
51         return buildTypeUid(resourceId, artifactLabel, 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<>();
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 uniqueID = nodeTypeToUniqueKeyMapper.get(nodeTypeEnum);
78         if (uniqueID == null) {
79             uniqueID = GraphPropertiesDictionary.UNIQUE_ID.getProperty();
80         }
81
82         return uniqueID;
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     static String buildCapabilityTypeUid(String type) {
99         return type;
100     }
101
102     static String buildRelationshipTypeUid(String type) {
103         return type;
104     }
105
106     public static String buildAttributeUid(String resourceId, String attName) {
107         return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName);
108     }
109     public static String buildRequirementUid(String resourceId, String reqName) {
110         return resourceId + DOT + reqName;
111     }
112
113     public static String buildCapabilityUid(String resourceId, String capabilityName) {
114         return buildTypeUid(NodeTypeEnum.Capability.getName(), resourceId, capabilityName);
115     }
116
117     public static String buildArtifactByInterfaceUniqueId(String resourceId, String interfaceName, String operation, String artifactLabel) {
118
119         return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
120     }
121
122     public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
123
124         return buildTypeUid(parentId, instanceId, artifactLabel);
125     }
126
127     public static String buildResourceInstanceUniuqeId(String serviceId, String resourceId, String logicalName) {
128
129         return buildTypeUid(serviceId, resourceId, logicalName);
130     }
131
132     public static String buildRelationsipInstInstanceUid(String resourceInstUid, String requirement) {
133
134         return generateUUID();
135     }
136
137     /*
138      * TODO Pavel To be removed when new category logic comes in
139      */
140     static String buildResourceCategoryUid(String categoryName, String subcategoryName, NodeTypeEnum type) {
141         return buildTypeUid(type.getName(), categoryName, subcategoryName);
142     }
143
144     /*
145      * TODO Pavel To be removed when new category logic comes in
146      */
147     static String buildServiceCategoryUid(String categoryName, NodeTypeEnum type) {
148         return type.getName() + DOT + categoryName;
149     }
150
151     // New logic
152     public static String buildCategoryUid(String categoryName, NodeTypeEnum type) {
153         return type.getName() + DOT + categoryName;
154     }
155     public static String buildComponentCategoryUid(String categoryName, VertexTypeEnum type) {
156         return type.getName() + DOT + ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
157     }
158
159     public static String buildSubCategoryUid(String categoryUid, String subCategoryName) {
160         return categoryUid + DOT + subCategoryName;
161     }
162
163     public static String buildGroupingUid(String subCategoryUid, String groupingName) {
164         return subCategoryUid + DOT + groupingName;
165     }
166
167     static String buildResourceInstancePropertyValueUid(String resourceInstanceUniqueId, Integer index) {
168         return resourceInstanceUniqueId + DOT + "property" + DOT + index;
169     }
170
171     public static String buildComponentPropertyUniqueId(String resourceId, String propertyName) {
172         return buildTypeUid(NodeTypeEnum.Property.getName(), resourceId, propertyName);
173     }
174
175     static String buildResourceInstanceAttributeValueUid(String resourceInstanceUniqueId, Integer index) {
176         return resourceInstanceUniqueId + DOT + "attribute" + DOT + index;
177     }
178
179     static String buildResourceInstanceInputValueUid(String resourceInstanceUniqueId, Integer index) {
180         return resourceInstanceUniqueId + DOT + "input" + DOT + index;
181     }
182
183     static String buildAdditionalInformationUniqueId(String resourceUniqueId) {
184         return resourceUniqueId + DOT + "additionalinformation";
185     }
186
187     static String buildDataTypeUid(String name) {
188         return name + DOT + "datatype";
189     }
190
191     public static String buildInvariantUUID() {
192         return generateUUID();
193     }
194
195     static String buildGroupTypeUid(String type, String version, String resourceName) {
196         return buildTypeUid(type, version, resourceName);
197     }
198
199     static String buildPolicyTypeUid(String type, String version, String resourceName) {
200         return buildTypeUid(type, version, resourceName);
201     }
202
203     static String buildTypeUid(String type, String version, String resourceName) {
204         return type + DOT + version + DOT + resourceName;
205     }
206
207     public static String buildPolicyUniqueId(String componentId, String name) {
208         return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
209     }
210
211     public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
212         return groupUniqueId + DOT + "property" + DOT + index;
213
214     }
215 }