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