View Javadoc
1   /*
2    * Copyright (c) 2002-2021, 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.contact.business;
35  
36  import fr.paris.lutece.plugins.contact.service.ContactListWorkgroupRemovalListener;
37  import fr.paris.lutece.portal.service.role.RoleRemovalListenerService;
38  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupResource;
39  import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
40  import fr.paris.lutece.portal.service.workgroup.WorkgroupRemovalListenerService;
41  
42  /**
43   * This class represents business object Contact
44   */
45  public class ContactList implements AdminWorkgroupResource
46  {
47      public static final String RESOURCE_TYPE = "CONTACT_LIST";
48      public static final String ROLE_NONE = "none";
49      private static ContactListWorkgroupRemovalListener _listenerWorkgroup;
50      private static ContactListRoleRemovalListener _listenerRole;
51      private static final String EMPTY_STRING = "";
52  
53      /////////////////////////////////////////////////////////////////////////////////
54      // Constants
55      private int _nId;
56      private String _strContactListLabel;
57      private String _strContactListDescription;
58      private int _nContactsNumber;
59      private String _strAdminWorkgroup;
60      private String _strRole;
61      private int _nContactListOrder;
62      private boolean _bActiveTos;
63      private String _strTosMessage;
64  
65      /**
66       * Initialize the ContactList
67       */
68      public static void init( )
69      {
70          // Create removal listeners and register them
71          if ( _listenerWorkgroup == null )
72          {
73              _listenerWorkgroup = new ContactListWorkgroupRemovalListener( );
74              WorkgroupRemovalListenerService.getService( ).registerListener( _listenerWorkgroup );
75          }
76  
77          if ( _listenerRole == null )
78          {
79              _listenerRole = new ContactListRoleRemovalListener( );
80              RoleRemovalListenerService.getService( ).registerListener( _listenerRole );
81          }
82      }
83  
84      /**
85       * Returns the identifier of this contactList.
86       * 
87       * @return the contact identifier
88       */
89      public int getId( )
90      {
91          return _nId;
92      }
93  
94      /**
95       * Sets the identifier of the contactList to the specified integer.
96       * 
97       * @param nId
98       *            the new identifier
99       */
100     public void setId( int nId )
101     {
102         _nId = nId;
103     }
104 
105     /**
106      * Returns the label of this list.
107      * 
108      * @return the contact name
109      */
110     public String getLabel( )
111     {
112         return _strContactListLabel;
113     }
114 
115     /**
116      * Sets the label of the contact List to the specified string.
117      * 
118      * @param strContactListLabel
119      *            the new name
120      */
121     public void setLabel( String strContactListLabel )
122     {
123         _strContactListLabel = ( strContactListLabel == null ) ? EMPTY_STRING : strContactListLabel;
124     }
125 
126     /**
127      * Returns the description of this contact list.
128      * 
129      * @return the contact name
130      */
131     public String getDescription( )
132     {
133         return _strContactListDescription;
134     }
135 
136     /**
137      * Sets the name of the contact to the specified string.
138      * 
139      * @param strContactListDescription
140      *            the description of the contact list
141      */
142     public void setDescription( String strContactListDescription )
143     {
144         _strContactListDescription = ( strContactListDescription == null ) ? EMPTY_STRING : strContactListDescription;
145     }
146 
147     /**
148      * gets the number of contacts assigned to list
149      * 
150      * @return returns the number of contacts assigned to this list
151      */
152     public int getContactsNumber( )
153     {
154         return _nContactsNumber;
155     }
156 
157     /**
158      * sets to the specified integer the number of contacts assigned to list
159      * 
160      * @param nContactsNumber
161      *            the number of contacts to set
162      */
163     public void setContactsNumber( int nContactsNumber )
164     {
165         _nContactsNumber = nContactsNumber;
166     }
167 
168     /**
169      * Returns the workgroup
170      * 
171      * @return The workgroup
172      */
173     public String getWorkgroup( )
174     {
175         return _strAdminWorkgroup;
176     }
177 
178     /**
179      * Sets the workgroup
180      * 
181      * @param strAdminWorkgroup
182      *            The workgroup
183      */
184     public void setWorkgroup( String strAdminWorkgroup )
185     {
186         _strAdminWorkgroup = AdminWorkgroupService.normalizeWorkgroupKey( strAdminWorkgroup );
187     }
188 
189     /**
190      * Sets the role
191      * 
192      * @param strRole
193      *            The role
194      */
195 
196     /**
197      * Gets the contactList role
198      * 
199      * @return contactList's role as a String
200      * @since v1.1
201      */
202     public String getRole( )
203     {
204         return _strRole;
205     }
206 
207     /**
208      * allows the contact List to be saw by a role
209      * 
210      * @param strRole
211      *            The role that can see the contact list
212      */
213     public void setRole( String strRole )
214     {
215         _strRole = ( ( strRole == null ) || ( strRole.equals( "" ) ) ) ? ROLE_NONE : strRole;
216     }
217 
218     /**
219      * Returns the order
220      * 
221      * @return The order
222      */
223     public int getContactListOrder( )
224     {
225         return _nContactListOrder;
226     }
227 
228     /**
229      * Sets the workgroup
230      * 
231      * @param nContactListOrder
232      *            the contact list
233      */
234     public void setContactListOrder( int nContactListOrder )
235     {
236         _nContactListOrder = nContactListOrder;
237     }
238 
239     public boolean getTos( )
240     {
241         return _bActiveTos;
242     }
243 
244     public void setTos( boolean bActiveTos )
245     {
246         _bActiveTos = bActiveTos;
247     }
248 
249     public String getTosMessage( )
250     {
251         return _strTosMessage;
252     }
253 
254     public void setTosMessage( String strTosMessage )
255     {
256         _strTosMessage = strTosMessage;
257     }
258 
259 }