dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13212
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4183: Fixed bug: Exception thrown when remove a program attribute option ( Patient module ).
------------------------------------------------------------
revno: 4183
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-07-21 16:03:49 +0700
message:
Fixed bug: Exception thrown when remove a program attribute option ( Patient module ).
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeOptionAction.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueStore.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/DefaultProgramAttributeValueService.java
dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programAttribute.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-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueService.java 2010-11-09 02:09:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueService.java 2011-07-21 09:03:49 +0000
@@ -30,6 +30,7 @@
import java.util.Collection;
import org.hisp.dhis.program.ProgramAttribute;
+import org.hisp.dhis.program.ProgramAttributeOption;
import org.hisp.dhis.program.ProgramInstance;
/**
@@ -59,6 +60,10 @@
Collection<ProgramAttributeValue> getProgramAttributeValues( ProgramAttribute programAttribute );
- Collection<ProgramAttributeValue> searchProgramAttributeValues( ProgramAttribute programAttribute, String searchText );
+ Collection<ProgramAttributeValue> searchProgramAttributeValues( ProgramAttribute programAttribute, String searchText );
+
+
+ int countByProgramAttributeOption( ProgramAttributeOption attributeOption );
+
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueStore.java 2010-11-09 02:09:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueStore.java 2011-07-21 09:03:49 +0000
@@ -31,6 +31,7 @@
import org.hisp.dhis.common.GenericStore;
import org.hisp.dhis.program.ProgramAttribute;
+import org.hisp.dhis.program.ProgramAttributeOption;
import org.hisp.dhis.program.ProgramInstance;
/**
@@ -41,7 +42,6 @@
public interface ProgramAttributeValueStore
extends GenericStore<ProgramAttributeValue>
{
-
void saveVoid( ProgramAttributeValue programAttributeValue );
int delete( ProgramAttribute programAttribute );
@@ -56,4 +56,5 @@
Collection<ProgramAttributeValue> search( ProgramAttribute programAttribute, String searchText );
+ int countByProgramAttributeoption( ProgramAttributeOption attributeOption );
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/DefaultProgramAttributeValueService.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/DefaultProgramAttributeValueService.java 2011-07-06 08:04:17 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/DefaultProgramAttributeValueService.java 2011-07-21 09:03:49 +0000
@@ -30,6 +30,7 @@
import java.util.Collection;
import org.hisp.dhis.program.ProgramAttribute;
+import org.hisp.dhis.program.ProgramAttributeOption;
import org.hisp.dhis.program.ProgramInstance;
import org.springframework.transaction.annotation.Transactional;
@@ -111,4 +112,10 @@
{
return programAttributeValueStore.search( programAttribute, searchText );
}
+
+ @Override
+ public int countByProgramAttributeOption( ProgramAttributeOption attributeOption )
+ {
+ return programAttributeValueStore.countByProgramAttributeoption( attributeOption );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java 2010-11-30 08:39:40 +0000
+++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java 2011-07-21 09:03:49 +0000
@@ -30,9 +30,11 @@
import java.util.Collection;
import org.hibernate.Query;
+import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.program.ProgramAttribute;
+import org.hisp.dhis.program.ProgramAttributeOption;
import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.programattributevalue.ProgramAttributeValue;
import org.hisp.dhis.programattributevalue.ProgramAttributeValueStore;
@@ -91,4 +93,12 @@
return getCriteria( Restrictions.eq( "programAttribute", programAttribute ),
Restrictions.ilike( "value", "%" + searchText + "%" ) ).list();
}
+
+ @Override
+ public int countByProgramAttributeoption( ProgramAttributeOption attributeOption )
+ {
+ Number rs = (Number) getCriteria( Restrictions.eq( "programAttributeOption", attributeOption ) ).setProjection(
+ Projections.rowCount() ).uniqueResult();
+ return rs != null ? rs.intValue() : 0;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeAction.java 2011-03-31 01:42:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeAction.java 2011-07-21 09:03:49 +0000
@@ -57,10 +57,6 @@
private Integer id;
- // -------------------------------------------------------------------------
- // Setters
- // -------------------------------------------------------------------------
-
public void setId( Integer id )
{
this.id = id;
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeOptionAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/java/org/hisp/dhis/patient/action/program/RemoveProgramAttributeOptionAction.java 2011-07-21 09:03:49 +0000
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2004-2009, 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.patient.action.program;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.program.ProgramAttributeOption;
+import org.hisp.dhis.program.ProgramAttributeOptionService;
+import org.hisp.dhis.programattributevalue.ProgramAttributeValueService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ RemoveProgramAttributeOptionAction.java Jul 21, 2011 3:32:15 PM $
+ *
+ */
+public class RemoveProgramAttributeOptionAction
+implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ProgramAttributeOptionService programAttributeOptionService;
+
+ private ProgramAttributeValueService programAttributeValueService;
+
+ // -------------------------------------------------------------------------
+ // Input/Output
+ // -------------------------------------------------------------------------
+
+ private int id;
+
+ private String message;
+
+ private I18n i18n;
+
+ // -------------------------------------------------------------------------
+ // Getter && Setter
+ // -------------------------------------------------------------------------
+
+ public void setProgramAttributeOptionService( ProgramAttributeOptionService programAttributeOptionService )
+ {
+ this.programAttributeOptionService = programAttributeOptionService;
+ }
+
+ public void setProgramAttributeValueService( ProgramAttributeValueService programAttributeValueService )
+ {
+ this.programAttributeValueService = programAttributeValueService;
+ }
+
+ public void setId( int id )
+ {
+ this.id = id;
+ }
+
+
+ public String getMessage()
+ {
+ return message;
+ }
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+ ProgramAttributeOption attributeOption = programAttributeOptionService.get( id );
+
+ if ( attributeOption != null )
+ {
+ int count = programAttributeValueService.countByProgramAttributeOption( attributeOption );
+ if ( count > 0 )
+ {
+ message = i18n.getString( "warning_delete_rogram_attribute_option" );
+ return INPUT;
+ }
+ else
+ {
+ programAttributeOptionService.deleteProgramAttributeOption( attributeOption );
+ message = i18n.getString( "success_delete_program_attribute_option" );
+ return SUCCESS;
+ }
+ }
+ else
+ {
+ message = i18n.getString( "error_delete_program_attribute_option" );
+ return ERROR;
+ }
+ }
+
+}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2011-07-20 09:15:06 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/META-INF/dhis/beans.xml 2011-07-21 09:03:49 +0000
@@ -695,6 +695,16 @@
<property name="programAttributeService"
ref="org.hisp.dhis.program.ProgramAttributeService" />
</bean>
+
+ <bean
+ id="org.hisp.dhis.patient.action.program.RemoveProgramAttributeOptionAction"
+ class="org.hisp.dhis.patient.action.program.RemoveProgramAttributeOptionAction"
+ scope="prototype">
+ <property name="programAttributeOptionService"
+ ref="org.hisp.dhis.program.ProgramAttributeOptionService" />
+ <property name="programAttributeValueService"
+ ref="org.hisp.dhis.programattributevalue.ProgramAttributeValueService" />
+ </bean>
<!-- Program_OrganisationUnit Association -->
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2011-07-21 07:54:54 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/org/hisp/dhis/patient/i18n_module.properties 2011-07-21 09:03:49 +0000
@@ -296,7 +296,7 @@
child_contact_name = Child contact name
patient_system_id = System generated ID
warning_delete_patient_attribute_option = This option has relationship with BeneficiaryAttributeValue. You must not delete it.
-success_delete_patient_attribute_option = Delete option successfully.
+success_delete_patient_attribute_option = Delete patient attribute option successfully.
error_delete_patient_attribute_option = Can not find BeneficiaryAttributeOption to delete.
attribute_combo_type = Predefined value
at_least_2_option = Please add at least two attribute options
@@ -470,4 +470,6 @@
patient_attribute_group_sort_order = Beneficiary Attribute Group Sort Order
enrol_success = Enrol successfully.
beneficiary_attribute_group_sort_order = Beneficiary Attribute Group Sort Order
-min_days_from_start = Mininum number of days from start
\ No newline at end of file
+min_days_from_start = Mininum number of days from start
+warning_delete_program_attribute_option = This option has relationship with ProgramAttributeValue. You must not delete it.
+success_delete_program_attribute_option = Delete program attribute option successfully.
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml 2011-07-19 03:48:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/resources/struts.xml 2011-07-21 09:03:49 +0000
@@ -657,6 +657,17 @@
<param name="onExceptionReturn">plainTextError</param>
</action>
+ <action name="removeProgramAttributeOption"
+ class="org.hisp.dhis.patient.action.program.RemoveProgramAttributeOptionAction">
+ <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>
+ <param name="requiredAuthorities">F_PATIENTATTRIBUTE_DELETE</param>
+ </action>
+
<!-- Program_OrganisationUnit Association -->
<action name="defineProgramAssociationsForm"
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programAttribute.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programAttribute.js 2011-05-19 08:13:38 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-patient/src/main/webapp/dhis-web-maintenance-patient/javascript/programAttribute.js 2011-07-21 09:03:49 +0000
@@ -4,20 +4,22 @@
function showProgramAttributeDetails( programAttributeId )
{
- var request = new Request();
- request.setResponseTypeXML( 'programAttribute' );
- request.setCallbackSuccess( programAttributeReceived );
- request.send( 'getProgramAttribute.action?id=' + programAttributeId );
+ $.ajax({
+ url: 'getProgramAttribute.action?id=' + programAttributeId,
+ cache: false,
+ dataType: "xml",
+ success: programAttributeReceived
+ });
}
function programAttributeReceived( programAttributeElement )
{
- setInnerHTML( 'idField', getElementValue( programAttributeElement, 'id' ) );
- setInnerHTML( 'nameField', getElementValue( programAttributeElement, 'name' ) );
- setInnerHTML( 'descriptionField', getElementValue( programAttributeElement, 'description' ) );
+ setInnerHTML( 'idField', $( programAttributeElement).find('id' ).text() );
+ setInnerHTML( 'nameField', $( programAttributeElement).find('name').text() );
+ setInnerHTML( 'descriptionField', $( programAttributeElement).find('description').text() );
var valueTypeMap = { 'NUMBER':i18n_number, 'BOOL':i18n_yes_no, 'TEXT':i18n_text, 'DATE':i18n_date, 'COMBO':i18n_combo };
- var valueType = getElementValue( programAttributeElement, 'valueType' );
+ var valueType = $( programAttributeElement).find('valueType' ).text();
setInnerHTML( 'valueTypeField', valueTypeMap[valueType] );
@@ -27,6 +29,7 @@
// -----------------------------------------------------------------------------
// Remove Program Attribute
// -----------------------------------------------------------------------------
+
function removeProgramAttribute( programAttributeId, name )
{
removeItem( programAttributeId, name, i18n_confirm_delete, 'removeProgramAttribute.action' );
@@ -72,22 +75,24 @@
},
remove : function (this_, optionId)
{
-
if( jQuery(this_).siblings("input").attr("name") != "attrOptions")
{
- jQuery.get("removeProgramAttributeOption.action?id="+optionId,function(data){
- var type = jQuery(data).find("message").attr("type");
- alert(type);
- if( type == "success")
- {
- alert("success");
- jQuery(this_).parent().parent().remove();
- alert(jQuery(data).text());
- }else
- {
- alert(jQuery(data).text());
- }
- });
+ jQuery.getJSON("removeProgramAttributeOption.action",
+ {
+ id: optionId
+ },function( json )
+ {
+ var type = json.response;
+
+ if( type == "success")
+ {
+ jQuery(this_).parent().parent().remove();
+ showSuccessMessage(json.message);
+ }else
+ {
+ showWarningMessage(json.message);
+ }
+ });
}else
{
jQuery(this_).parent().parent().remove();