dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #37825
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19314: Data value sets resource. Supporting limit and lastUpdated query parameters
------------------------------------------------------------
revno: 19314
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-06-09 10:37:13 +0200
message:
Data value sets resource. Supporting limit and lastUpdated query parameters
modified:
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/DataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.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-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-06-01 22:46:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataExportParams.java 2015-06-09 08:37:13 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Date;
import java.util.HashSet;
import java.util.Set;
@@ -51,6 +52,10 @@
private boolean includeChildren;
+ private Date lastUpdated;
+
+ private Integer limit;
+
private IdSchemes idSchemes;
// -------------------------------------------------------------------------
@@ -80,6 +85,16 @@
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.
@@ -144,6 +159,26 @@
this.includeChildren = includeChildren;
}
+ public Date getLastUpdated()
+ {
+ return lastUpdated;
+ }
+
+ public void setLastUpdated( Date lastUpdated )
+ {
+ this.lastUpdated = lastUpdated;
+ }
+
+ public Integer getLimit()
+ {
+ return limit;
+ }
+
+ public void setLimit( Integer limit )
+ {
+ this.limit = limit;
+ }
+
public IdSchemes getIdSchemes()
{
return idSchemes;
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2015-06-01 23:12:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java 2015-06-09 08:37:13 +0000
@@ -49,7 +49,7 @@
public interface DataValueSetService
{
DataExportParams getFromUrl( Set<String> dataSets, Set<String> periods, Date startDate, Date endDate,
- Set<String> organisationUnits, boolean includeChildren, IdSchemes idSchemes );
+ Set<String> organisationUnits, boolean includeChildren, Date lastUpdated, Integer limit, IdSchemes idSchemes );
void validate( DataExportParams params );
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-06-01 23:45:15 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-06-09 08:37:13 +0000
@@ -159,7 +159,7 @@
@Override
public DataExportParams getFromUrl( Set<String> dataSets, Set<String> periods, Date startDate, Date endDate,
- Set<String> organisationUnits, boolean includeChildren, IdSchemes idSchemes )
+ Set<String> organisationUnits, boolean includeChildren, Date lastUpdated, Integer limit, IdSchemes idSchemes )
{
DataExportParams params = new DataExportParams();
@@ -190,6 +190,8 @@
}
params.setIncludeChildren( includeChildren );
+ params.setLastUpdated( lastUpdated );
+ params.setLimit( limit );
params.setIdSchemes( idSchemes );
return params;
@@ -228,6 +230,11 @@
}
}
+ if ( params.hasLimit() && params.getLimit() < 0 )
+ {
+ violation = "Limit cannot be less than zero: " + params.getLimit();
+ }
+
if ( violation != null )
{
log.warn( "Validation failed: " + violation );
@@ -258,9 +265,7 @@
@Override
public void writeDataValueSetJson( Date lastUpdated, OutputStream outputStream, IdSchemes idSchemes )
- {
- //TODO validate
-
+ {
dataValueSetStore.writeDataValueSetJson( lastUpdated, outputStream, idSchemes );
}
=== 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-06-01 23:12:38 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java 2015-06-09 08:37:13 +0000
@@ -175,7 +175,7 @@
String ouScheme = idSchemes.getOrgUnitIdScheme().toString().toLowerCase();
String ocScheme = idSchemes.getCategoryOptionComboIdScheme().toString().toLowerCase();
- return
+ 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 " +
@@ -188,7 +188,19 @@
"join categoryoptioncombo aoc on (dv.attributeoptioncomboid=aoc.categoryoptioncomboid) " +
"where de.dataelementid in (" + getCommaDelimitedString( getIdentifiers( getDataElements( params.getDataSets() ) ) ) + ") " +
"and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( params.getPeriods() ) ) + ") " +
- "and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ")";
+ "and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( params.getOrganisationUnits() ) ) + ") ";
+
+ if ( params.hasLastUpdated() )
+ {
+ sql += "and dv.lastupdated >= '" + getLongGmtDateString( params.getLastUpdated() ) + "' ";
+ }
+
+ if ( params.hasLimit() )
+ {
+ sql += "limit " + params.getLimit();
+ }
+
+ return sql;
}
private Set<DataElement> getDataElements( Set<DataSet> dataSets )
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2015-06-01 23:45:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java 2015-06-09 08:37:13 +0000
@@ -79,12 +79,14 @@
@RequestParam( required = false ) Date endDate,
@RequestParam Set<String> orgUnit,
@RequestParam( required = false ) boolean children,
+ @RequestParam( required = false ) Date lastUpdated,
+ @RequestParam( required = false ) Integer limit,
IdSchemes idSchemes, HttpServletResponse response ) throws IOException
{
response.setContentType( CONTENT_TYPE_XML );
DataExportParams params = dataValueSetService.getFromUrl( dataSet, period,
- startDate, endDate, orgUnit, children, idSchemes );
+ startDate, endDate, orgUnit, children, lastUpdated, limit, idSchemes );
dataValueSetService.writeDataValueSetXml( params, response.getOutputStream() );
}
@@ -97,12 +99,14 @@
@RequestParam( required = false ) Date endDate,
@RequestParam Set<String> orgUnit,
@RequestParam( required = false ) boolean children,
+ @RequestParam( required = false ) Date lastUpdated,
+ @RequestParam( required = false ) Integer limit,
IdSchemes idSchemes, HttpServletResponse response ) throws IOException
{
response.setContentType( CONTENT_TYPE_JSON );
DataExportParams params = dataValueSetService.getFromUrl( dataSet, period,
- startDate, endDate, orgUnit, children, idSchemes );
+ startDate, endDate, orgUnit, children, lastUpdated, limit, idSchemes );
dataValueSetService.writeDataValueSetJson( params, response.getOutputStream() );
}
@@ -115,13 +119,15 @@
@RequestParam( required = false ) Date endDate,
@RequestParam Set<String> orgUnit,
@RequestParam( required = false ) boolean children,
+ @RequestParam( required = false ) Date lastUpdated,
+ @RequestParam( required = false ) Integer limit,
IdSchemes idSchemes,
HttpServletResponse response ) throws IOException
{
response.setContentType( CONTENT_TYPE_CSV );
DataExportParams params = dataValueSetService.getFromUrl( dataSet, period,
- startDate, endDate, orgUnit, children, idSchemes );
+ startDate, endDate, orgUnit, children, lastUpdated, limit, idSchemes );
dataValueSetService.writeDataValueSetCsv( params, response.getWriter() );
}
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2015-06-01 23:12:38 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/datavalue/ExportDataValueAction.java 2015-06-09 08:37:13 +0000
@@ -153,7 +153,7 @@
HttpServletResponse response = ServletActionContext.getResponse();
DataExportParams params = dataValueSetService.getFromUrl( selectedDataSets, null,
- getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, true, idSchemes );
+ getMediumDate( startDate ), getMediumDate( endDate ), orgUnits, true, null, null, idSchemes );
if ( FORMAT_CSV.equals( exportFormat ) )
{