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.ModelData;
50 import org.openecomp.sdc.be.resources.data.OperationData;
51 import org.openecomp.sdc.be.resources.data.PolicyTypeData;
52 import org.openecomp.sdc.be.resources.data.ProductMetadataData;
53 import org.openecomp.sdc.be.resources.data.PropertyData;
54 import org.openecomp.sdc.be.resources.data.PropertyValueData;
55 import org.openecomp.sdc.be.resources.data.RelationshipInstData;
56 import org.openecomp.sdc.be.resources.data.RelationshipTypeData;
57 import org.openecomp.sdc.be.resources.data.RequirementData;
58 import org.openecomp.sdc.be.resources.data.RequirementImplData;
59 import org.openecomp.sdc.be.resources.data.ResourceCategoryData;
60 import org.openecomp.sdc.be.resources.data.ResourceMetadataData;
61 import org.openecomp.sdc.be.resources.data.ServiceCategoryData;
62 import org.openecomp.sdc.be.resources.data.ServiceMetadataData;
63 import org.openecomp.sdc.be.resources.data.TagData;
64 import org.openecomp.sdc.be.resources.data.UserData;
65 import org.openecomp.sdc.be.resources.data.UserFunctionalMenuData;
66 import org.openecomp.sdc.be.resources.data.category.CategoryData;
67 import org.openecomp.sdc.be.resources.data.category.GroupingData;
68 import org.openecomp.sdc.be.resources.data.category.SubCategoryData;
70 public class GraphElementFactory {
72 public static <T extends GraphNode> T createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties, Class<T> clazz) {
74 if (type.equals(GraphElementTypeEnum.Node)) {
75 element = createNode(label, properties, clazz);
80 public static GraphNode createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties) {
81 GraphNode element = null;
82 if (type.equals(GraphElementTypeEnum.Node)) {
83 element = createNode(label, properties);
88 public static GraphRelation createRelation(String type, Map<String, Object> properties, GraphNode from, GraphNode to) {
89 GraphRelation element = new GraphRelation(type);
90 RelationEndPoint endPOintFrom = new RelationEndPoint(NodeTypeEnum.getByName(from.getLabel()), from.getUniqueIdKey(), from.getUniqueId());
91 RelationEndPoint endPOintTo = new RelationEndPoint(NodeTypeEnum.getByName(to.getLabel()), to.getUniqueIdKey(), to.getUniqueId());
92 element.setFrom(endPOintFrom);
93 element.setTo(endPOintTo);
94 element.addPropertis(properties);
98 private static GraphNode createNode(String label, Map<String, Object> properties) {
99 GraphNode element = null;
100 NodeTypeEnum type = NodeTypeEnum.getByName(label);
104 element = new UserData(properties);
106 case ResourceCategory:
107 element = new ResourceCategoryData(properties);
109 case ServiceCategory:
110 element = new ServiceCategoryData(properties);
113 element = new TagData(properties);
116 element = new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
119 element = new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
122 element = new PropertyData(properties);
125 element = new HeatParameterData(properties);
127 case HeatParameterValue:
128 element = new HeatParameterValueData(properties);
135 private static <T extends GraphNode> T createNode(String label, Map<String, Object> properties, Class<T> clazz) {
137 NodeTypeEnum type = NodeTypeEnum.getByName(label);
141 element = clazz.cast(new UserData(properties));
143 case ResourceCategory:
144 element = clazz.cast(new ResourceCategoryData(properties));
146 case ServiceCategory:
147 element = clazz.cast(new ServiceCategoryData(properties));
149 case ResourceNewCategory:
150 case ServiceNewCategory:
151 case ProductCategory:
152 element = clazz.cast(new CategoryData(properties));
154 case ResourceSubcategory:
155 case ProductSubcategory:
156 element = clazz.cast(new SubCategoryData(properties));
158 case ProductGrouping:
159 element = clazz.cast(new GroupingData(properties));
162 element = clazz.cast(new TagData(properties));
165 element = clazz.cast(new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
168 element = clazz.cast(new ProductMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
171 element = clazz.cast(new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
174 element = clazz.cast(new AttributeData(properties));
177 element = clazz.cast(new PropertyData(properties));
180 element = clazz.cast(new CapabilityTypeData(properties));
183 element = clazz.cast(new RequirementData(properties));
185 case RequirementImpl:
186 element = clazz.cast(new RequirementImplData(properties));
189 element = clazz.cast(new CapabilityData(properties));
192 element = clazz.cast(new CapabilityInstData(properties));
195 element = clazz.cast(new PropertyValueData(properties));
198 element = clazz.cast(new AttributeValueData(properties));
201 element = clazz.cast(new InputValueData(properties));
203 case RelationshipType:
204 element = clazz.cast(new RelationshipTypeData(properties));
207 element = clazz.cast(new GraphNodeLock(properties));
210 element = clazz.cast(new ArtifactData(properties));
213 element = clazz.cast(new InterfaceData(properties));
215 case InterfaceOperation:
216 element = clazz.cast(new OperationData(properties));
219 element = clazz.cast(new InputsData(properties));
221 case ResourceInstance:
222 element = clazz.cast(new ComponentInstanceData(properties));
224 case RelationshipInst:
225 element = clazz.cast(new RelationshipInstData(properties));
227 case AdditionalInfoParameters:
228 element = clazz.cast(new AdditionalInfoParameterData(properties));
230 case ConsumerCredentials:
231 element = clazz.cast(new ConsumerData(properties));
234 element = clazz.cast(new HeatParameterData(properties));
236 case HeatParameterValue:
237 element = clazz.cast(new HeatParameterValueData(properties));
240 element = clazz.cast(new DataTypeData(properties));
243 element = clazz.cast(new GroupData(properties));
246 element = clazz.cast(new GroupTypeData(properties));
248 case UserFunctionalMenu:
249 element = clazz.cast(new UserFunctionalMenuData(properties));
252 element = clazz.cast(new PolicyTypeData(properties));
255 element = clazz.cast(new GroupInstanceData(properties));
258 element = clazz.cast(new AnnotationTypeData(properties));
261 element = clazz.cast(new ModelData(properties));