1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.service.mailinglist;
35
36 import fr.paris.lutece.portal.business.mailinglist.MailingList;
37 import fr.paris.lutece.portal.business.mailinglist.MailingListFilter;
38 import fr.paris.lutece.portal.business.mailinglist.MailingListHome;
39 import fr.paris.lutece.portal.business.mailinglist.MailingListUsersFilter;
40 import fr.paris.lutece.portal.business.mailinglist.Recipient;
41 import fr.paris.lutece.portal.business.user.AdminUser;
42 import fr.paris.lutece.portal.business.user.AdminUserHome;
43 import fr.paris.lutece.portal.business.workgroup.AdminWorkgroupHome;
44 import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService;
45 import fr.paris.lutece.util.ReferenceItem;
46 import fr.paris.lutece.util.ReferenceList;
47
48 import java.util.ArrayList;
49 import java.util.Collection;
50 import java.util.List;
51
52
53
54
55 public final class AdminMailingListService
56 {
57 public static final String ALL_ROLES = "*";
58
59
60
61
62 private AdminMailingListService( )
63 {
64 }
65
66
67
68
69 public static void init( )
70 {
71
72 MailingList.init( );
73 }
74
75
76
77
78
79
80
81
82 public static ReferenceList getMailingLists( AdminUser user )
83 {
84 ReferenceListnceList.html#ReferenceList">ReferenceList list = new ReferenceList( );
85
86 for ( MailingList mailinglist : getUserMailingLists( user ) )
87 {
88 list.addItem( mailinglist.getId( ), mailinglist.getName( ) );
89 }
90
91 return list;
92 }
93
94
95
96
97
98
99
100
101 public static Collection<MailingList> getUserMailingLists( AdminUser user )
102 {
103 Collection<MailingList> listMailinglists = new ArrayList<>( );
104
105
106 listMailinglists.addAll( MailingListHome.findByWorkgroup( AdminWorkgroupService.ALL_GROUPS ) );
107
108
109 ReferenceList listWorkgroups = AdminWorkgroupHome.getUserWorkgroups( user );
110
111 for ( ReferenceItem workgroup : listWorkgroups )
112 {
113 listMailinglists.addAll( MailingListHome.findByWorkgroup( workgroup.getCode( ) ) );
114 }
115
116 return listMailinglists;
117 }
118
119
120
121
122
123
124
125
126
127
128 public static List<MailingList> getUserMailingListsByFilter( AdminUser user, MailingListFilter filter )
129 {
130 MailingListFilterMailingListFilter.html#MailingListFilter">MailingListFilter mailingListFilter = new MailingListFilter( filter );
131
132 mailingListFilter.setWorkgroup( AdminWorkgroupService.ALL_GROUPS );
133
134 List<MailingList> listMailingLists = MailingListHome.findsByFilter( mailingListFilter );
135
136
137 ReferenceList listWorkgroups = AdminWorkgroupHome.getUserWorkgroups( user );
138
139 for ( ReferenceItem workgroup : listWorkgroups )
140 {
141 mailingListFilter = new MailingListFilter( filter );
142 mailingListFilter.setWorkgroup( workgroup.getCode( ) );
143 listMailingLists.addAll( MailingListHome.findsByFilter( mailingListFilter ) );
144 }
145
146 return listMailingLists;
147 }
148
149
150
151
152
153
154
155
156 public static Collection<Recipient> getRecipients( int nIdMailingList )
157 {
158 Collection<Recipient> listRecipients = new ArrayList<>( );
159 MailingList mailinglist = MailingListHome.findByPrimaryKey( nIdMailingList );
160
161 if ( mailinglist != null )
162 {
163 for ( MailingListUsersFilter filter : mailinglist.getFilters( ) )
164 {
165 listRecipients.addAll( getRecipients( filter.getWorkgroup( ), filter.getRole( ) ) );
166 }
167 }
168
169 return listRecipients;
170 }
171
172
173
174
175
176
177
178
179
180
181 public static Collection<Recipient> getRecipients( String strWorkgroup, String strRole )
182 {
183 Collection<Recipient> listRecipients = new ArrayList<>( );
184 Collection<AdminUser> listUsers;
185
186 if ( ( strWorkgroup != null ) && ( !strWorkgroup.equals( AdminWorkgroupService.ALL_GROUPS ) ) )
187 {
188 listUsers = AdminWorkgroupHome.getUserListForWorkgroup( strWorkgroup );
189 }
190 else
191 {
192 listUsers = AdminUserHome.findUserList( );
193 }
194
195 for ( AdminUser user : listUsers )
196 {
197 if ( strRole != null && !strRole.equals( ALL_ROLES ) && !user.isInRole( strRole ) )
198 {
199
200 continue;
201 }
202
203 Recipientess/mailinglist/Recipient.html#Recipient">Recipient recipient = new Recipient( );
204 recipient.setName( user.getFirstName( ) + " " + user.getLastName( ) );
205 recipient.setEmail( user.getEmail( ) );
206 listRecipients.add( recipient );
207 }
208
209 return listRecipients;
210 }
211
212
213
214
215
216
217
218
219
220
221 public static boolean checkFilter( MailingListUsersFilter filter, int nIdMailingList )
222 {
223 return MailingListHome.checkFilter( filter, nIdMailingList );
224 }
225 }