dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43811
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22213: Period resource table. Provided check for uniquness of generated ISO date value. One might end up...
------------------------------------------------------------
revno: 22213
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-03-09 16:37:33 +0100
message:
Period resource table. Provided check for uniquness of generated ISO date value. One might end up with duplicate ISo values if inserting incorrect periods directly in period table, or through strange calendar types.
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.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-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/PeriodResourceTable.java 2016-03-09 15:37:33 +0000
@@ -30,8 +30,10 @@
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.common.IdentifiableObjectUtils;
@@ -87,18 +89,27 @@
Calendar calendar = PeriodType.getCalendar();
List<Object[]> batchArgs = new ArrayList<>();
-
+
+ Set<String> uniqueIsoDates = new HashSet<>();
+
for ( Period period : objects )
{
if ( period != null && period.isValid() )
{
final Date startDate = period.getStartDate();
final PeriodType rowType = period.getPeriodType();
+ final String isoDate = period.getIsoDate();
+ if ( !uniqueIsoDates.add( isoDate ) )
+ {
+ log.warn( "Duplicate ISO date for period, ignoring: " + period + ", ISO date: " + isoDate );
+ continue;
+ }
+
List<Object> values = new ArrayList<>();
values.add( period.getId() );
- values.add( period.getIsoDate() );
+ values.add( isoDate );
values.add( period.getDaysInPeriod() );
for ( PeriodType periodType : PeriodType.PERIOD_TYPES )