← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21674: Modified adx exporter to use codes instead of uids for data export params.

 

------------------------------------------------------------
revno: 21674
committer: bobjolliffe <bobjolliffe@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2016-01-08 16:54:54 +0000
message:
  Modified adx exporter to use codes instead of uids for data export params.
removed:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/PipedImporter.java
added:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxPipedImporter.java
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxDataService.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.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-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxDataService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxDataService.java	2016-01-06 11:26:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxDataService.java	2016-01-08 16:54:54 +0000
@@ -30,6 +30,9 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Date;
+import java.util.Set;
+import org.hisp.dhis.common.IdSchemes;
 
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.datavalueset.DataExportParams;
@@ -68,6 +71,10 @@
     // Methods
     //--------------------------------------------------------------------------
 
+    DataExportParams getFromUrl( Set<String> dataSets, Set<String> periods, Date startDate, Date endDate, 
+        Set<String> organisationUnits, boolean includeChildren, Date lastUpdated, Integer limit,  IdSchemes idSchemes);
+    
+    
     /**
      * Post data. Takes ADX Data from input stream and saves a series of DXF2 
      * DataValueSets.

=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxPipedImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxPipedImporter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/AdxPipedImporter.java	2016-01-08 16:54:54 +0000
@@ -0,0 +1,98 @@
+package org.hisp.dhis.dxf2.adx;
+
+/*
+ * Copyright (c) 2004-2016, 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.
+ */
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.concurrent.Callable;
+
+import org.apache.commons.io.IOUtils;
+import org.hisp.dhis.dxf2.common.ImportOptions;
+import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
+import org.hisp.dhis.dxf2.importsummary.ImportStatus;
+import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.scheduling.TaskId;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+/**
+ * @author bobj
+ */
+public class AdxPipedImporter
+    implements Callable<ImportSummary>
+{
+    public static final int PIPE_BUFFER_SIZE = 4096;
+
+    public static final int TOTAL_MINUTES_TO_WAIT = 5;
+
+    protected PipedInputStream pipeIn;
+
+    private final DataValueSetService dataValueSetService;
+
+    private final ImportOptions importOptions;
+
+    private final TaskId id;
+    
+    private final Authentication authentication;
+
+    public AdxPipedImporter( DataValueSetService dataValueSetService, ImportOptions importOptions,
+        TaskId id, PipedOutputStream pipeOut ) throws IOException
+    {
+        this.dataValueSetService = dataValueSetService;
+        this.pipeIn = new PipedInputStream( pipeOut, PIPE_BUFFER_SIZE );
+        this.importOptions = importOptions;
+        this.id = id;
+        this.authentication = SecurityContextHolder.getContext().getAuthentication();
+    }
+
+    @Override
+    public ImportSummary call()
+    {
+        ImportSummary result = null;
+        SecurityContextHolder.getContext().setAuthentication( authentication );
+
+        try
+        {
+            result = dataValueSetService.saveDataValueSet( pipeIn, importOptions, id );
+        }
+        catch ( Exception ex )
+        {
+            result = new ImportSummary();
+            result.setStatus( ImportStatus.ERROR );
+            result.setDescription( "Exception: " + ex.getMessage() );
+        }
+        finally
+        {
+            IOUtils.closeQuietly( pipeIn );
+        }
+                
+        return result;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java	2016-01-06 11:43:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/adx/DefaultAdxDataService.java	2016-01-08 16:54:54 +0000
@@ -55,7 +55,6 @@
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.datavalueset.DataExportParams;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
-import org.hisp.dhis.dxf2.datavalueset.PipedImporter;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.importsummary.ImportStatus;
 import org.hisp.dhis.dxf2.importsummary.ImportSummaries;
@@ -74,6 +73,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PipedOutputStream;
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
@@ -84,6 +85,8 @@
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
+import org.hisp.dhis.common.IdSchemes;
+import org.hisp.dhis.period.PeriodService;
 
 /**
  * @author bobj
@@ -113,6 +116,10 @@
 
     @Autowired
     protected DataSetService dataSetService;
+    
+    @Autowired
+    private PeriodService periodService;
+
 
     @Autowired
     private IdentifiableObjectManager identifiableObjectManager;
@@ -125,8 +132,45 @@
     // -------------------------------------------------------------------------
 
     @Override
+    public DataExportParams getFromUrl(Set<String> dataSets, Set<String> periods, Date startDate, Date endDate, 
+            Set<String> organisationUnits, boolean includeChildren, Date lastUpdated, Integer limit, IdSchemes idSchemes) 
+    {
+        DataExportParams params = new DataExportParams();
+
+        if ( dataSets != null )
+        {
+            params.getDataSets().addAll( identifiableObjectManager.getByCode( DataSet.class, dataSets ) );
+        }
+
+        if ( periods != null && !periods.isEmpty() )
+        {
+            params.getPeriods().addAll( periodService.reloadIsoPeriods( new ArrayList<>( periods ) ) );
+        }
+        else if ( startDate != null && endDate != null )
+        {
+            params.setStartDate( startDate );
+            params.setEndDate( endDate );
+        }
+
+        if ( organisationUnits != null )
+        {
+            params.getOrganisationUnits().addAll( identifiableObjectManager.getByCode( OrganisationUnit.class, organisationUnits ) );
+        }
+
+        params.setIncludeChildren( includeChildren );
+        params.setLastUpdated( lastUpdated );
+        params.setLimit( limit );
+        params.setIdSchemes( idSchemes );
+
+        return params;
+    }
+    
+    @Override
     public void writeDataValueSet( DataExportParams params, OutputStream out )
     {
+        dataValueSetService.decideAccess( params );
+        dataValueSetService.validate( params );
+        
         XMLWriter adxWriter = XMLFactory.getXMLWriter( out );
 
         adxWriter.openElement( AdxDataService.ROOT );
@@ -231,7 +275,7 @@
             try (PipedOutputStream pipeOut = new PipedOutputStream())
             {
                 Future<ImportSummary> futureImportSummary;
-                futureImportSummary = executor.submit( new PipedImporter( dataValueSetService, importOptions, id, pipeOut ) );
+                futureImportSummary = executor.submit( new AdxPipedImporter( dataValueSetService, importOptions, id, pipeOut ) );
                 XMLOutputFactory factory = XMLOutputFactory.newInstance();
                 XMLStreamWriter dxfWriter = factory.createXMLStreamWriter( pipeOut );
 
@@ -557,22 +601,4 @@
         
         return catOptMap;
     }
-
-    /**
-     * 
-     * select distinct de.categorycomboid from dataset ds join datasetmembers
-     * dsm on ds.datasetid=dsm.datasetid join dataelement de on
-     * dsm.dataelementid=de.dataelementid;
-     * 
-     * 
-     * select coc.categoryoptioncomboid, cat.code, co.code from
-     * categoryoptioncombos_categoryoptions cocco inner join
-     * dataelementcategoryoption co on cocco.categoryoptionid =
-     * co.categoryoptionid inner join categories_categoryoptions cco on
-     * co.categoryoptionid = cco.categoryoptionid inner join categoryoptioncombo
-     * coc on coc.categoryoptioncomboid = cocco.categoryoptioncomboid inner join
-     * dataelementcategory cat on cco.categoryid = cat.categoryid where coc.name
-     * != 'default' ;
-     * 
-     */
 }

=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/PipedImporter.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/PipedImporter.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/PipedImporter.java	1970-01-01 00:00:00 +0000
@@ -1,97 +0,0 @@
-package org.hisp.dhis.dxf2.datavalueset;
-
-/*
- * Copyright (c) 2004-2016, 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.
- */
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.util.concurrent.Callable;
-
-import org.apache.commons.io.IOUtils;
-import org.hisp.dhis.dxf2.common.ImportOptions;
-import org.hisp.dhis.dxf2.importsummary.ImportStatus;
-import org.hisp.dhis.dxf2.importsummary.ImportSummary;
-import org.hisp.dhis.scheduling.TaskId;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
-
-/**
- * @author bobj
- */
-public class PipedImporter
-    implements Callable<ImportSummary>
-{
-    public static final int PIPE_BUFFER_SIZE = 4096;
-
-    public static final int TOTAL_MINUTES_TO_WAIT = 5;
-
-    protected PipedInputStream pipeIn;
-
-    private final DataValueSetService dataValueSetService;
-
-    private final ImportOptions importOptions;
-
-    private final TaskId id;
-    
-    private final Authentication authentication;
-
-    public PipedImporter( DataValueSetService dataValueSetService, ImportOptions importOptions,
-        TaskId id, PipedOutputStream pipeOut ) throws IOException
-    {
-        this.dataValueSetService = dataValueSetService;
-        this.pipeIn = new PipedInputStream( pipeOut, PIPE_BUFFER_SIZE );
-        this.importOptions = importOptions;
-        this.id = id;
-        this.authentication = SecurityContextHolder.getContext().getAuthentication();
-    }
-
-    @Override
-    public ImportSummary call()
-    {
-        ImportSummary result = null;
-        SecurityContextHolder.getContext().setAuthentication( authentication );
-
-        try
-        {
-            result = dataValueSetService.saveDataValueSet( pipeIn, importOptions, id );
-        }
-        catch ( Exception ex )
-        {
-            result = new ImportSummary();
-            result.setStatus( ImportStatus.ERROR );
-            result.setDescription( "Exception: " + ex.getMessage() );
-        }
-        finally
-        {
-            IOUtils.closeQuietly( pipeIn );
-        }
-                
-        return result;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataValueSetController.java	2016-01-08 16:54:54 +0000
@@ -132,7 +132,7 @@
     {
         response.setContentType( CONTENT_TYPE_XML_ADX );
 
-        DataExportParams params = dataValueSetService.getFromUrl( dataSet, period,
+        DataExportParams params = adxDataService.getFromUrl( dataSet, period,
             startDate, endDate, orgUnit, children, lastUpdated, limit, idSchemes );
 
         adxDataService.writeDataValueSet( params, response.getOutputStream() );