← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11271: Mobile web api, codestyle and null checks

 

------------------------------------------------------------
revno: 11271
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-06-27 21:11:47 +0200
message:
  Mobile web api, codestyle and null checks
modified:
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java
  dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.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-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2013-04-10 10:07:56 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/controller/MobileClientController.java	2013-06-27 19:11:47 +0000
@@ -55,8 +55,8 @@
 
     @RequestMapping( method = RequestMethod.GET, value = "/{version}" )
     @ResponseBody
-    public OrgUnits getOrgUnitsForUser( HttpServletRequest request, @PathVariable
-    String version )
+    public OrgUnits getOrgUnitsForUser( HttpServletRequest request, 
+        @PathVariable String version )
         throws NotAllowedException
     {
         User user = currentUserService.getCurrentUser();
@@ -80,8 +80,8 @@
 
     @RequestMapping( method = RequestMethod.GET, value = "/{version}/LWUIT" )
     @ResponseBody
-    public OrgUnits getOrgUnitsForUserLWUIT( HttpServletRequest request, @PathVariable
-    String version )
+    public OrgUnits getOrgUnitsForUserLWUIT( HttpServletRequest request, 
+        @PathVariable String version )
         throws NotAllowedException
     {
         User user = currentUserService.getCurrentUser();

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java	2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializableMessageConverter.java	2013-06-27 19:11:47 +0000
@@ -41,28 +41,32 @@
 public class DataStreamSerializableMessageConverter
     implements HttpMessageConverter<DataStreamSerializable>
 {
-
     @Override
     public boolean canRead( Class<?> clazz, MediaType mediaType )
     {
-    	if (mediaType == null){
-    		return DataStreamSerializable.class.isAssignableFrom( clazz );
-    	}
-    	else {
-    		return MediaTypes.MEDIA_TYPES.contains( mediaType) && DataStreamSerializable.class.isAssignableFrom( clazz );
-    	}
+        if ( mediaType == null )
+        {
+            return DataStreamSerializable.class.isAssignableFrom( clazz );
+        }
+        else
+        {
+            return MediaTypes.MEDIA_TYPES.contains( mediaType )
+                && DataStreamSerializable.class.isAssignableFrom( clazz );
+        }
     }
 
-
     @Override
     public boolean canWrite( Class<?> clazz, MediaType mediaType )
     {
-    	if (mediaType == null){
-    		return DataStreamSerializable.class.isAssignableFrom( clazz );
-    	}
-    	else {
-    		return MediaTypes.MEDIA_TYPES.contains( mediaType) && DataStreamSerializable.class.isAssignableFrom( clazz );
-    	}
+        if ( mediaType == null )
+        {
+            return DataStreamSerializable.class.isAssignableFrom( clazz );
+        }
+        else
+        {
+            return MediaTypes.MEDIA_TYPES.contains( mediaType )
+                && DataStreamSerializable.class.isAssignableFrom( clazz );
+        }
     }
 
     @Override
@@ -85,7 +89,5 @@
     {
         outputMessage.getHeaders().setContentType( contentType );
         DataStreamSerializer.write( entity, outputMessage.getBody() );
-
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java	2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/DataStreamSerializer.java	2013-06-27 19:11:47 +0000
@@ -41,7 +41,6 @@
 
 public class DataStreamSerializer
 {
-
     public static DataStreamSerializable read( Class<? extends DataStreamSerializable> clazz, InputStream input )
         throws IOException
     {
@@ -82,8 +81,16 @@
         }
         finally
         {
-            dos.flush();
-            gzip.finish();
+            if ( dos != null )
+            {
+                dos.flush();
+                dos.close();
+            }
+            
+            if ( gzip != null )
+            {
+                gzip.finish();
+            }
         }
     }
 
@@ -96,5 +103,4 @@
         out.flush();
         return baos;
     }
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java	2013-03-13 10:11:52 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MediaTypes.java	2013-06-27 19:11:47 +0000
@@ -34,7 +34,6 @@
 
 public class MediaTypes
 {
-
     public static String ACTIVITYVALUELIST_SERIALIZED = "application/vnd.org.dhis2.activityvaluelist+serialized";
     public static MediaType ACTIVITYVALUELIST_SERIALIZED_TYPE = 
         MediaType.parseMediaType( ACTIVITYVALUELIST_SERIALIZED );
@@ -54,5 +53,4 @@
 
     public static List<MediaType> MEDIA_TYPES = Arrays.asList( new MediaType[] { ACTIVITYVALUELIST_SERIALIZED_TYPE,
             DATASETVALUE_SERIALIZED_TYPE, MOBILE_SERIALIZED_TYPE, MOBILE_SERIALIZED_TYPE_WITH_CHARSET } );
-
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java'
--- dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java	2013-04-11 07:19:40 +0000
+++ dhis-2/dhis-web/dhis-web-api-mobile/src/main/java/org/hisp/dhis/api/mobile/support/MessageConverterAddingPostProcessor.java	2013-06-27 19:11:47 +0000
@@ -28,8 +28,7 @@
  */
 
 import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.http.converter.HttpMessageConverter;
@@ -40,9 +39,6 @@
 public class MessageConverterAddingPostProcessor
     implements BeanPostProcessor
 {
-
-    private final static Log logger = LogFactory.getLog( MessageConverterAddingPostProcessor.class );
-
     private HttpMessageConverter<?> messageConverter = new DataStreamSerializableMessageConverter();
 
     public Object postProcessBeforeInitialization( Object bean, String beanName )
@@ -65,18 +61,4 @@
         handlerAdapter.setMessageConverters( converters );
         return handlerAdapter;
     }
-
-    private void log( HttpMessageConverter<?>[] array )
-    {
-        StringBuilder sb = new StringBuilder( "Converters after adding custom one: " );
-
-        for ( HttpMessageConverter<?> httpMessageConverter : array )
-        {
-            sb.append( httpMessageConverter.getClass().getName() ).append( ", " );
-        }
-
-        String string = sb.toString();
-        logger.info( string.substring( 0, string.length() - 2 ) );
-    }
-
 }