Catalog alignment
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / graph / GraphElementFactory.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.dao.graph;
22
23 import org.openecomp.sdc.be.dao.graph.datatype.GraphElementTypeEnum;
24 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
25 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
26 import org.openecomp.sdc.be.dao.graph.datatype.RelationEndPoint;
27 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionaryExtractor;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import org.openecomp.sdc.be.resources.data.*;
30 import org.openecomp.sdc.be.resources.data.category.CategoryData;
31 import org.openecomp.sdc.be.resources.data.category.GroupingData;
32 import org.openecomp.sdc.be.resources.data.category.SubCategoryData;
33
34 import java.util.Map;
35
36 public class GraphElementFactory {
37
38         public static <T extends GraphNode> T createElement(String label, GraphElementTypeEnum type,
39                         Map<String, Object> properties, Class<T> clazz) {
40                 T element = null;
41
42                 if (type.equals(GraphElementTypeEnum.Node)) {
43                         element = createNode(label, properties, clazz);
44                 }
45                 return element;
46         }
47
48         public static GraphNode createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties) {
49                 GraphNode element = null;
50
51                 if (type.equals(GraphElementTypeEnum.Node)) {
52                         element = createNode(label, properties);
53                 }
54                 return element;
55         }
56
57         public static GraphRelation createRelation(String type, Map<String, Object> properties, GraphNode from,
58                         GraphNode to) {
59                 GraphRelation element = new GraphRelation(type);
60                 RelationEndPoint endPOintFrom = new RelationEndPoint(NodeTypeEnum.getByName(from.getLabel()),
61                                 from.getUniqueIdKey(), from.getUniqueId());
62                 RelationEndPoint endPOintTo = new RelationEndPoint(NodeTypeEnum.getByName(to.getLabel()), to.getUniqueIdKey(),
63                                 to.getUniqueId());
64                 element.setFrom(endPOintFrom);
65                 element.setTo(endPOintTo);
66                 element.addPropertis(properties);
67                 return element;
68         }
69
70         private static GraphNode createNode(String label, Map<String, Object> properties) {
71                 GraphNode element = null;
72                 NodeTypeEnum type = NodeTypeEnum.getByName(label);
73                 if (type != null) {
74                         switch (type) {
75                         case User:
76                                 element = new UserData(properties);
77                                 break;
78                         case ResourceCategory:
79                                 element = new ResourceCategoryData(properties);
80                                 break;
81                         case ServiceCategory:
82                                 element = new ServiceCategoryData(properties);
83                                 break;
84                         case Tag:
85                                 element = new TagData(properties);
86                                 break;
87                         case Service:
88                                 element = new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
89                                 break;
90                         case Resource:
91                                 element = new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
92                                 break;
93                         case Property:
94                                 element = new PropertyData(properties);
95                                 break;
96                         case HeatParameter:
97                                 element = new HeatParameterData(properties);
98                                 break;
99                         case HeatParameterValue:
100                                 element = new HeatParameterValueData(properties);
101                                 break;
102                         }
103                 }
104                 return element;
105         }
106
107         private static <T extends GraphNode> T createNode(String label, Map<String, Object> properties, Class<T> clazz) {
108                 T element = null;
109                 NodeTypeEnum type = NodeTypeEnum.getByName(label);
110                 if (type != null) {
111                         switch (type) {
112                         case User:
113                                 element = clazz.cast(new UserData(properties));
114                                 break;
115                         case ResourceCategory:
116                                 element = clazz.cast(new ResourceCategoryData(properties));
117                                 break;
118                         case ServiceCategory:
119                                 element = clazz.cast(new ServiceCategoryData(properties));
120                                 break;
121                         case ResourceNewCategory:
122                         case ServiceNewCategory:
123                         case ProductCategory:
124                                 element = clazz.cast(new CategoryData(properties));
125                                 break;
126                         case ResourceSubcategory:
127                         case ProductSubcategory:
128                                 element = clazz.cast(new SubCategoryData(properties));
129                                 break;
130                         case ProductGrouping:
131                                 element = clazz.cast(new GroupingData(properties));
132                                 break;
133                         case Tag:
134                                 element = clazz.cast(new TagData(properties));
135                                 break;
136                         case Service:
137                                 element = clazz.cast(new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
138                                 break;
139                         case Product:
140                                 element = clazz.cast(new ProductMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
141                                 break;
142                         case Resource:
143                                 element = clazz.cast(new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
144                                 break;
145                         case Attribute:
146                                 element = clazz.cast(new AttributeData(properties));
147                                 break;
148                         case Property:
149                                 element = clazz.cast(new PropertyData(properties));
150                                 break;
151                         case CapabilityType:
152                                 element = clazz.cast(new CapabilityTypeData(properties));
153                                 break;
154                         case Requirement:
155                                 element = clazz.cast(new RequirementData(properties));
156                                 break;
157                         case RequirementImpl:
158                                 element = clazz.cast(new RequirementImplData(properties));
159                                 break;
160                         case Capability:
161                                 element = clazz.cast(new CapabilityData(properties));
162                                 break;
163                         case CapabilityInst:
164                                 element = clazz.cast(new CapabilityInstData(properties));
165                                 break;
166                         case PropertyValue:
167                                 element = clazz.cast(new PropertyValueData(properties));
168                                 break;
169                         case AttributeValue:
170                                 element = clazz.cast(new AttributeValueData(properties));
171                                 break;
172                         case InputValue:
173                                 element = clazz.cast(new InputValueData(properties));
174                                 break;
175                         case RelationshipType:
176                                 element = clazz.cast(new RelationshipTypeData(properties));
177                                 break;
178                         case LockNode:
179                                 element = clazz.cast(new GraphNodeLock(properties));
180                                 break;
181                         case ArtifactRef:
182                                 element = clazz.cast(new ArtifactData(properties));
183                                 break;
184                         case Interface:
185                                 element = clazz.cast(new InterfaceData(properties));
186                                 break;
187                         case InterfaceOperation:
188                                 element = clazz.cast(new OperationData(properties));
189                                 break;
190                         case Input:
191                                 element = clazz.cast(new InputsData(properties));
192                                 break;
193                         case ResourceInstance:
194                                 element = clazz.cast(new ComponentInstanceData(properties));
195                                 break;
196                         case RelationshipInst:
197                                 element = clazz.cast(new RelationshipInstData(properties));
198                                 break;
199                         case AdditionalInfoParameters:
200                                 element = clazz.cast(new AdditionalInfoParameterData(properties));
201                                 break;
202                         case ConsumerCredentials:
203                                 element = clazz.cast(new ConsumerData(properties));
204                                 break;
205                         case HeatParameter:
206                                 element = clazz.cast(new HeatParameterData(properties));
207                                 break;
208                         case HeatParameterValue:
209                                 element = clazz.cast(new HeatParameterValueData(properties));
210                                 break;
211                         case DataType:
212                                 element = clazz.cast(new DataTypeData(properties));
213                                 break;
214                         case Group:
215                                 element = clazz.cast(new GroupData(properties));
216                                 break;
217                         case GroupType:
218                                 element = clazz.cast(new GroupTypeData(properties));
219                                 break;
220                         case UserFunctionalMenu:
221                                 element = clazz.cast(new UserFunctionalMenuData(properties));
222                                 break;
223                         case PolicyType:
224                                 element = clazz.cast(new PolicyTypeData(properties));
225                                 break;
226                         case GroupInstance:
227                                 element = clazz.cast(new GroupInstanceData(properties));
228                                 break;
229                         case AnnotationType:
230                                 element = clazz.cast(new AnnotationTypeData(properties));
231                         default:
232                                 break;
233                         }
234
235                 }
236                 return element;
237         }
238
239 }