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.resources.data;
23 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
29 import java.util.HashMap;
32 public class ComponentInstanceData extends GraphNode {
34 ComponentInstanceDataDefinition componentInstDataDefinition;
35 protected Integer groupInstanceCounter;
37 public ComponentInstanceData() {
38 super(NodeTypeEnum.ResourceInstance);
39 this.componentInstDataDefinition = new ComponentInstanceDataDefinition();
40 this.groupInstanceCounter = 0;
43 public ComponentInstanceData(ComponentInstanceDataDefinition componentInstDataDefinition) {
44 super(NodeTypeEnum.ResourceInstance);
45 this.componentInstDataDefinition = componentInstDataDefinition;
46 this.groupInstanceCounter = 0;
49 public ComponentInstanceData(ComponentInstanceDataDefinition componentInstDataDefinition, Integer groupInstanceCounter) {
50 super(NodeTypeEnum.ResourceInstance);
51 this.componentInstDataDefinition = componentInstDataDefinition;
52 this.groupInstanceCounter = groupInstanceCounter;
55 public ComponentInstanceData(Map<String, Object> properties) {
59 componentInstDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
60 componentInstDataDefinition.setComponentUid((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
61 componentInstDataDefinition.setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
62 componentInstDataDefinition.setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
63 componentInstDataDefinition.setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
64 componentInstDataDefinition.setPosX((String) properties.get(GraphPropertiesDictionary.POSITION_X.getProperty()));
65 componentInstDataDefinition.setPosY((String) properties.get(GraphPropertiesDictionary.POSITION_Y.getProperty()));
66 componentInstDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
67 componentInstDataDefinition.setPropertyValueCounter((Integer) properties.get(GraphPropertiesDictionary.PROPERTY_COUNTER.getProperty()));
68 componentInstDataDefinition.setAttributeValueCounter((Integer) properties.get(GraphPropertiesDictionary.ATTRIBUTE_COUNTER.getProperty()));
69 componentInstDataDefinition.setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
70 componentInstDataDefinition.setOriginType(OriginTypeEnum.findByValue((String) properties.get(GraphPropertiesDictionary.ORIGIN_TYPE.getProperty())));
71 componentInstDataDefinition.setCustomizationUUID((String) properties.get(GraphPropertiesDictionary.CUSTOMIZATION_UUID.getProperty()));
72 groupInstanceCounter = (Integer) properties.get(GraphPropertiesDictionary.INSTANCE_COUNTER.getProperty());
76 public Map<String, Object> toGraphMap() {
78 Map<String, Object> map = new HashMap<>();
80 addIfExists(map, GraphPropertiesDictionary.TYPE, componentInstDataDefinition.getComponentUid());
81 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, componentInstDataDefinition.getCreationTime());
82 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, componentInstDataDefinition.getModificationTime());
83 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, componentInstDataDefinition.getDescription());
84 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, componentInstDataDefinition.getUniqueId());
85 addIfExists(map, GraphPropertiesDictionary.POSITION_X, componentInstDataDefinition.getPosX());
86 addIfExists(map, GraphPropertiesDictionary.POSITION_Y, componentInstDataDefinition.getPosY());
87 addIfExists(map, GraphPropertiesDictionary.NAME, componentInstDataDefinition.getName());
88 addIfExists(map, GraphPropertiesDictionary.PROPERTY_COUNTER, componentInstDataDefinition.getPropertyValueCounter());
89 addIfExists(map, GraphPropertiesDictionary.ATTRIBUTE_COUNTER, componentInstDataDefinition.getAttributeValueCounter());
90 addIfExists(map, GraphPropertiesDictionary.INSTANCE_COUNTER, groupInstanceCounter);
91 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, componentInstDataDefinition.getNormalizedName());
92 if (componentInstDataDefinition.getOriginType() != null) {
93 addIfExists(map, GraphPropertiesDictionary.ORIGIN_TYPE, componentInstDataDefinition.getOriginType().getValue());
95 addIfExists(map, GraphPropertiesDictionary.CUSTOMIZATION_UUID, componentInstDataDefinition.getCustomizationUUID());
101 public String getUniqueId() {
102 return componentInstDataDefinition.getUniqueId();
105 public String getName() {
106 return componentInstDataDefinition.getName();
110 public String getUniqueIdKey() {
111 return GraphPropertiesDictionary.UNIQUE_ID.getProperty();
114 public ComponentInstanceDataDefinition getComponentInstDataDefinition() {
115 return componentInstDataDefinition;
118 public void setComponentInstDataDefinition(ComponentInstanceDataDefinition componentInstDataDefinition) {
119 this.componentInstDataDefinition = componentInstDataDefinition;
123 public String toString() {
124 return "ComponentInstanceData [componentInstDataDefinition=" + componentInstDataDefinition + "]";
127 public Integer getGroupInstanceCounter() {
128 return groupInstanceCounter;
131 public void setGroupInstanceCounter(Integer componentInstanceCounter) {
132 this.groupInstanceCounter = componentInstanceCounter;
135 public Integer increaseAndGetGroupInstanceCounter() {
136 return ++groupInstanceCounter;