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()));
68 policyTypeDataDefinition
69 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
71 policyTypeDataDefinition.setHighestVersion(
72 (boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
74 policyTypeDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
76 policyTypeDataDefinition
77 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
79 policyTypeDataDefinition
80 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
85 public Map<String, Object> toGraphMap() {
87 Map<String, Object> map = new HashMap<String, Object>();
89 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, policyTypeDataDefinition.getUniqueId());
91 addIfExists(map, GraphPropertiesDictionary.TYPE, policyTypeDataDefinition.getType());
93 addIfExists(map, GraphPropertiesDictionary.VERSION, policyTypeDataDefinition.getVersion());
95 addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, policyTypeDataDefinition.isHighestVersion());
97 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, policyTypeDataDefinition.getDescription());
99 addIfExists(map, GraphPropertiesDictionary.METADATA, policyTypeDataDefinition.getMetadata());
101 addIfExists(map, GraphPropertiesDictionary.TARGETS, policyTypeDataDefinition.getTargets());
103 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, policyTypeDataDefinition.getCreationTime());
105 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, policyTypeDataDefinition.getModificationTime());
111 public String toString() {
112 return "PolicyTypeData [policyTypeDataDefinition=" + policyTypeDataDefinition + "]";
116 public String getUniqueId() {
117 return this.policyTypeDataDefinition.getUniqueId();
120 public PolicyTypeDataDefinition getPolicyTypeDataDefinition() {
121 return policyTypeDataDefinition;