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