-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jerahmeel: add task to delete problem
- Loading branch information
Showing
14 changed files
with
186 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ackends/judgels-server-app/src/main/java/judgels/jerahmeel/problem/DeleteProblemTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package judgels.jerahmeel.problem; | ||
|
||
import io.dropwizard.hibernate.UnitOfWork; | ||
import io.dropwizard.servlets.tasks.Task; | ||
import judgels.jerahmeel.persistence.ChapterProblemDao; | ||
import judgels.jerahmeel.persistence.ProblemSetProblemDao; | ||
import judgels.jerahmeel.persistence.ProgrammingGradingDao; | ||
import judgels.jerahmeel.persistence.ProgrammingSubmissionDao; | ||
import judgels.jerahmeel.persistence.StatsUserProblemDao; | ||
import judgels.sandalphon.persistence.ProblemDao; | ||
import judgels.sandalphon.persistence.ProblemModel; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class DeleteProblemTask extends Task { | ||
private final ProblemDao problemDao; | ||
private final ChapterProblemDao chapterProblemDao; | ||
private final ProblemSetProblemDao problemSetProblemDao; | ||
private final ProgrammingSubmissionDao programmingSubmissionDao; | ||
private final ProgrammingGradingDao programmingGradingDao; | ||
private final StatsUserProblemDao statsUserProblemDao; | ||
|
||
public DeleteProblemTask( | ||
ProblemDao problemDao, | ||
ChapterProblemDao chapterProblemDao, | ||
ProblemSetProblemDao problemSetProblemDao, | ||
ProgrammingSubmissionDao programmingSubmissionDao, | ||
ProgrammingGradingDao programmingGradingDao, | ||
StatsUserProblemDao statsUserProblemDao) { | ||
|
||
super("jerahmeel-delete-problem"); | ||
|
||
this.problemDao = problemDao; | ||
this.chapterProblemDao = chapterProblemDao; | ||
this.problemSetProblemDao = problemSetProblemDao; | ||
this.programmingSubmissionDao = programmingSubmissionDao; | ||
this.programmingGradingDao = programmingGradingDao; | ||
this.statsUserProblemDao = statsUserProblemDao; | ||
} | ||
|
||
@Override | ||
@UnitOfWork | ||
public void execute(Map<String, List<String>> parameters, PrintWriter out) { | ||
List<String> problemSlugs = parameters.get("problemSlug"); | ||
if (problemSlugs == null || problemSlugs.isEmpty()) { | ||
return; | ||
} | ||
String problemSlug = problemSlugs.get(0); | ||
|
||
Optional<ProblemModel> maybeProblemModel = problemDao.selectBySlug(problemSlug); | ||
if (maybeProblemModel.isEmpty()) { | ||
return; | ||
} | ||
String problemJid = maybeProblemModel.get().jid; | ||
|
||
statsUserProblemDao.deleteAllByProblemJid(problemJid); | ||
programmingGradingDao.deleteAllByProblemJid(problemJid); | ||
programmingSubmissionDao.deleteAllByProblemJid(problemJid); | ||
chapterProblemDao.selectByProblemJid(problemJid).ifPresent(chapterProblemDao::delete); | ||
problemSetProblemDao.selectAllByProblemJid(problemJid).forEach(problemSetProblemDao::delete); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters