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