Search in sources :

Example 6 with DeleteNotAllowedException

use of org.hisp.dhis.common.DeleteNotAllowedException in project dhis2-core by dhis2.

the class RemoveProgramStageAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
    try {
        ProgramStage programStage = programStageService.getProgramStage(id);
        Program program = programStage.getProgram();
        program.getProgramStages().remove(programStage);
        programStageService.deleteProgramStage(programStage);
    } 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;
}
Also used : Program(org.hisp.dhis.program.Program) DeleteNotAllowedException(org.hisp.dhis.common.DeleteNotAllowedException) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

DeleteNotAllowedException (org.hisp.dhis.common.DeleteNotAllowedException)6 Program (org.hisp.dhis.program.Program)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ProxyObject (javassist.util.proxy.ProxyObject)1 PageRange (org.hisp.dhis.commons.util.PageRange)1 I18nLocale (org.hisp.dhis.i18n.locale.I18nLocale)1 Period (org.hisp.dhis.period.Period)1 ProgramStage (org.hisp.dhis.program.ProgramStage)1 Transactional (org.springframework.transaction.annotation.Transactional)1