Catalog alignment
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / ConsumerData.java
1 package org.openecomp.sdc.be.resources.data;
2 /*-
3  * ============LICENSE_START=======================================================
4  * SDC
5  * ================================================================================
6  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 import org.apache.commons.lang3.tuple.ImmutablePair;
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<>();
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     //added to handle fortify security violation - t avoid printing consumer data to log
96     @Override
97     public ImmutablePair<String, Object> getKeyValueIdForLog() {
98         return new ImmutablePair<>(getUniqueIdKey(), "consumerName");
99     }
100
101     @Override
102     public String toString() {
103         return "ConsumerData [consumerDataDefinition=" + consumerDataDefinition + "]";
104     }
105 }
106
107