KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > efs > openreports > objects > ReportUser


1 /*
2  * Copyright (C) 2002 Erik Swenson - erik@oreports.com
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the Free
6  * Software Foundation; either version 2 of the License, or (at your option)
7  * any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */

19
20 package org.efs.openreports.objects;
21
22 import java.io.Serializable JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.TreeSet JavaDoc;
29
30 import org.efs.openreports.ORStatics;
31
32 public class ReportUser implements Serializable JavaDoc
33 {
34     private static final long serialVersionUID = 7715901858866413034L;
35     
36     private Integer JavaDoc id;
37     private String JavaDoc name;
38     private String JavaDoc password;
39     private String JavaDoc externalId;
40     private String JavaDoc email;
41     
42     private Set JavaDoc roles;
43     private List JavaDoc groups;
44     private List JavaDoc alerts;
45     private Report defaultReport;
46     
47     //TODO remove pdfExportType, update DB schema
48
private int pdfExportType;
49
50     public ReportUser()
51     {
52         roles = new TreeSet JavaDoc();
53         groups = new ArrayList JavaDoc();
54         alerts = new ArrayList JavaDoc();
55     }
56
57     public void setId(Integer JavaDoc id)
58     {
59         this.id = id;
60     }
61
62     public String JavaDoc getPassword()
63     {
64         return password;
65     }
66
67     public String JavaDoc getName()
68     {
69         return name;
70     }
71
72     public void setPassword(String JavaDoc password)
73     {
74         this.password = password;
75     }
76
77     public void setName(String JavaDoc name)
78     {
79         this.name = name;
80     }
81
82     public Integer JavaDoc getId()
83     {
84         return id;
85     }
86
87     public List JavaDoc getGroups()
88     {
89         return groups;
90     }
91
92     public void setGroups(List JavaDoc groups)
93     {
94         this.groups = groups;
95     }
96     
97     public Set JavaDoc getReports()
98     {
99         TreeSet JavaDoc set = new TreeSet JavaDoc();
100             
101         Iterator JavaDoc iterator = groups.iterator();
102         while(iterator.hasNext())
103         {
104             ReportGroup group = (ReportGroup) iterator.next();
105             set.addAll(group.getReports());
106         }
107         
108         return set;
109     }
110     
111     public boolean isValidReport(Report report)
112     {
113         Iterator JavaDoc iterator = groups.iterator();
114         while(iterator.hasNext())
115         {
116             ReportGroup group = (ReportGroup) iterator.next();
117             if (group.isValidReport(report)) return true;
118         }
119         
120         return false;
121     }
122
123     public String JavaDoc getEmail()
124     {
125         return email;
126     }
127
128     public void setEmail(String JavaDoc email)
129     {
130         this.email = email;
131     }
132
133     public String JavaDoc getExternalId()
134     {
135         return externalId;
136     }
137
138     public void setExternalId(String JavaDoc externalId)
139     {
140         this.externalId = externalId;
141     }
142
143     public boolean isValidGroup(ReportGroup reportGroup)
144     {
145         if (groups != null && groups.size() > 0)
146         {
147             Iterator JavaDoc iterator = groups.iterator();
148             while (iterator.hasNext())
149             {
150                 ReportGroup group = (ReportGroup) iterator.next();
151                 if (group.getId().equals(reportGroup.getId()))
152                     return true;
153             }
154         }
155
156         return false;
157     }
158
159     public int getPdfExportType()
160     {
161         return pdfExportType;
162     }
163
164     public void setPdfExportType(int pdfExportType)
165     {
166         this.pdfExportType = pdfExportType;
167     }
168
169     public List JavaDoc getAlerts()
170     {
171         if (alerts != null) Collections.sort(alerts);
172         return alerts;
173     }
174
175     public void setAlerts(List JavaDoc alerts)
176     {
177         this.alerts = alerts;
178     }
179     
180     public ReportUserAlert getUserAlert(Integer JavaDoc alertId)
181     {
182         Iterator JavaDoc iterator = alerts.iterator();
183         while (iterator.hasNext())
184         {
185             ReportUserAlert map = (ReportUserAlert) iterator.next();
186
187             if (map.getAlert().getId().equals(alertId))
188             {
189                 return map;
190             }
191         }
192
193         return null;
194     }
195
196     public Report getDefaultReport()
197     {
198         return defaultReport;
199     }
200
201     public void setDefaultReport(Report defaultReport)
202     {
203         this.defaultReport = defaultReport;
204     }
205
206     public Set JavaDoc getRoles()
207     {
208         return roles;
209     }
210
211     public void setRoles(Set JavaDoc roles)
212     {
213         this.roles = roles;
214     }
215     
216     public boolean isAdminUser()
217     {
218         for (int i=0; i < ORStatics.ADMIN_ROLES.length; i++)
219         {
220             if (roles.contains(ORStatics.ADMIN_ROLES[i])) return true;
221         }
222         
223         return false;
224     }
225     
226     public boolean isRootAdmin()
227     {
228          return roles.contains(ORStatics.ROOT_ADMIN_ROLE);
229     }
230     
231     public void setRootAdmin(boolean hasRole)
232     {
233         roles.remove(ORStatics.ROOT_ADMIN_ROLE);
234         if (hasRole) roles.add(ORStatics.ROOT_ADMIN_ROLE);
235     }
236     
237     public boolean isScheduler()
238     {
239          return roles.contains(ORStatics.SCHEDULER_ROLE) || isRootAdmin();
240     }
241     
242     public void setScheduler(boolean hasRole)
243     {
244         roles.remove(ORStatics.SCHEDULER_ROLE);
245         if (hasRole) roles.add(ORStatics.SCHEDULER_ROLE);
246     }
247     
248     public boolean isAdvancedScheduler()
249     {
250          return roles.contains(ORStatics.ADVANCED_SCHEDULER_ROLE) || isRootAdmin();
251     }
252     
253     public void setAdvancedScheduler(boolean hasRole)
254     {
255         roles.remove(ORStatics.ADVANCED_SCHEDULER_ROLE);
256         if (hasRole) roles.add(ORStatics.ADVANCED_SCHEDULER_ROLE);
257     }
258     
259     public boolean isDashboardUser()
260     {
261          return false;
262     }
263     
264     public void setDashboardUser(boolean hasRole)
265     {
266         roles.remove(ORStatics.DASHBOARD_ROLE);
267         if (hasRole) roles.add(ORStatics.DASHBOARD_ROLE);
268     }
269     
270     public boolean isDataSourceAdmin()
271     {
272          return roles.contains(ORStatics.DATASOURCE_ADMIN_ROLE) || isRootAdmin();
273     }
274     
275     public void setDataSourceAdmin(boolean hasRole)
276     {
277         roles.remove(ORStatics.DATASOURCE_ADMIN_ROLE);
278         if (hasRole) roles.add(ORStatics.DATASOURCE_ADMIN_ROLE);
279     }
280     
281     public boolean isReportAdmin()
282     {
283          return roles.contains(ORStatics.REPORT_ADMIN_ROLE) || isRootAdmin();
284     }
285     
286     public void setReportAdmin(boolean hasRole)
287     {
288         roles.remove(ORStatics.REPORT_ADMIN_ROLE);
289         if (hasRole) roles.add(ORStatics.REPORT_ADMIN_ROLE);
290     }
291     
292     public boolean isParameterAdmin()
293     {
294          return roles.contains(ORStatics.PARAMETER_ADMIN_ROLE) || isRootAdmin();
295     }
296     
297     public void setParameterAdmin(boolean hasRole)
298     {
299         roles.remove(ORStatics.PARAMETER_ADMIN_ROLE);
300         if (hasRole) roles.add(ORStatics.PARAMETER_ADMIN_ROLE);
301     }
302     
303     public boolean isUserAdmin()
304     {
305          return roles.contains(ORStatics.USER_ADMIN_ROLE) || isRootAdmin();
306     }
307     
308     public void setUserAdmin(boolean hasRole)
309     {
310         roles.remove(ORStatics.USER_ADMIN_ROLE);
311         if (hasRole) roles.add(ORStatics.USER_ADMIN_ROLE);
312     }
313     
314     public boolean isGroupAdmin()
315     {
316          return roles.contains(ORStatics.GROUP_ADMIN_ROLE) || isRootAdmin();
317     }
318     
319     public void setGroupAdmin(boolean hasRole)
320     {
321         roles.remove(ORStatics.GROUP_ADMIN_ROLE);
322         if (hasRole) roles.add(ORStatics.GROUP_ADMIN_ROLE);
323     }
324     
325     public boolean isChartAdmin()
326     {
327          return roles.contains(ORStatics.CHART_ADMIN_ROLE) || isRootAdmin();
328     }
329     
330     public void setChartAdmin(boolean hasRole)
331     {
332         roles.remove(ORStatics.CHART_ADMIN_ROLE);
333         if (hasRole) roles.add(ORStatics.CHART_ADMIN_ROLE);
334     }
335     
336     public boolean isAlertAdmin()
337     {
338          return false;
339     }
340     
341     public void setAlertAdmin(boolean hasRole)
342     {
343         roles.remove(ORStatics.ALERT_ADMIN_ROLE);
344         if (hasRole) roles.add(ORStatics.ALERT_ADMIN_ROLE);
345     }
346     
347     public boolean isAlertUser()
348     {
349          return false;
350     }
351     
352     public void setAlertUser(boolean hasRole)
353     {
354         roles.remove(ORStatics.ALERT_USER_ROLE);
355         if (hasRole) roles.add(ORStatics.ALERT_USER_ROLE);
356     }
357     
358     public boolean isLogViewer()
359     {
360          return roles.contains(ORStatics.LOG_VIEWER_ROLE) || isRootAdmin();
361     }
362     
363     public void setLogViewer(boolean hasRole)
364     {
365         roles.remove(ORStatics.LOG_VIEWER_ROLE);
366         if (hasRole) roles.add(ORStatics.LOG_VIEWER_ROLE);
367     }
368     
369     public boolean isUploader()
370     {
371          return roles.contains(ORStatics.UPLOAD_ROLE) || isRootAdmin();
372     }
373     
374     public void setUploader(boolean hasRole)
375     {
376         roles.remove(ORStatics.UPLOAD_ROLE);
377         if (hasRole) roles.add(ORStatics.UPLOAD_ROLE);
378     }
379     
380     public boolean isSchedulerAdmin()
381     {
382          return false;
383     }
384     
385     public void setSchedulerAdmin(boolean hasRole)
386     {
387         roles.remove(ORStatics.SCHEDULER_ADMIN_ROLE);
388         if (hasRole) roles.add(ORStatics.SCHEDULER_ADMIN_ROLE);
389     }
390 }
Popular Tags