~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to local/vn/dhis-web-hue-reporttool/src/main/java/org/hisp/dhis/rt/action/AbstractAction.java

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hisp.dhis.rt.action;
 
2
 
 
3
/*
 
4
 * Copyright (c) 2004-2007, University of Oslo
 
5
 * All rights reserved.
 
6
 *
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 * * Redistributions of source code must retain the above copyright notice, this
 
10
 *   list of conditions and the following disclaimer.
 
11
 * * Redistributions in binary form must reproduce the above copyright notice,
 
12
 *   this list of conditions and the following disclaimer in the documentation
 
13
 *   and/or other materials provided with the distribution.
 
14
 * * Neither the name of the HISP project nor the names of its contributors may
 
15
 *   be used to endorse or promote products derived from this software without
 
16
 *   specific prior written permission.
 
17
 *
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 
22
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 
25
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
 
 
30
import java.io.InputStream;
 
31
import java.util.Collection;
 
32
 
 
33
import org.hisp.dhis.i18n.I18n;
 
34
import org.hisp.dhis.i18n.I18nFormat;
 
35
import org.hisp.dhis.organisationunit.OrganisationUnit;
 
36
import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 
37
import org.hisp.dhis.rt.report.ReportStore;
 
38
 
 
39
import com.opensymphony.xwork.ActionContext;
 
40
import com.opensymphony.xwork.ActionSupport;
 
41
 
 
42
/**
 
43
 * @author Lars Helge Overland
 
44
 * @version $Id: AbstractAction.java 2871 2007-02-20 16:04:11Z andegje $
 
45
 */
 
46
public abstract class AbstractAction
 
47
    extends ActionSupport
 
48
{
 
49
    // -----------------------------------------------------------------------
 
50
    // Dependencies
 
51
    // -----------------------------------------------------------------------
 
52
 
 
53
    protected ReportStore reportStore;
 
54
 
 
55
    protected OrganisationUnitSelectionManager selectionManager;
 
56
 
 
57
    public void setReportStore( ReportStore reportStore )
 
58
    {
 
59
        this.reportStore = reportStore;
 
60
    }
 
61
 
 
62
    public void setSelectionManager( OrganisationUnitSelectionManager selectionManager )
 
63
    {
 
64
        this.selectionManager = selectionManager;
 
65
    }
 
66
 
 
67
    // -----------------------------------------------------------------------
 
68
    // Constants
 
69
    // -----------------------------------------------------------------------
 
70
 
 
71
    protected final String REPORT = "Report";
 
72
 
 
73
    protected final String REPORT_TYPE = "ReportType";
 
74
 
 
75
    protected final String HTML_BUFFER = "HTML_buffer";
 
76
 
 
77
    protected final int ALL = 0;
 
78
 
 
79
    public int getALL()
 
80
    {
 
81
        return ALL;
 
82
    }
 
83
 
 
84
    // -----------------------------------------------------------------------
 
85
    // Parameters
 
86
    // -----------------------------------------------------------------------
 
87
 
 
88
    protected String report;
 
89
 
 
90
    protected String reportName;
 
91
 
 
92
    protected Collection dataElementId;
 
93
 
 
94
    protected Collection indicatorId;
 
95
 
 
96
    protected int dataElementGroupId;
 
97
 
 
98
    protected int indicatorGroupId;
 
99
 
 
100
    protected int designTemplate;
 
101
 
 
102
    protected int chartTemplate;
 
103
 
 
104
    protected String elementId;
 
105
 
 
106
    protected String startDate;
 
107
 
 
108
    protected String endDate;
 
109
 
 
110
    protected String message;
 
111
 
 
112
    protected int organisationUnitId;
 
113
 
 
114
    protected InputStream inputStream;
 
115
 
 
116
    public String getReport()
 
117
    {
 
118
        return report;
 
119
    }
 
120
 
 
121
    public void setReport( String report )
 
122
    {
 
123
        this.report = report;
 
124
    }
 
125
 
 
126
    public String getReportName()
 
127
    {
 
128
        return reportName;
 
129
    }
 
130
 
 
131
    public void setReportName( String reportName )
 
132
    {
 
133
        this.reportName = reportName;
 
134
    }
 
135
 
 
136
    public Collection getDataElementId()
 
137
    {
 
138
        return dataElementId;
 
139
    }
 
140
 
 
141
    public void setDataElementId( Collection dataElementId )
 
142
    {
 
143
        this.dataElementId = dataElementId;
 
144
    }
 
145
 
 
146
    public Collection getIndicatorId()
 
147
    {
 
148
        return indicatorId;
 
149
    }
 
150
 
 
151
    public void setIndicatorId( Collection indicatorId )
 
152
    {
 
153
        this.indicatorId = indicatorId;
 
154
    }
 
155
 
 
156
    public int getDataElementGroupId()
 
157
    {
 
158
        return dataElementGroupId;
 
159
    }
 
160
 
 
161
    public void setDataElementGroupId( int dataElementGroupId )
 
162
    {
 
163
        this.dataElementGroupId = dataElementGroupId;
 
164
    }
 
165
 
 
166
    public int getIndicatorGroupId()
 
167
    {
 
168
        return indicatorGroupId;
 
169
    }
 
170
 
 
171
    public void setIndicatorGroupId( int indicatorGroupId )
 
172
    {
 
173
        this.indicatorGroupId = indicatorGroupId;
 
174
    }
 
175
 
 
176
    public int getChartTemplate()
 
177
    {
 
178
        return chartTemplate;
 
179
    }
 
180
 
 
181
    public void setChartTemplate( int chartTemplate )
 
182
    {
 
183
        this.chartTemplate = chartTemplate;
 
184
    }
 
185
 
 
186
    public int getDesignTemplate()
 
187
    {
 
188
        return designTemplate;
 
189
    }
 
190
 
 
191
    public void setDesignTemplate( int designTemplate )
 
192
    {
 
193
        this.designTemplate = designTemplate;
 
194
    }
 
195
 
 
196
    public void setElementId( String elementId )
 
197
    {
 
198
        this.elementId = elementId;
 
199
    }
 
200
 
 
201
    public String getEndDate()
 
202
    {
 
203
        return endDate;
 
204
    }
 
205
 
 
206
    public void setEndDate( String endDate )
 
207
    {
 
208
        this.endDate = endDate;
 
209
    }
 
210
 
 
211
    public String getStartDate()
 
212
    {
 
213
        return startDate;
 
214
    }
 
215
 
 
216
    public void setStartDate( String startDate )
 
217
    {
 
218
        this.startDate = startDate;
 
219
    }
 
220
 
 
221
    public String getMessage()
 
222
    {
 
223
        return message;
 
224
    }
 
225
 
 
226
    public void setMessage( String message )
 
227
    {
 
228
        this.message = message;
 
229
    }
 
230
 
 
231
    public InputStream getInputStream()
 
232
    {
 
233
        return inputStream;
 
234
    }
 
235
 
 
236
    public void setInputStream( InputStream inputStream )
 
237
    {
 
238
        this.inputStream = inputStream;
 
239
    }
 
240
 
 
241
    // -----------------------------------------------------------------------
 
242
    // I18n
 
243
    // -----------------------------------------------------------------------
 
244
 
 
245
    protected I18n i18n;
 
246
 
 
247
    public void setI18n( I18n i18n )
 
248
    {
 
249
        this.i18n = i18n;
 
250
    }
 
251
 
 
252
    protected I18nFormat format;
 
253
 
 
254
    public void setFormat( I18nFormat format )
 
255
    {
 
256
        this.format = format;
 
257
    }
 
258
 
 
259
    // -----------------------------------------------------------------------
 
260
    // Organisation Unit Tree
 
261
    // -----------------------------------------------------------------------
 
262
 
 
263
    protected int getSelectedOrganisationUnitId()
 
264
    {
 
265
        int organisationUnitId = 0;
 
266
 
 
267
        OrganisationUnit selectedUnit = selectionManager.getSelectedOrganisationUnit();
 
268
 
 
269
        if ( selectedUnit != null )
 
270
        {
 
271
            organisationUnitId = selectedUnit.getId();
 
272
        }
 
273
 
 
274
        return organisationUnitId;
 
275
    }
 
276
 
 
277
    // -----------------------------------------------------------------------
 
278
    // Session
 
279
    // -----------------------------------------------------------------------
 
280
 
 
281
    protected final Object getSessionVar( String name )
 
282
    {
 
283
        return ActionContext.getContext().getSession().get( name );
 
284
    }
 
285
 
 
286
    @SuppressWarnings( "unchecked" )
 
287
    protected final void setSessionVar( String name, Object value )
 
288
    {
 
289
        ActionContext.getContext().getSession().put( name, value );
 
290
    }
 
291
 
 
292
    protected final boolean containsSessionVar( String name )
 
293
    {
 
294
        return ActionContext.getContext().getSession().containsKey( name );
 
295
    }
 
296
 
 
297
    protected final void removeSessionVar( String name )
 
298
    {
 
299
        ActionContext.getContext().getSession().remove( name );
 
300
    }
 
301
 
 
302
    // -----------------------------------------------------------------------
 
303
    // Validation
 
304
    // -----------------------------------------------------------------------
 
305
 
 
306
    protected boolean reportName()
 
307
    {
 
308
        if ( reportName == null || reportName.equals( "" ) )
 
309
        {
 
310
            message = i18n.getString( "error_reportName" );
 
311
            return false;
 
312
        }
 
313
        return true;
 
314
    }
 
315
 
 
316
    protected boolean report()
 
317
    {
 
318
        if ( report == null || report.equals( "" ) )
 
319
        {
 
320
            message = i18n.getString( "error_report" );
 
321
            return false;
 
322
        }
 
323
        return true;
 
324
    }
 
325
 
 
326
    protected boolean startDate()
 
327
    {
 
328
        if ( format.parseDate( startDate ) == null )
 
329
        {
 
330
            message = i18n.getString( "error_startDate" );
 
331
            return false;
 
332
        }
 
333
        return true;
 
334
    }
 
335
 
 
336
    protected boolean endDate()
 
337
    {
 
338
        if ( format.parseDate( endDate ) == null )
 
339
        {
 
340
            message = i18n.getString( "error_endDate" );
 
341
            return false;
 
342
        }
 
343
        return true;
 
344
    }
 
345
 
 
346
    protected boolean indicatorId()
 
347
    {
 
348
        if ( indicatorId == null )
 
349
        {
 
350
            message = i18n.getString( "error_indicatorId" );
 
351
            return false;
 
352
        }
 
353
        return true;
 
354
    }
 
355
 
 
356
    protected boolean dataElementId()
 
357
    {
 
358
        if ( dataElementId == null )
 
359
        {
 
360
            message = i18n.getString( "error_dataElementId" );
 
361
            return false;
 
362
        }
 
363
        return true;
 
364
    }
 
365
 
 
366
    protected boolean organisationUnitId()
 
367
    {
 
368
        if ( organisationUnitId == 0 )
 
369
        {
 
370
            message = i18n.getString( "error_organisationUnitId" );
 
371
            return false;
 
372
        }
 
373
        return true;
 
374
    }
 
375
 
 
376
}