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

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/report/XmlReportStore.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.reporting.dataset.report;
 
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.File;
 
31
import java.io.FileInputStream;
 
32
import java.io.FileNotFoundException;
 
33
import java.io.FileOutputStream;
 
34
import java.io.IOException;
 
35
import java.io.InputStreamReader;
 
36
import java.io.OutputStreamWriter;
 
37
import java.io.Reader;
 
38
import java.io.Writer;
 
39
import java.util.ArrayList;
 
40
import java.util.Collection;
 
41
import java.util.Iterator;
 
42
import java.util.List;
 
43
 
 
44
import org.hisp.dhis.external.location.LocationManager;
 
45
import org.hisp.dhis.external.location.LocationManagerException;
 
46
import org.hisp.dhis.reporting.dataset.dataaccess.ReportDataAccess;
 
47
import org.hisp.dhis.reporting.dataset.dataaccess.ReportDataAccessException;
 
48
import org.hisp.dhis.reporting.dataset.utils.FileUtils;
 
49
import org.hisp.dhis.reporting.dataset.utils.JRXmlFilter;
 
50
import org.hisp.dhis.reporting.dataset.utils.XMLUtils;
 
51
import org.hisp.dhis.reporting.dataset.utils.XmlFilter;
 
52
 
 
53
import static org.hisp.dhis.reporting.dataset.utils.FileUtils.getXMLFileName;
 
54
import static org.hisp.dhis.reporting.dataset.utils.FileUtils.getJRXMLFileName;
 
55
import static org.hisp.dhis.reporting.dataset.utils.FileUtils.XML_DIR;
 
56
import static org.hisp.dhis.reporting.dataset.utils.FileUtils.JRXML_DIR;
 
57
 
 
58
import com.thoughtworks.xstream.XStream;
 
59
 
 
60
/**
 
61
 * @author Lars Helge Overland
 
62
 * @version $Id: XmlReportStore.java 5282 2008-05-28 10:41:06Z larshelg $
 
63
 */
 
64
public class XmlReportStore
 
65
    implements ReportStore
 
66
{
 
67
    // -------------------------------------------------------------------------
 
68
    // Options
 
69
    // -------------------------------------------------------------------------
 
70
    
 
71
    private static final String CHARSET = "UTF-8";
 
72
    
 
73
    private static final String NAME = "name";
 
74
    
 
75
    private static final String SHORT_NAME = "shortname";
 
76
    
 
77
    private String reportDisplayProperty;    
 
78
 
 
79
    public void setReportDisplayProperty( String reportDisplayProperty )
 
80
    {
 
81
        this.reportDisplayProperty = reportDisplayProperty;
 
82
    }
 
83
    
 
84
    // -------------------------------------------------------------------------
 
85
    // Dependencies
 
86
    // -------------------------------------------------------------------------
 
87
    
 
88
    private ReportDataAccess reportDataAccess;
 
89
 
 
90
    public void setReportDataAccess( ReportDataAccess reportDataAccess )
 
91
    {
 
92
        this.reportDataAccess = reportDataAccess;
 
93
    }
 
94
    
 
95
    private LocationManager locationManager;
 
96
 
 
97
    public void setLocationManager( LocationManager locationManager )
 
98
    {
 
99
        this.locationManager = locationManager;
 
100
    }
 
101
    
 
102
    // -------------------------------------------------------------------------
 
103
    // Report
 
104
    // -------------------------------------------------------------------------
 
105
    
 
106
    public void addReport( String name, int reportType )
 
107
        throws ReportStoreException, LocationManagerException
 
108
    {
 
109
        try
 
110
        {
 
111
            File file = locationManager.getFileForWriting( getXMLFileName( name ), XML_DIR );
 
112
            
 
113
            Report report = new Report( reportType );
 
114
            
 
115
            XStream xStream = new XStream();
 
116
            
 
117
            Writer out = new OutputStreamWriter( new FileOutputStream( file ), CHARSET );
 
118
                        
 
119
            xStream.toXML( report, out );
 
120
            
 
121
            out.close();            
 
122
        }
 
123
        catch ( IOException ex )
 
124
        {
 
125
            throw new ReportStoreException( "Failed to add report", ex );
 
126
        }
 
127
    }
 
128
    
 
129
    private void updateReport( String name, Report report )
 
130
        throws ReportStoreException, LocationManagerException
 
131
    {
 
132
        try
 
133
        {
 
134
            File file = locationManager.getFileForWriting( getXMLFileName( name ), XML_DIR );
 
135
            
 
136
            XStream xStream = new XStream();
 
137
            
 
138
            Writer out = new OutputStreamWriter( new FileOutputStream( file ), CHARSET );
 
139
                        
 
140
            xStream.toXML( report, out ); 
 
141
            
 
142
            out.close();
 
143
        }
 
144
        catch ( IOException ex )
 
145
        {
 
146
            throw new ReportStoreException( "Failed to add report", ex );
 
147
        }
 
148
    }
 
149
    
 
150
    public Report getReport( String name )
 
151
        throws ReportStoreException, LocationManagerException
 
152
    {
 
153
        try
 
154
        {
 
155
            File file = locationManager.getFileForReading( getXMLFileName( name ), XML_DIR );           
 
156
            
 
157
            XStream xStream = new XStream();
 
158
            
 
159
            Reader in = new InputStreamReader( new FileInputStream( file ), CHARSET );
 
160
                
 
161
            Report report = (Report) xStream.fromXML( in );
 
162
            
 
163
            in.close();
 
164
            
 
165
            return report;
 
166
        }
 
167
        catch ( FileNotFoundException ex )
 
168
        {
 
169
            throw new ReportStoreException( "File not found, failed to get report", ex );
 
170
        }
 
171
        catch ( IOException ex )
 
172
        {
 
173
            throw new ReportStoreException( "Failed to close inputstream", ex );
 
174
        }
 
175
    }
 
176
    
 
177
    public int getReportType( String reportName )
 
178
        throws ReportStoreException, LocationManagerException
 
179
    {
 
180
        Report report = getReport( reportName );
 
181
        
 
182
        return report.getReportType();
 
183
    }
 
184
    
 
185
    public boolean deleteReport( String name )
 
186
        throws ReportStoreException, LocationManagerException
 
187
    {
 
188
        try
 
189
        {
 
190
            File file = locationManager.getFileForWriting( getJRXMLFileName( name ), JRXML_DIR );
 
191
            
 
192
            file.delete();
 
193
        }
 
194
        catch ( LocationManagerException ex )
 
195
        {   
 
196
        }
 
197
        
 
198
        File file = locationManager.getFileForWriting( getXMLFileName( name ), XML_DIR );
 
199
            
 
200
        return file.delete();
 
201
    }
 
202
    
 
203
    public Collection<String> getAllReports()
 
204
        throws ReportStoreException, LocationManagerException
 
205
    {
 
206
        File dir = locationManager.getFileForReading( XML_DIR );
 
207
        
 
208
        File[] files = dir.listFiles( new XmlFilter() );
 
209
        
 
210
        List<String> list = new ArrayList<String>();
 
211
        
 
212
        for ( int i = 0; i < files.length; i++ )
 
213
        {
 
214
            list.add( FileUtils.getBaseName( files[ i ] ) );            
 
215
        }
 
216
        
 
217
        return list;
 
218
    }
 
219
    
 
220
    public Collection<String> getAllDesigns()
 
221
        throws ReportStoreException, LocationManagerException
 
222
    {
 
223
        File dir = locationManager.getFileForReading( XML_DIR );
 
224
        
 
225
        File[] files = dir.listFiles( new JRXmlFilter() );
 
226
        
 
227
        List<String> list = new ArrayList<String>();
 
228
        
 
229
        for ( int i = 0; i < files.length; i++ )
 
230
        {
 
231
            list.add( FileUtils.getBaseName( files[ i ] ) );            
 
232
        }
 
233
        
 
234
        return list;
 
235
    }
 
236
 
 
237
    public Collection<String> getDesignsByType( int reportType )
 
238
        throws ReportStoreException, LocationManagerException
 
239
    {        
 
240
        List<String> designNamesByType = new ArrayList<String>();
 
241
        
 
242
        for ( String designName : getAllDesigns() )
 
243
        {
 
244
            if ( getReportType( designName ) == reportType )
 
245
            {
 
246
                designNamesByType.add( designName );
 
247
            }
 
248
        }
 
249
        
 
250
        return designNamesByType;
 
251
    }
 
252
    
 
253
    public boolean isXMLReportExists( String reportName )
 
254
    {
 
255
        try
 
256
        {
 
257
            locationManager.getFileForReading( getXMLFileName( reportName ), XML_DIR );
 
258
            
 
259
            return true;
 
260
        }
 
261
        catch ( LocationManagerException ex )
 
262
        {
 
263
            return false;
 
264
        }
 
265
    }
 
266
 
 
267
    public boolean isJRXMLReportExists( String reportName )
 
268
    {
 
269
        try
 
270
        {
 
271
            locationManager.getFileForReading( getJRXMLFileName( reportName ), JRXML_DIR );
 
272
            
 
273
            return true;
 
274
        }
 
275
        catch ( LocationManagerException ex )
 
276
        {
 
277
            return false;
 
278
        }
 
279
    }
 
280
        
 
281
    // -----------------------------------------------------------------------
 
282
    // ReportElement
 
283
    // -----------------------------------------------------------------------
 
284
    
 
285
    public void addReportElement( String reportName, String type, int elementId )
 
286
        throws ReportStoreException, LocationManagerException
 
287
    {
 
288
        try
 
289
        {
 
290
            reportName = XMLUtils.encode( reportName );
 
291
            
 
292
            Report report = getReport( reportName );
 
293
            
 
294
            List<Element> reportElements = report.getReportElements();
 
295
            
 
296
            String elementName = "";
 
297
            
 
298
            if ( type.equals( ReportStore.DATAELEMENT ) )
 
299
            {
 
300
                if ( reportDisplayProperty.equals( NAME ) )
 
301
                {
 
302
                    elementName = reportDataAccess.getDataElementName( elementId );
 
303
                }
 
304
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
305
                {
 
306
                    elementName = reportDataAccess.getDataElementShortName( elementId );
 
307
                }
 
308
            }
 
309
            else if ( type.equals( ReportStore.INDICATOR ) )
 
310
            {
 
311
                if ( reportDisplayProperty.equals( NAME ) )
 
312
                {
 
313
                    elementName = reportDataAccess.getIndicatorName( elementId );
 
314
                }
 
315
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
316
                {
 
317
                    elementName = reportDataAccess.getIndicatorShortName( elementId );
 
318
                }
 
319
            }
 
320
            
 
321
            elementName = XMLUtils.encode( elementName );
 
322
            
 
323
            Element element = new Element( type, elementId, elementName );
 
324
            
 
325
            reportElements.add( element );
 
326
            
 
327
            updateReport( reportName, report );
 
328
        }
 
329
        catch ( ReportDataAccessException ex )
 
330
        {
 
331
            throw new ReportStoreException( "Failed to retrieve data", ex );
 
332
        }
 
333
    }
 
334
    
 
335
    public void addReportElement( String reportName, String type, int elementId, int organisationUnitId )
 
336
        throws ReportStoreException, LocationManagerException
 
337
    {
 
338
        try
 
339
        {
 
340
            Report report = getReport( reportName );
 
341
            
 
342
            List<Element> reportElements = report.getReportElements();
 
343
            
 
344
            String elementName = "";
 
345
            
 
346
            if ( type.equals( ReportStore.DATAELEMENT ) )
 
347
            {
 
348
                if ( reportDisplayProperty.equals( NAME ) )
 
349
                {
 
350
                    elementName = reportDataAccess.getDataElementName( elementId );
 
351
                }
 
352
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
353
                {
 
354
                    elementName = reportDataAccess.getDataElementShortName( elementId );
 
355
                }
 
356
            }
 
357
            else if ( type.equals( ReportStore.INDICATOR ) )
 
358
            {
 
359
                if ( reportDisplayProperty.equals( NAME ) )
 
360
                {
 
361
                    elementName = reportDataAccess.getIndicatorName( elementId );
 
362
                }
 
363
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
364
                {
 
365
                    elementName = reportDataAccess.getIndicatorShortName( elementId );
 
366
                }
 
367
            }
 
368
                        
 
369
            String organisationUnitName = reportDataAccess.getOrganisationUnitShortName( organisationUnitId );
 
370
 
 
371
            elementName = XMLUtils.encode( elementName );
 
372
            
 
373
            organisationUnitName = XMLUtils.encode( organisationUnitName );
 
374
            
 
375
            OrgUnitSpecificElement element = new OrgUnitSpecificElement( type, elementId, elementName, 
 
376
                organisationUnitId, organisationUnitName );
 
377
            
 
378
            reportElements.add( element );
 
379
            
 
380
            updateReport( reportName, report );
 
381
        }
 
382
        catch ( ReportDataAccessException ex )
 
383
        {
 
384
            throw new ReportStoreException( "Failed to retrieve data", ex );
 
385
        }
 
386
    }
 
387
    
 
388
    public void removeReportElement( String reportName, String id )
 
389
        throws ReportStoreException, LocationManagerException
 
390
    {
 
391
        reportName = XMLUtils.encode( reportName );
 
392
        
 
393
        Report report = getReport( reportName );
 
394
        
 
395
        List<Element> reportElements = report.getReportElements();
 
396
        
 
397
        Element element = getReportElement( reportName, id );
 
398
        
 
399
        reportElements.remove( element );
 
400
        
 
401
        updateReport( reportName, report );
 
402
    }
 
403
    
 
404
    private Element getReportElement( String reportName, String id )
 
405
        throws ReportStoreException, LocationManagerException
 
406
    {
 
407
        reportName = XMLUtils.encode( reportName );
 
408
        
 
409
        Collection<Element> reportElements = getAllReportElements( reportName );
 
410
        
 
411
        Iterator<Element> iterator = reportElements.iterator();
 
412
        
 
413
        while ( iterator.hasNext() )
 
414
        {
 
415
            Element element = iterator.next();
 
416
            
 
417
            if ( element.getId().equals( id ) )
 
418
            {
 
419
                return element;
 
420
            }
 
421
        }
 
422
        
 
423
        return null;
 
424
    }
 
425
    
 
426
    public void moveUpReportElement( String reportName, String id )
 
427
        throws ReportStoreException, LocationManagerException
 
428
    {
 
429
        reportName = XMLUtils.encode( reportName );
 
430
        
 
431
        Report report = getReport( reportName );
 
432
        
 
433
        List<Element> reportElements = report.getReportElements();
 
434
        
 
435
        Element element = getReportElement( reportName, id );
 
436
        
 
437
        int index = reportElements.indexOf( element );
 
438
        
 
439
        if ( index > 0 )
 
440
        {
 
441
            Element tempElement = reportElements.get( index - 1 );
 
442
            
 
443
            reportElements.set( index - 1, element );
 
444
            
 
445
            reportElements.set( index, tempElement );
 
446
        }
 
447
        
 
448
        updateReport( reportName, report );
 
449
    }
 
450
    
 
451
    public void moveDownReportElement( String reportName, String id )
 
452
        throws ReportStoreException, LocationManagerException
 
453
    {
 
454
        reportName = XMLUtils.encode( reportName );
 
455
        
 
456
        Report report = getReport( reportName );
 
457
        
 
458
        List<Element> reportElements = report.getReportElements();
 
459
        
 
460
        Element element = getReportElement( reportName, id );
 
461
        
 
462
        int index = reportElements.indexOf( element );
 
463
        
 
464
        if ( index < reportElements.size() - 1 )
 
465
        {
 
466
            Element tempElement = reportElements.get( index + 1 );
 
467
            
 
468
            reportElements.set( index + 1, element );
 
469
            
 
470
            reportElements.set( index, tempElement );
 
471
        }
 
472
        
 
473
        updateReport( reportName, report );
 
474
    }
 
475
    
 
476
    public Collection<Element> getAllReportElements( String reportName )
 
477
        throws ReportStoreException, LocationManagerException
 
478
    {
 
479
        Report report = getReport( reportName );
 
480
        
 
481
        return report.getReportElements();
 
482
    }
 
483
 
 
484
    // -----------------------------------------------------------------------
 
485
    // ChartElement
 
486
    // -----------------------------------------------------------------------
 
487
    
 
488
    public void addChartElement( String reportName, String type, int elementId )
 
489
        throws ReportStoreException, LocationManagerException
 
490
    {
 
491
        try
 
492
        {
 
493
            reportName = XMLUtils.encode( reportName );
 
494
            
 
495
            Report report = getReport( reportName );
 
496
            
 
497
            List<Element> chartElements = report.getChartElements();
 
498
            
 
499
            String elementName = "";
 
500
            
 
501
            if ( type.equals( ReportStore.DATAELEMENT ) )
 
502
            {
 
503
                if ( reportDisplayProperty.equals( NAME ) )
 
504
                {
 
505
                    elementName = reportDataAccess.getDataElementName( elementId );
 
506
                }
 
507
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
508
                {
 
509
                    elementName = reportDataAccess.getDataElementShortName( elementId );
 
510
                }
 
511
            }
 
512
            else if ( type.equals( ReportStore.INDICATOR ) )
 
513
            {
 
514
                if ( reportDisplayProperty.equals( NAME ) )
 
515
                {
 
516
                    elementName = reportDataAccess.getIndicatorName( elementId );
 
517
                }
 
518
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
519
                {
 
520
                    elementName = reportDataAccess.getIndicatorShortName( elementId );
 
521
                }
 
522
            }
 
523
            
 
524
            elementName = XMLUtils.encode( elementName );
 
525
            
 
526
            Element element = new Element( type, elementId, elementName );
 
527
                        
 
528
            chartElements.add( element );
 
529
            
 
530
            updateReport( reportName, report );
 
531
        }
 
532
        catch ( ReportDataAccessException ex )
 
533
        {
 
534
            throw new ReportStoreException( "Failed to retrieve data", ex );
 
535
        }
 
536
    }
 
537
    
 
538
    public void addChartElement( String reportName, String type, int elementId, int organisationUnitId )
 
539
        throws ReportStoreException, LocationManagerException
 
540
    {
 
541
        try
 
542
        {
 
543
            reportName = XMLUtils.encode( reportName );
 
544
            
 
545
            Report report = getReport( reportName );
 
546
            
 
547
            List<Element> chartElements = report.getChartElements();
 
548
            
 
549
            String elementName = "";
 
550
            
 
551
            if ( type.equals( ReportStore.DATAELEMENT ) )
 
552
            {
 
553
                if ( reportDisplayProperty.equals( NAME ) )
 
554
                {
 
555
                    elementName = reportDataAccess.getDataElementName( elementId );
 
556
                }
 
557
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
558
                {
 
559
                    elementName = reportDataAccess.getDataElementShortName( elementId );
 
560
                }
 
561
            }
 
562
            else if ( type.equals( ReportStore.INDICATOR ) )
 
563
            {
 
564
                if ( reportDisplayProperty.equals( NAME ) )
 
565
                {
 
566
                    elementName = reportDataAccess.getIndicatorName( elementId );
 
567
                }
 
568
                else if ( reportDisplayProperty.equals( SHORT_NAME ) )
 
569
                {
 
570
                    elementName = reportDataAccess.getIndicatorShortName( elementId );
 
571
                }
 
572
            }
 
573
            
 
574
            String organisationUnitName = reportDataAccess.getOrganisationUnitShortName( organisationUnitId );
 
575
            
 
576
            elementName = XMLUtils.encode( elementName );
 
577
            
 
578
            organisationUnitName = XMLUtils.encode( organisationUnitName );
 
579
            
 
580
            OrgUnitSpecificElement element = new OrgUnitSpecificElement( type, elementId, elementName,
 
581
                organisationUnitId, organisationUnitName );
 
582
                        
 
583
            chartElements.add( element );
 
584
            
 
585
            updateReport( reportName, report );
 
586
        }
 
587
        catch ( ReportDataAccessException ex )
 
588
        {
 
589
            throw new ReportStoreException( "Failed to retrieve data", ex );
 
590
        }
 
591
    }
 
592
    
 
593
    public void removeChartElement( String reportName, String id )
 
594
        throws ReportStoreException, LocationManagerException
 
595
    {
 
596
        reportName = XMLUtils.encode( reportName );
 
597
        
 
598
        Report report = getReport( reportName );
 
599
        
 
600
        List<Element> chartElements = report.getChartElements();
 
601
        
 
602
        Iterator<Element> iterator = chartElements.iterator();
 
603
        
 
604
        while ( iterator.hasNext() )
 
605
        {
 
606
            Element element = iterator.next();
 
607
            
 
608
            if ( element.getId().equals( id ) )
 
609
            {
 
610
                iterator.remove();
 
611
            }
 
612
        }
 
613
        
 
614
        updateReport( reportName, report );
 
615
    }
 
616
    
 
617
    private Element getChartElement( String reportName, String id )
 
618
        throws ReportStoreException, LocationManagerException
 
619
    {
 
620
        reportName = XMLUtils.encode( reportName );
 
621
        
 
622
        Collection<Element> chartElements = getAllChartElements( reportName );
 
623
        
 
624
        Iterator<Element> iterator = chartElements.iterator();
 
625
        
 
626
        while ( iterator.hasNext() )
 
627
        {
 
628
            Element element = iterator.next();
 
629
            
 
630
            if ( element.getId().equals( id ) )
 
631
            {
 
632
                return element;
 
633
            }
 
634
        }
 
635
        
 
636
        return null;
 
637
    }
 
638
    
 
639
    public void moveUpChartElement( String reportName, String id )
 
640
        throws ReportStoreException, LocationManagerException
 
641
    {
 
642
        reportName = XMLUtils.encode( reportName );
 
643
        
 
644
        Report report = getReport( reportName );
 
645
        
 
646
        List<Element> chartElements = report.getChartElements();
 
647
        
 
648
        Element element = getChartElement( reportName, id );
 
649
        
 
650
        int index = chartElements.indexOf( element );
 
651
        
 
652
        if ( index > 0 )
 
653
        {
 
654
            Element tempElement = chartElements.get( index - 1 );
 
655
            
 
656
            chartElements.set( index - 1, element );
 
657
            
 
658
            chartElements.set( index, tempElement );
 
659
        }
 
660
        
 
661
        updateReport( reportName, report );
 
662
    }
 
663
    
 
664
    public void moveDownChartElement( String reportName, String id )
 
665
        throws ReportStoreException, LocationManagerException
 
666
    {
 
667
        reportName = XMLUtils.encode( reportName );
 
668
        
 
669
        Report report = getReport( reportName );
 
670
        
 
671
        List<Element> chartElements = report.getChartElements();
 
672
        
 
673
        Element element = getChartElement( reportName, id );
 
674
        
 
675
        int index = chartElements.indexOf( element );
 
676
        
 
677
        if ( index < chartElements.size() - 1 )
 
678
        {
 
679
            Element tempElement = chartElements.get( index + 1 );
 
680
            
 
681
            chartElements.set( index + 1, element );
 
682
            
 
683
            chartElements.set( index, tempElement );
 
684
        }
 
685
        
 
686
        updateReport( reportName, report );
 
687
    }
 
688
        
 
689
    public Collection<Element> getAllChartElements( String reportName )
 
690
        throws ReportStoreException, LocationManagerException
 
691
    {
 
692
        reportName = XMLUtils.encode( reportName );
 
693
        
 
694
        Report report = getReport( reportName );
 
695
        
 
696
        return report.getChartElements();
 
697
    }
 
698
        
 
699
    // -----------------------------------------------------------------------
 
700
    // Design Template
 
701
    // -----------------------------------------------------------------------
 
702
    
 
703
    public void setDesignTemplate( String reportName, int number )
 
704
        throws ReportStoreException, LocationManagerException
 
705
    {
 
706
        reportName = XMLUtils.encode( reportName );
 
707
        
 
708
        Report report = getReport( reportName );
 
709
        
 
710
        report.setDesignTemplate( number );
 
711
        
 
712
        updateReport( reportName, report );
 
713
    }
 
714
    
 
715
    public int getDesignTemplate( String reportName )
 
716
        throws ReportStoreException, LocationManagerException
 
717
    {
 
718
        reportName = XMLUtils.encode( reportName );
 
719
        
 
720
        Report report = getReport( reportName );
 
721
        
 
722
        return report.getDesignTemplate();
 
723
    }
 
724
 
 
725
    // -------------------------------------------------------------------------
 
726
    // Chart Template
 
727
    // -------------------------------------------------------------------------
 
728
    
 
729
    public void setChartTemplate( String reportName, int number )
 
730
        throws ReportStoreException, LocationManagerException
 
731
    {
 
732
        reportName = XMLUtils.encode( reportName );
 
733
        
 
734
        Report report = getReport( reportName );
 
735
        
 
736
        report.setChartTemplate( number );
 
737
        
 
738
        updateReport( reportName, report );
 
739
    }
 
740
    
 
741
    public int getChartTemplate( String reportName )
 
742
        throws ReportStoreException, LocationManagerException
 
743
    {
 
744
        reportName = XMLUtils.encode( reportName );
 
745
        
 
746
        Report report = getReport( reportName );
 
747
        
 
748
        return report.getChartTemplate();
 
749
    }
 
750
}
 
751
 
 
752