dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40401
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20481: Converting report tables
------------------------------------------------------------
revno: 20481
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-02 18:28:45 +0200
message:
Converting report tables
added:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.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
--
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/resourcetable/ResourceTableStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2015-10-02 16:14:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/resourcetable/ResourceTableStore.java 2015-10-02 16:28:45 +0000
@@ -41,7 +41,6 @@
String ID = ResourceTableStore.class.getName();
String TABLE_NAME_CATEGORY_OPTION_COMBO_NAME = "_categoryoptioncomboname";
- String TABLE_NAME_ORGANISATION_UNIT_STRUCTURE = "_orgunitstructure";
String TABLE_NAME_DATA_ELEMENT_STRUCTURE = "_dataelementstructure";
String TABLE_NAME_PERIOD_STRUCTURE = "_periodstructure";
String TABLE_NAME_DATE_PERIOD_STRUCTURE = "_dateperiodstructure";
@@ -67,11 +66,6 @@
/**
* Creates table.
*/
- void createDataElementStructure();
-
- /**
- * Creates table.
- */
void createDatePeriodStructure();
/**
=== 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 2015-10-02 16:14:33 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2015-10-02 16:28:45 +0000
@@ -28,8 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.dataapproval.DataApprovalLevelService.APPROVAL_LEVEL_HIGHEST;
-import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_DATA_ELEMENT_STRUCTURE;
import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_DATE_PERIOD_STRUCTURE;
import static org.hisp.dhis.resourcetable.ResourceTableStore.TABLE_NAME_PERIOD_STRUCTURE;
@@ -54,7 +52,6 @@
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementGroupSet;
-import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.indicator.IndicatorGroupSet;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
@@ -69,6 +66,7 @@
import org.hisp.dhis.resourcetable.table.CategoryOptionGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.CategoryResourceTable;
import org.hisp.dhis.resourcetable.table.DataElementGroupSetResourceTable;
+import org.hisp.dhis.resourcetable.table.DataElementResourceTable;
import org.hisp.dhis.resourcetable.table.IndicatorGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.OrganisationUnitGroupSetResourceTable;
import org.hisp.dhis.resourcetable.table.OrganisationUnitStructureResourceTable;
@@ -202,10 +200,6 @@
statementBuilder.getColumnQuote() ) );
}
- // -------------------------------------------------------------------------
- // CategoryTable
- // -------------------------------------------------------------------------
-
@Override
@Transactional
public void generateCategoryTable()
@@ -215,56 +209,13 @@
statementBuilder.getColumnQuote() ) );
}
- // -------------------------------------------------------------------------
- // DataElementTable
- // -------------------------------------------------------------------------
-
@Override
@Transactional
public void generateDataElementTable()
{
- // ---------------------------------------------------------------------
- // Create table
- // ---------------------------------------------------------------------
-
- List<DataElement> dataElements = new ArrayList<>( idObjectManager.getAllNoAcl( DataElement.class ) );
-
- resourceTableStore.createDataElementStructure();
-
- // ---------------------------------------------------------------------
- // Populate table
- // ---------------------------------------------------------------------
-
- List<Object[]> batchArgs = new ArrayList<>();
-
- for ( DataElement dataElement : dataElements )
- {
- List<Object> values = new ArrayList<>();
-
- final DataSet dataSet = dataElement.getDataSet();
- final PeriodType periodType = dataElement.getPeriodType();
-
- // -----------------------------------------------------------------
- // Use highest approval level if data set does not require approval,
- // or null if approval is required.
- // -----------------------------------------------------------------
-
- 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( dataSet != null && dataSet.isApproveData() ? null : APPROVAL_LEVEL_HIGHEST );
- values.add( periodType != null ? periodType.getId() : null );
- values.add( periodType != null ? periodType.getName() : null );
-
- batchArgs.add( values.toArray() );
- }
-
- resourceTableStore.batchUpdate( 9, TABLE_NAME_DATA_ELEMENT_STRUCTURE, batchArgs );
-
- log.info( "Data element table generated" );
+ resourceTableStore.generateResourceTable( new DataElementResourceTable(
+ "_dataelementstructure", idObjectManager.getAllNoAcl( DataElement.class ),
+ statementBuilder.getColumnQuote() ) );
}
// -------------------------------------------------------------------------
=== 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 2015-10-02 16:14:33 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/jdbc/JdbcResourceTableStore.java 2015-10-02 16:28:45 +0000
@@ -164,48 +164,6 @@
jdbcTemplate.batchUpdate( builder.toString(), batchArgs );
}
-
- // -------------------------------------------------------------------------
- // DataElementStructure
- // -------------------------------------------------------------------------
-
- @Override
- public void createDataElementStructure()
- {
- try
- {
- jdbcTemplate.execute( "DROP TABLE IF EXISTS " + TABLE_NAME_DATA_ELEMENT_STRUCTURE );
- }
- catch ( BadSqlGrammarException ex )
- {
- // Do nothing, table does not exist
- }
-
- 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), " +
- "datasetapprovallevel INTEGER, " +
- "periodtypeid INTEGER, " +
- "periodtypename VARCHAR(250) )";
-
- log.info( "Create data element structure SQL: " + sql );
-
- jdbcTemplate.execute( sql );
-
- final String deUdInSql = "create unique index in_dataelementstructure_dataelementuid on _dataelementstructure(dataelementuid)";
- final String dsIdInSql = "create index in_dataelementstructure_datasetid on _dataelementstructure(datasetid)";
- final String dsUdInSql = "create index in_dataelementstructure_datasetuid on _dataelementstructure(datasetuid)";
- final String ptIdInSql = "create index in_dataelementstructure_periodtypeid on _dataelementstructure(periodtypeid)";
-
- jdbcTemplate.execute( deUdInSql );
- jdbcTemplate.execute( dsIdInSql );
- jdbcTemplate.execute( dsUdInSql );
- jdbcTemplate.execute( ptIdInSql );
- }
// -------------------------------------------------------------------------
// PeriodTable
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/table/DataElementResourceTable.java 2015-10-02 16:28:45 +0000
@@ -0,0 +1,120 @@
+package org.hisp.dhis.resourcetable.table;
+
+/*
+ * Copyright (c) 2004-2015, 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 static org.hisp.dhis.dataapproval.DataApprovalLevelService.APPROVAL_LEVEL_HIGHEST;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.resourcetable.ResourceTable;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class DataElementResourceTable
+ extends ResourceTable<DataElement>
+{
+ public DataElementResourceTable( String tableName, List<DataElement> objects, String columnQuote )
+ {
+ super( tableName, objects, columnQuote );
+ }
+
+ @Override
+ public String getCreateTempTableStatement()
+ {
+ String sql = "CREATE TABLE " + getTempTableName() + " (" +
+ "dataelementid INTEGER NOT NULL PRIMARY KEY, " +
+ "dataelementuid CHARACTER(11), " +
+ "dataelementname VARCHAR(230), " +
+ "datasetid INTEGER, " +
+ "datasetuid CHARACTER(11), " +
+ "datasetname VARCHAR(230), " +
+ "datasetapprovallevel INTEGER, " +
+ "periodtypeid INTEGER, " +
+ "periodtypename VARCHAR(230))";
+
+ return sql;
+ }
+
+ @Override
+ public Optional<String> getPopulateTempTableStatement()
+ {
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<List<Object[]>> getPopulateTempTableContent()
+ {
+ List<Object[]> batchArgs = new ArrayList<>();
+
+ for ( DataElement dataElement : objects )
+ {
+ List<Object> values = new ArrayList<>();
+
+ final DataSet dataSet = dataElement.getDataSet();
+ final PeriodType periodType = dataElement.getPeriodType();
+
+ // -----------------------------------------------------------------
+ // Use highest approval level if data set does not require approval,
+ // or null if approval is required.
+ // -----------------------------------------------------------------
+
+ 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( dataSet != null && dataSet.isApproveData() ? null : APPROVAL_LEVEL_HIGHEST );
+ values.add( periodType != null ? periodType.getId() : null );
+ values.add( periodType != null ? periodType.getName() : null );
+
+ batchArgs.add( values.toArray() );
+ }
+
+ return Optional.of( batchArgs );
+ }
+
+ @Override
+ public Optional<String> getCreateIndexStatement()
+ {
+ String sql =
+ "create unique index in_dataelementstructure_dataelementuid_" + getRandomSuffix() + " on _dataelementstructure(dataelementuid);" +
+ "create index in_dataelementstructure_datasetid_" + getRandomSuffix() + " on _dataelementstructure(datasetid);" +
+ "create index in_dataelementstructure_datasetuid_" + getRandomSuffix() + " on _dataelementstructure(datasetuid);" +
+ "create index in_dataelementstructure_periodtypeid_" + getRandomSuffix() + " on _dataelementstructure(periodtypeid);";
+
+ return Optional.of( sql );
+ }
+}