← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16953: in event controller, if trackedEntityInstance is given, check that it exists, if not return confl...

 

------------------------------------------------------------
revno: 16953
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-10-04 09:30:53 +0700
message:
  in event controller, if trackedEntityInstance is given, check that it exists, if not return conflict (and not just ignore, as we do now)
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java	2014-10-01 03:52:37 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataelement/DataElementOperandController.java	2014-10-04 02:30:53 +0000
@@ -87,8 +87,6 @@
             {
                 DataElementGroup dataElementGroup = manager.get( DataElementGroup.class, deGroup );
                 dataElementOperands = new ArrayList<>( categoryService.getFullOperands( dataElementGroup.getMembers() ) );
-
-                System.err.println( "operands:" + dataElementOperands );
             }
             else
             {

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-09-29 18:38:31 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/EventController.java	2014-10-04 02:30:53 +0000
@@ -28,19 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-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.webapi.webdomain.WebOptions;
-import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
 import org.hisp.dhis.common.Pager;
@@ -71,6 +58,8 @@
 import org.hisp.dhis.system.scheduling.Scheduler;
 import org.hisp.dhis.system.util.StreamUtils;
 import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.webdomain.WebOptions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.http.HttpStatus;
@@ -83,6 +72,16 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseStatus;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -109,7 +108,7 @@
 
     @Autowired
     private EventService eventService;
-    
+
     @Autowired
     private EventRowService eventRowService;
 
@@ -140,7 +139,7 @@
         @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 )
+        @RequestParam Map<String, String> parameters, Model model, HttpServletResponse response, HttpServletRequest request )
     {
         WebOptions options = new WebOptions( parameters );
 
@@ -153,6 +152,12 @@
         if ( trackedEntityInstance != null )
         {
             tei = trackedEntityInstanceService.getTrackedEntityInstance( trackedEntityInstance );
+
+            if ( tei == null )
+            {
+                ContextUtils.conflictResponse( response, "Invalid trackedEntityInstance ID." );
+                return null;
+            }
         }
 
         if ( orgUnit != null )
@@ -204,11 +209,11 @@
 
         return "events";
     }
-    
+
     @RequestMapping( value = "/overdue", method = RequestMethod.GET )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
     public String getOverdueEvents(
-        @RequestParam( required = false ) String program,        
+        @RequestParam( required = false ) String program,
         @RequestParam( required = false ) String orgUnit,
         @RequestParam( required = false ) OrganisationUnitSelectionMode ouMode,
         @RequestParam( required = false ) ProgramStatus programStatus,
@@ -245,15 +250,15 @@
             }
         }
 
-        EventRows eventRows = eventRowService.getEventRows( pr, organisationUnits, programStatus, eventStatus, startDate, endDate);
-        
+        EventRows eventRows = eventRowService.getEventRows( pr, organisationUnits, programStatus, eventStatus, startDate, endDate );
+
         if ( options.hasPaging() )
         {
             Pager pager = new Pager( options.getPage(), eventRows.getEventRows().size(), options.getPageSize() );
             eventRows.setPager( pager );
             eventRows.setEventRows( PagerUtils.pageCollection( eventRows.getEventRows(), pager ) );
         }
-        
+
         model.addAttribute( "model", eventRows );
         model.addAttribute( "viewClass", options.getViewClass( "detailed" ) );
 
@@ -454,7 +459,7 @@
 
         DataElement dataElement = dataElementService.getDataElement( dataElementUid );
 
-        if( dataElement == null )
+        if ( dataElement == null )
         {
             ContextUtils.notFoundResponse( response, "DataElement not found for uid: " + dataElementUid );
             return;
@@ -467,7 +472,7 @@
         ContextUtils.okResponse( response, "Event updated: " + uid );
 
     }
-    
+
     @RequestMapping( value = "/{uid}/addNote", method = RequestMethod.PUT, consumes = "application/json" )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
     public void putJsonEventForNote( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException
@@ -486,7 +491,7 @@
         eventService.updateEventForNote( updatedEvent );
         ContextUtils.okResponse( response, "Event updated: " + uid );
     }
-    
+
     @RequestMapping( value = "/{uid}/updateEventDate", method = RequestMethod.PUT, consumes = "application/json" )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_TRACKED_ENTITY_DATAVALUE_ADD')" )
     public void putJsonEventForEventDate( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, ImportOptions importOptions ) throws IOException