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=========================================================
21 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.*;
30 import org.openecomp.sdc.be.resources.data.category.CategoryData;
31 import org.openecomp.sdc.be.resources.data.category.GroupingData;
32 import org.openecomp.sdc.be.resources.data.category.SubCategoryData;
36 public class GraphElementFactory {
38 public static <T extends GraphNode> T createElement(String label, GraphElementTypeEnum type,
39 Map<String, Object> properties, Class<T> clazz) {
42 if (type.equals(GraphElementTypeEnum.Node)) {
43 element = createNode(label, properties, clazz);
48 public static GraphNode createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties) {
49 GraphNode element = null;
51 if (type.equals(GraphElementTypeEnum.Node)) {
52 element = createNode(label, properties);
57 public static GraphRelation createRelation(String type, Map<String, Object> properties, GraphNode from,
59 GraphRelation element = new GraphRelation(type);
60 RelationEndPoint endPOintFrom = new RelationEndPoint(NodeTypeEnum.getByName(from.getLabel()),
61 from.getUniqueIdKey(), from.getUniqueId());
62 RelationEndPoint endPOintTo = new RelationEndPoint(NodeTypeEnum.getByName(to.getLabel()), to.getUniqueIdKey(),
64 element.setFrom(endPOintFrom);
65 element.setTo(endPOintTo);
66 element.addPropertis(properties);
70 private static GraphNode createNode(String label, Map<String, Object> properties) {
71 GraphNode element = null;
72 NodeTypeEnum type = NodeTypeEnum.getByName(label);
76 element = new UserData(properties);
78 case ResourceCategory:
79 element = new ResourceCategoryData(properties);
82 element = new ServiceCategoryData(properties);
85 element = new TagData(properties);
88 element = new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
91 element = new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties));
94 element = new PropertyData(properties);
97 element = new HeatParameterData(properties);
99 case HeatParameterValue:
100 element = new HeatParameterValueData(properties);
107 private static <T extends GraphNode> T createNode(String label, Map<String, Object> properties, Class<T> clazz) {
109 NodeTypeEnum type = NodeTypeEnum.getByName(label);
113 element = clazz.cast(new UserData(properties));
115 case ResourceCategory:
116 element = clazz.cast(new ResourceCategoryData(properties));
118 case ServiceCategory:
119 element = clazz.cast(new ServiceCategoryData(properties));
121 case ResourceNewCategory:
122 case ServiceNewCategory:
123 case ProductCategory:
124 element = clazz.cast(new CategoryData(properties));
126 case ResourceSubcategory:
127 case ProductSubcategory:
128 element = clazz.cast(new SubCategoryData(properties));
130 case ProductGrouping:
131 element = clazz.cast(new GroupingData(properties));
134 element = clazz.cast(new TagData(properties));
137 element = clazz.cast(new ServiceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
140 element = clazz.cast(new ProductMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
143 element = clazz.cast(new ResourceMetadataData(new GraphPropertiesDictionaryExtractor(properties)));
146 element = clazz.cast(new AttributeData(properties));
149 element = clazz.cast(new PropertyData(properties));
152 element = clazz.cast(new CapabilityTypeData(properties));
155 element = clazz.cast(new RequirementData(properties));
157 case RequirementImpl:
158 element = clazz.cast(new RequirementImplData(properties));
161 element = clazz.cast(new CapabilityData(properties));
164 element = clazz.cast(new CapabilityInstData(properties));
167 element = clazz.cast(new PropertyValueData(properties));
170 element = clazz.cast(new AttributeValueData(properties));
173 element = clazz.cast(new InputValueData(properties));
175 case RelationshipType:
176 element = clazz.cast(new RelationshipTypeData(properties));
179 element = clazz.cast(new GraphNodeLock(properties));
182 element = clazz.cast(new ArtifactData(properties));
185 element = clazz.cast(new InterfaceData(properties));
187 case InterfaceOperation:
188 element = clazz.cast(new OperationData(properties));
191 element = clazz.cast(new InputsData(properties));
193 case ResourceInstance:
194 element = clazz.cast(new ComponentInstanceData(properties));
196 case RelationshipInst:
197 element = clazz.cast(new RelationshipInstData(properties));
199 case AdditionalInfoParameters:
200 element = clazz.cast(new AdditionalInfoParameterData(properties));
202 case ConsumerCredentials:
203 element = clazz.cast(new ConsumerData(properties));
206 element = clazz.cast(new HeatParameterData(properties));
208 case HeatParameterValue:
209 element = clazz.cast(new HeatParameterValueData(properties));
212 element = clazz.cast(new DataTypeData(properties));
215 element = clazz.cast(new GroupData(properties));
218 element = clazz.cast(new GroupTypeData(properties));
220 case UserFunctionalMenu:
221 element = clazz.cast(new UserFunctionalMenuData(properties));
224 element = clazz.cast(new PolicyTypeData(properties));
227 element = clazz.cast(new GroupInstanceData(properties));
230 element = clazz.cast(new AnnotationTypeData(properties));