← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7154: Enabled passing through of web-api importOptions to datavalueset importer

 

------------------------------------------------------------
revno: 7154
committer: Bob Jolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-06-02 16:42:02 +0100
message:
  Enabled passing through of web-api importOptions to datavalueset importer
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


--
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-01 21:56:18 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/DefaultIntegrationService.java	2012-06-02 15:42:02 +0000
@@ -28,14 +28,12 @@
  */
 
 import java.io.InputStream;
-import org.apache.camel.CamelContext;
 import org.apache.camel.EndpointInject;
 import org.apache.camel.ProducerTemplate;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.integration.routes.SDMXDataIn;
 import org.hisp.dhis.integration.routes.XMLDataIn;
-import org.springframework.beans.factory.annotation.Autowired;
 
 /**
  *
@@ -43,8 +41,6 @@
  */
 public class DefaultIntegrationService implements IntegrationService
 {
-    @Autowired
-    CamelContext camelContext;
     
     @EndpointInject(uri = XMLDataIn.XMLDATA_IN)
     private ProducerTemplate xmlIn;
@@ -56,13 +52,13 @@
     @Override
     public ImportSummary importXMLDataValueSet( InputStream in, ImportOptions importOptions )
     {
-       return (ImportSummary) xmlIn.requestBodyAndHeader( in, "ImportOptions", importOptions);
+       return (ImportSummary) xmlIn.requestBodyAndHeader( in, IMPORT_OPTIONS_HDR, importOptions);
     }
 
     @Override
     public ImportSummary importSDMXDataValueSet( InputStream in, ImportOptions importOptions )
     {
-       return (ImportSummary) sdmxIn.requestBodyAndHeader( in, "ImportOptions", importOptions);
+       return (ImportSummary) sdmxIn.requestBodyAndHeader( in, IMPORT_OPTIONS_HDR, importOptions);
     }
     
 }

=== 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-01 21:56:18 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/IntegrationService.java	2012-06-02 15:42:02 +0000
@@ -37,6 +37,8 @@
  */
 public interface IntegrationService
 {
+    public static final String IMPORT_OPTIONS_HDR = "ImportOptions";
+
     ImportSummary importXMLDataValueSet(InputStream in, ImportOptions options);
 
     ImportSummary importSDMXDataValueSet(InputStream in, ImportOptions options);

=== 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-01 21:56:18 +0000
+++ dhis-2/dhis-services/dhis-service-integration/src/main/java/org/hisp/dhis/integration/components/Dxf2DataProducer.java	2012-06-02 15:42:02 +0000
@@ -28,10 +28,13 @@
  */
 
 import java.io.InputStream;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.DefaultProducer;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.metadata.ImportOptions;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.integration.IntegrationService;
 
 /**
  * @author bobj
@@ -47,15 +50,18 @@
     @Override
     public void process( Exchange exchange ) throws Exception
     {
-        log.info( this.getEndpoint().getEndpointUri() + " : " + exchange.getIn().getBody() );
+        log.debug( this.getEndpoint().getEndpointUri() + " : " + exchange.getIn().getBody() );
         
         Dxf2DataEndpoint endpoint =  (Dxf2DataEndpoint) this.getEndpoint();
         
+        // get importOptions off the message header or default to options set on the endpoint
+        ImportOptions options = (ImportOptions) exchange.getIn().
+            getHeader( IntegrationService.IMPORT_OPTIONS_HDR, endpoint.getImportOptions() );
+        
         ImportSummary summary = endpoint.getDataValueSetService().saveDataValueSet( (InputStream)exchange.getIn().getBody(), 
-             endpoint.getImportOptions() );
+             options );
         
-        //exchange.getOut().setBody(JacksonUtils.toXmlAsString( summary ) );
         exchange.getOut().setBody( summary );
-        log.info( this.getEndpoint().getEndpointUri() + " : " + JacksonUtils.toXmlAsString(exchange.getOut().getBody()) );
+        log.debug( this.getEndpoint().getEndpointUri() + " : " + JacksonUtils.toXmlAsString(exchange.getOut().getBody()) );
     }
 }