← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14869: Event query, including data elements part of requested program as part of meta data in response.

 

------------------------------------------------------------
revno: 14869
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-15 11:59:01 +0200
message:
  Event query, including data elements part of requested program as part of meta data in response.
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Events.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.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/events/event/Events.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Events.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/Events.java	2014-04-15 09:59:01 +0000
@@ -33,9 +33,11 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.Pager;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -48,7 +50,11 @@
     private String programInstance;
 
     private List<Event> events = new ArrayList<Event>();
+    
+    private Map<Object, Object> metaData;
 
+    private Pager pager;
+    
     public Events()
     {
     }
@@ -90,6 +96,30 @@
         this.events = events;
     }
 
+    @JsonProperty
+    @JacksonXmlProperty
+    public Map<Object, Object> getMetaData()
+    {
+        return metaData;
+    }
+
+    public void setMetaData( Map<Object, Object> metaData )
+    {
+        this.metaData = metaData;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty
+    public Pager getPager()
+    {
+        return pager;
+    }
+
+    public void setPager( Pager pager )
+    {
+        this.pager = pager;
+    }
+
     @Override
     public String toString()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-04-15 07:12:15 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/JdbcEventStore.java	2014-04-15 09:59:01 +0000
@@ -210,7 +210,7 @@
             sql += hlp.whereAnd() + " pi.followup is " + ( followUp ? "true" : "false" ) + " ";
         }
 
-        if ( !orgUnitIds.isEmpty() )
+        if ( orgUnitIds != null && !orgUnitIds.isEmpty() )
         {
             sql += hlp.whereAnd() + " ou.organisationunitid in (" + getCommaDelimitedString( orgUnitIds ) + ") ";
         }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2014-04-15 09:43:23 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java	2014-04-15 09:59:01 +0000
@@ -32,13 +32,13 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.hisp.dhis.api.controller.WebMetaData;
 import org.hisp.dhis.api.controller.WebOptions;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.common.IdentifiableObjectManager;
@@ -89,6 +89,8 @@
 public class EventController
 {
     public static final String RESOURCE_PATH = "/events";
+    
+    private static final String META_DATA_KEY_DE = "de";
 
     //--------------------------------------------------------------------------
     // Dependencies
@@ -132,10 +134,10 @@
         @RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
         @RequestParam( required = false ) @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
         @RequestParam( required = false ) EventStatus status,
+        @RequestParam( required = false ) boolean skipMeta,
         @RequestParam Map<String, String> parameters, Model model, HttpServletRequest request )
     {
-        WebOptions options = new WebOptions( parameters );        
-        WebMetaData metaData = new WebMetaData();
+        WebOptions options = new WebOptions( parameters );
         
         Program pr = manager.get( Program.class, program );
         ProgramStage prs = manager.get( ProgramStage.class, programStage );
@@ -172,11 +174,9 @@
 
         Events events = eventService.getEvents( pr, prs, programStatus, followUp, organisationUnits, tei, startDate, endDate, status );
         
-        List<Event> eventList = new ArrayList<Event>( events.getEvents() );
-
         if ( options.hasLinks() )
         {
-            for ( Event event : eventList )
+            for ( Event event : events.getEvents() )
             {
                 event.setHref( ContextUtils.getRootPath( request ) + RESOURCE_PATH + "/" + event.getEvent() );
             }
@@ -184,14 +184,17 @@
         
         if ( options.hasPaging() )
         {      	
-            Pager pager = new Pager( options.getPage(), eventList.size(), options.getPageSize() );
-            metaData.setPager( pager );
-            eventList = PagerUtils.pageCollection( eventList, pager );        	
+            Pager pager = new Pager( options.getPage(), events.getEvents().size(), options.getPageSize() );
+            events.setPager( pager );
+            events.setEvents( PagerUtils.pageCollection( events.getEvents(), pager ) );        	
         }        
         
-        metaData.setEvents( eventList );
-
-        model.addAttribute( "model", metaData );
+        if ( !skipMeta && pr != null )
+        {
+            events.setMetaData( getMetaData( pr ) );
+        }
+        
+        model.addAttribute( "model", events );
         model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
 
         return "events";
@@ -222,6 +225,24 @@
         return "event";
     }
 
+    private Map<Object, Object> getMetaData( Program program )
+    {
+        Map<Object, Object> metaData = new HashMap<Object, Object>();
+        
+        if ( program != null )
+        {
+            Map<String, String> dataElements = new HashMap<String, String>();
+            
+            for ( DataElement de : program.getAllDataElements() )
+            {
+                dataElements.put( de.getUid(), de.getDisplayName() );
+            }
+
+            metaData.put( META_DATA_KEY_DE, dataElements );
+        }
+        
+        return metaData;
+    }
     // -------------------------------------------------------------------------
     // CREATE
     // -------------------------------------------------------------------------