KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jaspersoft > jasperserver > war > action > ScheduleReportParametersAction


1 /*
2  * Copyright (C) 2006 JasperSoft http://www.jaspersoft.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed WITHOUT ANY WARRANTY; and without the
10  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
15  * or write to:
16  *
17  * Free Software Foundation, Inc.,
18  * 59 Temple Place - Suite 330,
19  * Boston, MA USA 02111-1307
20  */

21 package com.jaspersoft.jasperserver.war.action;
22
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import org.springframework.webflow.AttributeMap;
27 import org.springframework.webflow.Event;
28 import org.springframework.webflow.RequestContext;
29 import org.springframework.webflow.ScopeType;
30
31 import com.jaspersoft.jasperserver.api.engine.scheduling.domain.ReportJob;
32 import com.jaspersoft.jasperserver.api.metadata.jasperreports.domain.ReportUnit;
33 import com.jaspersoft.jasperserver.war.dto.RuntimeInputControlWrapper;
34
35 /**
36  * @author Lucian Chirita (lucianc@users.sourceforge.net)
37  * @version $Id: ScheduleReportParametersAction.java 4106 2006-08-04 15:21:10Z lucian $
38  */

39 public class ScheduleReportParametersAction extends ReportParametersAction {
40
41
42     private String JavaDoc jobFormObjectName;
43     private Class JavaDoc jobFormObjectClass;
44     private ScopeType jobFormObjectScope;
45
46     public Class JavaDoc getJobFormObjectClass() {
47         return jobFormObjectClass;
48     }
49
50     public void setJobFormObjectClass(Class JavaDoc jobFormObjectClass) {
51         this.jobFormObjectClass = jobFormObjectClass;
52     }
53
54     public String JavaDoc getJobFormObjectName() {
55         return jobFormObjectName;
56     }
57
58     public void setJobFormObjectName(String JavaDoc jobFormObjectName) {
59         this.jobFormObjectName = jobFormObjectName;
60     }
61
62     public ScopeType getJobFormObjectScope() {
63         return jobFormObjectScope;
64     }
65
66     public void setJobFormObjectScope(ScopeType jobFormObjectScope) {
67         this.jobFormObjectScope = jobFormObjectScope;
68     }
69
70     public Event checkForParameters(RequestContext context) throws Exception JavaDoc
71     {
72         Event event = createWrappers(context, false);
73         if (event.getId().equals("error")) {
74             return event;
75         }
76         return success();
77     }
78
79     public Event setParameterValues(RequestContext context) {
80         Map JavaDoc parameterValues = getParameterValues(context, false);
81         if (parameterValues == null) {
82             return error();
83         }
84         
85         ReportJob reportJob = getReportJob(context);
86         reportJob.getSource().setParametersMap(parameterValues);
87
88         return success();
89     }
90
91     protected void addCustomParameters(RequestContext context, Map JavaDoc parameterValues) {
92     }
93
94     protected List JavaDoc createWrappers(RequestContext context, ReportUnit reportUnit) throws Exception JavaDoc
95     {
96         List JavaDoc wrappers = super.createWrappers(context, reportUnit);
97
98         for (int i = 0; i < wrappers.size(); i++) {
99             RuntimeInputControlWrapper wrapper = (RuntimeInputControlWrapper) wrappers.get(i);
100             ReportJob reportJob = getReportJob(context);
101             Map JavaDoc paramValues = reportJob.getSource().getParametersMap();
102             if (paramValues != null && !paramValues.isEmpty()) {
103                 String JavaDoc paramName = wrapper.getInputControl().getName();
104                 if (paramValues.containsKey(paramName)) {
105                     Object JavaDoc value = paramValues.get(paramName);
106                     wrapper.setValue(value);
107                 }
108             }
109         }
110
111         return wrappers;
112     }
113     
114     protected ReportJob getReportJob(RequestContext context) {
115         AttributeMap scope = getJobFormObjectScope().getScope(context);
116         return (ReportJob) scope.getRequired(getJobFormObjectName(), getJobFormObjectClass());
117     }
118
119 }
120
Popular Tags