dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20469
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9350: local vn - Added validation for auto generating form
------------------------------------------------------------
revno: 9350
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-18 15:08:53 +0700
message:
local vn - Added validation for auto generating form
modified:
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java
local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties
local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml
local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.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
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-18 06:44:18 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormByTemplate.java 2012-12-18 08:08:53 +0000
@@ -85,14 +85,13 @@
import org.hisp.dhis.reportsheet.ExportReport;
import org.hisp.dhis.reportsheet.ExportReportNormal;
import org.hisp.dhis.reportsheet.ExportReportService;
+import org.hisp.dhis.reportsheet.action.ActionSupport;
import org.hisp.dhis.reportsheet.importitem.ImportItem;
import org.hisp.dhis.reportsheet.state.SelectionManager;
import org.hisp.dhis.validation.ValidationRule;
import org.hisp.dhis.validation.ValidationRuleService;
import org.springframework.beans.factory.annotation.Autowired;
-import com.opensymphony.xwork2.Action;
-
/**
* Simple demo class which uses the api to present the contents of an excel 97
* spreadsheet as an XML document, using a workbook and output stream of your
@@ -104,7 +103,7 @@
*/
public class AutoGenerateFormByTemplate
- implements Action
+ extends ActionSupport
{
private static final String REPORT_EXCEL_GROUP = "BÁO CÁO KIỂM TRA BỆNH VIỆN";
@@ -122,6 +121,8 @@
private static final String INDICATOR_KEY = "id";
+ private static final String VALIDATIONRULE_KEY = "vr";
+
private static final String INDICATOR_NAME = " - CS ";
private static final String INDICATOR_TYPE_NAME = "Loại số";
@@ -255,6 +256,13 @@
return new HashSet<Integer>( vrList );
}
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@@ -271,6 +279,13 @@
excelFileName = getName( pathFileName );
commonName = getBaseName( pathFileName );
+ if ( dataSetService.getDataSetByName( commonName ) != null )
+ {
+ message = i18n.getString( "form_name_already_exists" );
+
+ return INPUT;
+ }
+
if ( getExtension( pathFileName ).equals( "xls" ) )
{
WORKBOOK = new HSSFWorkbook( new FileInputStream( pathFileName ) );
@@ -309,6 +324,8 @@
}
catch ( Exception e )
{
+ xml = null;
+
e.printStackTrace();
return ERROR;
@@ -368,6 +385,7 @@
{
int colIdx = convertColumnNameToNumber( colName );
String name = deName + " (" + colIdx + ")";
+ message = DATAELEMENT_KEY + "@" + name;
// Generate DataElement
DataElement dataElement = new DataElement( name );
@@ -408,19 +426,23 @@
Integer colIdx = colIndex + 1;
String idName = commonName + INDICATOR_NAME;
- if ( values.length == 3 )
+ switch ( values.length )
{
+ case 3:
idName += "(" + values[2];
colIdx = convertColumnNameToNumber( values[2] );
- }
- else if ( values.length == 4 )
- {
+ break;
+ case 4:
idName += "(" + values[2];
colIdx = convertColumnNameToNumber( values[2] );
rowIndex = Integer.parseInt( values[3] ) - 1;
+ default:
+ idName += "(" + convertColumnNumberToName( colIdx + 1 );
+ break;
}
idName += rowIndex + ")";
+ message = INDICATOR_KEY + "@" + idName;
// Create Indicator
Indicator indicator = new Indicator();
@@ -428,7 +450,7 @@
indicator.setShortName( idName );
indicator.setAnnualized( false );
indicator.setIndicatorType( indicatorType );
- indicator.setNumerator( prepareExcelFormulaForAutoForm( values[2] ) );
+ indicator.setNumerator( prepareExcelFormulaForAutoForm( values[1] ) );
indicator.setNumeratorDescription( DESCRIPTION );
indicator.setDenominator( 1 + "" );
indicator.setDenominatorDescription( DESCRIPTION );
@@ -457,6 +479,7 @@
{
String name = commonName + VALIDATION_RULE_NAME + "("
+ convertColumnNumberToName( colIndex + 1 ) + (rowIndex + 1) + ")";
+ message = VALIDATIONRULE_KEY + "@" + name;
// Validation rules
Expression leftSide = new Expression();
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java 2012-12-17 12:53:25 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/java/org/hisp/dhis/reportsheet/preview/action/AutoGenerateFormRollBack.java 2012-12-18 08:08:53 +0000
@@ -27,7 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.hisp.dhis.dataelement.DataElementService;
@@ -49,6 +51,20 @@
public class AutoGenerateFormRollBack
extends ActionSupport
{
+ private static final Map<String, String> keyMap = new HashMap<String, String>()
+ {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ {
+ put( "de", "data_element_duplicated" );
+ put( "id", "indicator_duplicated" );
+ put( "vr", "validation_rule_duplicated" );
+ }
+ };
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
@@ -115,7 +131,19 @@
{
try
{
- message = "";
+ if ( message == null || message.trim().isEmpty() )
+ {
+ message = "";
+ }
+ else
+ {
+ String values[] = message.split( "@" );
+
+ message = i18n.getString( keyMap.get( values[0] ) ) + " \"" + values[1] + "\"<br/>";
+ message += "----------------------------------<br/>";
+ message += i18n.getString( "rollback_result" ) + "<br/>";
+ message += "----------------------------------<br/>";
+ }
if ( exportReportId > 0 )
{
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties 2012-12-17 10:36:42 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module.properties 2012-12-18 08:08:53 +0000
@@ -165,7 +165,6 @@
input_sheet_no = Not input sheet yet
choose_export_report = Not choose export report yet
choose_import_report = Not choose import report yet
-choose_dataelement = Not choose dataelement yet
warning_upload_is_null = Please choose your excel file to upload \!
list_of_import_items = List of import items
selected_dataelements = Selected Data Elements
@@ -393,4 +392,9 @@
auto_generate_form = Automatic generating form
generate_form = Generate form
generate_form_confirm = Would you like to generate form now ?
-auto_generate_form_completed = Form generated
\ No newline at end of file
+auto_generate_form_completed = Form generated
+form_name_already_exists = Form name already exists
+data_element_duplicated = Data element duplicated
+indicator_duplicated = Indicator duplicated
+validation_rule_duplicated = Validation rule duplicated
+rollback_result = ROLLBACK RESULT
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties 2012-12-17 10:36:42 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/org/hisp/dhis/reportsheet/i18n_module_vi_VN.properties 2012-12-18 08:08:53 +0000
@@ -424,4 +424,9 @@
auto_generate_form = T\u1ef1 \u0111\u1ed9ng t\u1ea1o bi\u1ec3u m\u1eabu
generate_form = T\u1ea1o bi\u1ec3u m\u1eabu
generate_form_confirm = B\u1ea1n c\u00f3 mu\u1ed1n t\u1ea1o bi\u1ec3u m\u1eabu ngay b\u00e2y gi\u1edd ?
-auto_generate_form_completed = Bi\u1ec3u m\u1eabu \u0111\u01b0\u1ee3c ho\u00e0n th\u00e0nh
\ No newline at end of file
+auto_generate_form_completed = Bi\u1ec3u m\u1eabu \u0111\u01b0\u1ee3c ho\u00e0n th\u00e0nh
+form_name_already_exists = Bi\u1ec3u m\u1eabu b\u1ecb tr\u00f9ng t\u00ean
+data_element_duplicated = Ph\u1ea7n t\u1eed d\u1eef li\u1ec7u tr\u00f9ng t\u00ean
+indicator_duplicated = Ch\u1ec9 s\u1ed1 b\u1ecb tr\u00f9ng t\u00ean
+validation_rule_duplicated = \u0110i\u1ec1u ki\u1ec7n ki\u1ec3m tra tr\u00f9ng t\u00ean
+rollback_result = K\u1ebeT Q\u1ee6A PH\u1ee4C H\u1ed2I D\u1eee LI\u1ec6U
\ No newline at end of file
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-17 10:36:42 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/resources/struts.xml 2012-12-18 08:08:53 +0000
@@ -1862,6 +1862,8 @@
/dhis-web-spreadsheet-reporting/responseExportReportPreview.vm</result>
<result name="error" type="velocity-xml">
/dhis-web-spreadsheet-reporting/responseAutoGenerateFormError.vm</result>
+ <result name="input" type="velocity-xml">
+ ../dhis-web-commons/ajax/xmlResponseInput.vm</result>
</action>
<action name="autoGenerateFormRollback"
=== modified file 'local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js'
--- local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-17 12:53:25 +0000
+++ local/vn/dhis-web-spreadsheet-reporting/src/main/webapp/dhis-web-spreadsheet-reporting/javascript/autoGenerateForm.js 2012-12-18 08:08:53 +0000
@@ -62,8 +62,13 @@
{
var type = getElementAttribute( parentElement, 'message', 'type' );
- if ( type && type == 'error' )
- {
+ if ( type && type == 'input' )
+ {
+ showErrorMessage( parentElement.firstChild.nodeValue, 5000 );
+ }
+ else if ( type && type == 'error' )
+ {
+ var messageTag = parentElement.getElementsByTagName( 'message' )[0];
var dataElementTag = parentElement.getElementsByTagName( 'dataElements' )[0];
var indicatorTag = parentElement.getElementsByTagName( 'indicators' )[0];
var validationRuleTag = parentElement.getElementsByTagName( 'validationRules' )[0];
@@ -90,18 +95,18 @@
url += 'validationRuleIds=' + validationRules[i].firstChild.nodeValue + '&';
}
- url += 'exportReportId=' + reportId + '&dataSetId=' + dataSetId;
+ url += 'exportReportId=' + reportId + '&dataSetId=' + dataSetId + '&message=' + messageTag.firstChild.nodeValue;
jQuery.post( url, {}, function( json ) {
if ( json.response == "success" ) {
- showSuccessMessage( json.message, 8000 );
+ showWarningMessage( json.message, 8000 );
} else {
showErrorMessage( json.message, 5000 );
}
} );
}
- else
- {
+ else if ( type && type == 'success' )
+ {
var aKey = new Array();
var aMerged = new Array();
var cells = parentElement.getElementsByTagName( 'cell' );