← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9330: Codestyle and logging

 

------------------------------------------------------------
revno: 9330
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-12-16 20:18:03 +0100
message:
  Codestyle and logging
modified:
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/DefaultIntegrationService.java
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/IntegrationService.java
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2DataProducer.java
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/management/DHIS2LifecycleStrategy.java
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/SDMXDataIn.java
  dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/XMLDataIn.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-integration/src/main/java/org/hisp/dhis/integration/DefaultIntegrationService.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/DefaultIntegrationService.java	2012-06-27 15:16:51 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/DefaultIntegrationService.java	2012-12-16 19:18:03 +0000
@@ -41,44 +41,44 @@
 /**
  * @author bobj
  */
-public class DefaultIntegrationService 
+public class DefaultIntegrationService
     implements IntegrationService
-{    
-    @EndpointInject(uri = XMLDataIn.XMLDATA_IN)
+{
+    @EndpointInject( uri = XMLDataIn.XMLDATA_IN )
     private ProducerTemplate xmlIn;
 
-    @EndpointInject(uri = SDMXDataIn.SDMXDATA_IN)
+    @EndpointInject( uri = SDMXDataIn.SDMXDATA_IN )
     private ProducerTemplate sdmxIn;
 
     @Override
     public ImportSummary importXMLDataValueSet( InputStream in, ImportOptions importOptions )
     {
-       return (ImportSummary) xmlIn.requestBodyAndHeader( in, IMPORT_OPTIONS_HDR, importOptions);
+        return (ImportSummary) xmlIn.requestBodyAndHeader( in, IMPORT_OPTIONS_HDR, importOptions );
     }
 
     @Override
     public ImportSummary importSDMXDataValueSet( InputStream in, ImportOptions importOptions )
     {
-       return (ImportSummary) sdmxIn.requestBodyAndHeader( in, IMPORT_OPTIONS_HDR, importOptions);
+        return (ImportSummary) sdmxIn.requestBodyAndHeader( in, IMPORT_OPTIONS_HDR, importOptions );
     }
 
     @Override
     public ImportSummary importXMLDataValueSet( InputStream in, ImportOptions options, TaskId taskId )
     {
-        Map<String,Object> headers = new HashMap<String,Object>();
+        Map<String, Object> headers = new HashMap<String, Object>();
         headers.put( TASK_ID_HDR, taskId );
-        headers.put( IMPORT_OPTIONS_HDR, options);
-        
-       return (ImportSummary) xmlIn.requestBodyAndHeaders( in, headers);
+        headers.put( IMPORT_OPTIONS_HDR, options );
+
+        return (ImportSummary) xmlIn.requestBodyAndHeaders( in, headers );
     }
 
     @Override
     public ImportSummary importSDMXDataValueSet( InputStream in, ImportOptions options, TaskId taskId )
     {
-        Map<String,Object> headers = new HashMap<String,Object>();
+        Map<String, Object> headers = new HashMap<String, Object>();
         headers.put( TASK_ID_HDR, taskId );
-        headers.put( IMPORT_OPTIONS_HDR, options);
-        
-       return (ImportSummary) sdmxIn.requestBodyAndHeaders( in, headers);
+        headers.put( IMPORT_OPTIONS_HDR, options );
+
+        return (ImportSummary) sdmxIn.requestBodyAndHeaders( in, headers );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/IntegrationService.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/IntegrationService.java	2012-06-27 15:16:51 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/IntegrationService.java	2012-12-16 19:18:03 +0000
@@ -33,22 +33,20 @@
 import org.hisp.dhis.scheduling.TaskId;
 
 /**
- *
+ * 
  * @author bobj
  */
 public interface IntegrationService
 {
     public static final String IMPORT_OPTIONS_HDR = "ImportOptions";
-    
+
     public static final String TASK_ID_HDR = "TASK_ID";
 
-
-    ImportSummary importXMLDataValueSet(InputStream in, ImportOptions options);
-
-    ImportSummary importSDMXDataValueSet(InputStream in, ImportOptions options);
-
-    ImportSummary importXMLDataValueSet(InputStream in, ImportOptions options, TaskId taskId);
-
-    ImportSummary importSDMXDataValueSet(InputStream in, ImportOptions options, TaskId taskId);
-
+    ImportSummary importXMLDataValueSet( InputStream in, ImportOptions options );
+
+    ImportSummary importSDMXDataValueSet( InputStream in, ImportOptions options );
+
+    ImportSummary importXMLDataValueSet( InputStream in, ImportOptions options, TaskId taskId );
+
+    ImportSummary importSDMXDataValueSet( InputStream in, ImportOptions options, TaskId taskId );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2DataProducer.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2DataProducer.java	2012-06-29 10:51:48 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2DataProducer.java	2012-12-16 19:18:03 +0000
@@ -55,7 +55,7 @@
         
         Dxf2DataEndpoint endpoint =  (Dxf2DataEndpoint) this.getEndpoint();
         
-        // get importOptions off the message header or default to options set on the endpoint
+        // get importOptions off the message header or default to options set on the end point
         ImportOptions options = (ImportOptions) exchange.getIn().
             getHeader( IntegrationService.IMPORT_OPTIONS_HDR, endpoint.getImportOptions() );
         

=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/management/DHIS2LifecycleStrategy.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/management/DHIS2LifecycleStrategy.java	2012-11-15 16:38:39 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/management/DHIS2LifecycleStrategy.java	2012-12-16 19:18:03 +0000
@@ -62,8 +62,12 @@
         try
         {
             log.info( "Camel context started" );
-            if ( locationManager == null ) throw new LocationManagerException( "No locationManager configured" );
-
+            
+            if ( locationManager == null )
+            {
+                throw new LocationManagerException( "No locationManager configured" );
+            }
+            
             File rootsDir = new File( locationManager.getExternalDirectory().getAbsolutePath() + "/routes/" );
 
             if ( !rootsDir.exists() )
@@ -71,11 +75,13 @@
                 rootsDir.mkdir();
             }
 
+            log.info( "Searching for routes in directory: " + rootsDir.getAbsolutePath() );
+            
             File[] routeFiles = rootsDir.listFiles();
+            
             for ( File routeFile : routeFiles )
             {
-                // load xml route
-                if ( routeFile.getName().endsWith( ".xml" ) )
+                if ( routeFile != null && routeFile.getName().endsWith( ".xml" ) )
                 {
                     InputStream is = null;
                     try
@@ -83,21 +89,24 @@
                         is = new FileInputStream( routeFile );
                         RoutesDefinition routes = context.loadRoutesDefinition( is );
                         context.addRouteDefinitions( routes.getRoutes() );
-                    } catch ( Exception ex )
+                        log.info( "Loaded route from " + routeFile.getName() );
+                    }
+                    catch ( Exception ex )
                     {
                         log.info( "Unable to load routes from " + routeFile.getName() + " : " + ex.getMessage() );
-                    } finally
+                    }
+                    finally
                     {
                         IOUtils.closeQuietly( is );
                     }
                 }
             }
-        } catch ( LocationManagerException ex )
+        }
+        catch ( LocationManagerException ex )
         {
-            // no dhis2_home directory configured .. no routes to load ... that's ok
+            // no dhis2_home directory configured .. no routes to load ...
             log.info( "Not loading external routes from DHIS2_HOME" );
         }
-
     }
 
     @Override
@@ -171,7 +180,8 @@
     }
 
     @Override
-    public void onThreadPoolAdd( CamelContext cc, ThreadPoolExecutor tpe, String string, String string1, String string2, String string3 )
+    public void onThreadPoolAdd( CamelContext cc, ThreadPoolExecutor tpe, String string, String string1,
+        String string2, String string3 )
     {
         log.debug( "Camel threadPool added" );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/SDMXDataIn.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/SDMXDataIn.java	2012-09-12 09:39:18 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/SDMXDataIn.java	2012-12-16 19:18:03 +0000
@@ -30,37 +30,39 @@
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.model.DescriptionDefinition;
 import org.apache.camel.model.RouteDefinition;
+import java.io.InputStream;
 
 /**
- * SDMXDataIn route takes an SDMX cross-sectional message, transforms to dxf2 datavalueset
- * and sends to dxf2 endpoint
+ * SDMXDataIn route takes an SDMX cross-sectional message, transforms to dxf2
+ * datavalueset and sends to dxf2 endpoint
  * 
  * @author bobj
  */
-public class SDMXDataIn 
+public class SDMXDataIn
     extends RouteBuilder
-{ 
+{
     // DataInput endpoint
     public static final String SDMXDATA_IN = "direct:sdmxDataIn";
-    
+
     // Route description and ID
     public static final String SDMXDATA_IN_DESC = "Internal: SDMX Data to DXF2 Input";
-    
+
     // IDs beginning with 'internal-*' do not show up in UI
     public static final String SDMXDATA_IN_ID = "internal-sdmx-datain";
-    
+
     @Override
-    public void configure() throws Exception
+    public void configure()
+        throws Exception
     {
         DescriptionDefinition desc = new DescriptionDefinition();
-        desc.setText(SDMXDATA_IN_DESC);
-        
-        RouteDefinition sdmxDataIn = from(SDMXDATA_IN).
-            convertBodyTo( java.lang.String.class, "UTF-8" ).to( "log:org.hisp.dhis.integration?level=INFO").
-            to("xslt:transform/cross2dxf2.xsl").convertBodyTo( java.io.InputStream.class).
-            inOut("dhis2:data?orgUnitIdScheme=CODE&dataElementIdScheme=CODE&importStrategy=NEW_AND_UPDATES");
-        
+        desc.setText( SDMXDATA_IN_DESC );
+
+        RouteDefinition sdmxDataIn = from( SDMXDATA_IN ).convertBodyTo( String.class, "UTF-8" )
+            .to( "log:org.hisp.dhis.integration?level=INFO" ).to( "xslt:transform/cross2dxf2.xsl" )
+            .convertBodyTo( InputStream.class )
+            .inOut( "dhis2:data?orgUnitIdScheme=CODE&dataElementIdScheme=CODE&importStrategy=NEW_AND_UPDATES" );
+
         sdmxDataIn.setDescription( desc );
         sdmxDataIn.setId( SDMXDATA_IN_ID );
-    }    
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/XMLDataIn.java'
--- dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/XMLDataIn.java	2012-07-26 14:47:31 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/routes/XMLDataIn.java	2012-12-16 19:18:03 +0000
@@ -31,6 +31,7 @@
 import org.apache.camel.builder.xml.Namespaces;
 import org.apache.camel.model.DescriptionDefinition;
 import org.apache.camel.model.RouteDefinition;
+import java.io.InputStream;
 
 /**
  * XMLDataIn route implements a Content Based Routing pattern
@@ -41,12 +42,12 @@
 public class XMLDataIn 
     extends RouteBuilder
 {
-    // DataInput endpoint
-    
+    // DataInput endpoint    
     public static final String XMLDATA_IN = "direct:xmlDataIn"; 
 
     // Route description and ID
     public static final String XMLDATA_IN_DESC = "Internal: XML Data to DXF2 Input";
+    
     // IDs beginning with 'internal-*' do not show up in UI
     public static final String XMLDATA_IN_ID = "internal-xml-datain";
     
@@ -61,15 +62,14 @@
         DescriptionDefinition xmlDesc = new DescriptionDefinition();
         xmlDesc.setText( XMLDATA_IN_DESC);
         
-        RouteDefinition xmlDataIn = (RouteDefinition) from(XMLDATA_IN).convertBodyTo(java.lang.String.class, "UTF-8")
+        RouteDefinition xmlDataIn = (RouteDefinition) from( XMLDATA_IN ).convertBodyTo( String.class, "UTF-8" )
             .choice()
             // send native dxf2 data directly to dhis2:data 
-            .when().xpath( "boolean(/d:dataValueSet)", ns).convertBodyTo( java.io.InputStream.class).to("dhis2:data")
+            .when().xpath( "boolean(/d:dataValueSet)", ns).convertBodyTo( InputStream.class).to( "dhis2:data" )
             // send sdmx data to sdmx route
-            .when().xpath( "boolean(/m:CrossSectionalData)", ns).to("direct:sdmxDataIn")
+            .when().xpath( "boolean(/m:CrossSectionalData)", ns).to( "direct:sdmxDataIn" )
             // unknown xml
-            .otherwise().to("log:org.hisp.dhis.integration?level=DEBUG" )
-            .end();
+            .otherwise().to( "log:org.hisp.dhis.integration?level=DEBUG" ).end();
         
         xmlDataIn.setDescription( xmlDesc );
         xmlDataIn.setId( XMLDATA_IN_ID );