=== modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java 2010-10-22 06:43:14 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/program/ProgramInstanceDeletionHandler.java 2010-11-30 08:39:40 +0000 @@ -34,6 +34,8 @@ import org.hisp.dhis.patient.Patient; import org.hisp.dhis.patientdatavalue.PatientDataValue; import org.hisp.dhis.patientdatavalue.PatientDataValueService; +import org.hisp.dhis.programattributevalue.ProgramAttributeValue; +import org.hisp.dhis.programattributevalue.ProgramAttributeValueService; import org.hisp.dhis.system.deletion.DeletionHandler; /** @@ -61,13 +63,20 @@ this.patientDataValueService = patientDataValueService; } - ProgramStageDataElementService programStageDEService; + public ProgramStageDataElementService programStageDEService; public void setProgramStageDEService( ProgramStageDataElementService programStageDEService ) { this.programStageDEService = programStageDEService; } + + private ProgramAttributeValueService programAttributeValueService; + public void setProgramAttributeValueService( ProgramAttributeValueService programAttributeValueService ) + { + this.programAttributeValueService = programAttributeValueService; + } + // ------------------------------------------------------------------------- // DeletionHandler implementation // ------------------------------------------------------------------------- @@ -86,7 +95,7 @@ // --------------------------------------------------------------------- // Delete Patient data values // --------------------------------------------------------------------- - + Set dataValues = new HashSet(); for ( ProgramInstance programInstance : programInstances ) @@ -102,11 +111,27 @@ patientDataValueService.deletePatientDataValue( dataValue ); } } + + // --------------------------------------------------------------------- + // Delete Program attribute values + // --------------------------------------------------------------------- + + for ( ProgramInstance programInstance : programInstances ) + { + Collection attributeValues = programAttributeValueService + .getProgramAttributeValues( programInstance ); + + for ( ProgramAttributeValue attributeValue : attributeValues ) + { + programAttributeValueService.deleteProgramAttributeValue( attributeValue ); + } + + } // --------------------------------------------------------------------- // Delete Program Instances // --------------------------------------------------------------------- - +System.out.println("\n\n Delete Program Instances "); if ( programInstances != null && programInstances.size() > 0 ) { for ( ProgramInstance programInstance : programInstances ) @@ -114,6 +139,7 @@ programInstanceService.deleteProgramInstance( programInstance ); } } + } @Override @@ -130,12 +156,12 @@ for ( ProgramInstance programInstance : programInstances ) { Collection stageInstances = programInstance.getProgramStageInstances(); - if ( stageInstances != null && stageInstances.size() > 0) + if ( stageInstances != null && stageInstances.size() > 0 ) { dataValues.addAll( patientDataValueService.getPatientDataValues( stageInstances ) ); } } - + if ( dataValues != null && dataValues.size() > 0 ) { for ( PatientDataValue dataValue : dataValues ) @@ -145,6 +171,22 @@ } // --------------------------------------------------------------------- + // Delete Program attribute values + // --------------------------------------------------------------------- + + for ( ProgramInstance programInstance : programInstances ) + { + Collection attributeValues = programAttributeValueService + .getProgramAttributeValues( programInstance ); + + for ( ProgramAttributeValue attributeValue : attributeValues ) + { + programAttributeValueService.deleteProgramAttributeValue( attributeValue ); + } + + } + + // --------------------------------------------------------------------- // Delete Program Instances // --------------------------------------------------------------------- === added file 'dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java' --- dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/ProgramAttributeValueDeletionHandler.java 2010-11-30 08:39:40 +0000 @@ -0,0 +1,99 @@ +/* + * 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.programattributevalue; + +import java.util.Collection; + +import org.hisp.dhis.patient.Patient; +import org.hisp.dhis.program.Program; +import org.hisp.dhis.program.ProgramAttribute; +import org.hisp.dhis.program.ProgramInstance; +import org.hisp.dhis.program.ProgramInstanceService; +import org.hisp.dhis.system.deletion.DeletionHandler; + +/** + * @author Chau Thu Tran + * @version $Id ProgramAttributeValueDeletionHandler.java 2010-11-30 14:06:12Z $ + */ + +public class ProgramAttributeValueDeletionHandler + extends DeletionHandler +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ProgramAttributeValueService programAttributeValueService; + + public void setProgramAttributeValueService( ProgramAttributeValueService programAttributeValueService ) + { + this.programAttributeValueService = programAttributeValueService; + } + + private ProgramInstanceService programInstanceService; + + public void setProgramInstanceService( ProgramInstanceService programInstanceService ) + { + this.programInstanceService = programInstanceService; + } + + // ------------------------------------------------------------------------- + // DeletionHandler implementation + // ------------------------------------------------------------------------- + + @Override + public String getClassName() + { + return ProgramAttributeValue.class.getSimpleName(); + } + + @Override + public void deleteProgram( Program program ) + { + Collection programInstances = programInstanceService.getProgramInstances( program ); + + for ( ProgramInstance programInstance : programInstances ) + { + programAttributeValueService.deleteProgramAttributeValues( programInstance ); + } + } + + public void deleteProgramAttribute( ProgramAttribute programAttribute ) + { + Collection attributeValues = programAttributeValueService + .getProgramAttributeValues( programAttribute ); + + if ( attributeValues != null && attributeValues.size() > 0 ) + { + for ( ProgramAttributeValue attributeValue : attributeValues ) + { + programAttributeValueService.deleteProgramAttributeValue( attributeValue ); + } + } + } +} === 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-10 13:49:29 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/java/org/hisp/dhis/programattributevalue/hibernate/HibernateProgramAttributeValueStore.java 2010-11-30 08:39:40 +0000 @@ -74,9 +74,9 @@ } @SuppressWarnings("unchecked") - public Collection get( ProgramInstance progranInstance ) + public Collection get( ProgramInstance programInstance ) { - return getCriteria( Restrictions.eq( "progranInstance", progranInstance ) ).list(); + return getCriteria( Restrictions.eq( "programInstance", programInstance ) ).list(); } @SuppressWarnings("unchecked") === modified file 'dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2010-11-29 02:04:22 +0000 +++ dhis-2/dhis-services/dhis-service-patient/src/main/resources/META-INF/dhis/beans.xml 2010-11-30 08:39:40 +0000 @@ -298,6 +298,7 @@ + + + + + + @@ -356,6 +363,7 @@ + @@ -372,6 +380,7 @@ + @@ -412,6 +421,9 @@ pointcut="execution( * org.hisp.dhis.program.ProgramInstanceService.delete*(..) )" method="intercept"/> +