← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2039: Fixed datamart internal process issues in import-export and charting

 

------------------------------------------------------------
revno: 2039
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Thu 2010-06-24 13:50:08 +0200
message:
  Fixed datamart internal process issues in import-export and charting
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartExport.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/XMLPreConverter.java
  dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ExportDataMartExportAction.java
  dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportDataSourceAction.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-api/src/main/java/org/hisp/dhis/datamart/DataMartExport.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartExport.java	2010-06-23 22:12:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datamart/DataMartExport.java	2010-06-24 11:50:08 +0000
@@ -28,8 +28,8 @@
  */
 
 import java.io.Serializable;
+import java.util.Collection;
 import java.util.HashSet;
-import java.util.Set;
 
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.indicator.Indicator;
@@ -48,13 +48,13 @@
     
     private String name;
     
-    private Set<DataElement> dataElements = new HashSet<DataElement>();
-    
-    private Set<Indicator> indicators = new HashSet<Indicator>();
-    
-    private Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
-    
-    private Set<Period> periods = new HashSet<Period>();
+    private Collection<DataElement> dataElements = new HashSet<DataElement>();
+    
+    private Collection<Indicator> indicators = new HashSet<Indicator>();
+    
+    private Collection<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
+    
+    private Collection<Period> periods = new HashSet<Period>();
 
     private RelativePeriods relatives;
     
@@ -66,8 +66,8 @@
     {   
     }
 
-    public DataMartExport( String name, Set<DataElement> dataElements, Set<Indicator> indicators,
-        Set<OrganisationUnit> organisationUnits, Set<Period> periods, RelativePeriods relatives )
+    public DataMartExport( String name, Collection<DataElement> dataElements, Collection<Indicator> indicators,
+        Collection<OrganisationUnit> organisationUnits, Collection<Period> periods, RelativePeriods relatives )
     {
         this.name = name;
         this.dataElements = dataElements;
@@ -101,42 +101,42 @@
         this.name = name;
     }
 
-    public Set<DataElement> getDataElements()
+    public Collection<DataElement> getDataElements()
     {
         return dataElements;
     }
 
-    public void setDataElements( Set<DataElement> dataElements )
+    public void setDataElements( Collection<DataElement> dataElements )
     {
         this.dataElements = dataElements;
     }
 
-    public Set<Indicator> getIndicators()
+    public Collection<Indicator> getIndicators()
     {
         return indicators;
     }
 
-    public void setIndicators( Set<Indicator> indicators )
+    public void setIndicators( Collection<Indicator> indicators )
     {
         this.indicators = indicators;
     }
 
-    public Set<OrganisationUnit> getOrganisationUnits()
+    public Collection<OrganisationUnit> getOrganisationUnits()
     {
         return organisationUnits;
     }
 
-    public void setOrganisationUnits( Set<OrganisationUnit> organisationUnits )
+    public void setOrganisationUnits( Collection<OrganisationUnit> organisationUnits )
     {
         this.organisationUnits = organisationUnits;
     }
 
-    public Set<Period> getPeriods()
+    public Collection<Period> getPeriods()
     {
         return periods;
     }
 
-    public void setPeriods( Set<Period> periods )
+    public void setPeriods( Collection<Period> periods )
     {
         this.periods = periods;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java	2010-06-23 22:12:43 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/DataMartInternalProcess.java	2010-06-24 11:50:08 +0000
@@ -27,13 +27,22 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+
+import java.util.Collection;
+
 import org.amplecode.cave.process.SerialToGroup;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.system.process.AbstractStatementInternalProcess;
 
 /**
+ * Either the identifier or the DataMartExport object must be set. The
+ * identifier is given priority.
+ * 
  * @author Lars Helge Overland
- * 
- * @version $Id: DataMartInternalProcess.java 6222 2008-11-07 12:20:46Z larshelg $
  */
 public class DataMartInternalProcess
     extends AbstractStatementInternalProcess implements SerialToGroup
@@ -61,6 +70,19 @@
         this.id = id;
     }
 
+    private Collection<Integer> dataElementIds;
+    private Collection<Integer> indicatorIds;
+    private Collection<Integer> periodIds;
+    private Collection<Integer> organisationUnitIds;
+    
+    public void setExport( DataMartExport export )
+    {
+        this.dataElementIds = getIdentifiers( DataElement.class, export.getDataElements() );
+        this.indicatorIds = getIdentifiers( Indicator.class, export.getIndicators() );
+        this.periodIds = getIdentifiers( Period.class, export.getPeriods() );
+        this.organisationUnitIds = getIdentifiers( OrganisationUnit.class, export.getOrganisationUnits() );
+    }
+
     // -------------------------------------------------------------------------
     // SerialToGroup implementation
     // -------------------------------------------------------------------------
@@ -78,6 +100,13 @@
     protected void executeStatements()
         throws Exception
     {
-        dataMartService.export( id );
+        if ( id != null )
+        {
+            dataMartService.export( id );
+        }
+        else
+        {
+            dataMartService.export( dataElementIds, indicatorIds, periodIds, organisationUnitIds );
+        }
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/XMLPreConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/XMLPreConverter.java	2010-06-08 08:14:55 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xml/XMLPreConverter.java	2010-06-24 11:50:08 +0000
@@ -27,11 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-/**
- *
- * @author bobj
- * @version created 31-May-2010
- */
 import java.io.BufferedInputStream;
 import java.io.InputStream;
 import java.util.HashMap;
@@ -62,14 +57,13 @@
 import org.springframework.stereotype.Component;
 
 /**
- * GenericXMLConvertor transforms imported foreign XML to dxf
- *
+ * GenericXMLConvertor transforms imported foreign XML to dxf.
+ * 
  * @author bobj
  */
-@Component("preConverter")
+@Component( "preConverter" )
 public class XMLPreConverter
 {
-
     private final Log log = LogFactory.getLog( XMLPreConverter.class );
 
     public static final String DXF_ROOT = "dxf";
@@ -88,14 +82,17 @@
     protected URIResolver resolver;
 
     /**
-     * This method is called for an anonymous xml stream ie. we don't yet know if or how to transform it
+     * This method is called for an anonymous xml stream ie. we don't yet know
+     * if or how to transform it
+     * 
      * @param xmlDataStream
      * @param params
      * @param state
      * @return
      * @throws ImportException
      */
-    public XMLReader transform( InputStream xmlDataStream, ImportParams params, ProcessState state ) throws ImportException
+    public XMLReader transform( InputStream xmlDataStream, ImportParams params, ProcessState state )
+        throws ImportException
     {
         XMLReader dxfReader = null;
 
@@ -105,15 +102,13 @@
 
         QName rootName = null;
 
-
         BufferedInputStream bufin = new BufferedInputStream( xmlDataStream );
         Map<QName, String> attributes = new HashMap<QName, String>();
 
-
         try
         {
-             XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory.newInstance();
-             XMLStreamReader2 streamReader = (XMLStreamReader2) factory.createXMLStreamReader( xmlDataStream );
+            XMLInputFactory2 factory = (XMLInputFactory2) XMLInputFactory.newInstance();
+            XMLStreamReader2 streamReader = (XMLStreamReader2) factory.createXMLStreamReader( xmlDataStream );
 
             // buffer enough space to read root element
             bufin.mark( BUFFER_SIZE );
@@ -128,9 +123,9 @@
                 String value = streamReader.getAttributeValue( i );
                 attributes.put( attribute, value );
             }
+            
             bufin.reset();
 
-
             log.info( "Importing " + rootName.toString() );
 
             // first test if its a dxf stream
@@ -139,7 +134,8 @@
                 // Native DXF stream - no transform required
 
                 // -----------------------------------------------------------------
-                // Retrieve namespace and minor version from root element and set on
+                // Retrieve namespace and minor version from root element and
+                // set on
                 // import params. Use default if not found.
                 // -----------------------------------------------------------------
 
@@ -151,24 +147,27 @@
 
                 // no transform required
                 dxfReader = XMLFactory.getXMLReader( streamReader );
-
-            } else
-            {        // use the stringified form of the qname as an id
+            }
+            else
+            {
+                // use the stringified form of the qname as an id
                 xsltIdentifierTag = rootName.toString();
                 log.debug( "Tag for transformer: " + xsltIdentifierTag );
 
                 dxfReader = this.transform( streamReader, params, state, xsltParams, xsltIdentifierTag );
             }
-        } catch ( Exception ex )
+        }
+        catch ( Exception ex )
         {
             log.info( ex );
             throw new ImportException( "Failed to transform xml stream" );
         }
+        
         return dxfReader;
     }
 
     /**
-     *
+     * 
      * @param streamReader
      * @param params
      * @param state
@@ -193,7 +192,7 @@
         XMLEventReader2 pipeoutput = pipe.getOutput();
 
         StAXResult result = new StAXResult( pipeinput ); // Set result of transform to input of pipe
-        //tt.transform( source, result, resolver );
+        // tt.transform( source, result, resolver );
         tt.transform( source, result, null );
         log.info( "Transform successful" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ExportDataMartExportAction.java'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ExportDataMartExportAction.java	2010-06-23 22:12:43 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/java/org/hisp/dhis/datamart/action/ExportDataMartExportAction.java	2010-06-24 11:50:08 +0000
@@ -34,7 +34,6 @@
 import org.amplecode.cave.process.ProcessCoordinator;
 import org.amplecode.cave.process.ProcessExecutor;
 import org.hisp.dhis.datamart.DataMartInternalProcess;
-import org.hisp.dhis.datamart.DataMartService;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
@@ -64,13 +63,6 @@
         this.currentUserService = currentUserService;
     }
 
-    private DataMartService dataMartService;
-
-    public void setDataMartService( DataMartService dataMartService )
-    {
-        this.dataMartService = dataMartService;
-    }
-
     // -------------------------------------------------------------------------
     // Input
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml	2010-06-23 22:12:43 +0000
+++ dhis-2/dhis-web/dhis-web-datamart/src/main/resources/META-INF/dhis/beans.xml	2010-06-24 11:50:08 +0000
@@ -13,8 +13,6 @@
       ref="processCoordinator"/>
     <property name="currentUserService"
       ref="org.hisp.dhis.user.CurrentUserService"/>
-    <property name="dataMartService"
-      ref="org.hisp.dhis.datamart.DataMartService"/>
   </bean>
   
   <bean id="org.hisp.dhis.datamart.action.GetExportStatusAction"

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/ExportDataMartAction.java	2010-06-24 11:50:08 +0000
@@ -183,7 +183,7 @@
         // Get OrganisationUnit
         // ---------------------------------------------------------------------
         
-        Collection<OrganisationUnit> selectedUnits = selectionTreeManager.getSelectedOrganisationUnits();
+        Collection<OrganisationUnit> selectedUnits = selectionTreeManager.getReloadedSelectedOrganisationUnits();
         
         if ( selectedUnits != null )
         {
@@ -203,7 +203,7 @@
         
         DataMartInternalProcess process = (DataMartInternalProcess) executor.getProcess();
         
-        process.setProperties( export );
+        process.setExport( export );
         
         processCoordinator.requestProcessExecution( executor );
         

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/chart/action/CreateChartAction.java	2010-06-24 11:50:08 +0000
@@ -28,7 +28,6 @@
  */
 
 import static org.hisp.dhis.datamart.DataMartInternalProcess.PROCESS_TYPE;
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 import static org.hisp.dhis.util.InternalProcessUtil.PROCESS_KEY_REPORT;
 import static org.hisp.dhis.util.InternalProcessUtil.setCurrentRunningProcess;
 
@@ -38,10 +37,9 @@
 import org.amplecode.cave.process.ProcessExecutor;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.chart.ChartService;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.datamart.DataMartExport;
 import org.hisp.dhis.datamart.DataMartInternalProcess;
-import org.hisp.dhis.indicator.Indicator;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.period.Period;
 import org.hisp.dhis.user.CurrentUserService;
 
 import com.opensymphony.xwork2.Action;
@@ -104,12 +102,11 @@
         ProcessExecutor executor = processCoordinator.newProcess( PROCESS_TYPE, owner );
         
         DataMartInternalProcess process = (DataMartInternalProcess) executor.getProcess();
-        
-        process.setDataElementIds( new HashSet<Integer>() );
-        process.setIndicatorIds( getIdentifiers( Indicator.class, chart.getIndicators() ) );
-        process.setPeriodIds( getIdentifiers( Period.class, chart.getPeriods() ) );
-        process.setOrganisationUnitIds( getIdentifiers( OrganisationUnit.class, chart.getOrganisationUnits() ) );
 
+        DataMartExport export = new DataMartExport( null, new HashSet<DataElement>(), chart.getIndicators(), chart.getOrganisationUnits(), chart.getPeriods(), null );
+        
+        process.setExport( export );
+        
         processCoordinator.requestProcessExecution( executor );
         
         setCurrentRunningProcess( PROCESS_KEY_REPORT, executor.getId() );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportDataSourceAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportDataSourceAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/dataset/action/GenerateDataSetReportDataSourceAction.java	2010-06-24 11:50:08 +0000
@@ -28,17 +28,20 @@
  */
 
 import static org.hisp.dhis.datamart.DataMartInternalProcess.PROCESS_TYPE;
-import static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
 import static org.hisp.dhis.util.InternalProcessUtil.PROCESS_KEY_REPORT;
 import static org.hisp.dhis.util.InternalProcessUtil.setCurrentRunningProcess;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.HashSet;
 
 import org.amplecode.cave.process.ProcessCoordinator;
 import org.amplecode.cave.process.ProcessExecutor;
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.datamart.DataMartExport;
 import org.hisp.dhis.datamart.DataMartInternalProcess;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.reporting.dataset.state.SelectedStateManager;
 import org.hisp.dhis.user.CurrentUserService;
 
@@ -90,17 +93,18 @@
 
         DataMartInternalProcess process = (DataMartInternalProcess) executor.getProcess();
         
-        List<Integer> periods = new ArrayList<Integer>();
-        periods.add( selectedStateManager.getSelectedPeriod().getId() );
-        
-        List<Integer> organisationUnits = new ArrayList<Integer>();
-        organisationUnits.add( selectedStateManager.getSelectedOrganisationUnit().getId() );
-        
-        process.setDataElementIds( getIdentifiers( DataElement.class, selectedStateManager.getSelectedDataSet().getDataElements() ) );
-        process.setIndicatorIds( new ArrayList<Integer>() );
-        process.setPeriodIds( periods  );
-        process.setOrganisationUnitIds( organisationUnits );
-
+        Collection<DataElement> dataElements = selectedStateManager.getSelectedDataSet().getDataElements();
+        
+        Collection<OrganisationUnit> units = new HashSet<OrganisationUnit>();
+        units.add( selectedStateManager.getSelectedOrganisationUnit() );
+        
+        Collection<Period> periods = new HashSet<Period>();
+        periods.add( selectedStateManager.getSelectedPeriod() );
+        
+        DataMartExport export = new DataMartExport( null, dataElements, new HashSet<Indicator>(), units, periods, null );
+        
+        process.setExport( export );
+        
         processCoordinator.requestProcessExecution( executor );
 
         setCurrentRunningProcess( PROCESS_KEY_REPORT, executor.getId() );