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

import org.xcolab.client.contest.pojo.Contest;
import org.xcolab.view.pages.contestmanagement.entities.MassActionRequiresConfirmationException;
import org.xcolab.view.pages.contestmanagement.wrappers.ContestOverviewWrapper;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ActiveMassAction extends ContestMassAction {

    public ActiveMassAction() {
        super("Active", "Prior");
    }

    @Override
    void execute(HttpServletRequest request, HttpServletResponse response,
            ContestOverviewWrapper contestOverviewWrapper)
            throws IOException, MassActionRequiresConfirmationException {
        Contest.setContestActive(true);
    }
}

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

import org.xcolab.client.contest.ContestClientUtil;
import org.xcolab.client.contest.pojo.Contest;

import java.util.List;

public class ActiveMassAction extends ContestMassActionAdapter {

    private final boolean setActive;

    public ActiveMassAction() {
        this(false);
    }

    public ActiveMassAction(boolean setActive) {
        super(setActive ? "Active" : "Prior");
        this.setActive = setActive;
    }

    @Override
    public void execute(List<Contest> contests, boolean actionConfirmed) {
        for (Contest contest : contests) {
            if (contest.getIsSharedContestInForeignColab()) {
                contest = ContestClientUtil.getContest(contest.getContestPK());
            }
            contest.setContestActive(setActive);
            contest.persist();
        }
    }
}

implement ActiveMassAction