001: /*
002: * Copyright (C) 2006 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.actions.admin;
021:
022: import java.util.*;
023:
024: import com.opensymphony.xwork2.ActionContext;
025: import com.opensymphony.xwork2.ActionSupport;
026:
027: import org.apache.log4j.Logger;
028: import org.apache.struts2.interceptor.SessionAware;
029: import org.efs.openreports.ORStatics;
030: import org.efs.openreports.objects.*;
031: import org.efs.openreports.providers.*;
032:
033: public class EditUserAlertsAction extends ActionSupport implements
034: SessionAware {
035: private static final long serialVersionUID = -164042143249798706L;
036:
037: protected static Logger log = Logger
038: .getLogger(EditUserAlertsAction.class);
039:
040: private Map<Object, Object> session;
041:
042: private int id;
043: private int alertId;
044: private int reportId;
045:
046: private int alertLimit;
047: private String alertOperator;
048:
049: private String submitAdd;
050: private String submitUpdate;
051: private String submitDelete;
052:
053: private String command;
054:
055: private ReportUser reportUser;
056:
057: private UserProvider userProvider;
058: private AlertProvider alertProvider;
059: private ReportProvider reportProvider;
060:
061: @Override
062: public String execute() {
063: try {
064: reportUser = userProvider.getUser(new Integer(id));
065:
066: if (submitAdd != null) {
067: ReportAlert alert = alertProvider
068: .getReportAlert(new Integer(alertId));
069:
070: ReportUserAlert userAlert = new ReportUserAlert();
071: userAlert.setAlert(alert);
072: userAlert.setUser(reportUser);
073: userAlert.setLimit(alertLimit);
074: userAlert.setOperator(alertOperator);
075:
076: if (reportId > 0) {
077: userAlert.setReport(reportProvider
078: .getReport(new Integer(reportId)));
079: } else {
080: userAlert.setReport(null);
081: }
082:
083: reportUser.getAlerts().add(userAlert);
084:
085: userProvider.updateUser(reportUser);
086: }
087:
088: if (submitUpdate != null) {
089: ReportUserAlert userAlert = reportUser.getAlerts().get(
090: alertId - 1);
091: userAlert.setLimit(alertLimit);
092: userAlert.setOperator(alertOperator);
093:
094: if (reportId > 0) {
095: userAlert.setReport(reportProvider
096: .getReport(new Integer(reportId)));
097: } else {
098: userAlert.setReport(null);
099: }
100:
101: userProvider.updateUser(reportUser);
102: }
103:
104: if (submitDelete != null) {
105: ReportUserAlert userAlert = reportUser.getAlerts().get(
106: alertId);
107:
108: reportUser.getAlerts().remove(userAlert);
109:
110: userProvider.updateUser(reportUser);
111: }
112:
113: if (submitAdd != null || submitUpdate != null
114: || submitDelete != null) {
115: ReportUser currentUser = (ReportUser) ActionContext
116: .getContext().getSession().get(
117: ORStatics.REPORT_USER);
118: if (currentUser.getId().equals(reportUser.getId())) {
119: session.put(ORStatics.REPORT_USER, reportUser);
120: }
121: }
122:
123: return INPUT;
124: } catch (Exception e) {
125: e.printStackTrace();
126: addActionError(e.toString());
127: return INPUT;
128: }
129: }
130:
131: @SuppressWarnings("unchecked")
132: public void setSession(Map session) {
133: this .session = session;
134: }
135:
136: public int getId() {
137: return id;
138: }
139:
140: public void setId(int id) {
141: this .id = id;
142: }
143:
144: public List<ReportAlert> getAlerts() {
145: try {
146: return alertProvider.getReportAlerts();
147: } catch (Exception e) {
148: addActionError(e.toString());
149: return null;
150: }
151: }
152:
153: public List<ReportUserAlert> getUserAlerts() {
154: return reportUser.getAlerts();
155: }
156:
157: public int getAlertId() {
158: return alertId;
159: }
160:
161: public void setAlertId(int alertId) {
162: this .alertId = alertId;
163: }
164:
165: public int getAlertLimit() {
166: return alertLimit;
167: }
168:
169: public void setAlertLimit(int alertLimit) {
170: this .alertLimit = alertLimit;
171: }
172:
173: public String getAlertOperator() {
174: return alertOperator;
175: }
176:
177: public void setAlertOperator(String alertOperator) {
178: this .alertOperator = alertOperator;
179: }
180:
181: public String getCommand() {
182: return command;
183: }
184:
185: public void setCommand(String command) {
186: this .command = command;
187: }
188:
189: public String getSubmitAdd() {
190: return submitAdd;
191: }
192:
193: public void setSubmitAdd(String submitAdd) {
194: this .submitAdd = submitAdd;
195: }
196:
197: public String getSubmitDelete() {
198: return submitDelete;
199: }
200:
201: public void setSubmitDelete(String submitDelete) {
202: this .submitDelete = submitDelete;
203: }
204:
205: public String getSubmitUpdate() {
206: return submitUpdate;
207: }
208:
209: public void setSubmitUpdate(String submitUpdate) {
210: this .submitUpdate = submitUpdate;
211: }
212:
213: public ReportUser getReportUser() {
214: return reportUser;
215: }
216:
217: public void setAlertProvider(AlertProvider alertProvider) {
218: this .alertProvider = alertProvider;
219: }
220:
221: public void setUserProvider(UserProvider userProvider) {
222: this .userProvider = userProvider;
223: }
224:
225: public String[] getOperators() {
226: return new String[] { ReportAlert.OPERATOR_EQUAL,
227: ReportAlert.OPERATOR_GREATER, ReportAlert.OPERATOR_LESS };
228: }
229:
230: public void setReportProvider(ReportProvider reportProvider) {
231: this .reportProvider = reportProvider;
232: }
233:
234: public int getReportId() {
235: return reportId;
236: }
237:
238: public void setReportId(int reportId) {
239: this.reportId = reportId;
240: }
241: }
|