dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41799
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21326: minor fixes related to DVS export
------------------------------------------------------------
revno: 21326
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-12-04 18:47:08 +0700
message:
minor fixes related to DVS export
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.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/common/IdScheme.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java 2015-12-04 05:41:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdScheme.java 2015-12-04 11:47:08 +0000
@@ -112,6 +112,11 @@
return identifiableProperty;
}
+ public String getIdentifiableString()
+ {
+ return identifiableProperty != null ? identifiableProperty.toString() : null;
+ }
+
public void setIdentifiableProperty( IdentifiableProperty identifiableProperty )
{
this.identifiableProperty = identifiableProperty;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-12-04 05:41:43 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-12-04 11:47:08 +0000
@@ -28,38 +28,37 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.google.common.base.MoreObjects;
+import org.hisp.dhis.common.IdSchemes;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
+
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.common.IdSchemes;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.period.Period;
-
-import com.google.common.base.MoreObjects;
-
/**
* @author Lars Helge Overland
*/
public class DataExportParams
{
private Set<DataSet> dataSets = new HashSet<>();
-
+
private Set<Period> periods = new HashSet<>();
-
+
private Date startDate;
-
+
private Date endDate;
-
+
private Set<OrganisationUnit> organisationUnits = new HashSet<>();
private boolean includeChildren;
-
+
private Date lastUpdated;
-
+
private Integer limit;
-
+
private IdSchemes idSchemes;
// -------------------------------------------------------------------------
@@ -78,32 +77,32 @@
{
return dataSets != null && !dataSets.isEmpty() ? dataSets.iterator().next() : null;
}
-
+
public Period getFirstPeriod()
{
return periods != null && !periods.isEmpty() ? periods.iterator().next() : null;
}
-
+
public boolean hasStartEndDate()
{
return startDate != null && endDate != null;
}
-
+
public OrganisationUnit getFirstOrganisationUnit()
{
return organisationUnits != null && !organisationUnits.isEmpty() ? organisationUnits.iterator().next() : null;
}
-
+
public boolean hasLastUpdated()
{
return lastUpdated != null;
}
-
+
public boolean hasLimit()
{
return limit != null;
}
-
+
/**
* Indicates whether this parameters represents a single data value set, implying
* that it contains exactly one of data sets, periods and organisation units.
@@ -112,7 +111,7 @@
{
return dataSets.size() == 1 && periods.size() == 1 && organisationUnits.size() == 1;
}
-
+
@Override
public String toString()
{
@@ -121,9 +120,9 @@
add( "periods", periods ).
add( "org units", organisationUnits ).
add( "children", includeChildren ).
- add( "id schemes", idSchemes ).toString();
+ add( "id schemes", idSchemes ).toString();
}
-
+
// -------------------------------------------------------------------------
// Get and set methods
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-12-04 05:41:43 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-12-04 11:47:08 +0000
@@ -28,28 +28,16 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
-import static org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString;
-import static org.hisp.dhis.system.util.DateUtils.getLongGmtDateString;
-import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
-
-import java.io.OutputStream;
-import java.io.Writer;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
+import com.csvreader.CsvWriter;
import org.amplecode.staxwax.factory.XMLFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.calendar.Calendar;
+import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.common.IdSchemes;
import org.hisp.dhis.dxf2.datavalue.DataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.PeriodType;
@@ -58,7 +46,18 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
-import com.csvreader.CsvWriter;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
+import static org.hisp.dhis.commons.util.TextUtils.getCommaDelimitedString;
+import static org.hisp.dhis.system.util.DateUtils.getLongGmtDateString;
+import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
/**
* @author Lars Helge Overland
@@ -67,7 +66,7 @@
implements DataValueSetStore
{
private static final Log log = LogFactory.getLog( SpringDataValueSetStore.class );
-
+
private static final char CSV_DELIM = ',';
@Autowired
@@ -83,7 +82,7 @@
DataValueSet dataValueSet = new StreamingDataValueSet( XMLFactory.getXMLWriter( out ) );
String sql = getDataValueSql( params );
-
+
writeDataValueSet( sql, params, completeDate, dataValueSet );
IOUtils.closeQuietly( out );
@@ -95,7 +94,7 @@
DataValueSet dataValueSet = new StreamingJsonDataValueSet( out );
String sql = getDataValueSql( params );
-
+
writeDataValueSet( sql, params, completeDate, dataValueSet );
IOUtils.closeQuietly( out );
@@ -107,7 +106,7 @@
DataValueSet dataValueSet = new StreamingCsvDataValueSet( new CsvWriter( writer, CSV_DELIM ) );
String sql = getDataValueSql( params );
-
+
writeDataValueSet( sql, params, completeDate, dataValueSet );
IOUtils.closeQuietly( writer );
@@ -124,16 +123,16 @@
final String sql =
"select de." + deScheme + " as deid, pe.startdate as pestart, pt.name as ptname, ou." + ouScheme + " as ouid, " +
- "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " +
- "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
- "from datavalue dv " +
- "join dataelement de on (dv.dataelementid=de.dataelementid) " +
- "join period pe on (dv.periodid=pe.periodid) " +
- "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
- "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
- "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
- "join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " +
- "where dv.lastupdated >= '" + DateUtils.getLongDateString( lastUpdated ) + "'";
+ "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " +
+ "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
+ "from datavalue dv " +
+ "join dataelement de on (dv.dataelementid=de.dataelementid) " +
+ "join period pe on (dv.periodid=pe.periodid) " +
+ "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
+ "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
+ "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
+ "join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " +
+ "where dv.lastupdated >= '" + DateUtils.getLongDateString( lastUpdated ) + "'";
writeDataValueSet( sql, new DataExportParams(), null, dataValueSet );
}
@@ -184,39 +183,39 @@
{
IdSchemes idSchemes = params.getIdSchemes() != null ? params.getIdSchemes() : new IdSchemes();
- String deScheme = idSchemes.getDataElementIdScheme().toString().toLowerCase();
- String ouScheme = idSchemes.getOrgUnitIdScheme().toString().toLowerCase();
- String ocScheme = idSchemes.getCategoryOptionComboIdScheme().toString().toLowerCase();
+ String deScheme = idSchemes.getDataElementIdScheme().getIdentifiableString().toLowerCase();
+ String ouScheme = idSchemes.getOrgUnitIdScheme().getIdentifiableString().toLowerCase();
+ String ocScheme = idSchemes.getCategoryOptionComboIdScheme().getIdentifiableString().toLowerCase();
String sql =
"select de." + deScheme + " as deid, pe.startdate as pestart, pt.name as ptname, ou." + ouScheme + " as ouid, " +
- "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " +
- "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
- "from datavalue dv " +
- "join dataelement de on (dv.dataelementid=de.dataelementid) " +
- "join period pe on (dv.periodid=pe.periodid) " +
- "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
- "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
- "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
- "join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " +
- "where de.dataelementid in (" + getCommaDelimitedString( getIdentifiers( getDataElements( params.getDataSets() ) ) ) + ") ";
-
+ "coc." + ocScheme + " as cocid, aoc." + ocScheme + " as aocid, " +
+ "dv.value, dv.storedby, dv.created, dv.lastupdated, dv.comment, dv.followup " +
+ "from datavalue dv " +
+ "join dataelement de on (dv.dataelementid=de.dataelementid) " +
+ "join period pe on (dv.periodid=pe.periodid) " +
+ "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
+ "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
+ "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
+ "join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " +
+ "where de.dataelementid in (" + getCommaDelimitedString( getIdentifiers( getDataElements( params.getDataSets() ) ) ) + ") ";
+
if ( params.isIncludeChildren() )
{
sql += "and (";
-
+
for ( OrganisationUnit parent : params.getOrganisationUnits() )
{
sql += "ou.path like '" + parent.getPath() + "%' or ";
}
-
- sql = TextUtils.removeLastOr( sql ) + ") ";
+
+ sql = TextUtils.removeLastOr( sql ) + ") ";
}
else
{
sql += "and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") ";
}
-
+
if ( params.hasStartEndDate() )
{
sql += "and (pe.startdate >= '" + getMediumDateString( params.getStartDate() ) + "' and pe.enddate <= '" + getMediumDateString( params.getEndDate() ) + "') ";
@@ -225,19 +224,19 @@
{
sql += "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( params.getPeriods() ) ) + ") ";
}
-
+
if ( params.hasLastUpdated() )
{
sql += "and dv.lastupdated >= '" + getLongGmtDateString( params.getLastUpdated() ) + "' ";
}
-
+
if ( params.hasLimit() )
{
sql += "limit " + params.getLimit();
}
-
+
log.debug( "Get data value set SQL: " + sql );
-
+
return sql;
}