package org.xcolab.view.pages.contestmanagement.entities.massactions;

import org.xcolab.client.contest.ContestClientUtil;
import org.xcolab.client.contest.pojo.Contest;
import org.xcolab.client.contest.pojo.phases.ContestPhase;
import org.xcolab.view.pages.contestmanagement.entities.MassActionRequiresConfirmationException;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

public class DeleteWithPhasesMassAction extends AbstractContestMassAction {

    public DeleteWithPhasesMassAction() {
        super("Delete contests including phases");
    }

    @Override
    public void execute(List<Contest> contests, boolean actionConfirmed,
            MassActionDataWrapper dataWrapper, HttpServletResponse response)
            throws MassActionRequiresConfirmationException {
        if (!actionConfirmed) {
            throw new MassActionRequiresConfirmationException();
        }

        for (Contest contest : contests) {
            if (!contest.getIsSharedContestInForeignColab()) {
                Long contestId = contest.getContestPK();
                List<ContestPhase> contestPhases = ContestClientUtil.getAllContestPhases(contestId);
                for (ContestPhase contestPhase : contestPhases) {
                    ContestClientUtil.deleteContestPhase(contestPhase.getContestPhasePK());
                }
                ContestClientUtil.deleteContest(contestId);
            }
        }
    }
}

@@ -1069,285 +1069,8 @@
 ();%0A
-                List%3CContestPhase%3E contestPhases = ContestClientUtil.getAllContestPhases(contestId);%0A                for (ContestPhase contestPhase : contestPhases) %7B%0A                    ContestClientUtil.deleteContestPhase(contestPhase.getContestPhasePK());%0A                %7D%0A
     

delete old phase deletion code