1 19 20 package org.efs.openreports.actions; 21 22 import java.util.*; 23 24 import com.opensymphony.xwork.ActionContext; 25 import com.opensymphony.xwork.ActionSupport; 26 27 import org.efs.openreports.ORStatics; 28 import org.efs.openreports.objects.*; 29 import org.efs.openreports.providers.*; 30 import org.efs.openreports.util.LocalStrings; 31 import org.hibernate.HibernateException; 32 33 public class ExecuteReportAction extends ActionSupport 34 implements 35 ReportProviderAware, 36 ParameterProviderAware, 37 UserProviderAware 38 { 39 private int reportId; 40 private String reportName; 41 private String exportType; 42 private String userName; 43 private String password; 44 private boolean displayInline; 45 private boolean promptForParameters; 46 47 private ParameterProvider parameterProvider; 48 private ReportProvider reportProvider; 49 private UserProvider userProvider; 50 51 public String execute() 52 { 53 try 54 { 55 ReportUser user = null; 57 58 if (userName == null || userName.length() < 1) 59 { 60 user = (ReportUser) ActionContext.getContext().getSession().get( 61 ORStatics.REPORT_USER); 62 if (user != null) password = user.getPassword(); 63 } 64 else 65 { 66 user = userProvider.getUser(userName); 67 } 68 69 if (user == null || !user.getPassword().equals(password)) 70 { 71 addActionError(LocalStrings.getString(LocalStrings.ERROR_LOGIN_INVALID)); 72 return ERROR; 73 } 74 75 ActionContext.getContext().getSession().put(ORStatics.REPORT_USER, user); 76 77 Report report = null; 78 if (reportName != null && reportName.length() > 0) 79 { 80 report = reportProvider.getReport(reportName); 81 } 82 else 83 { 84 report = reportProvider.getReport(new Integer (reportId)); 85 } 86 87 if (report == null) 88 { 89 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_INVALID)); 90 return ERROR; 91 } 92 93 if (!user.isValidReport(report)) 95 { 96 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_NOTAUTHORIZED)); 97 return ERROR; 98 } 99 100 report.setDisplayInline(displayInline); 101 ActionContext.getContext().getSession().put(ORStatics.REPORT, report); 102 103 105 if (exportType == null || exportType.length() < 1) 106 { 107 if (!report.isQueryReport() && !report.isChartReport()) 108 { 109 addActionError(LocalStrings.getString(LocalStrings.ERROR_EXPORTTYPE_REQUIRED)); 110 return ERROR; 111 } 112 } 113 114 ActionContext.getContext().getSession().put(ORStatics.EXPORT_TYPE, exportType); 115 116 List reportParameters = report.getParameters(); 117 118 if (reportParameters != null && reportParameters.size() > 0 119 && promptForParameters) 120 { 121 return ORStatics.PROMPT_PARAMETERS_ACTION; 122 } 123 124 126 parameterProvider.validateParameters(reportParameters, ActionContext.getContext() 127 .getParameters()); 128 129 Map map = parameterProvider.getReportParametersMap(reportParameters, ActionContext 130 .getContext().getParameters()); 131 map.put(ORStatics.USER_ID, user.getId()); 132 map.put(ORStatics.EXTERNAL_ID, user.getExternalId()); 133 map.put(ORStatics.USER_NAME, user.getName()); 134 135 ActionContext.getContext().getSession().remove(ORStatics.REPORT_PARAMETERS); 136 ActionContext.getContext().getSession().put(ORStatics.REPORT_PARAMETERS, map); 137 138 if (report.isQueryReport()) return ORStatics.QUERY_REPORT_ACTION; 139 if (report.isChartReport()) return ORStatics.CHART_REPORT_ACTION; 140 if (report.isJXLSReport()) return ORStatics.JXLSREPORT_ACTION; 141 142 return SUCCESS; 143 } 144 catch (ProviderException e) 145 { 146 if (e.getException() instanceof HibernateException) 147 { 148 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_INVALID)); 149 return ERROR; 150 } 151 152 addActionError(e.getMessage()); 153 return ERROR; 154 } 155 } 156 157 public int getReportId() 158 { 159 return reportId; 160 } 161 162 public void setReportId(int reportId) 163 { 164 this.reportId = reportId; 165 } 166 167 public String getExportType() 168 { 169 return exportType; 170 } 171 172 public void setExportType(String exportType) 173 { 174 this.exportType = exportType; 175 } 176 177 public String getPassword() 178 { 179 return password; 180 } 181 182 public void setPassword(String password) 183 { 184 this.password = password; 185 } 186 187 public String getUserName() 188 { 189 return userName; 190 } 191 192 public void setUserName(String userName) 193 { 194 this.userName = userName; 195 } 196 197 public void setParameterProvider(ParameterProvider parameterProvider) 198 { 199 this.parameterProvider = parameterProvider; 200 } 201 202 public void setReportProvider(ReportProvider reportProvider) 203 { 204 this.reportProvider = reportProvider; 205 } 206 207 public void setUserProvider(UserProvider userProvider) 208 { 209 this.userProvider = userProvider; 210 } 211 212 public String getReportName() 213 { 214 return reportName; 215 } 216 217 public void setReportName(String reportName) 218 { 219 this.reportName = reportName; 220 } 221 222 public boolean isDisplayInline() 223 { 224 return displayInline; 225 } 226 227 public void setDisplayInline(boolean displayInline) 228 { 229 this.displayInline = displayInline; 230 } 231 232 public boolean isPromptForParameters() 233 { 234 return promptForParameters; 235 } 236 237 public void setPromptForParameters(boolean promptForParameters) 238 { 239 this.promptForParameters = promptForParameters; 240 } 241 }
| Popular Tags
|