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;
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;
69 public class GraphElementFactory {
71 public static <T extends GraphNode> T createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties, Class<T> clazz) {
73 if (type.equals(GraphElementTypeEnum.Node)) {
74 element = createNode(label, properties, clazz);
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);
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);
97 private static GraphNode createNode(String label, Map<String, Object> properties) {
98 GraphNode element = null;
99 NodeTypeEnum type = NodeTypeEnum.getByName(label);
103 element = new UserData(properties);
105 case ResourceCategory:
106 element = new ResourceCategoryData(properties);
108 case ServiceCategory:
109 element = new ServiceCategoryData(properties);
112 element = new TagData(properties);
115 element = new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
118 element = new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
121 element = new PropertyData(properties);
124 element = new HeatParameterData(properties);
126 case HeatParameterValue:
127 element = new HeatParameterValueData(properties);
134 private static <T extends GraphNode> T createNode(String label, Map<String, Object> properties, Class<T> clazz) {
136 NodeTypeEnum type = NodeTypeEnum.getByName(label);
140 element = clazz.cast(new UserData(properties));
142 case ResourceCategory:
143 element = clazz.cast(new ResourceCategoryData(properties));
145 case ServiceCategory:
146 element = clazz.cast(new ServiceCategoryData(properties));
148 case ResourceNewCategory:
149 case ServiceNewCategory:
150 case ProductCategory:
151 element = clazz.cast(new CategoryData(properties));
153 case ResourceSubcategory:
154 case ProductSubcategory:
155 element = clazz.cast(new SubCategoryData(properties));
157 case ProductGrouping:
158 element = clazz.cast(new GroupingData(properties));
161 element = clazz.cast(new TagData(properties));
164 element = clazz.cast(new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
167 element = clazz.cast(new ProductMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
170 element = clazz.cast(new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
173 element = clazz.cast(new AttributeData(properties));
176 element = clazz.cast(new PropertyData(properties));
179 element = clazz.cast(new CapabilityTypeData(properties));
182 element = clazz.cast(new RequirementData(properties));
184 case RequirementImpl:
185 element = clazz.cast(new RequirementImplData(properties));
188 element = clazz.cast(new CapabilityData(properties));
191 element = clazz.cast(new CapabilityInstData(properties));
194 element = clazz.cast(new PropertyValueData(properties));
197 element = clazz.cast(new AttributeValueData(properties));
200 element = clazz.cast(new InputValueData(properties));
202 case RelationshipType:
203 element = clazz.cast(new RelationshipTypeData(properties));
206 element = clazz.cast(new GraphNodeLock(properties));
209 element = clazz.cast(new ArtifactData(properties));
212 element = clazz.cast(new InterfaceData(properties));
214 case InterfaceOperation:
215 element = clazz.cast(new OperationData(properties));
218 element = clazz.cast(new InputsData(properties));
220 case ResourceInstance:
221 element = clazz.cast(new ComponentInstanceData(properties));
223 case RelationshipInst:
224 element = clazz.cast(new RelationshipInstData(properties));
226 case AdditionalInfoParameters:
227 element = clazz.cast(new AdditionalInfoParameterData(properties));
229 case ConsumerCredentials:
230 element = clazz.cast(new ConsumerData(properties));
233 element = clazz.cast(new HeatParameterData(properties));
235 case HeatParameterValue:
236 element = clazz.cast(new HeatParameterValueData(properties));
239 element = clazz.cast(new DataTypeData(properties));
242 element = clazz.cast(new GroupData(properties));
245 element = clazz.cast(new GroupTypeData(properties));
247 case UserFunctionalMenu:
248 element = clazz.cast(new UserFunctionalMenuData(properties));
251 element = clazz.cast(new PolicyTypeData(properties));
254 element = clazz.cast(new GroupInstanceData(properties));
257 element = clazz.cast(new AnnotationTypeData(properties));