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 com.google.gson.reflect.TypeToken;
24 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
25 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
26 import org.openecomp.sdc.be.dao.utils.Constants;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
30 import java.lang.reflect.Type;
31 import java.util.HashMap;
32 import java.util.List;
35 public class PropertyValueData extends GraphNode {
37 public PropertyValueData() {
38 super(NodeTypeEnum.PropertyValue);
41 public PropertyValueData(Map<String, Object> properties) {
44 this.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
46 String updatedValue = (String) properties.get(GraphPropertiesDictionary.VALUE.getProperty());
47 if (Constants.GRAPH_EMPTY_VALUE.equals(updatedValue)) {
50 this.setValue(updatedValue);
53 this.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
55 this.setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
57 this.setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
59 Type mapType = new TypeToken<List<PropertyRule>>() {
61 List<PropertyRule> propertyRules = getGson().fromJson(
62 (String) properties.get(GraphPropertiesDictionary.PROPERTY_VALUE_RULES.getProperty()), mapType);
63 this.setRules(propertyRules);
67 private String uniqueId;
73 private Long creationTime;
75 private Long modificationTime;
77 private List<PropertyRule> rules;
80 public String getUniqueId() {
84 public void setUniqueId(String uniqueId) {
85 this.uniqueId = uniqueId;
88 public String getType() {
92 public void setType(String type) {
96 public Long getCreationTime() {
100 public void setCreationTime(Long creationTime) {
101 this.creationTime = creationTime;
104 public Long getModificationTime() {
105 return modificationTime;
108 public void setModificationTime(Long modificationTime) {
109 this.modificationTime = modificationTime;
112 public String getValue() {
116 public void setValue(String value) {
120 public List<PropertyRule> getRules() {
124 public void setRules(List<PropertyRule> rules) {
129 public Map<String, Object> toGraphMap() {
131 Map<String, Object> map = new HashMap<>();
133 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, uniqueId);
135 String updatedValue = value;
136 if (updatedValue == null) {
137 updatedValue = Constants.GRAPH_EMPTY_VALUE;
139 addIfExists(map, GraphPropertiesDictionary.VALUE, updatedValue);
141 addIfExists(map, GraphPropertiesDictionary.TYPE, type);
143 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, creationTime);
145 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, modificationTime);
147 addIfExists(map, GraphPropertiesDictionary.PROPERTY_VALUE_RULES, rules);
153 public String toString() {
154 return "PropertyValueData [uniqueId=" + uniqueId + ", value=" + value + ", type=" + type + ", creationTime="
155 + creationTime + ", modificationTime=" + modificationTime + ", rules=" + rules + "]";