dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32962
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16766: Added basic validation for periods. Using in period resource table to avoid exceptions caused by ...
------------------------------------------------------------
revno: 16766
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-09-22 08:49:26 +0200
message:
Added basic validation for periods. Using in period resource table to avoid exceptions caused by invalid periods.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2014-08-24 17:53:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/Period.java 2014-09-22 06:49:26 +0000
@@ -248,6 +248,24 @@
return days.getDays() + 1;
}
+ /**
+ * Validates this period. TODO Make more comprehensive.
+ */
+ public boolean isValid()
+ {
+ if ( startDate == null || endDate == null || periodType == null )
+ {
+ return false;
+ }
+
+ if ( !DailyPeriodType.NAME.equals( periodType.getName() ) && getDaysInPeriod() < 2 )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
// -------------------------------------------------------------------------
// hashCode, equals and toString
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-08-27 17:08:48 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-09-22 06:49:26 +0000
@@ -457,28 +457,31 @@
for ( Period period : periods )
{
- final Date startDate = period.getStartDate();
- final PeriodType rowType = period.getPeriodType();
-
- List<Object> values = new ArrayList<>();
-
- values.add( period.getId() );
- values.add( period.getIsoDate() );
- values.add( period.getDaysInPeriod() );
-
- for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
+ if ( period != null && period.isValid() )
{
- if ( rowType.getFrequencyOrder() <= periodType.getFrequencyOrder() )
- {
- values.add( periodType.createPeriod( startDate, calendar ).getIsoDate() );
- }
- else
+ final Date startDate = period.getStartDate();
+ final PeriodType rowType = period.getPeriodType();
+
+ List<Object> values = new ArrayList<>();
+
+ values.add( period.getId() );
+ values.add( period.getIsoDate() );
+ values.add( period.getDaysInPeriod() );
+
+ for ( PeriodType periodType : PeriodType.PERIOD_TYPES )
{
- values.add( null );
+ if ( rowType.getFrequencyOrder() <= periodType.getFrequencyOrder() )
+ {
+ values.add( periodType.createPeriod( startDate, calendar ).getIsoDate() );
+ }
+ else
+ {
+ values.add( null );
+ }
}
+
+ batchArgs.add( values.toArray() );
}
-
- batchArgs.add( values.toArray() );
}
resourceTableStore.batchUpdate( PeriodType.PERIOD_TYPES.size() + 3, TABLE_NAME_PERIOD_STRUCTURE, batchArgs );