dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10065
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2747: Fixed bug <702827> and <702828> excelreporting-io-exception.
------------------------------------------------------------
revno: 2747
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-01-26 00:29:41 +0700
message:
Fixed bug <702827> and <702828> excelreporting-io-exception.
removed:
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ExcelContentTypeMap.java
local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportLocationManager.java
local/vn/dhis-service-excel-reporting/pom.xml
local/vn/dhis-web-excel-reporting/pom.xml
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/UploadExcelFileAction.java
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/manager/InitializePOIStylesManager.java
local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java
local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties
local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties
local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml
local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/configuration.vm
local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm
local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm
local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js
local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js
--
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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ExcelContentTypeMap.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ExcelContentTypeMap.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ExcelContentTypeMap.java 2011-01-25 17:29:41 +0000
@@ -0,0 +1,63 @@
+package org.hisp.dhis.reportexcel;
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+
+public class ExcelContentTypeMap
+{
+ private static final String APPLICATION = "application/";
+
+ private static Map<String, String> contentTypes;
+
+ static
+ {
+ contentTypes = new HashMap<String, String>();
+
+ contentTypes.put( "xls", APPLICATION + "xls" );
+
+ //contentTypes.put( "default", APPLICATION + "vnd.ms-excel" );
+ //contentTypes.put( "ods", APPLICATION + "octet-stream" );
+ //contentTypes.put( "xlsx", APPLICATION + "vnd.openxmlformats-officedocument.spreadsheetml.sheet" );
+ }
+
+ public static String getContentTypeByKey( String key )
+ {
+ return contentTypes.get( key );
+ }
+
+ public static Map<String, String> getContentTypes()
+ {
+ return contentTypes;
+ }
+}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportLocationManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportLocationManager.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reportexcel/ReportLocationManager.java 2011-01-25 17:29:41 +0000
@@ -50,4 +50,6 @@
public File getReportExcelDirectory();
public File getReportExcelTemplateDirectory();
+
+ public boolean isFileTypeSupported( String extension, String contentType );
}
=== modified file 'local/vn/dhis-service-excel-reporting/pom.xml'
--- local/vn/dhis-service-excel-reporting/pom.xml 2010-08-20 09:13:09 +0000
+++ local/vn/dhis-service-excel-reporting/pom.xml 2011-01-25 17:29:41 +0000
@@ -29,6 +29,10 @@
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-aggregationengine-default</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hisp.dhis</groupId>
+ <artifactId>dhis-service-options</artifactId>
+ </dependency>
</dependencies>
<properties>
=== added file 'local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java'
--- local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java 1970-01-01 00:00:00 +0000
+++ local/vn/dhis-service-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java 2011-01-25 17:29:41 +0000
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+package org.hisp.dhis.reportexcel;
+
+import java.io.File;
+import java.util.List;
+
+import org.hisp.dhis.external.location.LocationManager;
+import org.hisp.dhis.external.location.LocationManagerException;
+import org.hisp.dhis.options.SystemSettingManager;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+/**
+ * @author Tran Thanh Tri
+ * @version $Id$
+ */
+public class DefaultReportLocationManager
+ implements ReportLocationManager
+{
+ private File REPORT;
+
+ private File REPORT_TEMP;
+
+ // -------------------------------------------------------------------------
+ // Dependency
+ // -------------------------------------------------------------------------
+
+ private LocationManager locationManager;
+
+ public void setLocationManager( LocationManager locationManager )
+ {
+ this.locationManager = locationManager;
+ }
+
+ private SystemSettingManager systemSettingManager;
+
+ public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+ {
+ this.systemSettingManager = systemSettingManager;
+ }
+
+ // -------------------------------------------------------------------------
+ // Initialize
+ // -------------------------------------------------------------------------
+
+ void init()
+ {
+ try
+ {
+ REPORT = new File( locationManager.getExternalDirectory(), REPORT_DIR );
+ REPORT.mkdir();
+ REPORT_TEMP = new File( REPORT, REPORT_TEMP_DIR );
+ REPORT_TEMP.mkdir();
+
+ }
+ catch ( LocationManagerException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Implemented
+ // -------------------------------------------------------------------------
+
+ public List<File> getListFileInOrganisationDirectory( OrganisationUnit arg0 )
+ {
+ return null;
+ }
+
+ public File getOrganisationDirectory( OrganisationUnit organisationUnit )
+ {
+ File dir = new File( REPORT, String.valueOf( organisationUnit.getId() ) );
+
+ if ( !dir.exists() )
+ {
+ dir.mkdir();
+ }
+
+ return dir;
+ }
+
+ public File getReportExcelDirectory()
+ {
+ return this.REPORT;
+ }
+
+ public File getReportExcelTempDirectory()
+ {
+ return this.REPORT_TEMP;
+ }
+
+ public File getReportExcelTemplateDirectory()
+ {
+ String path = (String) systemSettingManager
+ .getSystemSetting( SystemSettingManager.KEY_REPORT_TEMPLATE_DIRECTORY );
+
+ if ( path != null )
+ {
+ return new File( path );
+ }
+
+ return null;
+ }
+
+ public boolean isFileTypeSupported( String extension, String contentType )
+ {
+ String value = ExcelContentTypeMap.getContentTypeByKey( extension );
+
+ return (value == null ? false : value.contains( contentType ));
+ }
+}
=== modified file 'local/vn/dhis-web-excel-reporting/pom.xml'
--- local/vn/dhis-web-excel-reporting/pom.xml 2010-08-20 09:13:09 +0000
+++ local/vn/dhis-web-excel-reporting/pom.xml 2011-01-25 17:29:41 +0000
@@ -45,7 +45,7 @@
<dependency>
<groupId>org.hisp.dhis</groupId>
<artifactId>dhis-service-aggregationengine-default</artifactId>
- </dependency>
+ </dependency>
<!-- Other -->
@@ -84,7 +84,6 @@
</dependency>
-->
-
</dependencies>
<properties>
=== removed file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java 2010-10-29 12:19:15 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/DefaultReportLocationManager.java 1970-01-01 00:00:00 +0000
@@ -1,132 +0,0 @@
-/*
- * 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.
- */
-package org.hisp.dhis.reportexcel;
-
-import java.io.File;
-import java.util.List;
-
-import org.hisp.dhis.external.location.LocationManager;
-import org.hisp.dhis.external.location.LocationManagerException;
-import org.hisp.dhis.options.SystemSettingManager;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-
-/**
- * @author Tran Thanh Tri
- * @version $Id$
- */
-public class DefaultReportLocationManager
- implements ReportLocationManager
-{
- private File REPORT;
-
- private File REPORT_TEMP;
-
- // -------------------------------------------
- // Dependency
- // -------------------------------------------
-
- private LocationManager locationManager;
-
- public void setLocationManager( LocationManager locationManager )
- {
- this.locationManager = locationManager;
- }
-
- private SystemSettingManager systemSettingManager;
-
- public void setSystemSettingManager( SystemSettingManager systemSettingManager )
- {
- this.systemSettingManager = systemSettingManager;
- }
-
- // -------------------------------------------
- // Setter
- // -------------------------------------------
-
- // -------------------------------------------
- // Init
- // -------------------------------------------
-
- void init()
- {
- try
- {
- REPORT = new File( locationManager.getExternalDirectory(), REPORT_DIR );
- REPORT.mkdir();
- REPORT_TEMP = new File( REPORT, REPORT_TEMP_DIR );
- REPORT_TEMP.mkdir();
-
- }
- catch ( LocationManagerException e )
- {
- e.printStackTrace();
- }
-
- }
-
- // -------------------------------------------
- // Impletemented
- // -------------------------------------------
-
- public List<File> getListFileInOrganisationDirectory( OrganisationUnit arg0 )
- {
- return null;
- }
-
- public File getOrganisationDirectory( OrganisationUnit organisationUnit )
- {
- File dir = new File( REPORT, String.valueOf( organisationUnit.getId() ) );
- if ( !dir.exists() )
- {
- dir.mkdir();
- }
- return dir;
-
- }
-
- public File getReportExcelDirectory()
- {
- return this.REPORT;
- }
-
- public File getReportExcelTempDirectory()
- {
- return this.REPORT_TEMP;
- }
-
- public File getReportExcelTemplateDirectory()
- {
- String path = (String) systemSettingManager.getSystemSetting( SystemSettingManager.KEY_REPORT_TEMPLATE_DIRECTORY );
-
- if ( path != null )
- {
- return new File( path );
- }
-
- return null;
- }
-}
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java 2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/filemanager/action/ValidateUploadExcelTemplate.java 2011-01-25 17:29:41 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.apache.commons.io.FilenameUtils.getExtension;
+
import java.io.File;
import org.hisp.dhis.i18n.I18n;
@@ -36,15 +38,14 @@
/**
* @author Tran Thanh Tri
+ * @author Dang Duy Hieu
* @version $Id
*/
public class ValidateUploadExcelTemplate
implements Action
{
- private static final String TEMPLATE_TYPE = "application/vnd.ms-excel";
-
// -------------------------------------------
- // Dependency
+ // Dependencies
// -------------------------------------------
private ReportLocationManager reportLocationManager;
@@ -63,9 +64,11 @@
private String uploadContentType; // The content type of the file
private String uploadFileName; // The uploaded file name
-
+
private String message;
+ private boolean isDraft;
+
private I18n i18n;
// -------------------------------------------------------------------------
@@ -87,6 +90,11 @@
return message;
}
+ public void setDraft( boolean isDraft )
+ {
+ this.isDraft = isDraft;
+ }
+
public void setI18n( I18n i18n )
{
this.i18n = i18n;
@@ -104,8 +112,7 @@
@Override
public String execute()
throws Exception
- {
-
+ {
if ( upload == null || !upload.exists() )
{
message = i18n.getString( "upload_file_null" );
@@ -113,24 +120,53 @@
return ERROR;
}
- if ( !TEMPLATE_TYPE.contains( uploadContentType ) )
+ if ( !reportLocationManager.isFileTypeSupported( getExtension( upload.getName() ), uploadContentType ) )
{
message = i18n.getString( "file_type_not_supported" );
return ERROR;
}
-
+
+ if ( isDraft )
+ {
+ File tempImportDirectory = reportLocationManager.getReportExcelTempDirectory();
+
+ if ( !tempImportDirectory.canRead() || !tempImportDirectory.canWrite() )
+ {
+ message = i18n.getString( "access_denied_to_folder" );
+
+ return ERROR;
+ }
+
+ return SUCCESS;
+ }
+
File templateDirectoryConfig = reportLocationManager.getReportExcelTemplateDirectory();
- File output = new File( templateDirectoryConfig, uploadFileName );
+ if ( !templateDirectoryConfig.canRead() || !templateDirectoryConfig.canWrite() )
+ {
+ message = i18n.getString( "access_denied_to_folder" );
+
+ return ERROR;
+ }
+
+ File output = new File( templateDirectoryConfig, uploadFileName );
+
+ if ( !output.canWrite() )
+ {
+ message = i18n.getString( "access_denied_to_file" );
+
+ return ERROR;
+ }
if ( output.exists() )
{
- message = i18n.getString("override_confirm");
-
+ message = i18n.getString( "override_confirm" );
+
return INPUT;
}
return SUCCESS;
}
+
}
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java 2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/GetImportingParamsAction.java 2011-01-25 17:29:41 +0000
@@ -115,18 +115,15 @@
public String execute()
throws Exception
{
-
- // ---------------------------------------------------------
+ // ---------------------------------------------------------------------
// Get File Excel
- // ---------------------------------------------------------
+ // ---------------------------------------------------------------------
String path = selectionManager.getUploadFilePath();
if ( path != null && path != "" )
{
-
fileExcel = new File( path );
-
}
// ---------------------------------------------------------------------
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/UploadExcelFileAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/UploadExcelFileAction.java 2010-11-16 07:37:56 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/UploadExcelFileAction.java 2011-01-25 17:29:41 +0000
@@ -42,9 +42,9 @@
public class UploadExcelFileAction
extends ActionSupport
{
- // -------------------------------------------
+ // -------------------------------------------------------------------------
// Dependency
- // -------------------------------------------
+ // -------------------------------------------------------------------------
private ReportLocationManager reportLocationManager;
@@ -60,9 +60,9 @@
this.selectionManager = selectionManager;
}
- // -------------------------------------------
+ // -------------------------------------------------------------------------
// Input & Output
- // -------------------------------------------
+ // -------------------------------------------------------------------------
private String fileName;
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java 2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataFlowAction.java 2011-01-25 17:29:41 +0000
@@ -116,6 +116,5 @@
Collections.sort( excelItems, new ExcelItemComparator() );
return excelItemGroup.getType();
-
}
}
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java 2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/importing/action/ViewDataNormalAction.java 2011-01-25 17:29:41 +0000
@@ -32,8 +32,10 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.reportexcel.excelitem.ExcelItem;
import org.hisp.dhis.reportexcel.importing.ExcelItemValue;
import org.hisp.dhis.reportexcel.utils.ExcelUtils;
@@ -42,13 +44,13 @@
/**
* @author Chau Thu Tran
+ * @author Dang Duy Hieu
* @version $Id
*/
public class ViewDataNormalAction
implements Action
{
-
// --------------------------------------------------------------------
// Inputs && Outputs
// --------------------------------------------------------------------
@@ -58,6 +60,10 @@
private List<ExcelItemValue> excelItemValues;
private ArrayList<ExcelItem> excelItems;
+
+ private String message;
+
+ private I18n i18n;
// --------------------------------------------------------------------
// Getters and Setters
@@ -78,6 +84,16 @@
return excelItemValues;
}
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
// --------------------------------------------------------------------
// Action implementation
// --------------------------------------------------------------------
@@ -88,22 +104,24 @@
{
FileInputStream inputStream = new FileInputStream( upload );
- HSSFWorkbook wb = new HSSFWorkbook( inputStream );
+ Workbook wb = new HSSFWorkbook( inputStream );
excelItemValues = new ArrayList<ExcelItemValue>();
+ if ( excelItems == null || !excelItems.isEmpty() )
+ {
+ message = i18n.getString( "import_excel_items_cannot_be_empty" );
+
+ return ERROR;
+ }
+
for ( ExcelItem excelItem : excelItems )
{
- HSSFSheet sheet = wb.getSheetAt( excelItem.getSheetNo() - 1 );
+ Sheet sheet = wb.getSheetAt( excelItem.getSheetNo() - 1 );
String value = ExcelUtils.readValueImportingByPOI( excelItem.getRow(), excelItem.getColumn(), sheet );
- ExcelItemValue excelItemvalue = new ExcelItemValue( excelItem, value );
-
- if ( value.length() == 0 )
- {
- excelItemvalue.setValue( 0 + "" );
- }
+ ExcelItemValue excelItemvalue = new ExcelItemValue( excelItem, value.trim() );
excelItemValues.add( excelItemvalue );
}
@@ -113,10 +131,7 @@
}
catch ( Exception ex )
{
- ex.printStackTrace();
+ throw new RuntimeException("Error while previewing the imported value", ex);
}
-
- return ERROR;
}
-
}
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/manager/InitializePOIStylesManager.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/manager/InitializePOIStylesManager.java 2010-04-12 21:23:33 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/preview/manager/InitializePOIStylesManager.java 2011-01-25 17:29:41 +0000
@@ -38,10 +38,9 @@
*/
public interface InitializePOIStylesManager
{
-
- /** ************************************************** */
- /** Methods */
- /** ************************************************** */
+ // -------------------------------------------------------------------------
+ // Default methods
+ // -------------------------------------------------------------------------
// Header initDefaultHeader();
void initDefaultHeader( HSSFHeader header );
@@ -52,21 +51,21 @@
// CellStyle initDefaultCellStyle();
void initDefaultCellStyle( CellStyle cs, Font font );
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // -------------------------------------------------------------------------
// Use for XLS and XLSX Extension
- // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ // -------------------------------------------------------------------------
void initHeader( HSSFHeader header, String sCenter, String sLeft, String sRight );
void initFont( Font test_font, String sFontName, short fontHeightInPoints, short boldWeight, short fontColor );
- void initCellStyle( CellStyle test_cs, Font font, short borderBottom, short bottomBorderColor,
- short borderTop, short topBorderColor, short borderLeft, short leftBorderColor, short borderRight,
- short rightBorderColor, short alignment, boolean bAutoWrap );
-
- void initCellStyle( CellStyle test_cs, Font font, short fillBgColor, short fillFgColor,
- short fillPattern, short borderBottom, short bottomBorderColor, short borderTop, short topBorderColor,
- short borderLeft, short leftBorderColor, short borderRight, short rightBorderColor, short dataFormat,
+ void initCellStyle( CellStyle test_cs, Font font, short borderBottom, short bottomBorderColor, short borderTop,
+ short topBorderColor, short borderLeft, short leftBorderColor, short borderRight, short rightBorderColor,
short alignment, boolean bAutoWrap );
+ void initCellStyle( CellStyle test_cs, Font font, short fillBgColor, short fillFgColor, short fillPattern,
+ short borderBottom, short bottomBorderColor, short borderTop, short topBorderColor, short borderLeft,
+ short leftBorderColor, short borderRight, short rightBorderColor, short dataFormat, short alignment,
+ boolean bAutoWrap );
+
}
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java'
--- local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java 2010-07-10 14:50:48 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/java/org/hisp/dhis/reportexcel/utils/ExcelUtils.java 2011-01-25 17:29:41 +0000
@@ -49,19 +49,10 @@
*/
public class ExcelUtils
{
-
private static Pattern pattern = null;
private static Matcher matcher = null;
- public static final String ZERO = "0.0";
-
- public static final String TEXT = "TEXT";
-
- public static final String NUMBER = "NUMBER";
-
- public static final String EXTENSION_XLS = ".xls";
-
private static final String PATTERN_FOR_ROW = "(\\d{1,})";
private static final String PATTERN_FOR_COLUMN = "([a-zA-Z])";
@@ -76,6 +67,14 @@
private static final Byte POI_CELLERROR_INFINITE = (byte) org.apache.poi.ss.usermodel.ErrorConstants.ERROR_NUM;
+ public static final String ZERO = "0.0";
+
+ public static final String TEXT = "TEXT";
+
+ public static final String NUMBER = "NUMBER";
+
+ public static final String EXTENSION_XLS = ".xls";
+
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
@@ -132,7 +131,14 @@
public static org.apache.poi.ss.usermodel.Cell getCellByPOI( int row, int column,
org.apache.poi.ss.usermodel.Sheet sheetPOI )
{
- return sheetPOI.getRow( row - 1 ).getCell( column - 1 );
+ org.apache.poi.ss.usermodel.Row rowPOI = sheetPOI.getRow( row - 1 );
+
+ if ( rowPOI == null )
+ {
+ return null;
+ }
+
+ return rowPOI.getCell( column - 1 );
}
/* POI - Read the value of specified cell */
@@ -190,12 +196,16 @@
case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_BLANK:
value = cellPOI.getRichStringCellValue().toString();
break;
-
+
case org.apache.poi.ss.usermodel.Cell.CELL_TYPE_NUMERIC:
value = String.valueOf( cellPOI.getNumericCellValue() );
break;
}
}
+ else
+ {
+ System.out.println( "Cell at [" + row + "][" + column + "] is null" );
+ }
return value;
@@ -211,7 +221,6 @@
{
if ( row > 0 && column > 0 )
{
-
org.apache.poi.ss.usermodel.Row rowPOI = sheetPOI.getRow( row - 1 );
org.apache.poi.ss.usermodel.CellStyle cellStylePOI = sheetPOI.getColumnStyle( column - 1 );
@@ -282,7 +291,7 @@
}
else if ( type.equalsIgnoreCase( ExcelUtils.NUMBER ) )
{
- if ( value == null )
+ if ( value == null )
{
cellPOI.setCellType( POI_CELLSTYLE_BLANK );
}
@@ -353,7 +362,6 @@
public static String convertColNumberToColName( int column )
{
-
String ConvertToLetter = "";
int iAlpha = column / 27;
@@ -446,6 +454,10 @@
return string_formula;
}
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
private static void applyingPatternForColumn( String sCell, StringBuffer buffer, int iCol )
{
pattern = Pattern.compile( PATTERN_FOR_COLUMN );
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties'
--- local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2010-12-09 06:15:40 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module.properties 2011-01-25 17:29:41 +0000
@@ -267,4 +267,7 @@
category = Category
select_paramater_to_draw_chart = Select parameters to draw a chart
draw_chart = Draw Chart
-un_completed = Un completed
\ No newline at end of file
+un_completed = Un completed
+import_excel_items_cannot_be_empty = Excel items for importing cannot be empty
+access_denied_to_folder = Access denied to folder on server
+access_denied_to_file = Access denied to file on server
\ No newline at end of file
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties'
--- local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties 2010-12-09 06:15:40 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/org/hisp/dhis/reportexcel/i18n_module_vi_VN.properties 2011-01-25 17:29:41 +0000
@@ -259,4 +259,7 @@
category = Th\u1ec3 lo\u1ea1i
select_paramater_to_draw_chart = Ch\u1ecdn tham s\u1ed1 \u0111\u1ec3 v\u1ebd bi\u1ec3u \u0111\u1ed3
draw_chart = V\u1ebd bi\u1ec3u \u0111\u1ed3
-un_completed = Ch\u01b0a n\u1ed9p b\u00e1o c\u00e1o
\ No newline at end of file
+un_completed = Ch\u01b0a n\u1ed9p b\u00e1o c\u00e1o
+import_excel_items_cannot_be_empty = Vui l\u00f2ng t\u1ea1o ph\u1ea7n t\u1eed excel cho import d\u1eef li\u1ec7u
+access_denied_to_folder = Ba\u0323n kh\u00f4ng \u0111u\u0309 quy\u00ea\u0300n truy c\u00e2\u0323p va\u0300o th\u01b0 mu\u0323c tr\u00ean ma\u0301y chu\u0309
+access_denied_to_file = Truy c\u1eadp b\u1ecb t\u1eeb ch\u1ed1i \u0111\u00ea\u0301n t\u1eadp tin tr\u00ean m\u00e1y ch\u1ee7
\ No newline at end of file
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml'
--- local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml 2010-12-16 04:49:14 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/resources/struts.xml 2011-01-25 17:29:41 +0000
@@ -1043,12 +1043,12 @@
<action name="validateUploadExcelImport"
class="org.hisp.dhis.reportexcel.filemanager.action.ValidateUploadExcelTemplate">
<interceptor-ref name="fileUploadStack" />
- <result name="success" type="velocity-json">
- /dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
- <result name="error" type="velocity-json">
- /dhis-web-commons/ajax/jsonResponseError.vm</result>
- <result name="input" type="velocity-json">
- /dhis-web-commons/ajax/jsonResponseInput.vm</result>
+ <result name="success" type="velocity-xml">
+ /dhis-web-commons/ajax/xmlResponseSuccess.vm</result>
+ <result name="error" type="velocity-xml">
+ /dhis-web-commons/ajax/xmlResponseError.vm</result>
+ <result name="input" type="velocity-xml">
+ /dhis-web-commons/ajax/xmlResponseInput.vm</result>
</action>
<action name="uploadExcelImport"
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/configuration.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/configuration.vm 2010-08-20 08:34:39 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/configuration.vm 2011-01-25 17:29:41 +0000
@@ -18,7 +18,7 @@
</tr>
<tr>
<td><input type="submit" value="$i18n.getString('ok')" style="width:150px"/>
- <input type="button" value="$i18n.getString( "cancel" )" onclick="window.location='administration.action'" style="width:150px">
+ <input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location='administration.action'" style="width:150px">
</td>
</tr>
</table>
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm 2010-08-17 07:26:22 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/excelTemplateList.vm 2011-01-25 17:29:41 +0000
@@ -3,18 +3,19 @@
//init jQuery validation for uploadfile
//-----------------------------------------------------------------------
jQuery(document).ready(
- function()
- {
- jQuery("#uploadForm").validate({
- meta:"validate"
- ,errorElement:"td"
- ,submitHandler: function(form)
- {
- validateUploadExcelTemplate();
- }
- });
- }
+ function()
+ {
+ jQuery("#uploadForm").validate({
+ meta:"validate"
+ ,errorElement:"td"
+ ,submitHandler: function(form)
+ {
+ validateUploadExcelTemplate();
+ }
+ });
+ tableSorter( 'listTable' );
+ }
);
</script>
@@ -40,7 +41,7 @@
<input type="text" onkeyup="filterValues(this.value , 1)" style="width:300px"/>
</td>
<td align=right>
- <input type="button" value="$i18n.getString( "cancel" )" onclick="window.location='administration.action'" style="width:100px"/>
+ <input type="button" value="$i18n.getString( 'cancel' )" onclick="window.location='administration.action'" style="width:100px"/>
</td>
</tr>
</table>
@@ -67,7 +68,7 @@
#end
</td>
<td align="left">
- <a href="javascript:mode = 'edit'; openEditExcelTemplate( '$templateFileName' );" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
+ <a href="javascript: mode='edit'; openEditExcelTemplate( '$templateFileName' );" title="$i18n.getString( 'edit' )"><img src="../images/edit.png" alt="$i18n.getString( 'edit' )"></a>
<a href="downloadExcelTemplate.action?fileName=$templateFileName" title="$i18n.getString( 'download' )"><img src="images/download.png" alt="$i18n.getString( 'download' )"></a>
#if( !$value )
<a href="javascript:deleteExcelTemplate('$templateFileName');" title="$i18n.getString( 'remove' )"><img src="../images/delete.png" alt="$i18n.getString( 'remove' )"></a>
@@ -112,15 +113,10 @@
#if ( $message )
#if ( $newFileUploadedOrRenamed )
$(document).ready( function() {
-
setMessage( '<b>' + '$!newFileUploadedOrRenamed' + '</b><br/>' + '$i18n.getString( "$message" )' );
});
#end
#end
-
- jQuery(document).ready(function(){
- tableSorter( 'listTable' );
- });
</script>
<span id="message" style="top:100px;right:5px;position:fixed;width:200px;z-index:10002" onclick="hideById(this.id);"></span>
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm 2010-12-06 09:15:53 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/importDataParams.vm 2011-01-25 17:29:41 +0000
@@ -1,9 +1,8 @@
<body>
-#if($!fileExcel && $!organisationUnit)
+#if($!fileExcel)
<div id="messageUpload">
$i18n.getString( "upload_file" ) $i18n.getString( "success" )<br>$fileExcel.getName()
</div>
-
#end
<span id="message" style="top:70px;right:5px;position:fixed;width:200px;z-index:100009" onclick="hideById(this.id);"></span>
@@ -14,7 +13,7 @@
<td width="18%" style=" width:25% ">$i18n.getString( 'select_excel_file' )</td>
<td width="82%">
<input type="file" id="upload" name="upload" onChange="enable('uploadButton');">
- <input name="uploadButton" id="uploadButton" type="button" value="$i18n.getString( 'upload_file' )" onclick="uploadExcelImport();//validateUploadExcelImport();" disabled />
+ <input name="uploadButton" id="uploadButton" type="button" value="$i18n.getString( 'upload_file' )" onclick="validateUploadExcelImportByXML();" disabled />
</td>
</tr>
</form>
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js 2010-12-13 05:08:29 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/exceltemplate.js 2011-01-25 17:29:41 +0000
@@ -197,6 +197,26 @@
// Validate Upload Excel Template
//----------------------------------------------------------
+function validateUploadExcelManagement( fileName, columnIndex )
+{
+ var rows = byId( 'list' ).getElementsByTagName( 'tr' );
+
+ for ( var i = 0; i < rows.length; i++ )
+ {
+ var cell = rows[i].getElementsByTagName( 'td' )[columnIndex-1];
+ var value = cell.firstChild.nodeValue;
+
+ if ( value.toLowerCase().indexOf( fileName.toLowerCase() ) != -1 )
+ {
+ // file is existsing
+ return window.confirm( i18n_confirm_override );
+ }
+ }
+
+ // normally upload
+ return true;
+}
+
function validateUploadExcelTemplate()
{
$.ajaxFileUpload
@@ -213,7 +233,7 @@
if ( type == 'error' )
{
- setMessage(data.firstChild.nodeValue);
+ setMessage( data.firstChild.nodeValue );
}
else if ( type == 'input' )
{
=== modified file 'local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js'
--- local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js 2010-12-06 09:15:53 +0000
+++ local/vn/dhis-web-excel-reporting/src/main/webapp/dhis-web-excel-reporting/javascript/imports.js 2011-01-25 17:29:41 +0000
@@ -53,7 +53,7 @@
}
function getReportItemValuesReceived( xmlObject ){
-
+
if(xmlObject.getElementsByTagName('excelItemValueByOrgUnit').length > 0 ){
previewOrganisation(xmlObject);
}
@@ -309,29 +309,7 @@
request.send( 'nextPeriodsGeneric.action' );
}
-function validateUploadExcelImport ( fileName, columnIndex ) {
-
- var list = byId( 'list' );
-
- var rows = list.getElementsByTagName( 'tr' );
-
- for ( var i = 0; i < rows.length; i++ )
- {
- var cell = rows[i].getElementsByTagName( 'td' )[columnIndex-1];
- var value = cell.firstChild.nodeValue;
-
- if ( value.toLowerCase().indexOf( fileName.toLowerCase() ) != -1 )
- {
- // file is existsing
- return window.confirm( i18n_confirm_override );
- }
- }
-
- // normally upload
- return true;
-}
-
-function validateUploadExcelImport(){
+function validateUploadExcelImportByJSON(){
$.ajaxFileUpload
(
@@ -361,6 +339,37 @@
}
);
}
+
+function validateUploadExcelImportByXML(){
+
+ $.ajaxFileUpload
+ (
+ {
+ url:'validateUploadExcelImport.action?draft=true',
+ secureuri:false,
+ fileElementId:'upload',
+ dataType: 'xml',
+ success: function (data, status)
+ {
+ data = data.getElementsByTagName('message')[0];
+ var type = data.getAttribute("type");
+
+ if ( type == 'error' )
+ {
+ setMessage( data.firstChild.nodeValue );
+ }
+ else
+ {
+ uploadExcelImport();
+ }
+ },
+ error: function (data, status, e)
+ {
+ alert(e);
+ }
+ }
+ );
+}
function uploadExcelImport(){