← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4777: Removed checked exception class NoCurrentUserException, not really doing anything except causing ...

 

------------------------------------------------------------
revno: 4777
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-09-30 11:19:11 +0200
message:
  Removed checked exception class NoCurrentUserException, not really doing anything except causing a lot of boilerplate code
removed:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/NoCurrentUserException.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java
  dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java
  dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/displayproperty/DefaultDisplayPropertyManager.java
  dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultUserSettingManager.java
  dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java
  dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/style/DefaultUserStyleManager.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/manager/DefaultDashboardManager.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
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/NoCurrentUserException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/NoCurrentUserException.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/NoCurrentUserException.java	1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
-package org.hisp.dhis.user;
-
-/*
- * Copyright (c) 2004-2010, 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 Torgeir Lorange Ostby
- * @version $Id: NoCurrentUserException.java 2869 2007-02-20 14:26:09Z andegje $
- */
-public class NoCurrentUserException
-    extends Exception
-{
-    /**
-     * Determines if a de-serialized file is compatible with this class.
-     */
-    private static final long serialVersionUID = 4261030912284935962L;
-
-    public NoCurrentUserException( String message )
-    {
-        super( message );
-    }
-
-    public NoCurrentUserException( String message, Throwable cause )
-    {
-        super( message, cause );
-    }
-}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2011-04-05 18:10:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java	2011-09-30 09:19:11 +0000
@@ -53,8 +53,7 @@
      * @param value the value to store.
      * @throws NoCurrentUserException if there is no current user.
      */
-    void saveUserSetting( String name, Serializable value )
-        throws NoCurrentUserException;
+    void saveUserSetting( String name, Serializable value );
 
     /**
      * Returns the value of the user setting specified by the given name.
@@ -64,8 +63,7 @@
      *         there is no match.
      * @throws NoCurrentUserException if there is no current user.
      */
-    Serializable getUserSetting( String name )
-        throws NoCurrentUserException;
+    Serializable getUserSetting( String name );
 
     /**
      * Returns the value of the user setting specified by the given name. If
@@ -86,8 +84,7 @@
      * @return all user settings belonging to the current user.
      * @throws NoCurrentUserException if there is no current user.
      */
-    Collection<UserSetting> getAllUserSettings()
-        throws NoCurrentUserException;
+    Collection<UserSetting> getAllUserSettings();
 
     /**
      * Deletes the user setting with the given name.
@@ -95,6 +92,5 @@
      * @param name the name of the user setting to delete.
      * @throws NoCurrentUserException if there is no current user.
      */
-    void deleteUserSetting( String name )
-        throws NoCurrentUserException;
+    void deleteUserSetting( String name );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java	2010-05-11 14:20:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/locale/DatabaseLocaleManager.java	2011-09-30 09:19:11 +0000
@@ -31,7 +31,6 @@
 import java.util.List;
 import java.util.Locale;
 
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -67,14 +66,7 @@
     @Override
     public void setCurrentLocale( Locale locale )
     {
-        try
-        {
-            userSettingService.saveUserSetting( KEY_USER_SETTING, locale );
-        }
-        catch ( NoCurrentUserException e )
-        {
-            // Just ignore for now. No change compared to previous behaviour.
-        }
+        userSettingService.saveUserSetting( KEY_USER_SETTING, locale );
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java	2011-06-13 14:03:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java	2011-09-30 09:19:11 +0000
@@ -63,13 +63,12 @@
     // -------------------------------------------------------------------------
 
     public void saveUserSetting( String name, Serializable value )
-        throws NoCurrentUserException
     {
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
-            throw new NoCurrentUserException( "No current user. User setting not saved: " + name );
+            return;
         }
 
         UserSetting userSetting = userService.getUserSetting( currentUser, name );
@@ -92,13 +91,12 @@
     }
 
     public Serializable getUserSetting( String name )
-        throws NoCurrentUserException
     {
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
-            throw new NoCurrentUserException( "No current user. User setting not returned: " + name );
+            return null;
         }
 
         UserSetting userSetting = userService.getUserSetting( currentUser, name );
@@ -131,26 +129,24 @@
     }
 
     public Collection<UserSetting> getAllUserSettings()
-        throws NoCurrentUserException
     {
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
-            throw new NoCurrentUserException( "No current user. User settings not returned" );
+            return null;
         }
 
         return userService.getAllUserSettings( currentUser );
     }
 
     public void deleteUserSetting( String name )
-        throws NoCurrentUserException
     {
         User currentUser = currentUserService.getCurrentUser();
 
         if ( currentUser == null )
         {
-            throw new NoCurrentUserException( "No current user. User setting not deleted: " + name );
+            return;
         }
 
         userService.deleteUserSetting( userService.getUserSetting( currentUser, name ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java	2010-04-21 19:45:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/UserSettingDeletionHandler.java	2011-09-30 09:19:11 +0000
@@ -63,22 +63,15 @@
     @Override
     public void deleteDataDictionary( DataDictionary dataDictionary )
     {
-        try
+        for ( UserSetting setting : userSettingService.getAllUserSettings() )
         {
-            for ( UserSetting setting : userSettingService.getAllUserSettings() )
+            if ( setting.getName().equals( SETTING_NAME_DATADICTIONARY ) )
             {
-                if ( setting.getName().equals( SETTING_NAME_DATADICTIONARY ) )
+                if ( setting.getValue() != null && (Integer) setting.getValue() == dataDictionary.getId() )
                 {
-                    if ( setting.getValue() != null && (Integer) setting.getValue() == dataDictionary.getId() )
-                    {
-                        userSettingService.deleteUserSetting( SETTING_NAME_DATADICTIONARY );
-                    }
+                    userSettingService.deleteUserSetting( SETTING_NAME_DATADICTIONARY );
                 }
             }
         }
-        catch ( NoCurrentUserException ex )
-        {
-            // Do nothing
-        }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java'
--- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/locale/UserSettingLocaleManager.java	2011-09-30 09:19:11 +0000
@@ -31,7 +31,6 @@
 import java.util.List;
 import java.util.Locale;
 
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -89,14 +88,7 @@
 
     public void setCurrentLocale( Locale locale )
     {
-        try
-        {
-            userSettingService.saveUserSetting( userSettingKey, locale );
-        }
-        catch ( NoCurrentUserException e )
-        {
-            // Just ignore for now. No change compared to previous behaviour.
-        }
+        userSettingService.saveUserSetting( userSettingKey, locale );
     }
 
     public List<Locale> getLocalesOrderedByPriority()

=== modified file 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/displayproperty/DefaultDisplayPropertyManager.java'
--- dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/displayproperty/DefaultDisplayPropertyManager.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/displayproperty/DefaultDisplayPropertyManager.java	2011-09-30 09:19:11 +0000
@@ -30,7 +30,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -59,13 +58,7 @@
 
     public void setCurrentDisplayProperty( String displayProperty )
     {
-        try
-        {
-            userSettingService.saveUserSetting( SETTING_NAME_DISPLAY_PROPERTY, displayProperty );
-        }
-        catch ( NoCurrentUserException e )
-        {
-        }
+        userSettingService.saveUserSetting( SETTING_NAME_DISPLAY_PROPERTY, displayProperty );
     }
 
     public String getCurrentDisplayProperty()

=== modified file 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultUserSettingManager.java'
--- dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultUserSettingManager.java	2011-04-07 07:21:11 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/setting/DefaultUserSettingManager.java	2011-09-30 09:19:11 +0000
@@ -33,7 +33,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.options.UserSettingManager;
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 public class DefaultUserSettingManager
@@ -58,28 +57,12 @@
 
     public Serializable getUserSetting( String key )
     {
-        try
-        {
-            return userSettingService.getUserSetting( key );
-        }
-        catch ( NoCurrentUserException e )
-        {
-            log.warn( "No current user, could not get user setting for key " + key );
-        }
-
-        return null;
+        return userSettingService.getUserSetting( key );
     }
     
     public void saveUserSetting( String key, Serializable value )
     {
-        try
-        {
-            userSettingService.saveUserSetting( key, value );
-        }
-        catch ( NoCurrentUserException e )
-        {
-            log.warn( "No current user, could not save user setting for key " + key );
-        }
+        userSettingService.saveUserSetting( key, value );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java'
--- dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java	2011-02-15 13:45:11 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java	2011-09-30 09:19:11 +0000
@@ -54,7 +54,6 @@
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitCodeComparator;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitShortNameComparator;
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -119,13 +118,7 @@
 
     public void setCurrentSortOrder( String sortOrder )
     {
-        try
-        {
-            userSettingService.saveUserSetting( SETTING_NAME_SORT_ORDER, sortOrder );
-        }
-        catch ( NoCurrentUserException e )
-        {
-        }
+        userSettingService.saveUserSetting( SETTING_NAME_SORT_ORDER, sortOrder );
     }
 
     public String getCurrentSortOrder()

=== modified file 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/style/DefaultUserStyleManager.java'
--- dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/style/DefaultUserStyleManager.java	2010-10-28 09:25:22 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/style/DefaultUserStyleManager.java	2011-09-30 09:19:11 +0000
@@ -30,7 +30,6 @@
 
 import java.io.File;
 
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -64,25 +63,12 @@
 
     public void setCurrentStyle( String file )
     {
-        try
-        {
-            userSettingService.saveUserSetting( SETTING_NAME_STYLE, file );
-        }
-        catch ( NoCurrentUserException ex )
-        {
-        }
+        userSettingService.saveUserSetting( SETTING_NAME_STYLE, file );
     }
 
     public String getCurrentStyle()
     {
-        try
-        {
-            return (String) userSettingService.getUserSetting( SETTING_NAME_STYLE );
-        }
-        catch ( NoCurrentUserException ex )
-        {
-            return null;
-        }
+        return (String) userSettingService.getUserSetting( SETTING_NAME_STYLE );
     }
 
     public String getCurrentStyleDirectory()

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/manager/DefaultDashboardManager.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/manager/DefaultDashboardManager.java	2011-03-24 16:58:40 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/manager/DefaultDashboardManager.java	2011-09-30 09:19:11 +0000
@@ -35,7 +35,6 @@
 import org.hisp.dhis.dashboard.DashboardConfiguration;
 import org.hisp.dhis.dashboard.DashboardManager;
 import org.hisp.dhis.dashboard.provider.ContentProvider;
-import org.hisp.dhis.user.NoCurrentUserException;
 import org.hisp.dhis.user.UserSettingService;
 
 /**
@@ -115,16 +114,9 @@
 
     public DashboardConfiguration getConfiguration()
     {
-        try
-        {
-            DashboardConfiguration config = (DashboardConfiguration) userSettingService.getUserSetting( KEY_USERSETTING );
-            
-            return config != null ? config : new DashboardConfiguration();
-        }
-        catch ( NoCurrentUserException ex )
-        {
-            throw new RuntimeException( "Could not get configuration because no current user exists", ex );
-        }
+        DashboardConfiguration config = (DashboardConfiguration) userSettingService.getUserSetting( KEY_USERSETTING );
+        
+        return config != null ? config : new DashboardConfiguration();
     }
 
     // -------------------------------------------------------------------------
@@ -133,13 +125,6 @@
 
     private void setConfiguration( DashboardConfiguration config )
     {
-        try
-        {
-            userSettingService.saveUserSetting( KEY_USERSETTING, config );
-        }
-        catch ( NoCurrentUserException ex )
-        {
-            throw new RuntimeException( "Could not save configuration because no current user exists", ex );
-        }
+        userSettingService.saveUserSetting( KEY_USERSETTING, config );
     }
 }