1 /* 2 * Copyright (c) 2002-2017, Mairie de 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.wrapper.business; 35 36 import fr.paris.lutece.plugins.wrapper.service.WrapperWorkgroupRemovalListener; 37 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource; 38 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService; 39 import fr.paris.lutece.portal.service.workgroup.WorkgroupRemovalListenerService; 40 41 42 /** 43 * This class represents business object Wrapper 44 * @author lenaini 45 */ 46 public class Wrapper implements AdminWorkgroupResource 47 { 48 ///////////////////////////////////////////////////////////////////////////////// 49 // Constants 50 public static final String RESOURCE_TYPE = "WRAPPER"; 51 public static final String ROLE_NONE = "none"; 52 private static final String EMPTY_STRING = ""; 53 private static final int ENABLED = 0; 54 private static WrapperWorkgroupRemovalListener _listenerWorkgroup; 55 private int _nId; 56 private int _nStatus; 57 private String _strDescription; 58 private String _strWrapperUrl; 59 private String _strWrapperStyles; 60 private String _strWorkgroupKey; 61 private String _strAdminWorkgroup; 62 private String _strRole; 63 64 /** Creates a new instance of Wrapper */ 65 public Wrapper( ) 66 { 67 } 68 69 /** 70 * Initialize the WrapperList 71 */ 72 public static void init( ) 73 { 74 // Create removal listeners and register them 75 if ( _listenerWorkgroup == null ) 76 { 77 _listenerWorkgroup = new WrapperWorkgroupRemovalListener( ); 78 WorkgroupRemovalListenerService.getService( ).registerListener( _listenerWorkgroup ); 79 } 80 } 81 82 /** 83 * Returns the identifier of this wrapper. 84 * 85 * @return the wrapper identifier 86 */ 87 public int getId( ) 88 { 89 return _nId; 90 } 91 92 /** 93 * Sets the identifier of the wrapper to the specified integer. 94 * 95 * @param nId the new identifier 96 */ 97 public void setId( int nId ) 98 { 99 _nId = nId; 100 } 101 102 /** 103 * Returns the description of this wrapper. 104 * 105 * @return the wrapper description 106 */ 107 public String getDescription( ) 108 { 109 return _strDescription; 110 } 111 112 /** 113 * Sets the description of the wrapper to the specified string. 114 * 115 * @param strDescription the new description 116 */ 117 public void setDescription( String strDescription ) 118 { 119 _strDescription = ( strDescription == null ) ? EMPTY_STRING : strDescription; 120 } 121 122 /** 123 * Returns the WrapperUrl of this wrapper. 124 * 125 * @return the wrapper Url 126 */ 127 public String getWrapperUrl( ) 128 { 129 return _strWrapperUrl; 130 } 131 132 /** 133 * Sets the url of the wrapper to the specified string. 134 * 135 * @param strWrapperUrl the new url 136 */ 137 public void setWrapperUrl( String strWrapperUrl ) 138 { 139 _strWrapperUrl = ( strWrapperUrl == null ) ? EMPTY_STRING : strWrapperUrl; 140 } 141 142 /** 143 * Returns the WrapperStyles of this wrapper. 144 * 145 * @return the wrapper Styles 146 */ 147 public String getWrapperStyles( ) 148 { 149 return _strWrapperStyles; 150 } 151 152 /** 153 * Sets the Styles of the wrapper to the specified string. 154 * 155 * @param strWrapperStyles the new Styles 156 */ 157 public void setWrapperStyles( String strWrapperStyles ) 158 { 159 _strWrapperStyles = ( strWrapperStyles == null ) ? EMPTY_STRING : strWrapperStyles; 160 } 161 162 /** 163 * Returns the status of this wrapper. 164 * 165 * @return the wrapper status 166 */ 167 public int getStatus( ) 168 { 169 return _nStatus; 170 } 171 172 /** 173 * Sets the description of the wrapper to the specified string. 174 * 175 * @param strDescription the new description 176 */ 177 public void setStatus( int nStatus ) 178 { 179 _nStatus = nStatus; 180 } 181 182 /** 183 * Gets the contactList role 184 * @return contactList's role as a String 185 * @since v1.1 186 */ 187 public String getRole( ) 188 { 189 return _strRole; 190 } 191 192 /** 193 * allows the contact List to be saw by a role 194 * @param strRole The role that can see the contact list 195 */ 196 public void setRole( String strRole ) 197 { 198 _strRole = ( ( strRole == null ) || ( strRole.equals( "" ) ) ) ? ROLE_NONE : strRole; 199 } 200 201 //////////////////////////////////////////////////////////////////////////////////////// 202 // Workgtoup management 203 204 /** 205 * Return the WorkgroupKey Contact Label 206 * @return The label of the selected Workgroup Key 207 */ 208 public String getWorkgroupKey( ) 209 { 210 return _strWorkgroupKey; 211 } 212 213 /** 214 * Sets the description of the Contact with the specified String 215 * @param strWorkgroupKey The workgroup key 216 */ 217 public void setWorkgroupKey( String strWorkgroupKey ) 218 { 219 _strWorkgroupKey = strWorkgroupKey; 220 } 221 222 /** 223 * Returns the workgroup 224 * @return The workgroup 225 */ 226 public String getWorkgroup( ) 227 { 228 return _strAdminWorkgroup; 229 } 230 231 /** 232 * Sets the workgroup 233 * @param strAdminWorkgroup The workgroup 234 */ 235 public void setWorkgroup( String strAdminWorkgroup ) 236 { 237 _strAdminWorkgroup = AdminWorkgroupService.normalizeWorkgroupKey( strAdminWorkgroup ); 238 } 239 240 public boolean isEnabled( ) 241 { 242 return ( _nStatus == ENABLED ); 243 } 244 }