dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08509
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2053: Meta data export to XLS
------------------------------------------------------------
revno: 2053
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-11-13 00:58:03 +0700
message:
Meta data export to XLS
added:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/XLSConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/DataElementConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/ExtendedDataElementConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/IndicatorConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitHierarchyConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/DefaultXLSExportService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/XLSExportPipeThread.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-support/dhis-support-system/pom.xml
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/process/OpenSessionThread.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/MetaDataExportAction.java
dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/externalExportMenu.vm
--
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-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java 2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/concept/DefaultConceptService.java 2010-11-12 17:58:03 +0000
@@ -57,46 +57,39 @@
// Concept
// -------------------------------------------------------------------------
- @Override
public int saveConcept( Concept concept )
{
return conceptStore.save( concept );
}
- @Override
public void updateConcept( Concept concept )
{
conceptStore.update( concept );
}
- @Override
public void deleteConcept( Concept concept )
{
conceptStore.delete( concept );
}
- @Override
public Concept getConcept( int conceptId )
{
return conceptStore.get( conceptId );
}
- @Override
public Concept getConceptByName( String conceptName )
{
return conceptStore.getByName( conceptName );
}
- @Override
public Collection<Concept> getAllConcepts()
{
return conceptStore.getAll();
}
- @Override
public void generateDefaultConcept()
{
- Concept defaultConcept = new Concept("default");
+ Concept defaultConcept = new Concept( "default" );
conceptStore.save( defaultConcept );
}
}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/XLSConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/XLSConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/XLSConverter.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.importexport;
+
+/*
+ * Copyright (c) 2004-2010, 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 jxl.write.WritableWorkbook;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public interface XLSConverter
+{
+ void write( WritableWorkbook workbook, ExportParams params, int sheetIndex );
+}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java 2010-10-29 08:56:13 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/exporter/DefaultCSVExportService.java 2010-11-12 17:58:03 +0000
@@ -33,6 +33,7 @@
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.hibernate.SessionFactory;
@@ -48,6 +49,8 @@
public class DefaultCSVExportService
implements ExportService
{
+ private static final String ZIP_ENTRY_NAME = "Export.csv";
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -85,7 +88,7 @@
ZipOutputStream zipOut = new ZipOutputStream( new BufferedOutputStream( out ) );
- //zipOut.putNextEntry( new ZipEntry( ZIP_ENTRY_NAME ) );
+ zipOut.putNextEntry( new ZipEntry( ZIP_ENTRY_NAME ) );
// -----------------------------------------------------------------
// Writes to one end of the pipe
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls'
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/DataElementConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/DataElementConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/DataElementConverter.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,112 @@
+package org.hisp.dhis.importexport.xls.converter;
+
+/*
+ * Copyright (c) 2004-2010, 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.util.Collection;
+
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.UnderlineStyle;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.XLSConverter;
+import org.hisp.dhis.system.util.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class DataElementConverter
+ extends ExcelUtils
+ implements XLSConverter
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private DataElementService dataElementService;
+
+ public DataElementConverter( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ // -------------------------------------------------------------------------
+ // PDFConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( WritableWorkbook workbook, ExportParams params, int sheetIndex )
+ {
+ I18n i18n = params.getI18n();
+
+ int rowNumber = 0;
+ int columnIndex = 0;
+
+ Collection<DataElement> elements = dataElementService.getDataElements( params.getDataElements() );
+
+ WritableSheet sheet = workbook.createSheet( i18n.getString( "data_elements" ), sheetIndex );
+
+ WritableCellFormat FORMAT_LABEL = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 13,
+ WritableFont.NO_BOLD, true, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 11,
+ WritableFont.NO_BOLD, false ) );
+
+ try
+ {
+ setUpFormat( FORMAT_LABEL, Alignment.CENTRE, Border.ALL, BorderLineStyle.THIN, Colour.TAN );
+ setUpFormat( FORMAT_TEXT, Alignment.GENERAL, Border.ALL, BorderLineStyle.DOTTED, Colour.BLACK );
+
+ printDataElementHeaders( sheet, FORMAT_LABEL, i18n, rowNumber++, columnIndex );
+
+ for ( DataElement element : elements )
+ {
+ addDataElementCellToSheet( sheet, FORMAT_TEXT, element, i18n, rowNumber++, columnIndex );
+ }
+ }
+ catch ( RowsExceededException e1 )
+ {
+ e1.printStackTrace();
+ }
+ catch ( WriteException e1 )
+ {
+ e1.printStackTrace();
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/ExtendedDataElementConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/ExtendedDataElementConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/ExtendedDataElementConverter.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,118 @@
+package org.hisp.dhis.importexport.xls.converter;
+
+/*
+ * Copyright (c) 2004-2010, 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.util.Collection;
+
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.UnderlineStyle;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.XLSConverter;
+import org.hisp.dhis.system.util.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $$
+ */
+public class ExtendedDataElementConverter
+ extends ExcelUtils
+ implements XLSConverter
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private DataElementService dataElementService;
+
+ public ExtendedDataElementConverter( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ // -------------------------------------------------------------------------
+ // PDFConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( WritableWorkbook workbook, ExportParams params, int sheetIndex )
+ {
+ I18n i18n = params.getI18n();
+
+ int rowNumber = 0;
+ int columnIndex = 0;
+
+ WritableSheet sheet = workbook.createSheet( i18n.getString( "data_elements" ), sheetIndex );
+
+ WritableCellFormat FORMAT_LABEL_MERGED = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 14,
+ WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_LABEL = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 13,
+ WritableFont.NO_BOLD, true, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 11,
+ WritableFont.NO_BOLD, false ) );
+
+ Collection<DataElement> elements = dataElementService.getDataElements( params.getDataElements() );
+
+ try
+ {
+ setUpFormat( FORMAT_LABEL_MERGED, Alignment.JUSTIFY, Border.ALL, BorderLineStyle.THIN, Colour.BROWN );
+ setUpFormat( FORMAT_LABEL, Alignment.CENTRE, Border.ALL, BorderLineStyle.THIN, Colour.TAN );
+ setUpFormat( FORMAT_TEXT, Alignment.GENERAL, Border.ALL, BorderLineStyle.DOTTED, Colour.BLACK );
+
+ printExtendedDataElementHeaders( sheet, FORMAT_LABEL_MERGED, FORMAT_LABEL, i18n, rowNumber++, columnIndex );
+
+ rowNumber++;
+
+ for ( DataElement element : elements )
+ {
+ addExtendedDataElementCellToSheet( sheet, FORMAT_TEXT, element, i18n, rowNumber++, columnIndex );
+ }
+ }
+ catch ( RowsExceededException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( WriteException e )
+ {
+ e.printStackTrace();
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/IndicatorConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/IndicatorConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/IndicatorConverter.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,117 @@
+package org.hisp.dhis.importexport.xls.converter;
+
+/*
+ * Copyright (c) 2004-2010, 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.util.Collection;
+
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.UnderlineStyle;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.XLSConverter;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.system.util.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class IndicatorConverter
+ extends ExcelUtils
+ implements XLSConverter
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private IndicatorService indicatorService;
+
+ private ExpressionService expressionService;
+
+ public IndicatorConverter( IndicatorService indicatorService, ExpressionService expressionService )
+ {
+ this.indicatorService = indicatorService;
+ this.expressionService = expressionService;
+ }
+
+ // -------------------------------------------------------------------------
+ // PDFConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( WritableWorkbook workbook, ExportParams params, int sheetIndex )
+ {
+ I18n i18n = params.getI18n();
+
+ int rowNumber = 0;
+ int columnIndex = 0;
+
+ WritableSheet sheet = workbook.createSheet( i18n.getString( "indicators" ), sheetIndex );
+
+ WritableCellFormat FORMAT_LABEL = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 13,
+ WritableFont.NO_BOLD, true, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 11,
+ WritableFont.NO_BOLD, false ) );
+
+ Collection<Indicator> indicators = indicatorService.getIndicators( params.getIndicators() );
+
+ try
+ {
+ setUpFormat( FORMAT_LABEL, Alignment.CENTRE, Border.ALL, BorderLineStyle.THIN, Colour.TAN );
+ setUpFormat( FORMAT_TEXT, Alignment.GENERAL, Border.ALL, BorderLineStyle.DOTTED, Colour.BLACK );
+
+ printIndicatorHeaders( sheet, FORMAT_LABEL, i18n, rowNumber++, columnIndex );
+
+ for ( Indicator indicator : indicators )
+ {
+ addIndicatorCellToSheet( sheet, FORMAT_TEXT, indicator, i18n, expressionService, rowNumber++,
+ columnIndex );
+ }
+ }
+ catch ( RowsExceededException e1 )
+ {
+ e1.printStackTrace();
+ }
+ catch ( WriteException e1 )
+ {
+ e1.printStackTrace();
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitConverter.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,115 @@
+package org.hisp.dhis.importexport.xls.converter;
+
+/*
+ * Copyright (c) 2004-2010, 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.util.Collection;
+
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.UnderlineStyle;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.XLSConverter;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.system.util.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class OrganisationUnitConverter
+ extends ExcelUtils
+ implements XLSConverter
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public OrganisationUnitConverter( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ // -------------------------------------------------------------------------
+ // PDFConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( WritableWorkbook workbook, ExportParams params, int sheetIndex )
+ {
+ I18n i18n = params.getI18n();
+ I18nFormat format = params.getFormat();
+
+ int rowNumber = 0;
+ int columnIndex = 0;
+
+ WritableSheet sheet = workbook.createSheet( i18n.getString( "organisation_units" ), sheetIndex );
+
+ WritableCellFormat FORMAT_LABEL = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 13,
+ WritableFont.NO_BOLD, true, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 11,
+ WritableFont.NO_BOLD, false ) );
+
+ Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnits( params
+ .getOrganisationUnits() );
+
+ try
+ {
+ setUpFormat( FORMAT_LABEL, Alignment.CENTRE, Border.ALL, BorderLineStyle.THIN, Colour.TAN );
+ setUpFormat( FORMAT_TEXT, Alignment.GENERAL, Border.ALL, BorderLineStyle.DOTTED, Colour.BLACK );
+
+ printOrganisationUnitHeaders( sheet, FORMAT_LABEL, i18n, rowNumber++, columnIndex );
+
+ for ( OrganisationUnit unit : units )
+ {
+ addOrganisationUnitCellToSheet( sheet, FORMAT_TEXT, unit, i18n, format, rowNumber++, columnIndex );
+ }
+ }
+ catch ( RowsExceededException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( WriteException e )
+ {
+ e.printStackTrace();
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitHierarchyConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitHierarchyConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/converter/OrganisationUnitHierarchyConverter.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,142 @@
+package org.hisp.dhis.importexport.xls.converter;
+
+/*
+ * Copyright (c) 2004-2010, 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.util.ArrayList;
+import java.util.Collection;
+
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.UnderlineStyle;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.XLSConverter;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.system.util.ExcelUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class OrganisationUnitHierarchyConverter
+ extends ExcelUtils
+ implements XLSConverter
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private OrganisationUnitService organisationUnitService;
+
+ public OrganisationUnitHierarchyConverter( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ // -------------------------------------------------------------------------
+ // PDFConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( WritableWorkbook workbook, ExportParams params, int sheetIndex )
+ {
+ // if ( params.getOrganisationUnits() != null &&
+ // params.getOrganisationUnits().size() > 0 )
+ // {
+ I18n i18n = params.getI18n();
+
+ int rowNumber = 0;
+ int columnIndex = 0;
+
+ WritableSheet sheet = workbook.createSheet( i18n.getString( "organisation_unit_hierarchy" ), sheetIndex );
+
+ WritableCellFormat FORMAT_LABEL_MERGED = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 14,
+ WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_LABEL = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 13,
+ WritableFont.NO_BOLD, true, UnderlineStyle.NO_UNDERLINE, Colour.WHITE ) );
+
+ WritableCellFormat FORMAT_TEXT = new WritableCellFormat( new WritableFont( WritableFont.ARIAL, 11,
+ WritableFont.NO_BOLD, false ) );
+
+ try
+ {
+ setUpFormat( FORMAT_LABEL_MERGED, Alignment.CENTRE, Border.ALL, BorderLineStyle.THIN, Colour.BROWN );
+ setUpFormat( FORMAT_LABEL, Alignment.CENTRE, Border.ALL, BorderLineStyle.THIN, Colour.TAN );
+ setUpFormat( FORMAT_TEXT, Alignment.GENERAL, Border.ALL, BorderLineStyle.DOTTED, Colour.BLACK );
+
+ printOrganisationUnitHierarchyHeaders( sheet, FORMAT_LABEL_MERGED, FORMAT_LABEL, i18n,
+ rowNumber++, columnIndex, organisationUnitService.getNumberOfOrganisationalLevels() );
+
+ rowNumber++;
+
+ Collection<OrganisationUnit> hierarchy = getHierarchy();
+
+ for ( OrganisationUnit unit : hierarchy )
+ {
+ addOrganisationUnitHierarchyCellToSheet( sheet, FORMAT_TEXT, unit, i18n, rowNumber++, unit.getLevel()-1 );
+ }
+ }
+ catch ( RowsExceededException e )
+ {
+ e.printStackTrace();
+ }
+ catch ( WriteException e )
+ {
+ e.printStackTrace();
+ }
+ // }
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private Collection<OrganisationUnit> getHierarchy()
+ {
+ Collection<OrganisationUnit> hierarchy = new ArrayList<OrganisationUnit>();
+
+ Collection<OrganisationUnit> roots = organisationUnitService.getRootOrganisationUnits();
+
+ for ( OrganisationUnit root : roots )
+ {
+ hierarchy.addAll( organisationUnitService.getOrganisationUnitWithChildren( root.getId() ) );
+ }
+
+ return hierarchy;
+ }
+}
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/DefaultXLSExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/DefaultXLSExportService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/DefaultXLSExportService.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,146 @@
+package org.hisp.dhis.importexport.xls.exporter;
+
+/*
+ * Copyright (c) 2004-2010, 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.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.hibernate.SessionFactory;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.ExportService;
+import org.hisp.dhis.importexport.xls.converter.DataElementConverter;
+import org.hisp.dhis.importexport.xls.converter.ExtendedDataElementConverter;
+import org.hisp.dhis.importexport.xls.converter.IndicatorConverter;
+import org.hisp.dhis.importexport.xls.converter.OrganisationUnitConverter;
+import org.hisp.dhis.importexport.xls.converter.OrganisationUnitHierarchyConverter;
+import org.hisp.dhis.indicator.IndicatorService;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class DefaultXLSExportService
+ implements ExportService
+{
+ private static final String ZIP_ENTRY_NAME = "Export.xls";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private SessionFactory sessionFactory;
+
+ public void setSessionFactory( SessionFactory sessionFactory )
+ {
+ this.sessionFactory = sessionFactory;
+ }
+
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ private IndicatorService indicatorService;
+
+ public void setIndicatorService( IndicatorService indicatorService )
+ {
+ this.indicatorService = indicatorService;
+ }
+
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
+ private ExpressionService expressionService;
+
+ public void setExpressionService( ExpressionService expressionService )
+ {
+ this.expressionService = expressionService;
+ }
+
+ // -------------------------------------------------------------------------
+ // ExportService implementation
+ // -------------------------------------------------------------------------
+
+ public InputStream exportData( ExportParams params )
+ {
+ try
+ {
+ // -------------------------------------------------------------------------
+ // Pipes are input/output pairs. Data written on the output stream
+ // shows
+ // up on the input stream at the other end of the pipe.
+ // -------------------------------------------------------------------------
+
+ PipedOutputStream out = new PipedOutputStream();
+
+ PipedInputStream in = new PipedInputStream( out );
+
+ ZipOutputStream zipOut = new ZipOutputStream( out );
+
+ zipOut.putNextEntry( new ZipEntry( ZIP_ENTRY_NAME ) );
+
+ // -------------------------------------------------------------------------
+ // Writes to one end of the pipe
+ // -------------------------------------------------------------------------
+
+ XLSExportPipeThread thread = new XLSExportPipeThread( sessionFactory );
+
+ thread.setOutputStream( zipOut );
+ thread.setExportParams( params );
+
+ thread.setDataElementConverter( new DataElementConverter( dataElementService ) );
+ thread.setIndicatorConverter( new IndicatorConverter( indicatorService, expressionService ) );
+ thread.setExtendedDataElementConverter( new ExtendedDataElementConverter( dataElementService ) );
+ thread.setOrganisationUnitHierarchyConverter( new OrganisationUnitHierarchyConverter(
+ organisationUnitService ) );
+ thread.setOrganisationUnitConverter( new OrganisationUnitConverter( organisationUnitService ) );
+
+ thread.start();
+
+ return new BufferedInputStream( in );
+ }
+ catch ( IOException ex )
+ {
+ throw new RuntimeException( "Error occured during PDF export", ex );
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/XLSExportPipeThread.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/XLSExportPipeThread.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/xls/exporter/XLSExportPipeThread.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,144 @@
+package org.hisp.dhis.importexport.xls.exporter;
+
+/*
+ * Copyright (c) 2004-2010, 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.util.zip.ZipOutputStream;
+
+import jxl.write.WritableWorkbook;
+
+import org.hibernate.SessionFactory;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.XLSConverter;
+import org.hisp.dhis.system.process.OpenSessionThread;
+import org.hisp.dhis.system.util.ExcelUtils;
+import org.hisp.dhis.system.util.StreamUtils;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class XLSExportPipeThread
+ extends OpenSessionThread
+{
+ private ZipOutputStream outputStream;
+
+ public void setOutputStream( ZipOutputStream outputStream )
+ {
+ this.outputStream = outputStream;
+ }
+
+ private ExportParams exportParams;
+
+ public void setExportParams( ExportParams exportParams )
+ {
+ this.exportParams = exportParams;
+ }
+
+ private XLSConverter dataElementConverter;
+
+ public void setDataElementConverter( XLSConverter dataElementConverter )
+ {
+ this.dataElementConverter = dataElementConverter;
+ }
+
+ private XLSConverter indicatorConverter;
+
+ public void setIndicatorConverter( XLSConverter indicatorConverter )
+ {
+ this.indicatorConverter = indicatorConverter;
+ }
+
+ private XLSConverter extendedDataElementConverter;
+
+ public void setExtendedDataElementConverter( XLSConverter extendedDataElementConverter )
+ {
+ this.extendedDataElementConverter = extendedDataElementConverter;
+ }
+
+ private XLSConverter organisationUnitHierarchyConverter;
+
+ public void setOrganisationUnitHierarchyConverter( XLSConverter organisationUnitHierarchyConverter )
+ {
+ this.organisationUnitHierarchyConverter = organisationUnitHierarchyConverter;
+ }
+
+ private XLSConverter organisationUnitConverter;
+
+ public void setOrganisationUnitConverter( XLSConverter organisationUnitConverter )
+ {
+ this.organisationUnitConverter = organisationUnitConverter;
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public XLSExportPipeThread( SessionFactory sessionFactory )
+ {
+ super( sessionFactory );
+ }
+
+ // -------------------------------------------------------------------------
+ // Thread implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void doRun()
+ {
+ int sheetIndex = 0;
+
+ WritableWorkbook workbook = null;
+
+ try
+ {
+ workbook = ExcelUtils.openWorkbook( outputStream );
+
+ if ( exportParams.isExtendedMode() )
+ {
+ extendedDataElementConverter.write( workbook, exportParams, sheetIndex++ );
+ }
+ else
+ {
+ dataElementConverter.write( workbook, exportParams, sheetIndex++ );
+ }
+
+ indicatorConverter.write( workbook, exportParams, sheetIndex++ );
+
+ organisationUnitConverter.write( workbook, exportParams, sheetIndex++ );
+
+ organisationUnitHierarchyConverter.write( workbook, exportParams, sheetIndex++ );
+
+ ExcelUtils.writeAndCloseWorkbook( workbook );
+ }
+ finally
+ {
+ StreamUtils.closeZipEntry( outputStream );
+ StreamUtils.closeOutputStream( outputStream );
+ }
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2010-10-29 08:56:13 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2010-11-12 17:58:03 +0000
@@ -35,6 +35,12 @@
</key>
<ref bean="org.hisp.dhis.importexport.CSVExportService" />
</entry>
+ <entry>
+ <key>
+ <value>XLS</value>
+ </key>
+ <ref bean="org.hisp.dhis.importexport.XLSExportService" />
+ </entry>
</map>
</property>
</bean>
@@ -362,6 +368,19 @@
</bean>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+ <!-- XLS Export -->
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+
+ <bean id="org.hisp.dhis.importexport.XLSExportService"
+ class="org.hisp.dhis.importexport.xls.exporter.DefaultXLSExportService">
+ <property name="sessionFactory" ref="sessionFactory"/>
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+ <property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ <property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
+ </bean>
+
+ <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<!-- Mapping -->
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
=== modified file 'dhis-2/dhis-support/dhis-support-system/pom.xml'
--- dhis-2/dhis-support/dhis-support-system/pom.xml 2010-10-12 07:36:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/pom.xml 2010-11-12 17:58:03 +0000
@@ -95,7 +95,11 @@
<dependency>
<groupId>org.amplecode</groupId>
<artifactId>quick</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.jexcelapi</groupId>
+ <artifactId>jxl</artifactId>
+ </dependency>
</dependencies>
<properties>
<rootDir>../../</rootDir>
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/process/OpenSessionThread.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/process/OpenSessionThread.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/process/OpenSessionThread.java 2010-11-12 17:58:03 +0000
@@ -38,7 +38,7 @@
extends Thread
{
private SessionFactory sessionFactory;
-
+
public OpenSessionThread( SessionFactory sessionFactory )
{
this.sessionFactory = sessionFactory;
@@ -52,7 +52,7 @@
public final void run()
{
DbmsUtils.bindSessionToThread( sessionFactory );
-
+
try
{
doRun();
@@ -62,11 +62,11 @@
DbmsUtils.unbindSessionFromThread( sessionFactory );
}
}
-
+
/**
* Method to override by subclasses.
*/
protected void doRun()
- {
+ {
}
}
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExcelUtils.java 2010-11-12 17:58:03 +0000
@@ -0,0 +1,443 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * Copyright (c) 2004-2010, 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.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import jxl.Workbook;
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.write.Label;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class ExcelUtils
+{
+ public static final String EXTENSION_XLS = ".xls";
+
+ // -------------------------------------------------------------------------
+ //
+ // -------------------------------------------------------------------------
+
+ /**
+ * @throws WriteException
+ */
+ public static void setUpFormat( WritableCellFormat cellFormat, Alignment alignment, Border border,
+ BorderLineStyle borderLineStyle, Colour colour )
+ throws WriteException
+ {
+ cellFormat.setAlignment( alignment );
+ cellFormat.setBackground( colour );
+ cellFormat.setBorder( border, borderLineStyle );
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+ public static void printDataElementHeaders( WritableSheet sheet, WritableCellFormat format, I18n i18n, int row,
+ int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column++, row, i18n.getString( "name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "alternative_name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "short_name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "code" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "description" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "active" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "type" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "aggregation_operator" ), format ) );
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+
+ public static void addDataElementCellToSheet( WritableSheet sheet, WritableCellFormat format, DataElement element,
+ I18n i18n, int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column++, row, element.getName(), format ) );
+ sheet.addCell( new Label( column++, row, element.getAlternativeName(), format ) );
+ sheet.addCell( new Label( column++, row, element.getShortName(), format ) );
+ sheet.addCell( new Label( column++, row, element.getCode(), format ) );
+ sheet.addCell( new Label( column++, row, element.getDescription(), format ) );
+ sheet.addCell( new Label( column++, row, getBoolean().get( element.isActive() ), format ) );
+ sheet.addCell( new Label( column++, row, getType().get( element.getType() ), format ) );
+ sheet.addCell( new Label( column++, row, getAggregationOperator().get( element.getAggregationOperator() ),
+ format ) );
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+ public static void printIndicatorHeaders( WritableSheet sheet, WritableCellFormat format, I18n i18n, int row,
+ int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column++, row, i18n.getString( "name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "alternative_name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "short_name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "code" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "description" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "annualized" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "indicator_type" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "numerator_description" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "numerator_aggregation_operator" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "numerator_formula" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "denominator_description" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "denominator_aggregation_operator" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "denominator_formula" ), format ) );
+
+ }
+
+ /**
+ * @param expressionService
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+ public static void addIndicatorCellToSheet( WritableSheet sheet, WritableCellFormat format, Indicator indicator,
+ I18n i18n, ExpressionService expressionService, int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column++, row, indicator.getName(), format ) );
+ sheet.addCell( new Label( column++, row, indicator.getAlternativeName(), format ) );
+ sheet.addCell( new Label( column++, row, indicator.getShortName(), format ) );
+ sheet.addCell( new Label( column++, row, indicator.getCode(), format ) );
+ sheet.addCell( new Label( column++, row, indicator.getDescription(), format ) );
+ sheet.addCell( new Label( column++, row, getBoolean().get( indicator.getAnnualized() ), format ) );
+ sheet.addCell( new Label( column++, row, getType().get( indicator.getIndicatorType().getName() ), format ) );
+
+ sheet.addCell( new Label( column++, row, indicator.getNumeratorDescription(), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( getAggregationOperator().get(
+ indicator.getNumeratorAggregationOperator() ) ), format ) );
+ sheet.addCell( new Label( column++, row,
+ expressionService.getExpressionDescription( indicator.getNumerator() ), format ) );
+
+ sheet.addCell( new Label( column++, row, indicator.getDenominatorDescription(), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( getAggregationOperator().get(
+ indicator.getDenominatorAggregationOperator() ) ), format ) );
+ sheet.addCell( new Label( column++, row, expressionService
+ .getExpressionDescription( indicator.getDenominator() ), format ) );
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+ public static void printExtendedDataElementHeaders( WritableSheet sheet, WritableCellFormat format1,
+ WritableCellFormat format2, I18n i18n, int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column, row, i18n.getString( "identifying_and_definitional_attributes" ), format1 ) );
+ sheet.mergeCells( column, row, 16, row );
+
+ column = 17;
+ sheet
+ .addCell( new Label( column, row, i18n.getString( "relational_and_representational_attributes" ), format1 ) );
+ sheet.mergeCells( column, row, 26, row );
+
+ column = 27;
+ sheet.addCell( new Label( column, row, i18n.getString( "administrative_attributes" ), format1 ) );
+ sheet.mergeCells( 27, row, 39, row );
+
+ // row = 2 & column = 1->8
+ row++;
+ column = 1;
+ printDataElementHeaders( sheet, format2, i18n, row, column );
+
+ // row = 2 & column = 9->16
+ column = 9;
+ sheet.addCell( new Label( column++, row, i18n.getString( "mnemonic" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "version" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "context" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "synonyms" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "hononyms" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "keywords" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "status" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "status_date" ), format2 ) );
+
+ // -------------------------------------------------------------------------
+ // Relational and representational attributes
+ // -------------------------------------------------------------------------
+
+ // row = 2 & column = 17->26
+ sheet.addCell( new Label( column++, row, i18n.getString( "data_type" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "representational_form" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "representational_layout" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "minimum_size" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "maximum_size" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "data_domain" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "validation_rules" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "related_data_references" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "guide_for_use" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "collection_methods" ), format2 ) );
+
+ // -------------------------------------------------------------------------
+ // Administrative attributes
+ // -------------------------------------------------------------------------
+
+ // row = 2 & column = 27->36
+ sheet.addCell( new Label( column++, row, i18n.getString( "responsible_authority" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "update_rules" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "access_authority" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "update_frequency" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "location" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "reporting_methods" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "version_status" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "previous_version_references" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "source_document" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "source_organisation" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "comment" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "saved" ), format2 ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "last_updated" ), format2 ) );
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+
+ public static void addExtendedDataElementCellToSheet( WritableSheet sheet, WritableCellFormat format,
+ DataElement element, I18n i18n, int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ // row = 3 & column = 1->8
+ addDataElementCellToSheet( sheet, format, element, i18n, row, column );
+
+ if ( element.getExtended() != null )
+ {
+ // row = 3 & column = 9->16
+ column = 9;
+ sheet.addCell( new Label( column++, row, element.getExtended().getMnemonic(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getVersion(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getContext(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getSynonyms(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getHononyms(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getKeywords(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getStatus(), format ) );
+ sheet.addCell( new Label( column++, row, DateUtils.getMediumDateString( element.getExtended()
+ .getStatusDate() ) ) );
+
+ // -------------------------------------------------------------------------
+ // Relational and representational attributes
+ // -------------------------------------------------------------------------
+
+ // row = 3 & column = 17->26
+ sheet.addCell( new Label( column++, row, element.getExtended().getDataType(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getRepresentationalForm(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getRepresentationalLayout(), format ) );
+ sheet.addCell( new Label( column++, row, String.valueOf( element.getExtended().getMinimumSize() ) ) );
+ sheet.addCell( new Label( column++, row, String.valueOf( element.getExtended().getMaximumSize() ) ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getDataDomain(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getValidationRules(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getRelatedDataReferences(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getGuideForUse(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getCollectionMethods(), format ) );
+
+ // -------------------------------------------------------------------------
+ // Administrative attributes
+ // -------------------------------------------------------------------------
+
+ // row = 3 & column = 27->36
+ sheet.addCell( new Label( column++, row, element.getExtended().getResponsibleAuthority(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getUpdateRules(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getAccessAuthority(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getUpdateFrequency(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getLocation(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getReportingMethods(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getVersionStatus(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getPreviousVersionReferences(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getSourceDocument(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getSourceOrganisation(), format ) );
+ sheet.addCell( new Label( column++, row, element.getExtended().getComment(), format ) );
+ sheet
+ .addCell( new Label( column++, row, DateUtils.getMediumDateString( element.getExtended().getSaved() ) ) );
+ sheet.addCell( new Label( column++, row, DateUtils.getMediumDateString( element.getExtended()
+ .getLastUpdated() ) ) );
+ }
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+
+ public static void printOrganisationUnitHeaders( WritableSheet sheet, WritableCellFormat format, I18n i18n,
+ int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column++, row, i18n.getString( "short_name" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "code" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "opening_date" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "closed_date" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "active" ), format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( "comment" ), format ) );
+
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+
+ public static void addOrganisationUnitCellToSheet( WritableSheet sheet, WritableCellFormat format,
+ OrganisationUnit unit, I18n i18n, I18nFormat i18nFormat, int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column++, row, unit.getShortName(), format ) );
+ sheet.addCell( new Label( column++, row, unit.getCode(), format ) );
+ sheet.addCell( new Label( column++, row, unit.getOpeningDate() != null ? i18nFormat.formatDate( unit
+ .getOpeningDate() ) : "", format ) );
+ sheet.addCell( new Label( column++, row, unit.getClosedDate() != null ? i18nFormat.formatDate( unit
+ .getClosedDate() ) : "", format ) );
+ sheet.addCell( new Label( column++, row, i18n.getString( getBoolean().get( unit.isActive() ) ), format ) );
+ sheet.addCell( new Label( column++, row, unit.getComment(), format ) );
+ }
+
+ /**
+ * @throws WriteException
+ * @throws RowsExceededException
+ */
+
+ public static void printOrganisationUnitHierarchyHeaders( WritableSheet sheet, WritableCellFormat format1,
+ WritableCellFormat format2, I18n i18n, int row, int column, int level )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column, row, i18n.getString( "organisation_unit_level" ), format1 ) );
+ sheet.mergeCells( column, row, level-1, row );
+
+ row++;
+
+ for ( int i = 1; i <= level; i++ )
+ {
+ sheet.addCell( new Label( column++, row, (i + ""), format2 ) );
+ }
+ }
+
+ public static void addOrganisationUnitHierarchyCellToSheet( WritableSheet sheet, WritableCellFormat format,
+ OrganisationUnit unit, I18n i18n, int row, int column )
+ throws RowsExceededException, WriteException
+ {
+ sheet.addCell( new Label( column, row, unit.getName(), format ) );
+ }
+
+ /**
+ * Creates a writable workbook.
+ *
+ * @param outputStream The output stream to write the document content.
+ * @param pageSize the page size.
+ * @return A Document.
+ */
+ public static WritableWorkbook openWorkbook( OutputStream outputStream )
+ {
+ try
+ {
+ return Workbook.createWorkbook( outputStream );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( "Failed to open a writable workbook", e );
+ }
+ }
+
+ /**
+ * @throws IOException
+ * @throws WriteException
+ */
+ public static void writeAndCloseWorkbook( WritableWorkbook workbook )
+ {
+ if ( workbook != null )
+ {
+ try
+ {
+ workbook.write();
+ workbook.close();
+ }
+ catch ( IOException ioe )
+ {
+ throw new RuntimeException( "Failed to write data to workbook", ioe );
+ }
+ catch ( WriteException we )
+ {
+ throw new RuntimeException( "Failed to close the workbook", we );
+ }
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private static Map<Boolean, String> getBoolean()
+ {
+ Map<Boolean, String> map = new HashMap<Boolean, String>();
+ map.put( true, "Yes" );
+ map.put( false, "No" );
+ return map;
+ }
+
+ private static Map<String, String> getType()
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put( DataElement.VALUE_TYPE_STRING, "Text" );
+ map.put( DataElement.VALUE_TYPE_INT, "Number" );
+ map.put( DataElement.VALUE_TYPE_BOOL, "Yes/No" );
+ return map;
+ }
+
+ private static Map<String, String> getAggregationOperator()
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put( DataElement.AGGREGATION_OPERATOR_SUM, "Sum" );
+ map.put( DataElement.AGGREGATION_OPERATOR_AVERAGE, "Average" );
+ map.put( DataElement.AGGREGATION_OPERATOR_COUNT, "Count" );
+ return map;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/MetaDataExportAction.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/MetaDataExportAction.java 2010-07-30 12:59:39 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/exp/MetaDataExportAction.java 2010-11-12 17:58:03 +0000
@@ -364,7 +364,7 @@
ExportService exportService = serviceProvider.provide( exportFormat );
inputStream = exportService.exportData( params );
-
+
fileName = FILENAME;
return SUCCESS;
=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/externalExportMenu.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/externalExportMenu.vm 2010-06-19 15:32:24 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/externalExportMenu.vm 2010-11-12 17:58:03 +0000
@@ -5,4 +5,6 @@
#introListImgItem( "displayMetaDataExportForm.action?exportFormat=DHIS14XML" "DHIS14_metadata_export" "dhis14" )
#introListImgItem( "displayDetailedMetaDataExportForm.action?exportFormat=DHIS14XML" "DHIS14_detailed_metadata_export" "dhis14" )
#introListImgItem( "displayDataValueExportForm.action?exportFormat=DHIS14XML" "DHIS14_data_export" "dhis14" )
- #introListImgItem( "displayMetaDataExportForm.action?exportFormat=PDF" "pdf_metadata_export" "pdf" )
\ No newline at end of file
+ #introListImgItem( "displayMetaDataExportForm.action?exportFormat=PDF" "pdf_metadata_export" "pdf" )
+ #introListImgItem( "displayMetaDataExportForm.action?exportFormat=XLS" "xls_metadata_export" "excel" )
+</ul>
\ No newline at end of file