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

« back to all changes in this revision

Viewing changes to dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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;
 
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.util.Calendar;
 
31
import java.util.Collection;
 
32
import java.util.Date;
 
33
import java.util.HashSet;
 
34
import java.util.Set;
 
35
 
 
36
import org.hisp.dhis.datadictionary.DataDictionary;
 
37
import org.hisp.dhis.datadictionary.DataDictionaryService;
 
38
import org.hisp.dhis.datadictionary.ExtendedDataElement;
 
39
import org.hisp.dhis.dataelement.CalculatedDataElement;
 
40
import org.hisp.dhis.dataelement.DataElement;
 
41
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 
42
import org.hisp.dhis.dataelement.DataElementCategoryComboService;
 
43
import org.hisp.dhis.dataelement.DataElementCategoryOption;
 
44
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 
45
import org.hisp.dhis.dataelement.DataElementCategoryOptionComboService;
 
46
import org.hisp.dhis.dataelement.DataElementCategoryOptionService;
 
47
import org.hisp.dhis.dataelement.DataElementCategoryService;
 
48
import org.hisp.dhis.dataelement.DataElementDimensionColumnOrderService;
 
49
import org.hisp.dhis.dataelement.DataElementDimensionRowOrderService;
 
50
import org.hisp.dhis.dataelement.DataElementGroup;
 
51
import org.hisp.dhis.dataelement.DataElementService;
 
52
import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 
53
import org.hisp.dhis.dataset.DataSet;
 
54
import org.hisp.dhis.dataset.DataSetService;
 
55
import org.hisp.dhis.datavalue.DataValue;
 
56
import org.hisp.dhis.datavalue.DataValueService;
 
57
import org.hisp.dhis.expression.Expression;
 
58
import org.hisp.dhis.expression.ExpressionService;
 
59
import org.hisp.dhis.importexport.ImportDataValue;
 
60
import org.hisp.dhis.importexport.ImportObjectStatus;
 
61
import org.hisp.dhis.indicator.Indicator;
 
62
import org.hisp.dhis.indicator.IndicatorGroup;
 
63
import org.hisp.dhis.indicator.IndicatorService;
 
64
import org.hisp.dhis.indicator.IndicatorType;
 
65
import org.hisp.dhis.organisationunit.OrganisationUnit;
 
66
import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 
67
import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 
68
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 
69
import org.hisp.dhis.organisationunit.OrganisationUnitService;
 
70
import org.hisp.dhis.period.Period;
 
71
import org.hisp.dhis.period.PeriodService;
 
72
import org.hisp.dhis.period.PeriodType;
 
73
import org.hisp.dhis.resourcetable.ResourceTableService;
 
74
import org.hisp.dhis.source.Source;
 
75
import org.hisp.dhis.source.SourceStore;
 
76
import org.hisp.dhis.validation.ValidationRule;
 
77
import org.hisp.dhis.validation.ValidationRuleGroup;
 
78
import org.hisp.dhis.validation.ValidationRuleService;
 
79
 
 
80
/**
 
81
 * @author Lars Helge Overland
 
82
 * @version $Id$
 
83
 */
 
84
public class DhisConvenienceTest
 
85
    extends DhisSpringTest
 
86
{
 
87
    private static final String BASE_UUID = "C3C2E28D-9686-4634-93FD-BE3133935EC";
 
88
 
 
89
    private static Date date;
 
90
    
 
91
    private static Calendar calendar;
 
92
 
 
93
    // -------------------------------------------------------------------------
 
94
    // Service references
 
95
    // -------------------------------------------------------------------------
 
96
 
 
97
    protected DataElementService dataElementService;
 
98
    
 
99
    protected DataElementCategoryService categoryService;
 
100
    
 
101
    protected DataElementCategoryComboService categoryComboService;
 
102
    
 
103
    protected DataElementCategoryOptionService categoryOptionService;
 
104
    
 
105
    protected DataElementCategoryOptionComboService categoryOptionComboService;
 
106
    
 
107
    protected DataElementDimensionColumnOrderService dimensionColumnOrderService;
 
108
    
 
109
    protected DataElementDimensionRowOrderService dimensionRowOrderService;
 
110
    
 
111
    protected DataDictionaryService dataDictionaryService;
 
112
    
 
113
    protected IndicatorService indicatorService;
 
114
    
 
115
    protected DataSetService dataSetService;
 
116
    
 
117
    protected CompleteDataSetRegistrationService completeDataSetRegistrationService;
 
118
    
 
119
    protected SourceStore sourceStore;
 
120
    
 
121
    protected OrganisationUnitService organisationUnitService;
 
122
    
 
123
    protected OrganisationUnitGroupService organisationUnitGroupService;
 
124
    
 
125
    protected PeriodService periodService;
 
126
    
 
127
    protected ValidationRuleService validationRuleService;
 
128
    
 
129
    protected ExpressionService expressionService;
 
130
    
 
131
    protected DataValueService dataValueService;
 
132
    
 
133
    protected ResourceTableService resourceTableService;
 
134
    
 
135
    static
 
136
    {
 
137
        calendar = Calendar.getInstance();
 
138
    
 
139
        calendar.set( 1970, Calendar.JANUARY, 1 );
 
140
    
 
141
        date = calendar.getTime();
 
142
    }
 
143
 
 
144
    // -------------------------------------------------------------------------
 
145
    // Convenience methods
 
146
    // -------------------------------------------------------------------------
 
147
 
 
148
    /**
 
149
     * Creates a date.
 
150
     * 
 
151
     * @param year the year.
 
152
     * @param month the month.
 
153
     * @param day the day of month.
 
154
     * @return a date.
 
155
     */
 
156
    protected static Date getDate( int year, int month, int day )
 
157
    {
 
158
        calendar.set( year, month - 1, day );
 
159
        
 
160
        return calendar.getTime();
 
161
    }
 
162
 
 
163
    /**
 
164
     * Compares two collections for equality. This method does not check for the
 
165
     * implementation type of the collection in contrast to the native equals
 
166
     * method. This is useful for black-box testing where one will not know the
 
167
     * implementation type of the returned collection for a method.
 
168
     * 
 
169
     * @param actual the actual collection to check.
 
170
     * @param reference the reference objects to check against.
 
171
     * @return true if the collections are equal, false otherwise.
 
172
     */
 
173
    protected static boolean equals( Collection<?> actual, Object... reference )
 
174
    {
 
175
        Collection<Object> collection = new HashSet<Object>();
 
176
        
 
177
        for ( Object object : reference )
 
178
        {
 
179
            collection.add( object );
 
180
        }
 
181
        
 
182
        if ( actual == collection )
 
183
        {
 
184
            return true;
 
185
        }
 
186
        
 
187
        if ( actual == null || collection == null )
 
188
        {
 
189
            return false;
 
190
        }
 
191
        
 
192
        if ( actual.size() != collection.size() )
 
193
        {
 
194
            return false;
 
195
        }
 
196
        
 
197
        for ( Object object : actual )
 
198
        {
 
199
            if ( !collection.contains( object ) )
 
200
            {
 
201
                return false;
 
202
            }
 
203
        }
 
204
        
 
205
        for ( Object object : collection )
 
206
        {
 
207
            if ( !actual.contains( object ) )
 
208
            {
 
209
                return false;
 
210
            }
 
211
        }
 
212
        
 
213
        return true;
 
214
    }
 
215
    
 
216
    // -------------------------------------------------------------------------
 
217
    // Create object methods 
 
218
    // -------------------------------------------------------------------------
 
219
 
 
220
    /**
 
221
     * @param uniqueCharacter A unique character to identify the object.
 
222
     */
 
223
    protected static DataElement createDataElement( char uniqueCharacter )
 
224
    {
 
225
        DataElement dataElement = new DataElement();
 
226
        
 
227
        dataElement.setUuid( BASE_UUID + uniqueCharacter );
 
228
        dataElement.setName( "DataElement" + uniqueCharacter );
 
229
        dataElement.setAlternativeName( "AlternativeName" + uniqueCharacter );
 
230
        dataElement.setShortName( "ShortName" + uniqueCharacter );
 
231
        dataElement.setCode( "Code" + uniqueCharacter );
 
232
        dataElement.setDescription( "Description" + uniqueCharacter );
 
233
        dataElement.setActive( true );
 
234
        dataElement.setType( DataElement.TYPE_INT );
 
235
        dataElement.setAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
 
236
        
 
237
        return dataElement;
 
238
    }
 
239
    
 
240
    /**
 
241
     * @param uniqueCharacter A unique character to identify the object.
 
242
     * @param categoryCombo The category combo.
 
243
     */
 
244
    protected static DataElement createDataElement( char uniqueCharacter, DataElementCategoryCombo categoryCombo )
 
245
    {
 
246
        DataElement dataElement = createDataElement( uniqueCharacter );
 
247
        
 
248
        dataElement.setCategoryCombo( categoryCombo );
 
249
        
 
250
        return dataElement;
 
251
    }
 
252
    
 
253
    /**
 
254
     * @param uniqueCharacter A unique character to identify the object.
 
255
     * @param type The type.
 
256
     * @param aggregationOperator The aggregation operator.
 
257
     */
 
258
    protected static DataElement createDataElement( char uniqueCharacter, String type, String aggregationOperator )
 
259
    {
 
260
        DataElement dataElement = createDataElement( uniqueCharacter );
 
261
        
 
262
        dataElement.setType( type );
 
263
        dataElement.setAggregationOperator( aggregationOperator );
 
264
        
 
265
        return dataElement;
 
266
    }
 
267
    
 
268
    /**
 
269
     * @param uniqueCharacter A unique character to identify the object.
 
270
     * @param type The type.
 
271
     * @param aggregationOperator The aggregation operator.
 
272
     * @param categoryCombo The category combo.
 
273
     */
 
274
    protected static DataElement createDataElement( char uniqueCharacter, String type, String aggregationOperator, DataElementCategoryCombo categoryCombo )
 
275
    {
 
276
        DataElement dataElement = createDataElement( uniqueCharacter );
 
277
        
 
278
        dataElement.setType( type );
 
279
        dataElement.setAggregationOperator( aggregationOperator );
 
280
        dataElement.setCategoryCombo( categoryCombo );
 
281
        
 
282
        return dataElement;
 
283
    }
 
284
    
 
285
    /**
 
286
     * @param uniqueCharacter A unique character to identify the object.
 
287
     * @param expression The Expression.
 
288
     */
 
289
    protected static CalculatedDataElement createCalculatedDataElement( char uniqueCharacter, String type, String aggregationOperator, DataElementCategoryCombo categoryCombo, Expression expression )
 
290
    {
 
291
        CalculatedDataElement dataElement = new CalculatedDataElement();
 
292
        
 
293
        dataElement.setUuid( BASE_UUID + uniqueCharacter );
 
294
        dataElement.setName( "DataElement" + uniqueCharacter );
 
295
        dataElement.setAlternativeName( "AlternativeName" + uniqueCharacter );
 
296
        dataElement.setShortName( "ShortName" + uniqueCharacter );
 
297
        dataElement.setCode( "Code" + uniqueCharacter );
 
298
        dataElement.setDescription( "Description" + uniqueCharacter );
 
299
        dataElement.setActive( true );
 
300
        dataElement.setType( type );
 
301
        dataElement.setAggregationOperator( aggregationOperator );
 
302
        dataElement.setCategoryCombo( categoryCombo );
 
303
        dataElement.setSaved( false );
 
304
        dataElement.setExpression( expression );
 
305
        
 
306
        return dataElement;
 
307
    }
 
308
 
 
309
    /**
 
310
     * @param categoryComboUniqueIdentifier A unique character to identify the category combo.
 
311
     * @param categoryOptionUniqueIdentifiers Unique characters to identify the category options.
 
312
     * @return
 
313
     */
 
314
    protected static DataElementCategoryOptionCombo createCategoryOptionCombo( char categoryComboUniqueIdentifier, char... categoryOptionUniqueIdentifiers )
 
315
    {
 
316
        DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
 
317
        
 
318
        categoryOptionCombo.setCategoryCombo( new DataElementCategoryCombo( "CategoryCombo" + categoryComboUniqueIdentifier ) );
 
319
        
 
320
        for ( char identifier : categoryOptionUniqueIdentifiers )
 
321
        {
 
322
            categoryOptionCombo.getCategoryOptions().add( new DataElementCategoryOption( "CategoryOption" + identifier, "CategoryOption" + identifier ) );
 
323
        }
 
324
        
 
325
        return categoryOptionCombo;
 
326
    }
 
327
    
 
328
    /**
 
329
     * @param uniqueCharacter A unique character to identify the object.
 
330
     */
 
331
    protected static DataElementGroup createDataElementGroup( char uniqueCharacter )
 
332
    {
 
333
        DataElementGroup group = new DataElementGroup();
 
334
        
 
335
        group.setUuid( BASE_UUID + uniqueCharacter );
 
336
        group.setName( "DataElementGroup" + uniqueCharacter );
 
337
        
 
338
        return group;
 
339
    }
 
340
    
 
341
    /**
 
342
     * @param uniqueCharacter A unique character to identify the object.
 
343
     */
 
344
    protected static DataDictionary createDataDictionary( char uniqueCharacter )
 
345
    {
 
346
        DataDictionary dictionary = new DataDictionary();
 
347
        
 
348
        dictionary.setName( "DataDictionary" + uniqueCharacter );
 
349
        dictionary.setDescription( "Description" + uniqueCharacter );
 
350
        dictionary.setRegion( "Region" + uniqueCharacter );
 
351
        
 
352
        return dictionary;
 
353
    }
 
354
    
 
355
    /**
 
356
     * @param uniqueCharacter A unique character to identify the object.
 
357
     */
 
358
    protected static IndicatorType createIndicatorType( char uniqueCharacter )
 
359
    {
 
360
        IndicatorType type = new IndicatorType();
 
361
        
 
362
        type.setName( "IndicatorType" + uniqueCharacter );
 
363
        type.setFactor( 100 );
 
364
        
 
365
        return type;
 
366
    }
 
367
 
 
368
    /**
 
369
     * @param uniqueCharacter A unique character to identify the object.
 
370
     * @param type The type.
 
371
     */
 
372
    protected static Indicator createIndicator( char uniqueCharacter, IndicatorType type )
 
373
    {
 
374
        Indicator indicator = new Indicator();
 
375
        
 
376
        indicator.setUuid( BASE_UUID + uniqueCharacter );
 
377
        indicator.setName( "Indicator" + uniqueCharacter );
 
378
        indicator.setAlternativeName( "AlternativeName" + uniqueCharacter );
 
379
        indicator.setShortName( "ShortName" + uniqueCharacter );
 
380
        indicator.setCode( "Code" + uniqueCharacter );
 
381
        indicator.setDescription( "Description" + uniqueCharacter );
 
382
        indicator.setAnnualized( false );
 
383
        indicator.setIndicatorType( type );
 
384
        indicator.setNumerator( "Numerator" );
 
385
        indicator.setNumeratorDescription( "NumeratorDescription" );
 
386
        indicator.setNumeratorAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
 
387
        indicator.setDenominator( "Denominator" );
 
388
        indicator.setDenominatorDescription( "DenominatorDescription" );
 
389
        indicator.setDenominatorAggregationOperator( DataElement.AGGREGATION_OPERATOR_SUM );
 
390
        
 
391
        return indicator;
 
392
    }
 
393
        
 
394
    /**
 
395
     * @param uniqueCharacter A unique character to identify the object.
 
396
     */
 
397
    protected static IndicatorGroup createIndicatorGroup( char uniqueCharacter )
 
398
    {
 
399
        IndicatorGroup group = new IndicatorGroup();
 
400
        
 
401
        group.setUuid( BASE_UUID + uniqueCharacter );
 
402
        group.setName( "IndicatorGroup" + uniqueCharacter );
 
403
        
 
404
        return group;
 
405
    }
 
406
    
 
407
    /**
 
408
     * @param uniqueCharacter A unique character to identify the object.
 
409
     * @param periodType The period type.
 
410
     */
 
411
    protected static DataSet createDataSet( char uniqueCharacter, PeriodType periodType )
 
412
    {
 
413
        DataSet dataSet = new DataSet();
 
414
        
 
415
        dataSet.setName( "DataSet" + uniqueCharacter );
 
416
        dataSet.setShortName( "ShortName" + uniqueCharacter );
 
417
        dataSet.setCode( "Code" + uniqueCharacter );
 
418
        dataSet.setPeriodType( periodType );
 
419
        
 
420
        return dataSet;
 
421
    }
 
422
    
 
423
    /**
 
424
     * @param uniqueCharacter A unique character to identify the object.
 
425
     */
 
426
    protected static OrganisationUnit createOrganisationUnit( char uniqueCharacter )
 
427
    {
 
428
        OrganisationUnit unit = new OrganisationUnit();
 
429
        
 
430
        unit.setUuid( BASE_UUID + uniqueCharacter );
 
431
        unit.setName( "OrganisationUnit" + uniqueCharacter );
 
432
        unit.setShortName( "ShortName" + uniqueCharacter );
 
433
        unit.setCode( "Code" + uniqueCharacter );
 
434
        unit.setOpeningDate( date );
 
435
        unit.setClosedDate( date );
 
436
        unit.setActive( true );
 
437
        unit.setComment( "Comment" + uniqueCharacter );
 
438
        unit.setGeoCode( "GeoCode" );
 
439
        unit.setLatitude( "Latitude" );
 
440
        unit.setLongitude( "Longitude" );
 
441
                
 
442
        return unit;
 
443
    }
 
444
    
 
445
    /**
 
446
     * @param uniqueCharacter A unique character to identify the object.
 
447
     * @param parent The parent.
 
448
     */
 
449
    protected static OrganisationUnit createOrganisationUnit( char uniqueCharacter, OrganisationUnit parent )
 
450
    {
 
451
        OrganisationUnit unit = createOrganisationUnit( uniqueCharacter );
 
452
        
 
453
        unit.setParent( parent );
 
454
        
 
455
        return unit;
 
456
    }
 
457
    
 
458
    /**
 
459
     * @param uniqueCharacter A unique character to identify the object.
 
460
     */
 
461
    protected static OrganisationUnitGroup createOrganisationUnitGroup( char uniqueCharacter )
 
462
    {
 
463
        OrganisationUnitGroup group = new OrganisationUnitGroup();
 
464
        
 
465
        group.setUuid( BASE_UUID + uniqueCharacter );
 
466
        group.setName( "OrganisationUnitGroup" + uniqueCharacter );
 
467
        
 
468
        return group;
 
469
    }
 
470
    
 
471
    /**
 
472
     * @param uniqueCharacter A unique character to identify the object.
 
473
     */
 
474
    protected static OrganisationUnitGroupSet createOrganisationUnitGroupSet( char uniqueCharacter )
 
475
    {
 
476
        OrganisationUnitGroupSet groupSet = new OrganisationUnitGroupSet();
 
477
        
 
478
        groupSet.setName( "OrganisationUnitGroupSet" + uniqueCharacter );
 
479
        groupSet.setDescription( "Description" + uniqueCharacter );
 
480
        groupSet.setCompulsory( true );
 
481
        groupSet.setExclusive( true );
 
482
        
 
483
        return groupSet;
 
484
    }
 
485
    
 
486
    /**
 
487
     * @param uniqueCharacter A unique character to identify the object.
 
488
     * @param startDate The start date.
 
489
     * @param endDate The end date.
 
490
     */
 
491
    protected static Period createPeriod( PeriodType type, Date startDate, Date endDate )
 
492
    {
 
493
        Period period = new Period();
 
494
        
 
495
        period.setPeriodType( type );
 
496
        period.setStartDate( startDate );
 
497
        period.setEndDate( endDate );
 
498
        
 
499
        return period;
 
500
    }
 
501
    
 
502
    /**
 
503
     * @param dataElement The data element.
 
504
     * @param period The period.
 
505
     * @param source The source.
 
506
     * @param value The value.
 
507
     * @param categoryOptionCombo The data element category option combo.
 
508
     */
 
509
    protected static DataValue createDataValue( DataElement dataElement, Period period, Source source, String value, DataElementCategoryOptionCombo categoryOptionCombo )
 
510
    {
 
511
        DataValue dataValue = new DataValue();
 
512
        
 
513
        dataValue.setDataElement( dataElement );
 
514
        dataValue.setPeriod( period );
 
515
        dataValue.setSource( source );
 
516
        dataValue.setValue( value );
 
517
        dataValue.setComment( "Comment" );
 
518
        dataValue.setStoredBy( "StoredBy" );
 
519
        dataValue.setTimestamp( date );
 
520
        dataValue.setOptionCombo( categoryOptionCombo );
 
521
        
 
522
        return dataValue;
 
523
    }
 
524
    
 
525
    /**
 
526
     * @param uniqueCharacter A unique character to identify the object.
 
527
     * @param operator The operator.
 
528
     * @param leftSide The left side expression.
 
529
     * @param rightSide The right side expression.
 
530
     */
 
531
    protected static ValidationRule createValidationRule( char uniqueCharacter, String operator, Expression leftSide, Expression rightSide )
 
532
    {
 
533
        ValidationRule validationRule = new ValidationRule();
 
534
        
 
535
        validationRule.setName( "ValidationRule" + uniqueCharacter );
 
536
        validationRule.setDescription( "Description" + uniqueCharacter );
 
537
        validationRule.setType( ValidationRule.TYPE_ABSOLUTE );
 
538
        validationRule.setOperator( operator );
 
539
        validationRule.setLeftSide( leftSide );
 
540
        validationRule.setRightSide( rightSide );
 
541
        
 
542
        return validationRule;
 
543
    }
 
544
    
 
545
    /**
 
546
     * @param uniqueCharacter A unique character to identify the object.
 
547
     * @return
 
548
     */
 
549
    protected static ValidationRuleGroup createValidationRuleGroup( char uniqueCharacter )
 
550
    {
 
551
        ValidationRuleGroup group = new ValidationRuleGroup();
 
552
        
 
553
        group.setName( "ValidationRuleGroup" + uniqueCharacter );
 
554
        group.setDescription( "Description" + uniqueCharacter );
 
555
        
 
556
        return group;
 
557
    }
 
558
    
 
559
    /**
 
560
     * @param uniqueCharacter A unique character to identify the object.
 
561
     * @param expressionString The expression string.
 
562
     * @param dataElementsInExpression A collection of the data elements entering into the expression.
 
563
     */
 
564
    protected static Expression createExpression( char uniqueCharacter, String expressionString, Set<DataElement> dataElementsInExpression )
 
565
    {
 
566
        Expression expression = new Expression();
 
567
        
 
568
        expression.setExpression( expressionString );
 
569
        expression.setDescription( "Description" + uniqueCharacter );
 
570
        expression.setDataElementsInExpression( dataElementsInExpression );
 
571
        
 
572
        return expression;
 
573
    }
 
574
    
 
575
    /**
 
576
     * @param uniqueCharacter A unique character to identify the object.
 
577
     */
 
578
    protected static DataElement createExtendedDataElement( char uniqueCharacter )
 
579
    {
 
580
        DataElement dataElement = createDataElement( uniqueCharacter );
 
581
        
 
582
        ExtendedDataElement extended = createExtendedElement( uniqueCharacter );
 
583
        
 
584
        dataElement.setExtended( extended );
 
585
        
 
586
        return dataElement;
 
587
    }
 
588
    
 
589
    /**
 
590
     * @param uniqueCharacter A unique character to identify the object.
 
591
     * @param type The type.
 
592
     */
 
593
    protected static Indicator createExtendedIndicator( char uniqueCharacter, IndicatorType type )
 
594
    {
 
595
        Indicator indicator = createIndicator( uniqueCharacter, type );
 
596
 
 
597
        ExtendedDataElement extended = createExtendedElement( uniqueCharacter );
 
598
        
 
599
        indicator.setExtended( extended );
 
600
        
 
601
        return indicator;
 
602
    }
 
603
 
 
604
    /**
 
605
     * @param dataElementId The data element identifier.
 
606
     * @param categoryOptionComboId The data element category option combo identifier.
 
607
     * @param periodId The period identifier.
 
608
     * @param sourceId The source identifier.
 
609
     * @param status The status.
 
610
     */
 
611
    protected static ImportDataValue createImportDataValue( int dataElementId, int categoryOptionComboId, int periodId, int sourceId, ImportObjectStatus status )
 
612
    {
 
613
        ImportDataValue importDataValue = new ImportDataValue();
 
614
        
 
615
        importDataValue.setDataElementId( dataElementId );
 
616
        importDataValue.setCategoryOptionComboId( categoryOptionComboId );
 
617
        importDataValue.setPeriodId( periodId );
 
618
        importDataValue.setSourceId( sourceId );
 
619
        importDataValue.setValue( String.valueOf( 10 ) );
 
620
        importDataValue.setStoredBy( "StoredBy" );
 
621
        importDataValue.setTimestamp( new Date() );
 
622
        importDataValue.setComment( "Comment" );
 
623
        importDataValue.setStatus( status.name() );
 
624
        
 
625
        return importDataValue;
 
626
    }
 
627
 
 
628
    // -------------------------------------------------------------------------
 
629
    // Supportive methods
 
630
    // -------------------------------------------------------------------------
 
631
    
 
632
    private static ExtendedDataElement createExtendedElement( char uniqueCharacter )
 
633
    {
 
634
        ExtendedDataElement extended = new ExtendedDataElement();
 
635
        
 
636
        extended.setMnemonic( "Mnemonic" + uniqueCharacter );
 
637
        extended.setVersion( "Version" + uniqueCharacter );
 
638
        extended.setContext( "Context" + uniqueCharacter );
 
639
        extended.setSynonyms( "Synonyms" + uniqueCharacter );
 
640
        extended.setHononyms( "Hononyms" + uniqueCharacter );
 
641
        extended.setKeywords( "Keywords" + uniqueCharacter );
 
642
        extended.setStatus( ExtendedDataElement.STATUS_CURRENT );
 
643
        extended.setStatusDate( date );
 
644
        extended.setDataElementType( ExtendedDataElement.TYPE_DATAELEMENT );
 
645
        
 
646
        extended.setDataType( ExtendedDataElement.DATATYPE_ALPHABETIC );
 
647
        extended.setRepresentationalForm( ExtendedDataElement.REPRESENTATIONAL_FORM_CODE );
 
648
        extended.setRepresentationalLayout( "RepresentationalLayout" + uniqueCharacter );
 
649
        extended.setMinimumSize( 0 );
 
650
        extended.setMaximumSize( 10 );
 
651
        extended.setDataDomain( "DataDomain" + uniqueCharacter );
 
652
        extended.setValidationRules( "ValidationRules" + uniqueCharacter );
 
653
        extended.setRelatedDataReferences( "RelatedDataReferences" + uniqueCharacter );
 
654
        extended.setGuideForUse( "GuideForUse" + uniqueCharacter );
 
655
        extended.setCollectionMethods( "CollectionMethods" + uniqueCharacter );
 
656
        
 
657
        extended.setResponsibleAuthority( "ResponsibleAuthority" + uniqueCharacter );
 
658
        extended.setUpdateRules( "UpdateRules" + uniqueCharacter );
 
659
        extended.setAccessAuthority( "AccessAuthority" + uniqueCharacter );
 
660
        extended.setUpdateFrequency( "UpdateFrequency" + uniqueCharacter );
 
661
        extended.setLocation( "Location" + uniqueCharacter );
 
662
        extended.setReportingMethods( "ReportingMethods" + uniqueCharacter );
 
663
        extended.setVersionStatus( "VersionStatus" + uniqueCharacter );
 
664
        extended.setPreviousVersionReferences( "PreviousVersionReferences" + uniqueCharacter );
 
665
        extended.setSourceDocument( "SourceDocument" + uniqueCharacter );
 
666
        extended.setSourceOrganisation( "SourceOrganisation" + uniqueCharacter );
 
667
        extended.setComment( "Comment" + uniqueCharacter );
 
668
        extended.setSaved( date );
 
669
        extended.setLastUpdated( date );
 
670
        
 
671
        return extended;
 
672
    }
 
673
}