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 java.io.Serializable;
020import java.util.List;
021import java.util.Map;
022import java.util.Set;
023
024import org.nuxeo.ecm.core.api.CoreSession;
025import org.nuxeo.ecm.core.api.DocumentModel;
026import org.nuxeo.ecm.core.api.DocumentModelList;
027import org.nuxeo.ecm.core.api.NuxeoPrincipal;
028
029public interface UserInvitationService {
030
031    public static final String REGISTRATION_CONFIGURATION_NAME = "configurationName";
032
033    public static final String REGISTRATION_DATA_DOC = "registrationDoc";
034
035    public static final String REGISTRATION_DATA_USER = "registeredUser";
036
037    public enum ValidationMethod {
038        EMAIL, NONE
039    }
040
041    /**
042     * Create a document model for the UserRegistration doctype.
043     *
044     * @param configurationName The name of the configuration.
045     * @return The document model
046     * @since 5.9.3
047     */
048    DocumentModel getUserRegistrationModel(String configurationName);
049
050    /**
051     * Stores a registration request and return a unique ID for it
052     *
053     * @return
054     */
055    String submitRegistrationRequest(DocumentModel userRegistrationModel, Map<String, Serializable> additionnalInfo,
056            ValidationMethod validationMethod, boolean autoAccept) throws UserRegistrationException;
057
058    /**
059     * accept the registration request
060     *
061     * @param requestId
062     */
063    void acceptRegistrationRequest(String requestId, Map<String, Serializable> additionnalInfo) throws
064            UserRegistrationException;
065
066    /**
067     * reject the registration request
068     *
069     * @param requestId
070     */
071    void rejectRegistrationRequest(String requestId, Map<String, Serializable> additionnalInfo) throws
072            UserRegistrationException;
073
074    /**
075     * Validate a registration request and generate the target User
076     *
077     * @param requestId
078     */
079    Map<String, Serializable> validateRegistration(String requestId, Map<String, Serializable> additionnalInfo);
080
081    /**
082     * Validate a registration request and generate the target User
083     *
084     * @param requestId
085     */
086    Map<String, Serializable> validateRegistrationAndSendEmail(String requestId,
087            Map<String, Serializable> additionnalInfo) throws UserRegistrationException;
088
089    NuxeoPrincipal createUser(CoreSession session, DocumentModel registrationDoc) throws
090            UserRegistrationException;
091
092    /**
093     * Send a mail to the invited user to revive his invitation If an error occured while sending an email, it logs it
094     * and continue.
095     *
096     * @since 5.6
097     */
098    void reviveRegistrationRequests(CoreSession session, List<DocumentModel> registrationDocs);
099
100    /**
101     * Delete a registration document
102     *
103     * @since 5.6
104     */
105    void deleteRegistrationRequests(CoreSession session, List<DocumentModel> registrationDoc);
106
107    UserRegistrationConfiguration getConfiguration();
108
109    /**
110     * Retrieve registrations for a document givent the username
111     *
112     * @since 5.6
113     */
114    DocumentModelList getRegistrationsForUser(String docId, String username, String configurationName);
115
116    /**
117     * Return specific configuration for the specified name
118     *
119     * @param name configuration name
120     * @since 5.6
121     */
122    UserRegistrationConfiguration getConfiguration(String name);
123
124    /**
125     * @since 5.6
126     */
127    UserRegistrationConfiguration getConfiguration(DocumentModel requestDoc);
128
129    /**
130     * Get documentmodel that stores request configuration using RegistrationConfiguration facet.
131     *
132     * @param session
133     * @return
134     */
135    DocumentModel getRegistrationRulesDocument(CoreSession session, String configurationName);
136
137    /**
138     * Stores a resgitration request like submitRegistrationRequest with Document information
139     *
140     * @return a unique ID for it
141     * @since 5.6
142     */
143    String submitRegistrationRequest(String configurationName, DocumentModel userRegistrationModel,
144            Map<String, Serializable> additionnalInfo, ValidationMethod validationMethod, boolean autoAccept)
145            throws UserRegistrationException;
146
147    /**
148     * Get registration rules adapter
149     *
150     * @since 5.6
151     */
152    RegistrationRules getRegistrationRules(String configurationName);
153
154    /**
155     * List all registered onfiguration name
156     */
157    Set<String> getConfigurationsName();
158
159    /**
160     * The method checks if the request id is a valid one.
161     *
162     * @param requestId The value of the request id.
163     * @since 5.9.3
164     */
165    void checkRequestId(String requestId) throws UserRegistrationException;
166
167    /**
168     * @return The name of the event when the registration is submitted.
169     * @since 5.9.3
170     */
171    String getNameEventRegistrationSubmitted();
172
173    /**
174     * @return The name of the event when the registration is accepted.
175     * @since 5.9.3
176     */
177    String getNameEventRegistrationAccepted();
178
179    /**
180     * @return The name of the event when the registration is rejected.
181     * @since 5.9.3
182     */
183    String getNameEventRegistrationRejected();
184
185    /**
186     * @return The name of the event when the registration is validated.
187     * @since 5.9.3
188     */
189    String getNameEventRegistrationValidated();
190
191}