dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30485
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15470: Add deletionHandler for deleting program instance.
------------------------------------------------------------
revno: 15470
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-05-30 00:14:36 +0800
message:
Add deletionHandler for deleting program instance.
modified:
dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java
--
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-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/ProgramStageInstanceDeletionHandler.java 2014-05-29 16:14:36 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.system.deletion.DeletionHandler;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
/**
@@ -50,7 +51,10 @@
{
this.jdbcTemplate = jdbcTemplate;
}
-
+
+ @Autowired
+ private ProgramStageInstanceService programStageInstanceService;
+
// -------------------------------------------------------------------------
// Implementation methods
// -------------------------------------------------------------------------
@@ -72,12 +76,21 @@
@Override
public String allowDeleteProgramInstance( ProgramInstance programInstance )
{
- String sql = "SELECT COUNT(*) FROM programstageinstance WHERE programinstanceid=" + programInstance.getId();
+ String sql = "SELECT COUNT(*) FROM programstageinstance WHERE programinstanceid=" + programInstance.getId() + " and executionDate is not null ";
return jdbcTemplate.queryForObject( sql, Integer.class ) == 0 ? null : ERROR;
}
@Override
+ public void deleteProgramInstance( ProgramInstance programInstance )
+ {
+ for ( ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances() )
+ {
+ programStageInstanceService.deleteProgramStageInstance( programStageInstance );
+ }
+ }
+
+ @Override
public String allowDeleteProgram( Program program )
{
String sql = "SELECT COUNT(*) FROM programstageinstance psi join programinstance pi on pi.programinstanceid=psi.programinstanceid where pi.programid = " + program.getId();
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/RemoveProgramInstanceAction.java 2014-05-29 16:14:36 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.DeleteNotAllowedException;
+import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.program.ProgramInstance;
import org.hisp.dhis.program.ProgramInstanceService;
@@ -52,6 +54,13 @@
this.programInstanceService = programInstanceService;
}
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
// -------------------------------------------------------------------------
// Input
// -------------------------------------------------------------------------
@@ -63,16 +72,35 @@
this.id = id;
}
+ private String message;
+
+ public String getMessage()
+ {
+ return message;
+ }
+
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
public String execute()
{
- ProgramInstance programInstance = programInstanceService.getProgramInstance( id );
-
- programInstanceService.deleteProgramInstance( programInstance );
-
+ try
+ {
+ ProgramInstance programInstance = programInstanceService.getProgramInstance( id );
+
+ programInstanceService.deleteProgramInstance( programInstance );
+ }
+ catch ( DeleteNotAllowedException ex )
+ {
+ if ( ex.getErrorCode().equals( DeleteNotAllowedException.ERROR_ASSOCIATED_BY_OTHER_OBJECTS ) )
+ {
+ message = i18n.getString( "object_not_deleted_associated_by_objects" ) + " " + ex.getMessage();
+
+ return ERROR;
+ }
+ }
+
return SUCCESS;
}