dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41670
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21245: implemented support for paging of audit requests
------------------------------------------------------------
revno: 21245
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-01 15:56:25 +0700
message:
implemented support for paging of audit requests
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueAuditStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.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/datavalue/DataValueAuditService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditService.java 2015-12-01 07:15:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditService.java 2015-12-01 08:56:25 +0000
@@ -65,7 +65,7 @@
* Returns all DataValueAudits for the given DataElement, Period,
* OrganisationUnit and DataElementCategoryOptionCombo.
*
- * @param dataElement the DataElement of the DataValueAudits.
+ * @param dataElements the DataElement of the DataValueAudits.
* @param periods the Period of the DataValueAudits.
* @param organisationUnits the OrganisationUnit of the DataValueAudits.
* @param categoryOptionCombo the DataElementCategoryOptionCombo of the DataValueAudits.
@@ -79,4 +79,7 @@
List<DataValueAudit> getDataValueAudits( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits,
DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType, int first, int max );
-}
+
+ int countDataValueAudits( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits,
+ DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType );
+}
\ No newline at end of file
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java 2015-12-01 07:15:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValueAuditStore.java 2015-12-01 08:56:25 +0000
@@ -80,4 +80,7 @@
List<DataValueAudit> getDataValueAudits( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits,
DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType, int first, int max );
+
+ int countDataValueAudits( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits,
+ DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java 2015-11-30 05:36:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditService.java 2015-12-01 08:56:25 +0000
@@ -46,4 +46,7 @@
List<TrackedEntityAttributeValueAudit> getTrackedEntityAttributeValueAudits( List<TrackedEntityAttribute> trackedEntityAttributes,
List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType, int first, int max );
+
+ int countTrackedEntityAttributeValueAudits( List<TrackedEntityAttribute> trackedEntityAttributes,
+ List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java 2015-11-30 05:36:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentityattributevalue/TrackedEntityAttributeValueAuditStore.java 2015-12-01 08:56:25 +0000
@@ -46,4 +46,7 @@
List<TrackedEntityAttributeValueAudit> getTrackedEntityAttributeValueAudits( List<TrackedEntityAttribute> trackedEntityAttributes,
List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType, int first, int max );
+
+ int countTrackedEntityAttributeValueAudits( List<TrackedEntityAttribute> trackedEntityAttributes,
+ List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java 2015-11-30 05:36:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditService.java 2015-12-01 08:56:25 +0000
@@ -52,4 +52,6 @@
List<TrackedEntityDataValueAudit> getTrackedEntityDataValueAudits( List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances,
AuditType auditType, int first, int max );
+
+ int countTrackedEntityDataValueAudits( List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java 2015-11-30 05:36:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/trackedentitydatavalue/TrackedEntityDataValueAuditStore.java 2015-12-01 08:56:25 +0000
@@ -46,4 +46,6 @@
List<TrackedEntityDataValueAudit> getTrackedEntityDataValueAudits( List<DataElement> dataElements,
List<ProgramStageInstance> programStageInstances, AuditType auditType, int first, int max );
+
+ int countTrackedEntityDataValueAudits( List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java 2015-12-01 07:15:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/DefaultDataValueAuditService.java 2015-12-01 08:56:25 +0000
@@ -83,4 +83,11 @@
{
return dataValueAuditStore.getDataValueAudits( dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, first, max );
}
+
+ @Override
+ public int countDataValueAudits( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits,
+ DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType )
+ {
+ return dataValueAuditStore.countDataValueAudits( dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueAuditStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueAuditStore.java 2015-12-01 07:15:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datavalue/hibernate/HibernateDataValueAuditStore.java 2015-12-01 08:56:25 +0000
@@ -33,6 +33,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.AuditType;
import org.hisp.dhis.dataelement.DataElement;
@@ -97,6 +98,8 @@
DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType )
{
Criteria criteria = getDataValueAuditCriteria( dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType );
+ criteria.addOrder( Order.desc( "created" ) );
+
return criteria.list();
}
@@ -106,12 +109,21 @@
DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType, int first, int max )
{
Criteria criteria = getDataValueAuditCriteria( dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType );
+ criteria.addOrder( Order.desc( "created" ) );
criteria.setFirstResult( first );
criteria.setMaxResults( max );
return criteria.list();
}
+ @Override
+ public int countDataValueAudits( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits,
+ DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType auditType )
+ {
+ return ((Number) getDataValueAuditCriteria( dataElements, periods, organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType )
+ .setProjection( Projections.countDistinct( "id" ) ).uniqueResult()).intValue();
+ }
+
private Criteria getDataValueAuditCriteria( List<DataElement> dataElements, List<Period> periods, List<OrganisationUnit> organisationUnits, DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, AuditType
auditType )
{
@@ -163,8 +175,6 @@
criteria.add( Restrictions.eq( "auditType", auditType ) );
}
- criteria.addOrder( Order.desc( "created" ) );
-
return criteria;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java 2015-11-30 05:36:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/DefaultTrackedEntityAttributeValueAuditService.java 2015-12-01 08:56:25 +0000
@@ -64,4 +64,11 @@
return trackedEntityAttributeValueAuditStore.getTrackedEntityAttributeValueAudits( trackedEntityAttributes, trackedEntityInstances,
auditType, first, max );
}
+
+ @Override
+ public int countTrackedEntityAttributeValueAudits( List<TrackedEntityAttribute> trackedEntityAttributes,
+ List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType )
+ {
+ return trackedEntityAttributeValueAuditStore.countTrackedEntityAttributeValueAudits( trackedEntityAttributes, trackedEntityInstances, auditType );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java 2015-12-01 04:59:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentityattributevalue/hibernate/HibernateTrackedEntityAttributeValueAuditStore.java 2015-12-01 08:56:25 +0000
@@ -32,6 +32,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.AuditType;
import org.hisp.dhis.trackedentity.TrackedEntityAttribute;
@@ -75,6 +76,8 @@
List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType )
{
Criteria criteria = getTrackedEntityAttributeValueAuditCriteria( trackedEntityAttributes, trackedEntityInstances, auditType );
+ criteria.addOrder( Order.desc( "created" ) );
+
return criteria.list();
}
@@ -84,12 +87,21 @@
List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType, int first, int max )
{
Criteria criteria = getTrackedEntityAttributeValueAuditCriteria( trackedEntityAttributes, trackedEntityInstances, auditType );
+ criteria.addOrder( Order.desc( "created" ) );
criteria.setFirstResult( first );
- criteria.setFirstResult( max );
+ criteria.setMaxResults( max );
return criteria.list();
}
+ @Override
+ public int countTrackedEntityAttributeValueAudits( List<TrackedEntityAttribute> trackedEntityAttributes,
+ List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType )
+ {
+ return ((Number) getTrackedEntityAttributeValueAuditCriteria( trackedEntityAttributes, trackedEntityInstances, auditType )
+ .setProjection( Projections.countDistinct( "id" ) ).uniqueResult()).intValue();
+ }
+
private Criteria getTrackedEntityAttributeValueAuditCriteria( List<TrackedEntityAttribute> trackedEntityAttributes, List<TrackedEntityInstance> trackedEntityInstances, AuditType auditType )
{
Session session = sessionFactory.getCurrentSession();
@@ -110,8 +122,6 @@
criteria.add( Restrictions.eq( "auditType", auditType ) );
}
- criteria.addOrder( Order.desc( "created" ) );
-
return criteria;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java 2015-11-30 05:36:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/DefaultTrackedEntityDataValueAuditService.java 2015-12-01 08:56:25 +0000
@@ -92,4 +92,10 @@
{
return trackedEntityDataValueAuditStore.getTrackedEntityDataValueAudits( dataElements, programStageInstances, auditType, first, max );
}
+
+ @Override
+ public int countTrackedEntityDataValueAudits( List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType )
+ {
+ return trackedEntityDataValueAuditStore.countTrackedEntityDataValueAudits( dataElements, programStageInstances, auditType );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java 2015-12-01 04:59:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/trackedentitydatavalue/hibernate/HibernateTrackedEntityDataValueAuditStore.java 2015-12-01 08:56:25 +0000
@@ -32,6 +32,7 @@
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.AuditType;
import org.hisp.dhis.dataelement.DataElement;
@@ -75,6 +76,8 @@
List<ProgramStageInstance> programStageInstances, AuditType auditType )
{
Criteria criteria = getTrackedEntityDataValueAuditCriteria( dataElements, programStageInstances, auditType );
+ criteria.addOrder( Order.desc( "created" ) );
+
return criteria.list();
}
@@ -84,12 +87,20 @@
List<ProgramStageInstance> programStageInstances, AuditType auditType, int first, int max )
{
Criteria criteria = getTrackedEntityDataValueAuditCriteria( dataElements, programStageInstances, auditType );
+ criteria.addOrder( Order.desc( "created" ) );
criteria.setFirstResult( first );
criteria.setMaxResults( max );
return criteria.list();
}
+ @Override
+ public int countTrackedEntityDataValueAudits( List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances, AuditType auditType )
+ {
+ return ((Number) getTrackedEntityDataValueAuditCriteria( dataElements, programStageInstances, auditType )
+ .setProjection( Projections.countDistinct( "id" ) ).uniqueResult()).intValue();
+ }
+
private Criteria getTrackedEntityDataValueAuditCriteria( List<DataElement> dataElements, List<ProgramStageInstance> programStageInstances,
AuditType auditType )
{
@@ -111,8 +122,6 @@
criteria.add( Restrictions.eq( "auditType", auditType ) );
}
- criteria.addOrder( Order.desc( "created" ) );
-
return criteria;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java 2015-12-01 07:15:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java 2015-12-01 08:56:25 +0000
@@ -30,6 +30,7 @@
import org.hisp.dhis.common.AuditType;
import org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.Pager;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataset.DataSet;
@@ -38,6 +39,7 @@
import org.hisp.dhis.dxf2.webmessage.WebMessageException;
import org.hisp.dhis.fieldfilter.FieldFilterService;
import org.hisp.dhis.node.NodeUtils;
+import org.hisp.dhis.node.types.CollectionNode;
import org.hisp.dhis.node.types.RootNode;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
@@ -94,7 +96,10 @@
@RequestParam( required = false, defaultValue = "" ) List<String> ou,
@RequestParam( required = false ) String co,
@RequestParam( required = false ) String cc,
- @RequestParam( required = false ) AuditType auditType
+ @RequestParam( required = false ) AuditType auditType,
+ @RequestParam( required = false ) boolean skipPaging,
+ @RequestParam( required = false, defaultValue = "50" ) int pageSize,
+ @RequestParam( required = false, defaultValue = "1" ) int page
) throws WebMessageException
{
List<DataElement> dataElements = new ArrayList<>();
@@ -106,11 +111,35 @@
DataElementCategoryOptionCombo categoryOptionCombo = getCategoryOptionCombo( co );
DataElementCategoryOptionCombo attributeOptionCombo = getAttributeOptionCombo( cc );
- List<DataValueAudit> dataValueAudits = dataValueAuditService.getDataValueAudits( dataElements, periods,
- organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType );
-
- RootNode rootNode = NodeUtils.createRootNode( "dataValueAudits" );
- rootNode.addChild( fieldFilterService.filter( DataValueAudit.class, dataValueAudits, new ArrayList<>() ) );
+ List<DataValueAudit> dataValueAudits;
+ Pager pager = null;
+
+ if ( skipPaging )
+ {
+ dataValueAudits = dataValueAuditService.getDataValueAudits( dataElements, periods,
+ organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType );
+ }
+ else
+ {
+ int total = dataValueAuditService.countDataValueAudits( dataElements, periods, organisationUnits, categoryOptionCombo,
+ attributeOptionCombo, auditType );
+
+ pager = new Pager( page, total, pageSize );
+
+ dataValueAudits = dataValueAuditService.getDataValueAudits( dataElements, periods,
+ organisationUnits, categoryOptionCombo, attributeOptionCombo, auditType, pager.getOffset(), pager.getPageSize() );
+ }
+
+ RootNode rootNode = NodeUtils.createMetadata();
+
+ if ( pager != null )
+ {
+ rootNode.addChild( NodeUtils.createPager( pager ) );
+ }
+
+ CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild( new CollectionNode( "dataValueAudits", true ) );
+ trackedEntityAttributeValueAudits.addChildren( fieldFilterService.filter( DataValueAudit.class,
+ dataValueAudits, new ArrayList<>() ).getChildren() );
return rootNode;
}
@@ -119,17 +148,43 @@
public @ResponseBody RootNode getTrackedEntityDataValueAudit(
@RequestParam( required = false, defaultValue = "" ) List<String> de,
@RequestParam( required = false, defaultValue = "" ) List<String> ps,
- @RequestParam( required = false ) AuditType auditType
+ @RequestParam( required = false ) AuditType auditType,
+ @RequestParam( required = false ) boolean skipPaging,
+ @RequestParam( required = false, defaultValue = "50" ) int pageSize,
+ @RequestParam( required = false, defaultValue = "1" ) int page
) throws WebMessageException
{
List<DataElement> dataElements = getDataElements( de );
List<ProgramStageInstance> programStageInstances = getProgramStageInstances( ps );
- List<TrackedEntityDataValueAudit> dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(
- dataElements, programStageInstances, auditType );
-
- RootNode rootNode = NodeUtils.createRootNode( "trackedEntityDataValueAudits" );
- rootNode.addChild( fieldFilterService.filter( TrackedEntityDataValueAudit.class, dataValueAudits, new ArrayList<>() ) );
+ List<TrackedEntityDataValueAudit> dataValueAudits;
+ Pager pager = null;
+
+ if ( skipPaging )
+ {
+ dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(
+ dataElements, programStageInstances, auditType );
+ }
+ else
+ {
+ int total = trackedEntityDataValueAuditService.countTrackedEntityDataValueAudits( dataElements, programStageInstances, auditType );
+
+ pager = new Pager( page, total, pageSize );
+
+ dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits(
+ dataElements, programStageInstances, auditType, pager.getOffset(), pager.getPageSize() );
+ }
+
+ RootNode rootNode = NodeUtils.createMetadata();
+
+ if ( pager != null )
+ {
+ rootNode.addChild( NodeUtils.createPager( pager ) );
+ }
+
+ CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild( new CollectionNode( "trackedEntityDataValueAudits", true ) );
+ trackedEntityAttributeValueAudits.addChildren( fieldFilterService.filter( TrackedEntityDataValueAudit.class,
+ dataValueAudits, new ArrayList<>() ).getChildren() );
return rootNode;
}
@@ -138,17 +193,44 @@
public @ResponseBody RootNode getTrackedEntityAttributeValueAudit(
@RequestParam( required = false, defaultValue = "" ) List<String> tea,
@RequestParam( required = false, defaultValue = "" ) List<String> te,
- @RequestParam( required = false ) AuditType auditType
+ @RequestParam( required = false ) AuditType auditType,
+ @RequestParam( required = false ) boolean skipPaging,
+ @RequestParam( required = false, defaultValue = "50" ) int pageSize,
+ @RequestParam( required = false, defaultValue = "1" ) int page
) throws WebMessageException
{
List<TrackedEntityAttribute> trackedEntityAttributes = getTrackedEntityAttributes( tea );
List<TrackedEntityInstance> trackedEntityInstances = getTrackedEntityInstances( te );
- List<TrackedEntityAttributeValueAudit> attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(
- trackedEntityAttributes, trackedEntityInstances, auditType );
-
- RootNode rootNode = NodeUtils.createRootNode( "trackedEntityAttributeValueAudits" );
- rootNode.addChild( fieldFilterService.filter( TrackedEntityAttributeValueAudit.class, attributeValueAudits, new ArrayList<>() ) );
+ List<TrackedEntityAttributeValueAudit> attributeValueAudits;
+ Pager pager = null;
+
+ if ( skipPaging )
+ {
+ attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(
+ trackedEntityAttributes, trackedEntityInstances, auditType );
+ }
+ else
+ {
+ int total = trackedEntityAttributeValueAuditService.countTrackedEntityAttributeValueAudits( trackedEntityAttributes,
+ trackedEntityInstances, auditType );
+
+ pager = new Pager( page, total, pageSize );
+
+ attributeValueAudits = trackedEntityAttributeValueAuditService.getTrackedEntityAttributeValueAudits(
+ trackedEntityAttributes, trackedEntityInstances, auditType, pager.getOffset(), pager.getPageSize() );
+ }
+
+ RootNode rootNode = NodeUtils.createMetadata();
+
+ if ( pager != null )
+ {
+ rootNode.addChild( NodeUtils.createPager( pager ) );
+ }
+
+ CollectionNode trackedEntityAttributeValueAudits = rootNode.addChild( new CollectionNode( "trackedEntityAttributeValueAudits", true ) );
+ trackedEntityAttributeValueAudits.addChildren( fieldFilterService.filter( TrackedEntityAttributeValueAudit.class,
+ attributeValueAudits, new ArrayList<>() ).getChildren() );
return rootNode;
}