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.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;
35 public class GraphElementFactory {
37 public static <T extends GraphNode> T createElement(String label, GraphElementTypeEnum type,
38 Map<String, Object> properties, Class<T> clazz) {
41 if (type.equals(GraphElementTypeEnum.Node)) {
42 element = createNode(label, properties, clazz);
47 public static GraphNode createElement(String label, GraphElementTypeEnum type, Map<String, Object> properties) {
48 GraphNode element = null;
50 if (type.equals(GraphElementTypeEnum.Node)) {
51 element = createNode(label, properties);
56 public static GraphRelation createRelation(String type, Map<String, Object> properties, GraphNode from,
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(),
63 element.setFrom(endPOintFrom);
64 element.setTo(endPOintTo);
65 element.addPropertis(properties);
69 private static GraphNode createNode(String label, Map<String, Object> properties) {
70 GraphNode element = null;
71 NodeTypeEnum type = NodeTypeEnum.getByName(label);
75 element = new UserData(properties);
77 case ResourceCategory:
78 element = new ResourceCategoryData(properties);
81 element = new ServiceCategoryData(properties);
84 element = new TagData(properties);
87 element = new ServiceMetadataData(properties);
90 element = new ResourceMetadataData(properties);
93 element = new PropertyData(properties);
96 element = new HeatParameterData(properties);
98 case HeatParameterValue:
99 element = new HeatParameterValueData(properties);
106 private static <T extends GraphNode> T createNode(String label, Map<String, Object> properties, Class<T> clazz) {
108 NodeTypeEnum type = NodeTypeEnum.getByName(label);
112 element = clazz.cast(new UserData(properties));
114 case ResourceCategory:
115 element = clazz.cast(new ResourceCategoryData(properties));
117 case ServiceCategory:
118 element = clazz.cast(new ServiceCategoryData(properties));
120 case ResourceNewCategory:
121 case ServiceNewCategory:
122 case ProductCategory:
123 element = clazz.cast(new CategoryData(properties));
125 case ResourceSubcategory:
126 case ProductSubcategory:
127 element = clazz.cast(new SubCategoryData(properties));
129 case ProductGrouping:
130 element = clazz.cast(new GroupingData(properties));
133 element = clazz.cast(new TagData(properties));
136 element = clazz.cast(new ServiceMetadataData(properties));
139 element = clazz.cast(new ProductMetadataData(properties));
142 element = clazz.cast(new ResourceMetadataData(properties));
145 element = clazz.cast(new AttributeData(properties));
148 element = clazz.cast(new PropertyData(properties));
151 element = clazz.cast(new CapabilityTypeData(properties));
154 element = clazz.cast(new RequirementData(properties));
156 case RequirementImpl:
157 element = clazz.cast(new RequirementImplData(properties));
160 element = clazz.cast(new CapabilityData(properties));
163 element = clazz.cast(new CapabilityInstData(properties));
166 element = clazz.cast(new PropertyValueData(properties));
169 element = clazz.cast(new AttributeValueData(properties));
172 element = clazz.cast(new InputValueData(properties));
174 case RelationshipType:
177 element = clazz.cast(new GraphNodeLock(properties));
180 element = clazz.cast(new ArtifactData(properties));
183 element = clazz.cast(new InterfaceData(properties));
185 case InterfaceOperation:
186 element = clazz.cast(new OperationData(properties));
189 element = clazz.cast(new InputsData(properties));
191 case ResourceInstance:
192 element = clazz.cast(new ComponentInstanceData(properties));
194 case RelationshipInst:
195 element = clazz.cast(new RelationshipInstData(properties));
197 case AdditionalInfoParameters:
198 element = clazz.cast(new AdditionalInfoParameterData(properties));
200 case ConsumerCredentials:
201 element = clazz.cast(new ConsumerData(properties));
204 element = clazz.cast(new HeatParameterData(properties));
206 case HeatParameterValue:
207 element = clazz.cast(new HeatParameterValueData(properties));
210 element = clazz.cast(new DataTypeData(properties));
213 element = clazz.cast(new GroupData(properties));
216 element = clazz.cast(new GroupTypeData(properties));
218 case UserFunctionalMenu:
219 element = clazz.cast(new UserFunctionalMenuData(properties));
222 element = clazz.cast(new PolicyTypeData(properties));
225 element = clazz.cast(new GroupInstanceData(properties));
228 element = clazz.cast(new AnnotationTypeData(properties));