3edd3bacc411182cddd90c92f19e7acd16dec582
[ui/dmaapbc.git] /
1 package org.openecomp.dcae.dmaapbc.dbcapp.domain;
2
3 import org.openecomp.portalsdk.core.domain.support.DomainVo;
4 import org.openecomp.portalsdk.core.onboarding.util.CipherUtil;
5
6 /**
7  * Hold an access profile for a DMaaP REST endpoint. Represents one row in the
8  * DBCA_DMAAP table.
9  */
10 public class DmaapAccess extends DomainVo {
11
12         private static final long serialVersionUID = 6443219375733216340L;
13
14         // parent class defines these fields:
15         // ID, created, modified, created_id, modified_id
16
17         /** Login ID for user who owns this row */
18         private String userId;
19         /** Nickname for this row */
20         private String name;
21         /** REST API endpoint */
22         private String dmaapUrl;
23         /** Credentials */
24         private String mechId;
25         /** Credentials */
26         private String password;
27         /** User's preferred access profile */
28         private boolean selected;
29
30         /**
31          * Standard POJO no-arg constructor
32          */
33         public DmaapAccess() {
34         }
35
36         /**
37          * Copy constructor
38          * 
39          * @param copy
40          *            Instance to copy
41          */
42         public DmaapAccess(final DmaapAccess copy) {
43                 // Unfortunately DomainVo doesn't provide a copy constructor;
44                 // only the ID field is needed.
45                 this.id = copy.id;
46                 // Our fields
47                 this.userId = copy.userId;
48                 this.name = copy.name;
49                 this.dmaapUrl = copy.dmaapUrl;
50                 this.mechId = copy.mechId;
51                 this.password = copy.password;
52                 this.selected = copy.selected;
53         }
54
55         public String getUserId() {
56                 return userId;
57         }
58
59         public void setUserId(String userId) {
60                 this.userId = userId;
61         }
62
63         public String getName() {
64                 return name;
65         }
66
67         public void setName(String name) {
68                 this.name = name;
69         }
70
71         public String getDmaapUrl() {
72                 return dmaapUrl;
73         }
74
75         public void setDmaapUrl(String dmaapUrl) {
76                 this.dmaapUrl = dmaapUrl;
77         }
78
79         public String getMechId() {
80                 return mechId;
81         }
82
83         public void setMechId(String mechId) {
84                 this.mechId = mechId;
85         }
86
87         /**
88          * Gets the encrypted password. Applications should use
89          * {@link #decryptPassword()}!
90          * 
91          * @return The encrypted password
92          */
93         public String getPassword() {
94                 return password;
95         }
96
97         /**
98          * Sets the encrypted password. Applications should use
99          * {@link #encryptPassword(String)}!
100          * 
101          * @param password
102          *            The encrypted password
103          */
104         public void setPassword(String password) {
105                 this.password = password;
106         }
107
108         public boolean getSelected() {
109                 return selected;
110         }
111
112         public void setSelected(boolean selected) {
113                 this.selected = selected;
114         }
115
116         /**
117          * A getter that decrypts the value read from the database and returns the
118          * clear text. Has no side effects.
119          * 
120          * @return Clear-text password.
121          * @throws Exception
122          *             If the password cannot be decrypted
123          */
124         public String decryptPassword() throws Exception {
125                 if (password == null)
126                         return null;
127                 return CipherUtil.decrypt(password);
128         }
129
130         /**
131          * A setter that encrypts the clear-text in preparation for storing in the
132          * database.
133          * 
134          * @param clearText
135          *            The clear-text password to be encrypted
136          * @throws Exception
137          *             If the password cannot be encrypted
138          */
139         public void encryptPassword(String clearText) throws Exception {
140                 if (clearText == null) {
141                         password = null;
142                         return;
143                 }
144                 password = CipherUtil.encrypt(clearText);
145         }
146
147         @Override
148         public String toString() {
149                 return "DmaapAccess[id=" + id + ", url=" + dmaapUrl + ", ...]";
150         }
151
152 }