Sync Integ to Master
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / ConsumerData.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.ConsumerDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class ConsumerData extends GraphNode {
32
33         private ConsumerDataDefinition consumerDataDefinition;
34
35         public ConsumerData() {
36                 super(NodeTypeEnum.ConsumerCredentials);
37                 consumerDataDefinition = new ConsumerDataDefinition();
38         }
39
40         public ConsumerData(ConsumerDataDefinition consumerDataDefinition) {
41                 super(NodeTypeEnum.ConsumerCredentials);
42                 this.consumerDataDefinition = consumerDataDefinition;
43
44         }
45
46         public ConsumerData(Map<String, Object> properties) {
47                 super(NodeTypeEnum.ConsumerCredentials);
48                 consumerDataDefinition = new ConsumerDataDefinition();
49                 consumerDataDefinition.setConsumerDetailsLastupdatedtime(
50                                 (Long) properties.get(GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME.getProperty()));
51                 consumerDataDefinition.setConsumerLastAuthenticationTime(
52                                 (Long) properties.get(GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME.getProperty()));
53                 consumerDataDefinition
54                                 .setConsumerName((String) properties.get(GraphPropertiesDictionary.CONSUMER_NAME.getProperty()));
55                 consumerDataDefinition.setConsumerPassword(
56                                 (String) properties.get(GraphPropertiesDictionary.CONSUMER_PASSWORD.getProperty()));
57                 consumerDataDefinition
58                                 .setConsumerSalt((String) properties.get(GraphPropertiesDictionary.CONSUMER_SALT.getProperty()));
59                 consumerDataDefinition.setLastModfierAtuid(
60                                 (String) properties.get(GraphPropertiesDictionary.LAST_MODIFIER_USER_ID.getProperty()));
61
62         }
63
64         @Override
65         public String getUniqueIdKey() {
66                 return GraphPropertiesDictionary.CONSUMER_NAME.getProperty();
67         }
68
69         @Override
70         public String getUniqueId() {
71                 return consumerDataDefinition.getConsumerName();
72         }
73
74         public ConsumerDataDefinition getConsumerDataDefinition() {
75                 return consumerDataDefinition;
76         }
77
78         @Override
79         public Map<String, Object> toGraphMap() {
80                 Map<String, Object> map = new HashMap<String, Object>();
81                 addIfExists(map, GraphPropertiesDictionary.CONSUMER_NAME, this.consumerDataDefinition.getConsumerName());
82                 addIfExists(map, GraphPropertiesDictionary.CONSUMER_PASSWORD,
83                                 this.consumerDataDefinition.getConsumerPassword());
84                 addIfExists(map, GraphPropertiesDictionary.CONSUMER_SALT, this.consumerDataDefinition.getConsumerSalt());
85                 addIfExists(map, GraphPropertiesDictionary.CONSUMER_LAST_AUTHENTICATION_TIME,
86                                 this.consumerDataDefinition.getConsumerLastAuthenticationTime());
87                 addIfExists(map, GraphPropertiesDictionary.CONSUMER_DETAILS_LAST_UPDATED_TIME,
88                                 this.consumerDataDefinition.getConsumerDetailsLastupdatedtime());
89                 addIfExists(map, GraphPropertiesDictionary.LAST_MODIFIER_USER_ID,
90                                 this.consumerDataDefinition.getLastModfierAtuid());
91
92                 return map;
93         }
94
95         @Override
96         public String toString() {
97                 return "ConsumerData [consumerDataDefinition=" + consumerDataDefinition + "]";
98         }
99 }