re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / ComponentInstanceData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.resources.data;
22
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;
28
29 import java.util.HashMap;
30 import java.util.Map;
31
32 public class ComponentInstanceData extends GraphNode {
33
34         ComponentInstanceDataDefinition componentInstDataDefinition;
35         protected Integer groupInstanceCounter;
36
37         public ComponentInstanceData() {
38                 super(NodeTypeEnum.ResourceInstance);
39                 this.componentInstDataDefinition = new ComponentInstanceDataDefinition();
40                 this.groupInstanceCounter = 0;
41         }
42
43         public ComponentInstanceData(ComponentInstanceDataDefinition componentInstDataDefinition) {
44                 super(NodeTypeEnum.ResourceInstance);
45                 this.componentInstDataDefinition = componentInstDataDefinition;
46                 this.groupInstanceCounter = 0;
47         }
48         
49         public ComponentInstanceData(ComponentInstanceDataDefinition componentInstDataDefinition, Integer groupInstanceCounter) {
50                 super(NodeTypeEnum.ResourceInstance);
51                 this.componentInstDataDefinition = componentInstDataDefinition;
52                 this.groupInstanceCounter = groupInstanceCounter;
53         }
54
55         public ComponentInstanceData(Map<String, Object> properties) {
56
57                 this();
58
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());
73         }
74
75         @Override
76         public Map<String, Object> toGraphMap() {
77
78                 Map<String, Object> map = new HashMap<>();
79
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());
94                 }
95                 addIfExists(map, GraphPropertiesDictionary.CUSTOMIZATION_UUID, componentInstDataDefinition.getCustomizationUUID());
96
97                 return map;
98         }
99
100         @Override
101         public String getUniqueId() {
102                 return componentInstDataDefinition.getUniqueId();
103         }
104
105         public String getName() {
106                 return componentInstDataDefinition.getName();
107         }
108
109         @Override
110         public String getUniqueIdKey() {
111                 return GraphPropertiesDictionary.UNIQUE_ID.getProperty();
112         }
113
114         public ComponentInstanceDataDefinition getComponentInstDataDefinition() {
115                 return componentInstDataDefinition;
116         }
117
118         public void setComponentInstDataDefinition(ComponentInstanceDataDefinition componentInstDataDefinition) {
119                 this.componentInstDataDefinition = componentInstDataDefinition;
120         }
121
122         @Override
123         public String toString() {
124                 return "ComponentInstanceData [componentInstDataDefinition=" + componentInstDataDefinition + "]";
125         }
126
127         public Integer getGroupInstanceCounter() {
128                 return groupInstanceCounter;
129         }
130
131         public void setGroupInstanceCounter(Integer componentInstanceCounter) {
132                 this.groupInstanceCounter = componentInstanceCounter;
133         }
134
135         public Integer increaseAndGetGroupInstanceCounter() {
136                 return ++groupInstanceCounter;
137         }
138
139 }