2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.openecomp.sdc.be.dao.graph;
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;
72 public class GraphElementFactory {
74 public static <T extends GraphNode> T createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties, Class<T> clazz) {
76 if (type.equals(GraphElementTypeEnum.Node)) {
77 element = createNode(label, properties, clazz);
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);
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);
100 private static GraphNode createNode(String label, Map<String, Object> properties) {
101 GraphNode element = null;
102 NodeTypeEnum type = NodeTypeEnum.getByName(label);
106 element = new UserData(properties);
108 case ResourceCategory:
109 element = new ResourceCategoryData(properties);
111 case ServiceCategory:
112 element = new ServiceCategoryData(properties);
115 element = new TagData(properties);
118 element = new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
121 element = new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
124 element = new PropertyData(properties);
127 element = new HeatParameterData(properties);
129 case HeatParameterValue:
130 element = new HeatParameterValueData(properties);
137 private static <T extends GraphNode> T createNode(String label, Map<String, Object> properties, Class<T> clazz) {
139 NodeTypeEnum type = NodeTypeEnum.getByName(label);
143 element = clazz.cast(new UserData(properties));
145 case ResourceCategory:
146 element = clazz.cast(new ResourceCategoryData(properties));
148 case ServiceCategory:
149 element = clazz.cast(new ServiceCategoryData(properties));
151 case ResourceNewCategory:
152 case ServiceNewCategory:
153 case ProductCategory:
154 element = clazz.cast(new CategoryData(properties));
156 case ResourceSubcategory:
157 case ProductSubcategory:
158 element = clazz.cast(new SubCategoryData(properties));
160 case ProductGrouping:
161 element = clazz.cast(new GroupingData(properties));
164 element = clazz.cast(new TagData(properties));
167 element = clazz.cast(new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
170 element = clazz.cast(new ProductMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
173 element = clazz.cast(new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
176 element = clazz.cast(new AttributeData(properties));
179 element = clazz.cast(new PropertyData(properties));
182 element = clazz.cast(new CapabilityTypeData(properties));
185 element = clazz.cast(new RequirementData(properties));
187 case RequirementImpl:
188 element = clazz.cast(new RequirementImplData(properties));
191 element = clazz.cast(new CapabilityData(properties));
194 element = clazz.cast(new CapabilityInstData(properties));
197 element = clazz.cast(new PropertyValueData(properties));
200 element = clazz.cast(new AttributeValueData(properties));
203 element = clazz.cast(new InputValueData(properties));
205 case RelationshipType:
206 element = clazz.cast(new RelationshipTypeData(properties));
209 element = clazz.cast(new GraphNodeLock(properties));
212 element = clazz.cast(new ArtifactData(properties));
215 element = clazz.cast(new InterfaceData(properties));
217 case InterfaceOperation:
218 element = clazz.cast(new OperationData(properties));
221 element = clazz.cast(new InputsData(properties));
223 case ResourceInstance:
224 element = clazz.cast(new ComponentInstanceData(properties));
226 case RelationshipInst:
227 element = clazz.cast(new RelationshipInstData(properties));
229 case AdditionalInfoParameters:
230 element = clazz.cast(new AdditionalInfoParameterData(properties));
232 case ConsumerCredentials:
233 element = clazz.cast(new ConsumerData(properties));
236 element = clazz.cast(new HeatParameterData(properties));
238 case HeatParameterValue:
239 element = clazz.cast(new HeatParameterValueData(properties));
242 element = clazz.cast(new DataTypeData(properties));
245 element = clazz.cast(new GroupData(properties));
248 element = clazz.cast(new GroupTypeData(properties));
250 case UserFunctionalMenu:
251 element = clazz.cast(new UserFunctionalMenuData(properties));
254 element = clazz.cast(new PolicyTypeData(properties));
257 element = clazz.cast(new GroupInstanceData(properties));
260 element = clazz.cast(new AnnotationTypeData(properties));
263 element = clazz.cast(new ModelData(properties));
266 element = clazz.cast(new ArtifactTypeData(properties));