/
AccountFactory.java
221 lines (188 loc) · 4.88 KB
/
AccountFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package org.georchestra.ldapadmin.dto;
/**
* Account factory.
*
* <p>
* This factory provide the convenient account object (data transfer object) used by this application.
* </p>
*
* @author Mauricio Pazos
*
*/
public class AccountFactory {
private AccountFactory(){}
public static String formatCommonName(String givenName, String surname) {
return givenName + " " + surname;
}
/**
* Brief data
*
* @param uid
* @param password
* @param firstName
* @param surname
* @param email
* @param phone
* @param org
* @param description
* @return
*/
public static Account createBrief(
String uid,
String password,
String firstName,
String surname,
String email,
String phone,
String org,
String title,
String description) {
Account account = new AccountImpl();
account.setUid(uid);
account.setPassword(password);
account.setGivenName(firstName);
account.setSurname(surname);
account.setCommonName(formatCommonName(firstName ,surname));
account.setEmail(email);
account.setPhone(phone);
account.setOrg(org);
account.setTitle(title);
account.setDescription(description);
return account;
}
/**
* Creates an account object with detailed data.
*/
public static Account createDetails(
String uid,
String givenName,
String surname,
String org,
String physicalDeliveryOfficeName,
String postalAddress,
String postalCode,
String postOfficeBox,
String registeredAddress,
String title) {
Account a = new AccountImpl();
a.setUid(uid);
a.setGivenName(givenName);
a.setSurname(surname);
a.setCommonName(formatCommonName(givenName, surname) );
a.setOrg(org);
a.setPhysicalDeliveryOfficeName(physicalDeliveryOfficeName);
a.setPostalAddress(postalAddress);
a.setPostalCode(postalCode);
a.setPostOfficeBox(postOfficeBox);
a.setRegisteredAddress(registeredAddress);
a.setTitle(title);
return a;
}
/**
* Creates an account object with all data.
*
* @param uid
* @param cn full name
* @param surname surname
* @param givenName first name
* @param email
* @param org
* @param title
* @param phone
* @param description
* @param postalAddress
* @param postalCode
* @param registeredAddress
* @param postOfficeBox
* @param physicalDeliveryOfficeName
* @param locality
* @param street
* @param facsimile
* @param organizationalUnit
* @param mobile
* @param roomNumber
*
* @return {@link Account}
*/
public static Account createFull(
String uid,
String cn,
String surname,
String givenName,
String email,
String org,
String title,
String phone,
String description,
String postalAddress,
String postalCode,
String registeredAddress ,
String postOfficeBox,
String physicalDeliveryOfficeName,
String street,
String locality,
String facsimile,
String organizationalUnit,
String homePostalAddress,
String mobile,
String roomNumber,
String stateOrProvince) {
Account a = new AccountImpl();
a.setUid(uid);
a.setCommonName(cn);
a.setGivenName(givenName);
a.setSurname(surname);
a.setEmail(email);
a.setOrg(org);
a.setTitle(title);
a.setPhone(phone);
a.setDescription(description);
a.setStreet(street);
a.setLocality(locality);
a.setPostalAddress(postalAddress);
a.setPostalCode(postalCode);
a.setRegisteredAddress(registeredAddress);
a.setPostOfficeBox(postOfficeBox);
a.setPhysicalDeliveryOfficeName(physicalDeliveryOfficeName);
a.setFacsimile(facsimile);
a.setOrganizationalUnit(organizationalUnit);
a.setHomePostalAddress(homePostalAddress);
a.setMobile(mobile);
a.setRoomNumber(roomNumber);
a.setStateOrProvince(stateOrProvince);
return a;
}
/**
* Creates an account object from another one, given as argument.
*
* @param o other account to copy
*/
public static Account create(Account o) {
Account a = new AccountImpl();
a.setUid(o.getUid());
a.setCommonName(o.getCommonName());
a.setSurname(o.getSurname());
a.setOrg(o.getOrg());
a.setEmail(o.getEmail());
a.setPhone(o.getPhone());
a.setDescription(o.getDescription());
// passwords / new passwords fields voluntarily omitted:
// the password update process should not go through this.
a.setGivenName(o.getGivenName());
a.setTitle(o.getTitle());
a.setPostalAddress(o.getPostalAddress());
a.setPostalCode(o.getPostalCode());
a.setRegisteredAddress(o.getRegisteredAddress());
a.setPostOfficeBox(o.getPostOfficeBox());
a.setPhysicalDeliveryOfficeName(o.getPhysicalDeliveryOfficeName());
a.setStreet(o.getStreet());
a.setLocality(o.getLocality());
a.setFacsimile(o.getFacsimile());
a.setMobile(o.getMobile());
a.setRoomNumber(o.getRoomNumber());
a.setStateOrProvince(o.getStateOrProvince());
a.setOrganizationalUnit(o.getOrganizationalUnit());
a.setHomePostalAddress(o.getHomePostalAddress());
return a;
}
}