1 /* 2 * Copyright (c) 2002-2022, City of Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 package fr.paris.lutece.plugins.unittree.service.unit; 35 36 import java.util.List; 37 import java.util.Map; 38 39 import javax.servlet.http.HttpServletRequest; 40 41 import org.springframework.transaction.annotation.Transactional; 42 43 import fr.paris.lutece.plugins.unittree.business.unit.Unit; 44 import fr.paris.lutece.portal.business.user.AdminUser; 45 46 /** 47 * 48 * IUnitUserService 49 * 50 */ 51 public interface IUnitUserService 52 { 53 // GET 54 55 /** 56 * Get the user from a given id user 57 * 58 * @param nIdUser 59 * the id user 60 * @return an {@link AdminUser} 61 */ 62 AdminUser getUser( int nIdUser ); 63 64 /** 65 * Get the list of {@link AdminUser} from a given id unit 66 * 67 * @param nIdUnit 68 * the id unit 69 * @param mapIdUserUnit 70 * the map of <idUser, Unit> 71 * @param isInDepthSearch 72 * true if it is an in depth search (search in the sub units too) 73 * @return a list of {@link AdminUser} 74 */ 75 List<AdminUser> getUsers( int nIdUnit, Map<String, Unit> mapIdUserUnit, boolean isInDepthSearch ); 76 77 /** 78 * Get the list of available users for a given unit. current user can administer. 79 * 80 * @param currentUser 81 * the current user 82 * @param nIdUnit 83 * The id of the unit 84 * @return a list of {@link AdminUser}. If multi affectation is not enabled, return users that can be administered by the current user and that are not 85 * associated with any unit. Otherwise returns users that are not associated directly or transitively to the unit and that the current user can 86 * administer. 87 */ 88 List<AdminUser> getAvailableUsers( AdminUser currentUser, int nIdUnit ); 89 90 /** 91 * Get the list of available users for a given unit. 92 * 93 * @param currentUser 94 * The current user 95 * @param nIdUnit 96 * The id of the unit 97 * @param bMultiAffectationEnabled 98 * True to include users already associated to a unit, false to ignore them. 99 * @return a list of {@link AdminUser} 100 */ 101 List<AdminUser> getAvailableUsers( AdminUser currentUser, int nIdUnit, boolean bMultiAffectationEnabled ); 102 103 // PROCESS 104 105 /** 106 * Do process adding the user to the unit 107 * 108 * @param nIdUser 109 * the id user 110 * @param currentUser 111 * the current user 112 * @param request 113 * the HTTP requesst 114 */ 115 void doProcessAddUser( int nIdUser, AdminUser currentUser, HttpServletRequest request ); 116 117 /** 118 * Do process modifying the user 119 * 120 * @param nIdUser 121 * the id user 122 * @param currentUser 123 * the current user 124 * @param request 125 * the HTTP request 126 */ 127 void doProcessModifyUser( int nIdUser, AdminUser currentUser, HttpServletRequest request ); 128 129 /** 130 * Do process removing an user from an unit 131 * 132 * @param nIdUser 133 * the id user 134 * @param currentUser 135 * the current user 136 * @param request 137 * the HTTP request 138 */ 139 void doProcessRemoveUser( int nIdUser, AdminUser currentUser, HttpServletRequest request ); 140 141 // CHECKS 142 143 /** 144 * Check if the given user is in a given unit 145 * 146 * @param nIdUser 147 * the id user 148 * @param nIdUnit 149 * The id of the unit 150 * @return true if the user is in an unit, false otherwise 151 */ 152 boolean isUserInUnit( int nIdUser, int nIdUnit ); 153 154 // CRUD 155 156 /** 157 * Add an user to an unit 158 * 159 * @param nIdUnit 160 * the id unit 161 * @param nIdUser 162 * the id user 163 * @return true if the user is added to the unit, false otherwise 164 */ 165 @Transactional( "unittree.transactionManager" ) 166 boolean addUserToUnit( int nIdUnit, int nIdUser ); 167 168 /** 169 * Remove the user from a unit 170 * 171 * @param nIdUser 172 * the id user 173 * @param nIdUnit 174 * The id of the unit 175 */ 176 @Transactional( "unittree.transactionManager" ) 177 void removeUserFromUnit( int nIdUser, int nIdUnit ); 178 179 /** 180 * Remove users from a given id unit 181 * 182 * @param nIdUnit 183 * the id unit 184 */ 185 @Transactional( "unittree.transactionManager" ) 186 void removeUsersFromUnit( int nIdUnit ); 187 188 /** 189 * Check if users can be affected to several units at the same time or not 190 * 191 * @return True if multi affectation is enabled, false otherwise. If the property is not defined, the default value is used which is false. 192 */ 193 boolean isMultiAffectationEnabled( ); 194 }