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.datatypes.elements.PolicyTypeDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import java.lang.reflect.Type;
30 import java.util.HashMap;
31 import java.util.List;
34 public class PolicyTypeData extends GraphNode {
36 private PolicyTypeDataDefinition policyTypeDataDefinition;
37 private static final Type mapType = new TypeToken<HashMap<String, String>>() {
39 private static final Type listType = new TypeToken<List<String>>() {
42 public PolicyTypeData() {
43 super(NodeTypeEnum.PolicyType);
44 policyTypeDataDefinition = new PolicyTypeDataDefinition();
47 public PolicyTypeData(PolicyTypeDataDefinition policyTypeDataDefinition) {
48 super(NodeTypeEnum.PolicyType);
49 this.policyTypeDataDefinition = policyTypeDataDefinition;
52 public PolicyTypeData(Map<String, Object> properties) {
56 policyTypeDataDefinition
57 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
59 HashMap<String, String> metatdata = getGson()
60 .fromJson((String) properties.get(GraphPropertiesDictionary.METADATA.getProperty()), mapType);
61 policyTypeDataDefinition.setMetadata(metatdata);
63 List<String> members = getGson()
64 .fromJson((String) properties.get(GraphPropertiesDictionary.TARGETS.getProperty()), listType);
65 policyTypeDataDefinition.setTargets(members);
66 policyTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
67 policyTypeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
68 policyTypeDataDefinition.setIcon((String) properties.get(GraphPropertiesDictionary.ICON.getProperty()));
69 policyTypeDataDefinition
70 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
72 if (properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) != null) {
73 policyTypeDataDefinition.setHighestVersion(
74 (boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
77 policyTypeDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
79 policyTypeDataDefinition
80 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
82 policyTypeDataDefinition
83 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
88 public Map<String, Object> toGraphMap() {
90 Map<String, Object> map = new HashMap<>();
92 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, policyTypeDataDefinition.getUniqueId());
94 addIfExists(map, GraphPropertiesDictionary.TYPE, policyTypeDataDefinition.getType());
96 addIfExists(map, GraphPropertiesDictionary.NAME, policyTypeDataDefinition.getName());
98 addIfExists(map, GraphPropertiesDictionary.ICON, policyTypeDataDefinition.getIcon());
100 addIfExists(map, GraphPropertiesDictionary.VERSION, policyTypeDataDefinition.getVersion());
102 addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, policyTypeDataDefinition.isHighestVersion());
104 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, policyTypeDataDefinition.getDescription());
106 addIfExists(map, GraphPropertiesDictionary.METADATA, policyTypeDataDefinition.getMetadata());
108 addIfExists(map, GraphPropertiesDictionary.TARGETS, policyTypeDataDefinition.getTargets());
110 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, policyTypeDataDefinition.getCreationTime());
112 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, policyTypeDataDefinition.getModificationTime());
118 public String toString() {
119 return "PolicyTypeData [policyTypeDataDefinition=" + policyTypeDataDefinition + "]";
123 public String getUniqueId() {
124 return this.policyTypeDataDefinition.getUniqueId();
127 public PolicyTypeDataDefinition getPolicyTypeDataDefinition() {
128 return policyTypeDataDefinition;