001/*
002 * (C) Copyright 2011 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 * Contributors:
014 * Nuxeo - initial API and implementation
015 */
016
017package org.nuxeo.ecm.user.invite;
018
019import org.apache.commons.lang.StringUtils;
020import org.apache.commons.logging.Log;
021import org.apache.commons.logging.LogFactory;
022import org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XObject;
024
025@XObject("configuration")
026public class UserRegistrationConfiguration {
027
028    private static Log log = LogFactory.getLog(UserRegistrationConfiguration.class);
029
030    public static final String DEFAULT_CONFIGURATION_NAME = "default_registration";
031
032    @XNode("@merge")
033    private boolean merge = false;
034
035    @XNode("@remove")
036    private boolean remove = false;
037
038    @XNode("@name")
039    private String name = DEFAULT_CONFIGURATION_NAME;
040
041    @XNode("requestDocType")
042    private String requestDocType;
043
044    @XNode("userInfo/schemaName")
045    private String userInfoSchemaName = "userinfo";
046
047    @XNode("userInfo/usernameField")
048    private String userInfoUsernameField = "userinfo:login";
049
050    @XNode("userInfo/emailField")
051    private String userInfoEmailField = "userinfo:email";
052
053    @XNode("userInfo/firstnameField")
054    private String userInfoFirstnameField = "userinfo:firstName";
055
056    @XNode("userInfo/lastnameField")
057    private String userInfoLastnameField = "userinfo:lastName";
058
059    @XNode("userInfo/companyField")
060    private String userInfoCompanyField = "userinfo:company";
061
062    /**
063     * @deprecated since 7.3. Not used anymore, the password is not stored.
064     */
065    @Deprecated
066    @XNode("userInfo/passwordField")
067    private String userInfoPasswordField = "userinfo:password";
068
069    @XNode("userInfo/groupsField")
070    private String userInfoGroupsField = "userinfo:groups";
071
072    @XNode("container/docType")
073    private String containerDocType;
074
075    @XNode("container/parentPath")
076    private String containerParentPath;
077
078    @XNode("container/name")
079    private String containerName;
080
081    @XNode("container/title")
082    private String containerTitle;
083
084    @XNode("validationEmail/title")
085    private String validationEmailTitle;
086
087    @XNode("validationEmail/template")
088    private String validationEmailTemplate;
089
090    @XNode("successEmail/title")
091    private String successEmailTitle;
092
093    @XNode("successEmail/template")
094    private String successEmailTemplate;
095
096    @XNode("reviveEmail/title")
097    private String reviveEmailTitle;
098
099    @XNode("reviveEmail/template")
100    private String reviveEmailTemplate;
101
102    @XNode("registrationUserFactory")
103    private Class<? extends InvitationUserFactory> registrationUserFactory;
104
105    @XNode("validationRelUrl")
106    private String validationRelUrl;
107
108    @XNode("enterPasswordUrl")
109    private String enterPasswordUrl;
110
111    @XNode("invitationLayout")
112    private String invitationLayout = "user_invitation_info";
113
114    @XNode("listingContentView")
115    private String listingLocalContentView = "local_user_requests_view";
116
117    public String getRequestDocType() {
118        return requestDocType;
119    }
120
121    public String getContainerDocType() {
122        return containerDocType;
123    }
124
125    public String getContainerParentPath() {
126        return containerParentPath;
127    }
128
129    public String getContainerName() {
130        return containerName;
131    }
132
133    public String getContainerTitle() {
134        return containerTitle;
135    }
136
137    public String getValidationEmailTitle() {
138        return validationEmailTitle;
139    }
140
141    public String getValidationEmailTemplate() {
142        return validationEmailTemplate;
143    }
144
145    public String getSuccessEmailTitle() {
146        return successEmailTitle;
147    }
148
149    public String getSuccessEmailTemplate() {
150        return successEmailTemplate;
151    }
152
153    public Class<? extends InvitationUserFactory> getRegistrationUserFactory() {
154        return registrationUserFactory;
155    }
156
157    public String getValidationRelUrl() {
158        if (StringUtils.isBlank(validationRelUrl)) {
159            log.info("Configuration " + name + " has empty validation url");
160            return "";
161        }
162        return validationRelUrl;
163    }
164
165    public String getEnterPasswordUrl() {
166        if (StringUtils.isBlank(enterPasswordUrl)) {
167            log.info("Configuration " + name + " has empty validation url");
168            return "";
169        }
170        if (enterPasswordUrl.startsWith("/")) {
171            enterPasswordUrl = enterPasswordUrl.substring(1);
172        }
173        return enterPasswordUrl;
174    }
175
176    public String getReviveEmailTitle() {
177        return reviveEmailTitle;
178    }
179
180    public String getReviveEmailTemplate() {
181        return reviveEmailTemplate;
182    }
183
184    public String getUserInfoSchemaName() {
185        return userInfoSchemaName;
186    }
187
188    public String getUserInfoUsernameField() {
189        return userInfoUsernameField;
190    }
191
192    public String getUserInfoEmailField() {
193        return userInfoEmailField;
194    }
195
196    public String getUserInfoFirstnameField() {
197        return userInfoFirstnameField;
198    }
199
200    public String getUserInfoLastnameField() {
201        return userInfoLastnameField;
202    }
203
204    public String getUserInfoCompanyField() {
205        return userInfoCompanyField;
206    }
207
208    public String getUserInfoPasswordField() {
209        return userInfoPasswordField;
210    }
211
212    public String getUserInfoGroupsField() {
213        return userInfoGroupsField;
214    }
215
216    public String getName() {
217        return name;
218    }
219
220    public void setName(String name) {
221        this.name = name;
222    }
223
224    public boolean isMerge() {
225        return merge;
226    }
227
228    public void setMerge(boolean merge) {
229        this.merge = merge;
230    }
231
232    public boolean isRemove() {
233        return remove;
234    }
235
236    public void setRemove(boolean remove) {
237        this.remove = remove;
238    }
239
240    public String getInvitationLayout() {
241        return invitationLayout;
242    }
243
244    public void setInvitationLayout(String invitationLayout) {
245        this.invitationLayout = invitationLayout;
246    }
247
248    public String getListingLocalContentView() {
249        return listingLocalContentView;
250    }
251
252    public void setListingLocalContentView(String listingLocalContentView) {
253        this.listingLocalContentView = listingLocalContentView;
254    }
255
256    public void mergeWith(UserRegistrationConfiguration other) {
257        if (!StringUtils.isEmpty(other.requestDocType)) {
258            this.requestDocType = other.requestDocType;
259        }
260
261        if (!StringUtils.isEmpty(other.containerDocType)) {
262            this.containerDocType = other.containerDocType;
263        }
264
265        if (!StringUtils.isEmpty(other.containerParentPath)) {
266            this.containerParentPath = other.containerParentPath;
267        }
268
269        if (!StringUtils.isEmpty(other.containerName)) {
270            this.containerName = other.containerName;
271        }
272
273        if (!StringUtils.isEmpty(other.containerTitle)) {
274            this.containerTitle = other.containerTitle;
275        }
276
277        if (!StringUtils.isEmpty(other.validationEmailTitle)) {
278            this.validationEmailTitle = other.validationEmailTitle;
279        }
280
281        if (!StringUtils.isEmpty(other.validationEmailTemplate)) {
282            this.validationEmailTemplate = other.validationEmailTemplate;
283        }
284
285        if (!StringUtils.isEmpty(other.successEmailTitle)) {
286            this.successEmailTitle = other.successEmailTitle;
287        }
288
289        if (!StringUtils.isEmpty(other.successEmailTemplate)) {
290            this.successEmailTemplate = other.successEmailTemplate;
291        }
292
293        if (!StringUtils.isEmpty(other.reviveEmailTitle)) {
294            this.reviveEmailTitle = other.reviveEmailTitle;
295        }
296
297        if (!StringUtils.isEmpty(other.reviveEmailTemplate)) {
298            this.reviveEmailTemplate = other.reviveEmailTemplate;
299        }
300
301        if (other.getRegistrationUserFactory() != null) {
302            this.registrationUserFactory = other.registrationUserFactory;
303        }
304
305        if (!StringUtils.isEmpty(other.validationRelUrl)) {
306            this.validationRelUrl = other.validationRelUrl;
307        }
308
309        if (!StringUtils.isEmpty(other.enterPasswordUrl)) {
310            this.enterPasswordUrl = other.enterPasswordUrl;
311        }
312
313        if (!StringUtils.isEmpty(other.invitationLayout)) {
314            this.invitationLayout = other.invitationLayout;
315        }
316
317        if (!StringUtils.isEmpty(other.listingLocalContentView)) {
318            this.listingLocalContentView = other.listingLocalContentView;
319        }
320
321        if (!StringUtils.isEmpty(other.userInfoSchemaName)) {
322            this.userInfoSchemaName = other.userInfoSchemaName;
323        }
324
325        if (!StringUtils.isEmpty(other.userInfoUsernameField)) {
326            this.userInfoUsernameField = other.userInfoUsernameField;
327        }
328
329        if (!StringUtils.isEmpty(other.userInfoFirstnameField)) {
330            this.userInfoFirstnameField = other.userInfoFirstnameField;
331        }
332
333        if (!StringUtils.isEmpty(other.userInfoLastnameField)) {
334            this.userInfoLastnameField = other.userInfoLastnameField;
335        }
336
337        if (!StringUtils.isEmpty(other.userInfoEmailField)) {
338            this.userInfoEmailField = other.userInfoEmailField;
339        }
340
341        if (!StringUtils.isEmpty(other.userInfoPasswordField)) {
342            this.userInfoPasswordField = other.userInfoPasswordField;
343        }
344
345        if (!StringUtils.isEmpty(other.userInfoCompanyField)) {
346            this.userInfoCompanyField = other.userInfoCompanyField;
347        }
348
349        if (!StringUtils.isEmpty(other.userInfoGroupsField)) {
350            this.userInfoGroupsField = other.userInfoGroupsField;
351        }
352    }
353}