dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41606
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21210: web-api audit controller for TEDV
------------------------------------------------------------
revno: 21210
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-11-27 16:12:45 +0700
message:
web-api audit controller for TEDV
modified:
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-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-11-27 05:26:25 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AuditController.java 2015-11-27 09:12:45 +0000
@@ -40,6 +40,10 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
+import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAudit;
+import org.hisp.dhis.trackedentitydatavalue.TrackedEntityDataValueAuditService;
import org.hisp.dhis.webapi.utils.WebMessageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -62,9 +66,15 @@
private IdentifiableObjectManager manager;
@Autowired
+ private ProgramStageInstanceService programStageInstanceService;
+
+ @Autowired
private DataValueAuditService dataValueAuditService;
@Autowired
+ private TrackedEntityDataValueAuditService trackedEntityDataValueAuditService;
+
+ @Autowired
private FieldFilterService fieldFilterService;
@RequestMapping( value = "dataValue", method = RequestMethod.GET )
@@ -91,10 +101,78 @@
return rootNode;
}
+ @RequestMapping( value = "trackedEntityDataValue", method = RequestMethod.GET )
+ public @ResponseBody RootNode getTrackedEntityDataValueAudit(
+ @RequestParam( required = false, defaultValue = "" ) List<String> de,
+ @RequestParam( required = false, defaultValue = "" ) List<String> ps
+ ) throws WebMessageException
+ {
+ List<DataElement> dataElements = getDataElements( de );
+ List<ProgramStageInstance> programStageInstances = getProgramStageInstances( ps );
+
+ List<TrackedEntityDataValueAudit> dataValueAudits = trackedEntityDataValueAuditService.getTrackedEntityDataValueAudits( dataElements, programStageInstances );
+
+ RootNode rootNode = NodeUtils.createRootNode( "trackedEntityDataValueAudits" );
+ rootNode.addChild( fieldFilterService.filter( TrackedEntityDataValueAudit.class, dataValueAudits, new ArrayList<>() ) );
+
+ return rootNode;
+ }
+
//-----------------------------------------------------------------------------------------------------------------
// Helpers
//-----------------------------------------------------------------------------------------------------------------
+ private List<ProgramStageInstance> getProgramStageInstances( List<String> psIdentifier ) throws WebMessageException
+ {
+ List<ProgramStageInstance> programStageInstances = new ArrayList<>();
+
+ for ( String ps : psIdentifier )
+ {
+ ProgramStageInstance programStageInstance = getProgramStageInstance( ps );
+
+ if ( programStageInstance != null )
+ {
+ programStageInstances.add( programStageInstance );
+ }
+ }
+
+ return programStageInstances;
+ }
+
+ private ProgramStageInstance getProgramStageInstance( String ps ) throws WebMessageException
+ {
+ if ( ps == null )
+ {
+ return null;
+ }
+
+ ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( ps );
+
+ if ( programStageInstance == null )
+ {
+ throw new WebMessageException( WebMessageUtils.conflict( "Illegal programStageInstance identifier: " + ps ) );
+ }
+
+ return programStageInstance;
+ }
+
+ private List<DataElement> getDataElements( List<String> deIdentifier ) throws WebMessageException
+ {
+ List<DataElement> dataElements = new ArrayList<>();
+
+ for ( String de : deIdentifier )
+ {
+ DataElement dataElement = getDataElement( de );
+
+ if ( dataElement != null )
+ {
+ dataElements.add( dataElement );
+ }
+ }
+
+ return dataElements;
+ }
+
private DataElement getDataElement( String de ) throws WebMessageException
{
if ( de == null )