dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29174
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14696: Data element resource table, including data set of each data element. If data element has multipl...
------------------------------------------------------------
revno: 14696
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-04-06 13:19:24 +0200
message:
Data element resource table, including data set of each data element. If data element has multiple data sets, the data set with highest collection frequncy wins.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetSortOrderComparator.java
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/jdbc/JdbcResourceTableStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.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/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2014-03-26 21:55:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2014-04-06 11:19:24 +0000
@@ -31,6 +31,7 @@
import static org.hisp.dhis.dataset.DataSet.NO_EXPIRY;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -43,6 +44,7 @@
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.comparator.DataSetFrequencyComparator;
import org.hisp.dhis.mapping.MapLegendSet;
import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.period.PeriodType;
@@ -297,12 +299,28 @@
}
/**
+ * Returns the data set of this data element. If this data element has
+ * multiple data sets, the data set with the highest collection frequency is
+ * returned.
+ */
+ public DataSet getDataSet()
+ {
+ List<DataSet> list = new ArrayList<DataSet>( dataSets );
+ Collections.sort( list, DataSetFrequencyComparator.INSTANCE );
+ return !list.isEmpty() ? list.get( 0 ) : null;
+ }
+
+ /**
* Returns the PeriodType of the DataElement, based on the PeriodType of the
- * DataSet which the DataElement is registered for.
+ * DataSet which the DataElement is registered for. If this data element has
+ * multiple data sets, the data set with the highest collection frequency is
+ * returned.
*/
public PeriodType getPeriodType()
{
- return dataSets != null && !dataSets.isEmpty() ? dataSets.iterator().next().getPeriodType() : null;
+ DataSet dataSet = getDataSet();
+
+ return dataSet != null ? dataSet.getPeriodType() : null;
}
/**
@@ -431,7 +449,7 @@
{
return optionSet != null;
}
-
+
// -------------------------------------------------------------------------
// Getters and setters
// -------------------------------------------------------------------------
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetFrequencyComparator.java 2014-04-06 11:19:24 +0000
@@ -0,0 +1,62 @@
+package org.hisp.dhis.dataset.comparator;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Comparator;
+
+import org.hisp.dhis.dataset.DataSet;
+
+/**
+ * Sorts data sets according to the frequency order of their period type, ordered
+ * from high to low collection frequency. A higher frequency order value implies
+ * lower data set collection frequency.
+ *
+ * @author Lars Helge Overland
+ */
+public class DataSetFrequencyComparator
+ implements Comparator<DataSet>
+{
+ public static final DataSetFrequencyComparator INSTANCE = new DataSetFrequencyComparator();
+
+ @Override
+ public int compare( DataSet d1, DataSet d2 )
+ {
+ if ( d1 == null || d1.getPeriodType() == null )
+ {
+ return -1;
+ }
+
+ if ( d2 == null || d2.getPeriodType() == null )
+ {
+ return 1;
+ }
+
+ return Integer.valueOf( d2.getPeriodType().getFrequencyOrder() ).compareTo( Integer.valueOf( d1.getPeriodType().getFrequencyOrder() ) );
+ }
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetSortOrderComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetSortOrderComparator.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/DataSetSortOrderComparator.java 2014-04-06 11:19:24 +0000
@@ -34,7 +34,6 @@
/**
* @author Lars Helge Overland
- * @version $Id$
*/
public class DataSetSortOrderComparator
implements Comparator<DataSet>
=== 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-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2014-04-06 11:19:24 +0000
@@ -56,6 +56,7 @@
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorGroup;
import org.hisp.dhis.indicator.IndicatorGroupSet;
@@ -501,17 +502,22 @@
{
List<Object> values = new ArrayList<Object>();
+ final DataSet dataSet = dataElement.getDataSet();
final PeriodType periodType = dataElement.getPeriodType();
values.add( dataElement.getId() );
+ values.add( dataElement.getUid() );
values.add( dataElement.getName() );
+ values.add( dataSet != null ? dataSet.getId() : null );
+ values.add( dataSet != null ? dataSet.getUid() : null );
+ values.add( dataSet != null ? dataSet.getName() : null );
values.add( periodType != null ? periodType.getId() : null );
values.add( periodType != null ? periodType.getName() : null );
batchArgs.add( values.toArray() );
}
- resourceTableStore.batchUpdate( 4, TABLE_NAME_DATA_ELEMENT_STRUCTURE, batchArgs );
+ resourceTableStore.batchUpdate( 8, TABLE_NAME_DATA_ELEMENT_STRUCTURE, batchArgs );
log.info( "Data element table generated" );
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java 2014-04-06 11:19:24 +0000
@@ -271,8 +271,15 @@
// Do nothing, table does not exist
}
- final String sql = "CREATE TABLE " + TABLE_NAME_DATA_ELEMENT_STRUCTURE +
- " ( dataelementid INTEGER NOT NULL PRIMARY KEY, dataelementname VARCHAR(250), periodtypeid INTEGER, periodtypename VARCHAR(250) )";
+ final String sql = "CREATE TABLE " + TABLE_NAME_DATA_ELEMENT_STRUCTURE + " ( " +
+ "dataelementid INTEGER NOT NULL PRIMARY KEY, " +
+ "dataelementuid CHARACTER(11), " +
+ "dataelementname VARCHAR(250), " +
+ "datasetid INTEGER, " +
+ "datasetuid CHARACTER(11), " +
+ "datasetname VARCHAR(250), " +
+ "periodtypeid INTEGER, " +
+ "periodtypename VARCHAR(250) )";
log.info( "Create data element structure SQL: " + sql );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-04-06 09:32:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-04-06 11:19:24 +0000
@@ -129,7 +129,7 @@
for ( OrganisationUnit orgUnit : user.getOrganisationUnits() )
{
- int orgUnitLevel = orgUnit.getLevel() != 0 ?
+ int orgUnitLevel = orgUnit.hasLevel() ?
orgUnit.getLevel() : organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getUid() );
userOrgUnitLevels.add( orgUnitLevel );
@@ -145,7 +145,7 @@
( !approvalLevel.hasCategoryOptionGroupSet() || securityService.canRead( approvalLevel.getCategoryOptionGroupSet() ) ) );
//
- // Test using assignedAtLevel and approvableAtLevel values from the previous (higher) level:
+ // Test using assignedAtLevel and approvableAtLevel values from the previous (higher) level.
//
Boolean addBecauseOfPreviousLevel = false;
@@ -168,7 +168,7 @@
approvableAtLevel = canReadThisLevel && ( ( mayApprove && assignedAtLevel ) || approvableAtAllLowerLevels );
//
- // Test using assignedAtLevel and approvableAtLevel values from the current level:
+ // Test using assignedAtLevel and approvableAtLevel values from the current level.
//
if ( approvableAtLevel || addBecauseOfPreviousLevel )
{