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