Reformat catalog-model
[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 package org.openecomp.sdc.be.model.operations.impl;
21
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.UUID;
25 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
26 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
28 import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
29 import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
30 import org.openecomp.sdc.be.resources.data.TagData;
31 import org.openecomp.sdc.be.resources.data.UserData;
32 import org.openecomp.sdc.common.api.Constants;
33 import org.openecomp.sdc.common.util.ValidationUtils;
34
35 public class UniqueIdBuilder {
36
37     private static final String HEAT_PARAM_PREFIX = "heat_";
38     private static String DOT = ".";
39     private static UserData userData = new UserData();
40     private static TagData tagData = new TagData();
41     private static ResourceCategoryData resCategoryData = new ResourceCategoryData();
42     private static ServiceCategoryData serCategoryData = new ServiceCategoryData();
43     private static Map<NodeTypeEnum, String> nodeTypeToUniqueKeyMapper = new HashMap<>();
44
45     static {
46         nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.User, userData.getUniqueIdKey());
47         nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.Tag, tagData.getUniqueIdKey());
48         nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ResourceCategory, resCategoryData.getUniqueIdKey());
49         nodeTypeToUniqueKeyMapper.put(NodeTypeEnum.ServiceCategory, serCategoryData.getUniqueIdKey());
50     }
51
52     public static String buildPropertyUniqueId(String resourceId, String propertyName) {
53         return resourceId + DOT + propertyName;
54     }
55
56     static String buildHeatParameterUniqueId(String resourceId, String propertyName) {
57         return resourceId + DOT + HEAT_PARAM_PREFIX + propertyName;
58     }
59
60     static String buildHeatParameterValueUniqueId(String resourceId, String artifactLabel, String propertyName) {
61         return buildTypeUid(resourceId, artifactLabel, propertyName);
62     }
63
64     /**
65      * find the unique id key of a node on the graph
66      *
67      * @param nodeTypeEnum
68      * @return
69      */
70     public static String getKeyByNodeType(NodeTypeEnum nodeTypeEnum) {
71         String uniqueID = nodeTypeToUniqueKeyMapper.get(nodeTypeEnum);
72         if (uniqueID == null) {
73             uniqueID = GraphPropertiesDictionary.UNIQUE_ID.getProperty();
74         }
75         return uniqueID;
76     }
77
78     public static String buildResourceUniqueId() {
79         return generateUUID();
80     }
81
82     public static String generateUUID() {
83         UUID uuid = UUID.randomUUID();
84         return uuid.toString();
85     }
86
87     public static String buildComponentUniqueId() {
88         return generateUUID();
89     }
90
91     static String buildCapabilityTypeUid(String type) {
92         return type;
93     }
94
95     static String buildRelationshipTypeUid(String type) {
96         return type;
97     }
98
99     public static String buildAttributeUid(String resourceId, String attName) {
100         return buildTypeUid(NodeTypeEnum.Attribute.getName(), resourceId, attName);
101     }
102
103     public static String buildRequirementUid(String resourceId, String reqName) {
104         return resourceId + DOT + reqName;
105     }
106
107     public static String buildCapabilityUid(String resourceId, String capabilityName) {
108         return buildTypeUid(NodeTypeEnum.Capability.getName(), resourceId, capabilityName);
109     }
110
111     public static String buildArtifactByInterfaceUniqueId(String resourceId, String interfaceName, String operation, String artifactLabel) {
112         return resourceId + DOT + interfaceName + DOT + operation + DOT + artifactLabel;
113     }
114
115     public static String buildInstanceArtifactUniqueId(String parentId, String instanceId, String artifactLabel) {
116         return buildTypeUid(parentId, instanceId, artifactLabel);
117     }
118
119     public static String buildResourceInstanceUniuqeId(String serviceId, String resourceId, String logicalName) {
120         return buildTypeUid(serviceId, resourceId, logicalName);
121     }
122
123     public static String buildRelationsipInstInstanceUid(String resourceInstUid, String requirement) {
124         return generateUUID();
125     }
126
127     /*
128      * TODO Pavel To be removed when new category logic comes in
129      */
130     static String buildResourceCategoryUid(String categoryName, String subcategoryName, NodeTypeEnum type) {
131         return buildTypeUid(type.getName(), categoryName, subcategoryName);
132     }
133
134     /*
135      * TODO Pavel To be removed when new category logic comes in
136      */
137     static String buildServiceCategoryUid(String categoryName, NodeTypeEnum type) {
138         return type.getName() + DOT + categoryName;
139     }
140
141     // New logic
142     public static String buildCategoryUid(String categoryName, NodeTypeEnum type) {
143         return type.getName() + DOT + categoryName;
144     }
145
146     public static String buildComponentCategoryUid(String categoryName, VertexTypeEnum type) {
147         return type.getName() + DOT + ValidationUtils.normalizeCategoryName4Uniqueness(categoryName);
148     }
149
150     public static String buildSubCategoryUid(String categoryUid, String subCategoryName) {
151         return categoryUid + DOT + subCategoryName;
152     }
153
154     public static String buildGroupingUid(String subCategoryUid, String groupingName) {
155         return subCategoryUid + DOT + groupingName;
156     }
157
158     static String buildResourceInstancePropertyValueUid(String resourceInstanceUniqueId, Integer index) {
159         return resourceInstanceUniqueId + DOT + "property" + DOT + index;
160     }
161
162     public static String buildComponentPropertyUniqueId(String resourceId, String propertyName) {
163         return buildTypeUid(NodeTypeEnum.Property.getName(), resourceId, propertyName);
164     }
165
166     static String buildResourceInstanceAttributeValueUid(String resourceInstanceUniqueId, Integer index) {
167         return resourceInstanceUniqueId + DOT + "attribute" + DOT + index;
168     }
169
170     static String buildResourceInstanceInputValueUid(String resourceInstanceUniqueId, Integer index) {
171         return resourceInstanceUniqueId + DOT + "input" + DOT + index;
172     }
173
174     static String buildAdditionalInformationUniqueId(String resourceUniqueId) {
175         return resourceUniqueId + DOT + "additionalinformation";
176     }
177
178     static String buildDataTypeUid(String name) {
179         return name + DOT + "datatype";
180     }
181
182     public static String buildInvariantUUID() {
183         return generateUUID();
184     }
185
186     static String buildGroupTypeUid(String type, String version, String resourceName) {
187         return buildTypeUid(type, version, resourceName);
188     }
189
190     static String buildPolicyTypeUid(String type, String version, String resourceName) {
191         return buildTypeUid(type, version, resourceName);
192     }
193
194     static String buildTypeUid(String type, String version, String resourceName) {
195         return type + DOT + version + DOT + resourceName;
196     }
197
198     public static String buildPolicyUniqueId(String componentId, String name) {
199         return componentId + DOT + name + Constants.POLICY_UID_POSTFIX;
200     }
201
202     public static String buildGroupPropertyValueUid(String groupUniqueId, Integer index) {
203         return groupUniqueId + DOT + "property" + DOT + index;
204     }
205 }