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