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 32 public class ReportDetailAction extends ActionSupport 33 implements 34 ReportProviderAware, 35 ParameterProviderAware, 36 DateProviderAware 37 { 38 private Report report; 39 private int reportId = Integer.MIN_VALUE; 40 41 private String submitType; 42 43 private ParameterProvider parameterProvider; 44 private ReportProvider reportProvider; 45 private DateProvider dateProvider; 46 47 private List reportParameters; 48 private int step = 0; 49 50 private boolean displayInline; 51 52 public String execute() 53 { 54 try 55 { 56 ReportUser user = (ReportUser) ActionContext.getContext().getSession().get( 57 ORStatics.REPORT_USER); 58 59 report = reportProvider.getReport(new Integer (reportId)); 60 61 if (report == null) 62 { 63 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_INVALID)); 64 return ERROR; 65 } 66 67 if (!user.isValidReport(report)) 68 { 69 addActionError(LocalStrings.getString(LocalStrings.ERROR_REPORT_NOTAUTHORIZED)); 70 return ERROR; 71 } 72 73 report.setDisplayInline(displayInline); 74 reportParameters = report.getReportParametersByStep(step); 75 76 if (submitType == null) 77 { 78 HashMap newMap = new HashMap(); 80 newMap.put(ORStatics.USER_ID, user.getId()); 81 newMap.put(ORStatics.EXTERNAL_ID, user.getExternalId()); 82 newMap.put(ORStatics.USER_NAME, user.getName()); 83 84 ActionContext.getContext().getSession().remove(ORStatics.REPORT_PARAMETERS); 85 ActionContext.getContext().getSession().put(ORStatics.REPORT_PARAMETERS, newMap); 86 ActionContext.getContext().getSession().put(ORStatics.REPORT, report); 87 88 if (report.getParameters().size() > 0 && report.getParameters().size() != report.getSubReportParameters().size()) 89 { 90 parameterProvider.loadReportParameterValues(reportParameters, newMap); 91 92 return INPUT; 93 } 94 else 95 { 96 return SUCCESS; 97 } 98 } 99 100 parameterProvider.validateParameters(reportParameters, ActionContext.getContext() 101 .getParameters()); 102 103 Map map = (Map) ActionContext.getContext().getSession().get( 104 ORStatics.REPORT_PARAMETERS); 105 106 Map currentMap = parameterProvider.getReportParametersMap(reportParameters, 107 ActionContext.getContext().getParameters()); 108 109 map.putAll(currentMap); 110 111 ActionContext.getContext().getSession().put(ORStatics.REPORT_PARAMETERS, map); 112 113 step++; 114 115 reportParameters = report.getReportParametersByStep(step); 116 117 if (reportParameters.size() > 0) 118 { 119 parameterProvider.loadReportParameterValues(reportParameters, map); 120 121 return INPUT; 122 } 123 124 return SUCCESS; 125 } 126 catch (Exception e) 127 { 128 Map map = (Map) ActionContext.getContext().getSession().get( 129 ORStatics.REPORT_PARAMETERS); 130 131 try 132 { 133 parameterProvider.loadReportParameterValues(reportParameters, map); 134 } 135 catch (ProviderException pe) 136 { 137 addActionError(pe.getMessage()); 138 } 139 140 addActionError(e.getMessage()); 141 return INPUT; 142 } 143 } 144 145 public String getSubmitType() 146 { 147 return submitType; 148 } 149 150 public void setSubmitType(String submitType) 151 { 152 this.submitType = submitType; 153 } 154 155 public int getReportId() 156 { 157 return reportId; 158 } 159 160 public void setReportId(int reportId) 161 { 162 this.reportId = reportId; 163 } 164 165 public void setParameterProvider(ParameterProvider parameterProvider) 166 { 167 this.parameterProvider = parameterProvider; 168 } 169 170 public void setReportProvider(ReportProvider reportProvider) 171 { 172 this.reportProvider = reportProvider; 173 } 174 175 public List getReportParameters() 176 { 177 return reportParameters; 178 } 179 180 public int getStep() 181 { 182 return step; 183 } 184 185 public void setStep(int step) 186 { 187 this.step = step; 188 } 189 190 public void setDateProvider(DateProvider dateProvider) 191 { 192 this.dateProvider = dateProvider; 193 } 194 195 public String getDateFormat() 196 { 197 return dateProvider.getDateFormat().toPattern(); 198 } 199 200 public String getDefaultDate() 201 { 202 return dateProvider.formatDate(new Date()); 203 } 204 205 public Report getReport() 206 { 207 return report; 208 } 209 210 public void setReport(Report report) 211 { 212 this.report = report; 213 } 214 215 public boolean isDisplayInline() 216 { 217 return displayInline; 218 } 219 220 public void setDisplayInline(boolean displayInline) 221 { 222 this.displayInline = displayInline; 223 } 224 }
| Popular Tags
|