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