← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20812: CrudControllerAdvice, removed catch of IllegalArgumentException and IOException, too generic and ...

 

------------------------------------------------------------
revno: 20812
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-10-20 21:03:27 +0200
message:
  CrudControllerAdvice, removed catch of IllegalArgumentException and IOException, too generic and hides stacktraces. Replaced some use of IllegalArgumentException with InvalidIdentifierReferenceException.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/exception/
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/exception/InvalidIdentifierReferenceException.java
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java
  dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.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
=== added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/exception'
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/exception/InvalidIdentifierReferenceException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/exception/InvalidIdentifierReferenceException.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/exception/InvalidIdentifierReferenceException.java	2015-10-20 19:03:27 +0000
@@ -0,0 +1,46 @@
+package org.hisp.dhis.common.exception;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @author Lars Helge Overland
+ */
+public class InvalidIdentifierReferenceException
+    extends RuntimeException
+{
+    public InvalidIdentifierReferenceException( String message )
+    {
+        super( message );
+    }
+    
+    public InvalidIdentifierReferenceException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2015-10-15 07:36:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2015-10-20 19:03:27 +0000
@@ -43,6 +43,7 @@
 import org.hibernate.SessionFactory;
 import org.hisp.dhis.common.NameableObject.NameableProperty;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.user.UserCredentials;
@@ -764,7 +765,7 @@
                 return store.getByName( identifiers );
             }
             
-            throw new IllegalArgumentException( "Invalid identifiable property / class combination: " + property );
+            throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + property );
         }
 
         return null;
@@ -816,7 +817,7 @@
                 return store.getByName( id );
             }
             
-            throw new IllegalArgumentException( "Invalid identifiable property / class combination: " + property );
+            throw new InvalidIdentifierReferenceException( "Invalid identifiable property / class combination: " + property );
         }
 
         return null;

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2015-09-07 12:10:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/expression/DefaultExpressionService.java	2015-10-20 19:03:27 +0000
@@ -52,6 +52,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.GenericStore;
 import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.constant.Constant;
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.dataelement.DataElement;
@@ -602,12 +603,12 @@
             
             if ( dataElement == null )
             {
-                throw new IllegalArgumentException( "Identifier does not reference a data element: " + de );
+                throw new InvalidIdentifierReferenceException( "Identifier does not reference a data element: " + de );
             }
 
             if ( !operandIsTotal( matcher ) && categoryOptionCombo == null )
             {
-                throw new IllegalArgumentException( "Identifier does not reference a category option combo: " + coc );
+                throw new InvalidIdentifierReferenceException( "Identifier does not reference a category option combo: " + coc );
             }
             
             matcher.appendReplacement( sb, Matcher.quoteReplacement( DataElementOperand.getPrettyName( dataElement, categoryOptionCombo ) ) );
@@ -630,7 +631,7 @@
             
             if ( constant == null )
             {
-                throw new IllegalArgumentException( "Identifier does not reference a constant: " + co );
+                throw new InvalidIdentifierReferenceException( "Identifier does not reference a constant: " + co );
             }
             
             matcher.appendReplacement( sb, Matcher.quoteReplacement( constant.getDisplayName() ) );
@@ -653,7 +654,7 @@
             
             if ( group == null )
             {
-                throw new IllegalArgumentException( "Identifier does not reference an organisation unit group: " + oug );
+                throw new InvalidIdentifierReferenceException( "Identifier does not reference an organisation unit group: " + oug );
             }
             
             matcher.appendReplacement( sb, Matcher.quoteReplacement( group.getDisplayName() ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/period/hibernate/HibernatePeriodStore.java	2015-10-20 19:03:27 +0000
@@ -34,6 +34,7 @@
 import org.hibernate.Criteria;
 import org.hibernate.Session;
 import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodStore;
@@ -241,7 +242,7 @@
 
         if ( reloadedPeriodType == null )
         {
-            throw new IllegalArgumentException( "The PeriodType referenced by the Period is not in database: "
+            throw new InvalidIdentifierReferenceException( "The PeriodType referenced by the Period is not in database: "
                 + periodType.getName() );
         }
 

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-10-02 09:07:28 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/enrollment/AbstractEnrollmentService.java	2015-10-20 19:03:27 +0000
@@ -32,6 +32,7 @@
 import com.google.common.collect.Maps;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.OrganisationUnitSelectionMode;
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.commons.collection.CachingMap;
 import org.hisp.dhis.dbms.DbmsManager;
 import org.hisp.dhis.dxf2.events.event.Note;
@@ -565,7 +566,7 @@
 
         if ( entityInstance == null )
         {
-            throw new IllegalArgumentException( "TrackedEntityInstance does not exist." );
+            throw new InvalidIdentifierReferenceException( "TrackedEntityInstance does not exist." );
         }
 
         return entityInstance;

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java	2015-09-13 21:54:23 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/pdfform/PdfDataEntryFormUtil.java	2015-10-20 19:03:27 +0000
@@ -36,6 +36,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
@@ -218,19 +219,19 @@
 
                 if ( periodId == null || periodId.isEmpty() )
                 {
-                    throw new IllegalArgumentException( ERROR_EMPTY_PERIOD );
+                    throw new InvalidIdentifierReferenceException( ERROR_EMPTY_PERIOD );
                 }
 
                 if ( orgUnitUid == null || orgUnitUid.isEmpty() )
                 {
-                    throw new IllegalArgumentException( ERROR_EMPTY_ORG_UNIT );
+                    throw new InvalidIdentifierReferenceException( ERROR_EMPTY_ORG_UNIT );
                 }
 
                 Period period = PeriodType.getPeriodFromIsoString( periodId );
                 
                 if ( period == null )
                 {
-                    throw new IllegalArgumentException( ERROR_INVALID_PERIOD + periodId );
+                    throw new InvalidIdentifierReferenceException( ERROR_INVALID_PERIOD + periodId );
                 }
                 
                 // Loop Through the Fields and get data.

=== modified file 'dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java'
--- dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java	2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-mobile/src/main/java/org/hisp/dhis/mobile/service/PeriodUtil.java	2015-10-20 19:03:27 +0000
@@ -35,6 +35,7 @@
 import java.util.Date;
 import java.util.Vector;
 
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.period.DailyPeriodType;
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
@@ -46,7 +47,7 @@
 public class PeriodUtil
 {
     public static Period getPeriod( String periodName, PeriodType periodType )
-        throws IllegalArgumentException
+        throws InvalidIdentifierReferenceException
     {
 
         if ( periodType instanceof DailyPeriodType )
@@ -60,7 +61,7 @@
             }
             catch ( ParseException e )
             {
-                throw new IllegalArgumentException( "Couldn't make a period of type " + periodType.getName()
+                throw new InvalidIdentifierReferenceException( "Couldn't make a period of type " + periodType.getName()
                     + " and name " + periodName, e );
             }
             return periodType.createPeriod( date );
@@ -78,7 +79,7 @@
             }
             catch ( ParseException e )
             {
-                throw new IllegalArgumentException( "Couldn't make a period of type " + periodType.getName()
+                throw new InvalidIdentifierReferenceException( "Couldn't make a period of type " + periodType.getName()
                     + " and name " + periodName, e );
             }
             return periodType.createPeriod( date );
@@ -159,7 +160,7 @@
 
         }
 
-        throw new IllegalArgumentException( "Couldn't make a period of type " + periodType.getName() + " and name "
+        throw new InvalidIdentifierReferenceException( "Couldn't make a period of type " + periodType.getName() + " and name "
             + periodName );
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java	2015-10-16 10:21:28 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java	2015-10-20 19:03:27 +0000
@@ -32,6 +32,7 @@
 import org.hisp.dhis.common.DeleteNotAllowedException;
 import org.hisp.dhis.common.IllegalQueryException;
 import org.hisp.dhis.common.MaintenanceModeException;
+import org.hisp.dhis.common.exception.InvalidIdentifierReferenceException;
 import org.hisp.dhis.dataapproval.exceptions.DataApprovalException;
 import org.hisp.dhis.dxf2.webmessage.WebMessageException;
 import org.hisp.dhis.dxf2.webmessage.WebMessageStatus;
@@ -52,7 +53,6 @@
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.ConstraintViolationException;
 import java.beans.PropertyEditorSupport;
-import java.io.IOException;
 import java.util.Date;
 
 /**
@@ -95,7 +95,7 @@
         webMessageService.send( WebMessageUtils.unprocessableEntity( ex.getMessage() ), response, request );
     }
 
-    @ExceptionHandler( { IllegalQueryException.class, IllegalArgumentException.class, DeleteNotAllowedException.class } )
+    @ExceptionHandler( { IllegalQueryException.class, DeleteNotAllowedException.class, InvalidIdentifierReferenceException.class } )
     public void conflictsExceptionHandler( Exception ex, HttpServletResponse response, HttpServletRequest request )
     {
         webMessageService.send( WebMessageUtils.conflict( ex.getMessage() ), response, request );
@@ -131,12 +131,6 @@
         webMessageService.send( WebMessageUtils.conflict( ex.getMessage() ), response, request );
     }
 
-    @ExceptionHandler( IOException.class )
-    public void ioExceptionHandler( IOException ex, HttpServletResponse response, HttpServletRequest request )
-    {
-        webMessageService.send( WebMessageUtils.conflict( ex.getMessage() ), response, request );
-    }
-
     @ExceptionHandler( HttpStatusCodeException.class )
     public void httpStatusCodeExceptionHandler( HttpStatusCodeException ex, HttpServletResponse response, HttpServletRequest request )
     {