dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24072
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11748: Analytics, error handling
------------------------------------------------------------
revno: 11748
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-08-22 16:33:21 +0200
message:
Analytics, error handling
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.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-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2013-08-22 09:26:39 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2013-08-22 14:33:21 +0000
@@ -165,7 +165,7 @@
{
if ( it != null && !it.contains( OPTION_SEP ) )
{
- params.getItems().add( new QueryItem( getItem( it ) ) );
+ params.getItems().add( new QueryItem( getItem( it, pr ) ) );
}
else if ( it != null )
{
@@ -176,7 +176,7 @@
throw new IllegalQueryException( "Item filter has invalid format: " + it );
}
- params.getItems().add( new QueryItem( getItem( split[0] ), split[1], split[2] ) );
+ params.getItems().add( new QueryItem( getItem( split[0], pr ), split[1], split[2] ) );
}
}
}
@@ -204,29 +204,29 @@
return params;
}
- private IdentifiableObject getItem( String item )
+ private IdentifiableObject getItem( String item, Program program )
{
DataElement de = dataElementService.getDataElement( item );
- if ( de != null )
+ if ( de != null && program.getAllDataElements().contains( de ) )
{
return de;
}
PatientAttribute at = attributeService.getPatientAttribute( item );
- if ( at != null )
+ if ( at != null && program.getPatientAttributes().contains( at ) )
{
return at;
}
PatientIdentifierType it = identifierTypeService.getPatientIdentifierType( item );
- if ( it != null )
+ if ( it != null && program.getPatientIdentifierTypes().contains( it ) )
{
return it;
}
- throw new IllegalQueryException( "Item identifier does not reference any item: " + item );
+ throw new IllegalQueryException( "Item identifier does not reference any item part of the program: " + item );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java 2013-08-22 07:53:43 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/EventAnalyticsController.java 2013-08-22 14:33:21 +0000
@@ -31,6 +31,7 @@
import javax.servlet.http.HttpServletResponse;
+import org.hisp.dhis.analytics.IllegalQueryException;
import org.hisp.dhis.analytics.event.EventAnalyticsService;
import org.hisp.dhis.analytics.event.EventQueryParams;
import org.hisp.dhis.api.utils.ContextUtils;
@@ -39,6 +40,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@@ -78,4 +80,13 @@
model.addAttribute( "viewClass", "detailed" );
return "grid";
}
+ // -------------------------------------------------------------------------
+ // Exception handling
+ // -------------------------------------------------------------------------
+
+ @ExceptionHandler(IllegalQueryException.class)
+ public void handleError( IllegalQueryException ex, HttpServletResponse response )
+ {
+ ContextUtils.conflictResponse( response, ex.getMessage() );
+ }
}