1 19 20 package org.efs.openreports.actions.admin; 21 22 23 import java.util.*; 24 25 import com.opensymphony.xwork.ActionContext; 26 import com.opensymphony.xwork.ActionSupport; 27 28 import org.apache.log4j.Logger; 29 import org.efs.openreports.ORStatics; 30 import org.efs.openreports.objects.*; 31 import org.efs.openreports.providers.*; 32 import org.efs.openreports.util.ORUtil; 33 34 public class EditReportParameterAction extends ActionSupport implements DataSourceProviderAware, ParameterProviderAware 35 { 36 protected static Logger log = 37 Logger.getLogger(EditReportParameterAction.class); 38 39 private String command; 40 41 private boolean submitOk; 42 private boolean submitValidate; 43 44 private int id; 45 private String name; 46 private String type; 47 private String className; 48 private String data; 49 private int dataSourceId = Integer.MIN_VALUE; 50 private String description; 51 private boolean required; 52 private boolean multipleSelect; 53 54 private ReportParameter reportParameter; 55 private ReportParameter queryParameter; 56 57 private ReportParameterValue[] parameterValues; 58 59 private DataSourceProvider dataSourceProvider; 60 private ParameterProvider parameterProvider; 61 62 public String execute() 63 { 64 try 65 { 66 if (command.equals("edit")) 67 { 68 reportParameter = 69 parameterProvider.getReportParameter(new Integer (id)); 70 } 71 else 72 { 73 reportParameter = new ReportParameter(); 74 } 75 76 if (command.equals("edit") && !submitOk && !submitValidate) 77 { 78 name = reportParameter.getName(); 79 type = reportParameter.getType(); 80 className = reportParameter.getClassName(); 81 data = reportParameter.getData(); 82 id = reportParameter.getId().intValue(); 83 if (reportParameter.getDataSource() != null) 84 { 85 dataSourceId = 86 reportParameter.getDataSource().getId().intValue(); 87 } 88 description = reportParameter.getDescription(); 89 required = reportParameter.isRequired(); 90 multipleSelect = reportParameter.isMultipleSelect(); 91 } 92 93 if (!submitOk && !submitValidate) 94 return INPUT; 95 96 reportParameter.setName(name); 97 reportParameter.setType(type); 98 reportParameter.setClassName(className); 99 reportParameter.setData(data); 100 if (dataSourceId != -1) 101 reportParameter.setDataSource( 102 dataSourceProvider.getDataSource( 103 new Integer (dataSourceId))); 104 reportParameter.setDescription(description); 105 reportParameter.setRequired(required); 106 reportParameter.setMultipleSelect(multipleSelect); 107 108 if (submitValidate) 109 { 110 if (type.equals(ReportParameter.LIST_PARAM) 111 || type.equals(ReportParameter.QUERY_PARAM)) 112 { 113 Map map = null; 114 115 if (type.equals(ReportParameter.QUERY_PARAM) 116 && data.toUpperCase().indexOf("$P") > -1) 117 { 118 ReportUser reportUser = (ReportUser) ActionContext.getContext().getSession().get(ORStatics.REPORT_USER); 119 map = ORUtil.buildQueryParameterMap(reportUser, data, parameterProvider); 120 } 121 122 parameterValues = parameterProvider.getParamValues(reportParameter, map); 123 } 124 125 return INPUT; 126 } 127 128 if (command.equals("edit")) 129 { 130 parameterProvider.updateReportParameter(reportParameter); 131 } 132 133 if (command.equals("add")) 134 { 135 parameterProvider.insertReportParameter(reportParameter); 136 } 137 138 return SUCCESS; 139 } 140 catch (Exception e) 141 { 142 addActionError(e.getMessage()); 143 return INPUT; 144 } 145 } 146 147 public String getCommand() 148 { 149 return command; 150 } 151 152 public void setCommand(String command) 153 { 154 this.command = command; 155 } 156 157 public void setSubmitOk(String submitOk) 158 { 159 if (submitOk != null) this.submitOk = true; 160 } 161 162 public void setSubmitValidate(String submitValidate) 163 { 164 if (submitValidate != null) this.submitValidate = true; 165 } 166 167 public int getDataSourceId() 168 { 169 return dataSourceId; 170 } 171 172 public String getName() 173 { 174 return name; 175 } 176 177 public void setDataSourceId(int dataSourceId) 178 { 179 this.dataSourceId = dataSourceId; 180 } 181 182 public void setName(String name) 183 { 184 this.name = name; 185 } 186 187 public ReportParameter getQueryParameter() 188 { 189 return queryParameter; 190 } 191 192 public List getDataSources() 193 { 194 try 195 { 196 return dataSourceProvider.getDataSources(); 197 } 198 catch (Exception e) 199 { 200 addActionError(e.getMessage()); 201 return null; 202 } 203 } 204 205 public String [] getTypes() 206 { 207 return ReportParameter.TYPES; 208 } 209 210 public String [] getClassNames() 211 { 212 return ReportParameter.CLASS_NAMES; 213 } 214 215 public int getId() 216 { 217 return id; 218 } 219 220 public void setId(int id) 221 { 222 this.id = id; 223 } 224 225 public String getClassName() 226 { 227 return className; 228 } 229 230 public String getData() 231 { 232 return data; 233 } 234 235 public String getType() 236 { 237 return type; 238 } 239 240 public void setClassName(String className) 241 { 242 this.className = className; 243 } 244 245 public void setData(String data) 246 { 247 this.data = data; 248 } 249 250 public void setType(String type) 251 { 252 this.type = type; 253 } 254 255 public ReportParameterValue[] getParameterValues() 256 { 257 return parameterValues; 258 } 259 260 public void setParameterValues(ReportParameterValue[] parameterValues) 261 { 262 this.parameterValues = parameterValues; 263 } 264 265 public void setDataSourceProvider(DataSourceProvider dataSourceProvider) 266 { 267 this.dataSourceProvider = dataSourceProvider; 268 } 269 270 public void setParameterProvider(ParameterProvider parameterProvider) 271 { 272 this.parameterProvider = parameterProvider; 273 } 274 275 public String getDescription() 276 { 277 return description; 278 } 279 280 public void setDescription(String description) 281 { 282 this.description = description; 283 } 284 285 public boolean isRequired() 286 { 287 return required; 288 } 289 290 public void setRequired(boolean required) 291 { 292 this.required = required; 293 } 294 295 public boolean isMultipleSelect() 296 { 297 return multipleSelect; 298 } 299 300 public void setMultipleSelect(boolean multipleSelect) 301 { 302 this.multipleSelect = multipleSelect; 303 } 304 305 } | Popular Tags |