001: /*
002: * Copyright (C) 2002 Erik Swenson - erik@oreports.com
003: *
004: * This program is free software; you can redistribute it and/or modify it
005: * under the terms of the GNU General Public License as published by the Free
006: * Software Foundation; either version 2 of the License, or (at your option)
007: * any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT
010: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
012: * more details.
013: *
014: * You should have received a copy of the GNU General Public License along with
015: * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
016: * Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package org.efs.openreports.objects;
021:
022: import java.io.Serializable;
023: import java.util.ArrayList;
024: import java.util.Collections;
025: import java.util.Iterator;
026: import java.util.List;
027: import java.util.Locale;
028: import java.util.Set;
029: import java.util.TimeZone;
030: import java.util.TreeSet;
031:
032: import org.efs.openreports.ORStatics;
033:
034: public class ReportUser implements Serializable {
035: private static final long serialVersionUID = 7715901858866413034L;
036:
037: private Integer id;
038: private String name;
039: private String password;
040: private String externalId;
041: private String email;
042:
043: private Locale locale = Locale.getDefault();
044: private TimeZone timeZone = TimeZone.getDefault();
045:
046: private Set<String> roles;
047: private List<ReportGroup> groups;
048: private List<ReportUserAlert> alerts;
049: private Report defaultReport;
050:
051: //TODO remove pdfExportType, update DB schema
052: private int pdfExportType;
053:
054: public ReportUser() {
055: roles = new TreeSet<String>();
056: groups = new ArrayList<ReportGroup>();
057: alerts = new ArrayList<ReportUserAlert>();
058: }
059:
060: public void setId(Integer id) {
061: this .id = id;
062: }
063:
064: public String getPassword() {
065: return password;
066: }
067:
068: public String getName() {
069: return name;
070: }
071:
072: public void setPassword(String password) {
073: this .password = password;
074: }
075:
076: public void setName(String name) {
077: this .name = name;
078: }
079:
080: public Integer getId() {
081: return id;
082: }
083:
084: public List<ReportGroup> getGroups() {
085: return groups;
086: }
087:
088: public void setGroups(List<ReportGroup> groups) {
089: this .groups = groups;
090: }
091:
092: public Set<Report> getReports() {
093: TreeSet<Report> set = new TreeSet<Report>();
094:
095: Iterator iterator = groups.iterator();
096: while (iterator.hasNext()) {
097: ReportGroup group = (ReportGroup) iterator.next();
098: set.addAll(group.getReports());
099: }
100:
101: return set;
102: }
103:
104: public boolean isValidReport(Report report) {
105: Iterator iterator = groups.iterator();
106: while (iterator.hasNext()) {
107: ReportGroup group = (ReportGroup) iterator.next();
108: if (group.isValidReport(report))
109: return true;
110: }
111:
112: return false;
113: }
114:
115: public String getEmail() {
116: return email;
117: }
118:
119: public void setEmail(String email) {
120: this .email = email;
121: }
122:
123: public String getExternalId() {
124: return externalId;
125: }
126:
127: public void setExternalId(String externalId) {
128: this .externalId = externalId;
129: }
130:
131: public boolean isValidGroup(ReportGroup reportGroup) {
132: if (groups != null && groups.size() > 0) {
133: Iterator iterator = groups.iterator();
134: while (iterator.hasNext()) {
135: ReportGroup group = (ReportGroup) iterator.next();
136: if (group.getId().equals(reportGroup.getId()))
137: return true;
138: }
139: }
140:
141: return false;
142: }
143:
144: public int getPdfExportType() {
145: return pdfExportType;
146: }
147:
148: public void setPdfExportType(int pdfExportType) {
149: this .pdfExportType = pdfExportType;
150: }
151:
152: public List<ReportUserAlert> getAlerts() {
153: if (alerts != null)
154: Collections.sort(alerts);
155: return alerts;
156: }
157:
158: public void setAlerts(List<ReportUserAlert> alerts) {
159: this .alerts = alerts;
160: }
161:
162: public ReportUserAlert getUserAlert(Integer alertId) {
163: Iterator iterator = alerts.iterator();
164: while (iterator.hasNext()) {
165: ReportUserAlert map = (ReportUserAlert) iterator.next();
166:
167: if (map.getAlert().getId().equals(alertId)) {
168: return map;
169: }
170: }
171:
172: return null;
173: }
174:
175: public Report getDefaultReport() {
176: return defaultReport;
177: }
178:
179: public void setDefaultReport(Report defaultReport) {
180: this .defaultReport = defaultReport;
181: }
182:
183: public Set getRoles() {
184: return roles;
185: }
186:
187: public void setRoles(Set<String> roles) {
188: this .roles = roles;
189: }
190:
191: public boolean isAdminUser() {
192: for (int i = 0; i < ORStatics.ADMIN_ROLES.length; i++) {
193: if (roles.contains(ORStatics.ADMIN_ROLES[i]))
194: return true;
195: }
196:
197: return false;
198: }
199:
200: public boolean isRootAdmin() {
201: return roles.contains(ORStatics.ROOT_ADMIN_ROLE);
202: }
203:
204: public void setRootAdmin(boolean hasRole) {
205: roles.remove(ORStatics.ROOT_ADMIN_ROLE);
206: if (hasRole)
207: roles.add(ORStatics.ROOT_ADMIN_ROLE);
208: }
209:
210: public boolean isScheduler() {
211: return roles.contains(ORStatics.SCHEDULER_ROLE)
212: || isRootAdmin();
213: }
214:
215: public void setScheduler(boolean hasRole) {
216: roles.remove(ORStatics.SCHEDULER_ROLE);
217: if (hasRole)
218: roles.add(ORStatics.SCHEDULER_ROLE);
219: }
220:
221: public boolean isAdvancedScheduler() {
222: return roles.contains(ORStatics.ADVANCED_SCHEDULER_ROLE)
223: || isRootAdmin();
224: }
225:
226: public void setAdvancedScheduler(boolean hasRole) {
227: roles.remove(ORStatics.ADVANCED_SCHEDULER_ROLE);
228: if (hasRole)
229: roles.add(ORStatics.ADVANCED_SCHEDULER_ROLE);
230: }
231:
232: public boolean isDashboardUser() {
233: return false;
234: }
235:
236: public void setDashboardUser(boolean hasRole) {
237: roles.remove(ORStatics.DASHBOARD_ROLE);
238: if (hasRole)
239: roles.add(ORStatics.DASHBOARD_ROLE);
240: }
241:
242: public boolean isDataSourceAdmin() {
243: return roles.contains(ORStatics.DATASOURCE_ADMIN_ROLE)
244: || isRootAdmin();
245: }
246:
247: public void setDataSourceAdmin(boolean hasRole) {
248: roles.remove(ORStatics.DATASOURCE_ADMIN_ROLE);
249: if (hasRole)
250: roles.add(ORStatics.DATASOURCE_ADMIN_ROLE);
251: }
252:
253: public boolean isReportAdmin() {
254: return roles.contains(ORStatics.REPORT_ADMIN_ROLE)
255: || isRootAdmin();
256: }
257:
258: public void setReportAdmin(boolean hasRole) {
259: roles.remove(ORStatics.REPORT_ADMIN_ROLE);
260: if (hasRole)
261: roles.add(ORStatics.REPORT_ADMIN_ROLE);
262: }
263:
264: public boolean isParameterAdmin() {
265: return roles.contains(ORStatics.PARAMETER_ADMIN_ROLE)
266: || isRootAdmin();
267: }
268:
269: public void setParameterAdmin(boolean hasRole) {
270: roles.remove(ORStatics.PARAMETER_ADMIN_ROLE);
271: if (hasRole)
272: roles.add(ORStatics.PARAMETER_ADMIN_ROLE);
273: }
274:
275: public boolean isUserAdmin() {
276: return roles.contains(ORStatics.USER_ADMIN_ROLE)
277: || isRootAdmin();
278: }
279:
280: public void setUserAdmin(boolean hasRole) {
281: roles.remove(ORStatics.USER_ADMIN_ROLE);
282: if (hasRole)
283: roles.add(ORStatics.USER_ADMIN_ROLE);
284: }
285:
286: public boolean isGroupAdmin() {
287: return roles.contains(ORStatics.GROUP_ADMIN_ROLE)
288: || isRootAdmin();
289: }
290:
291: public void setGroupAdmin(boolean hasRole) {
292: roles.remove(ORStatics.GROUP_ADMIN_ROLE);
293: if (hasRole)
294: roles.add(ORStatics.GROUP_ADMIN_ROLE);
295: }
296:
297: public boolean isChartAdmin() {
298: return roles.contains(ORStatics.CHART_ADMIN_ROLE)
299: || isRootAdmin();
300: }
301:
302: public void setChartAdmin(boolean hasRole) {
303: roles.remove(ORStatics.CHART_ADMIN_ROLE);
304: if (hasRole)
305: roles.add(ORStatics.CHART_ADMIN_ROLE);
306: }
307:
308: public boolean isAlertAdmin() {
309: return false;
310: }
311:
312: public void setAlertAdmin(boolean hasRole) {
313: roles.remove(ORStatics.ALERT_ADMIN_ROLE);
314: if (hasRole)
315: roles.add(ORStatics.ALERT_ADMIN_ROLE);
316: }
317:
318: public boolean isAlertUser() {
319: return false;
320: }
321:
322: public void setAlertUser(boolean hasRole) {
323: roles.remove(ORStatics.ALERT_USER_ROLE);
324: if (hasRole)
325: roles.add(ORStatics.ALERT_USER_ROLE);
326: }
327:
328: public boolean isLogViewer() {
329: return roles.contains(ORStatics.LOG_VIEWER_ROLE)
330: || isRootAdmin();
331: }
332:
333: public void setLogViewer(boolean hasRole) {
334: roles.remove(ORStatics.LOG_VIEWER_ROLE);
335: if (hasRole)
336: roles.add(ORStatics.LOG_VIEWER_ROLE);
337: }
338:
339: public boolean isUploader() {
340: return roles.contains(ORStatics.UPLOAD_ROLE) || isRootAdmin();
341: }
342:
343: public void setUploader(boolean hasRole) {
344: roles.remove(ORStatics.UPLOAD_ROLE);
345: if (hasRole)
346: roles.add(ORStatics.UPLOAD_ROLE);
347: }
348:
349: public boolean isSchedulerAdmin() {
350: return false;
351: }
352:
353: public void setSchedulerAdmin(boolean hasRole) {
354: roles.remove(ORStatics.SCHEDULER_ADMIN_ROLE);
355: if (hasRole)
356: roles.add(ORStatics.SCHEDULER_ADMIN_ROLE);
357: }
358:
359: public Locale getLocale() {
360: return locale;
361: }
362:
363: public void setLocale(Locale locale) {
364: this .locale = locale;
365: }
366:
367: public TimeZone getTimeZone() {
368: return timeZone;
369: }
370:
371: public void setTimeZone(TimeZone timeZone) {
372: this.timeZone = timeZone;
373: }
374: }
|