Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jerahmeel: support deleting bundle problems #673

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import judgels.jerahmeel.persistence.BundleItemSubmissionModel;
import judgels.persistence.hibernate.HibernateDaoData;
import judgels.sandalphon.hibernate.AbstractBundleItemSubmissionHibernateDao;
import org.hibernate.query.Query;

public class BundleItemSubmissionHibernateDao
extends AbstractBundleItemSubmissionHibernateDao<BundleItemSubmissionModel>
Expand All @@ -19,4 +20,14 @@ public BundleItemSubmissionHibernateDao(HibernateDaoData data) {
public BundleItemSubmissionModel createSubmissionModel() {
return new BundleItemSubmissionModel();
}

@Override
public void deleteAllByProblemJid(String problemJid) {
Query<?> query = currentSession().createQuery(
"DELETE FROM jerahmeel_bundle_item_submission "
+ "WHERE problemJid = :problemJid");

query.setParameter("problemJid", problemJid);
query.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import judgels.jerahmeel.persistence.BundleItemSubmissionDao;
import judgels.jerahmeel.persistence.ChapterProblemDao;
import judgels.jerahmeel.persistence.ProblemSetProblemDao;
import judgels.jerahmeel.persistence.ProgrammingGradingDao;
Expand All @@ -20,6 +21,7 @@ public class DeleteProblemTask extends Task {
private final ProblemSetProblemDao problemSetProblemDao;
private final ProgrammingSubmissionDao programmingSubmissionDao;
private final ProgrammingGradingDao programmingGradingDao;
private final BundleItemSubmissionDao bundleItemSubmissionDao;
private final StatsUserProblemDao statsUserProblemDao;

public DeleteProblemTask(
Expand All @@ -28,6 +30,7 @@ public DeleteProblemTask(
ProblemSetProblemDao problemSetProblemDao,
ProgrammingSubmissionDao programmingSubmissionDao,
ProgrammingGradingDao programmingGradingDao,
BundleItemSubmissionDao bundleItemSubmissionDao,
StatsUserProblemDao statsUserProblemDao) {

super("jerahmeel-delete-problem");
Expand All @@ -37,6 +40,7 @@ public DeleteProblemTask(
this.problemSetProblemDao = problemSetProblemDao;
this.programmingSubmissionDao = programmingSubmissionDao;
this.programmingGradingDao = programmingGradingDao;
this.bundleItemSubmissionDao = bundleItemSubmissionDao;
this.statsUserProblemDao = statsUserProblemDao;
}

Expand All @@ -55,9 +59,14 @@ public void execute(Map<String, List<String>> parameters, PrintWriter out) {
}
String problemJid = maybeProblemModel.get().jid;

if (problemJid.startsWith("JIDPROG")) {
programmingGradingDao.deleteAllByProblemJid(problemJid);
programmingSubmissionDao.deleteAllByProblemJid(problemJid);
} else {
bundleItemSubmissionDao.deleteAllByProblemJid(problemJid);
}

statsUserProblemDao.deleteAllByProblemJid(problemJid);
programmingGradingDao.deleteAllByProblemJid(problemJid);
programmingSubmissionDao.deleteAllByProblemJid(problemJid);
chapterProblemDao.selectByProblemJid(problemJid).ifPresent(chapterProblemDao::delete);
problemSetProblemDao.selectAllByProblemJid(problemJid).forEach(problemSetProblemDao::delete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dagger.Provides;
import io.dropwizard.hibernate.UnitOfWorkAwareProxyFactory;
import javax.inject.Singleton;
import judgels.jerahmeel.persistence.BundleItemSubmissionDao;
import judgels.jerahmeel.persistence.ChapterDao;
import judgels.jerahmeel.persistence.ChapterProblemDao;
import judgels.jerahmeel.persistence.ProblemSetProblemDao;
Expand All @@ -25,6 +26,7 @@ static DeleteProblemTask deleteProblemTask(
ProblemSetProblemDao problemSetProblemDao,
ProgrammingSubmissionDao programmingSubmissionDao,
ProgrammingGradingDao programmingGradingDao,
BundleItemSubmissionDao bundleItemSubmissionDao,
StatsUserProblemDao statsUserProblemDao) {

return unitOfWorkAwareProxyFactory.create(
Expand All @@ -35,13 +37,15 @@ static DeleteProblemTask deleteProblemTask(
ProblemSetProblemDao.class,
ProgrammingSubmissionDao.class,
ProgrammingGradingDao.class,
BundleItemSubmissionDao.class,
StatsUserProblemDao.class},
new Object[] {
problemDao,
chapterProblemDao,
problemSetProblemDao,
programmingSubmissionDao,
programmingGradingDao,
bundleItemSubmissionDao,
statsUserProblemDao});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public AbstractBundleItemSubmissionHibernateQueryBuilder<M> select() {
return new AbstractBundleItemSubmissionHibernateQueryBuilder<>(currentSession(), getEntityClass());
}

@Override
public void deleteAllByProblemJid(String problemJid) {
throw new UnsupportedOperationException();
}

private static class AbstractBundleItemSubmissionHibernateQueryBuilder<M extends AbstractBundleItemSubmissionModel> extends HibernateQueryBuilder<M> implements BaseBundleItemSubmissionQueryBuilder<M> {
AbstractBundleItemSubmissionHibernateQueryBuilder(Session currentSession, Class<M> entityClass) {
super(currentSession, entityClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface BaseBundleItemSubmissionDao<M extends AbstractBundleItemSubmiss
M createSubmissionModel();

BaseBundleItemSubmissionQueryBuilder<M> select();
void deleteAllByProblemJid(String problemJid);

interface BaseBundleItemSubmissionQueryBuilder<M extends AbstractBundleItemSubmissionModel> extends QueryBuilder<M> {
BaseBundleItemSubmissionQueryBuilder<M> whereContainerIs(String containerJid);
Expand Down