------------------------------------------------------------ revno: 5134 committer: Lars Helge Overland <larshe...@gmail.com> branch nick: dhis2 timestamp: Thu 2011-11-10 19:46:58 +0100 message: Implemented missing validation for add/update reports added: dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/ValidateReportAction.java modified: dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.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 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java 2011-09-19 13:34:58 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/AddReportAction.java 2011-11-10 18:46:58 +0000 @@ -167,18 +167,9 @@ // --------------------------------------------------------------------- // Validation // --------------------------------------------------------------------- - - if ( name == null || name.trim().length() == 0 ) - { - message = i18n.getString( "specify_name" ); - - return ERROR; - } if ( id == null && ( fileName == null || fileName.trim().length() == 0 ) ) { - message = i18n.getString( "select_file" ); - return ERROR; } === added file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/ValidateReportAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/ValidateReportAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/ValidateReportAction.java 2011-11-10 18:46:58 +0000 @@ -0,0 +1,126 @@ +package org.hisp.dhis.reporting.reportviewer.action; + +/* + * 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 org.hisp.dhis.i18n.I18n; +import org.hisp.dhis.report.Report; +import org.hisp.dhis.report.ReportService; + +import com.opensymphony.xwork2.Action; + +/** + * @author Lars Helge Overland + */ +public class ValidateReportAction + implements Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + public ReportService reportService; + + public void setReportService( ReportService reportService ) + { + this.reportService = reportService; + } + + private I18n i18n; + + public void setI18n( I18n i18n ) + { + this.i18n = i18n; + } + + // ------------------------------------------------------------------------- + // Input + // ------------------------------------------------------------------------- + + private Integer id; + + public void setId( Integer id ) + { + this.id = id; + } + + private String name; + + public void setName( String name ) + { + this.name = name; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private String message; + + public String getMessage() + { + return message; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + public String execute() + { + if ( name == null ) + { + message = i18n.getString( "specify_name" ); + + return INPUT; + } + else + { + name = name.trim(); + + if ( name.length() == 0 ) + { + message = i18n.getString( "specify_name" ); + + return INPUT; + } + + Report match = reportService.getReportByName( name ); + + if ( match != null && ( id == null || match.getId() != id ) ) + { + message = i18n.getString( "name_in_use" ); + + return INPUT; + } + } + + message = i18n.getString( "ok" ); + + return SUCCESS; + } +} === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java' --- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/tablecreator/action/ValidateTableAction.java 2011-11-10 18:46:58 +0000 @@ -76,6 +76,13 @@ this.name = name; } + private String fileName; + + public void setUploadFileName( String fileName ) + { + this.fileName = fileName; + } + // ------------------------------------------------------------------------- // Output // ------------------------------------------------------------------------- @@ -120,6 +127,13 @@ } } + if ( id == null && ( fileName == null || fileName.trim().length() == 0 ) ) + { + message = i18n.getString( "select_file" ); + + return ERROR; + } + message = i18n.getString( "ok" ); return SUCCESS; === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-11-02 14:39:42 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/META-INF/dhis/beans.xml 2011-11-10 18:46:58 +0000 @@ -252,7 +252,7 @@ <property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService" /> </bean> - <!-- ReportViewer --> + <!-- Report --> <bean id="org.hisp.dhis.reporting.reportviewer.action.AddReportAction" class="org.hisp.dhis.reporting.reportviewer.action.AddReportAction" scope="prototype"> @@ -298,6 +298,11 @@ <property name="reportService" ref="org.hisp.dhis.report.ReportService" /> </bean> + <bean id="org.hisp.dhis.reporting.reportviewer.action.ValidateReportAction" class="org.hisp.dhis.reporting.reportviewer.action.ValidateReportAction" + scope="prototype"> + <property name="reportService" ref="org.hisp.dhis.report.ReportService" /> + </bean> + <!-- ReportGroups --> <bean id="org.hisp.dhis.reporting.reportgroup.action.GetReportGroupAction" class="org.hisp.dhis.reporting.reportgroup.action.GetReportGroupAction" === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-11-02 14:39:42 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/resources/struts.xml 2011-11-10 18:46:58 +0000 @@ -224,6 +224,12 @@ <result name="success" type="outputStreamResult" /> </action> + <action name="validateReport" class="org.hisp.dhis.reporting.reportviewer.action.ValidateReportAction"> + <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result> + <result name="input" type="velocity-json">/dhis-web-commons/ajax/jsonResponseInput.vm</result> + <param name="onExceptionReturn">plainTextError</param> + </action> + <!-- ReportGroup --> <action name="reportGroup" class="org.hisp.dhis.reporting.reportgroup.action.GetReportGroupListAction"> === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm 2011-09-19 13:34:58 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/addReportForm.vm 2011-11-10 18:46:58 +0000 @@ -3,8 +3,8 @@ <form id="reportForm" action="addReport.action" method="post" enctype="multipart/form-data"> -<input type="hidden" name="id" value="$!report.id" /> -<input type="hidden" name="currentDesign" value="$!report.design" /> +<input type="hidden" id="id" name="id" value="$!report.id" /> +<input type="hidden" id="currentDesign" name="currentDesign" value="$!report.design" /> <table> <tr> === modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js' --- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js 2011-09-29 12:57:18 +0000 +++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/report.js 2011-11-10 18:46:58 +0000 @@ -1,6 +1,17 @@ function addReport() { - document.getElementById( "reportForm" ).submit(); + $.postJSON( "validateReport.action", { id:$( "#id" ).val(), "name":$( "#name" ).val() }, function( json ) + { + if ( json.response == "input" ) + { + setMessage( json.message ); + return false; + } + else if ( json.response == "success" ) + { + $( "#reportForm" ).submit(); + } + } ); } function removeReport( id )
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp