-
Notifications
You must be signed in to change notification settings - Fork 25
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 move problem to problem set (#674)
- Loading branch information
Showing
4 changed files
with
127 additions
and
1 deletion.
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
96 changes: 96 additions & 0 deletions
96
...dgels-server-app/src/main/java/judgels/jerahmeel/problem/MoveProblemToProblemSetTask.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,96 @@ | ||
package judgels.jerahmeel.problem; | ||
|
||
import io.dropwizard.hibernate.UnitOfWork; | ||
import io.dropwizard.servlets.tasks.Task; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import judgels.jerahmeel.persistence.ChapterProblemDao; | ||
import judgels.jerahmeel.persistence.ChapterProblemModel; | ||
import judgels.jerahmeel.persistence.ProblemSetDao; | ||
import judgels.jerahmeel.persistence.ProblemSetModel; | ||
import judgels.jerahmeel.persistence.ProblemSetProblemDao; | ||
import judgels.jerahmeel.persistence.ProblemSetProblemModel; | ||
import judgels.jerahmeel.persistence.ProgrammingSubmissionDao; | ||
import judgels.sandalphon.api.problem.ProblemType; | ||
import judgels.sandalphon.persistence.ProblemDao; | ||
import judgels.sandalphon.persistence.ProblemModel; | ||
|
||
public class MoveProblemToProblemSetTask extends Task { | ||
private final ProblemDao problemDao; | ||
private final ProblemSetDao problemSetDao; | ||
private final ChapterProblemDao chapterProblemDao; | ||
private final ProblemSetProblemDao problemSetProblemDao; | ||
private final ProgrammingSubmissionDao programmingSubmissionDao; | ||
|
||
public MoveProblemToProblemSetTask( | ||
ProblemDao problemDao, | ||
ProblemSetDao problemSetDao, | ||
ChapterProblemDao chapterProblemDao, | ||
ProblemSetProblemDao problemSetProblemDao, | ||
ProgrammingSubmissionDao programmingSubmissionDao) { | ||
|
||
super("jerahmeel-move-problem-to-problem-set"); | ||
|
||
this.problemDao = problemDao; | ||
this.problemSetDao = problemSetDao; | ||
this.chapterProblemDao = chapterProblemDao; | ||
this.problemSetProblemDao = problemSetProblemDao; | ||
this.programmingSubmissionDao = programmingSubmissionDao; | ||
} | ||
|
||
@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); | ||
|
||
List<String> toProblemSetJids = parameters.get("toProblemSetJid"); | ||
if (toProblemSetJids == null || toProblemSetJids.isEmpty()) { | ||
return; | ||
} | ||
String toProblemSetJid = toProblemSetJids.get(0); | ||
|
||
List<String> aliases = parameters.get("alias"); | ||
if (aliases == null || aliases.isEmpty()) { | ||
return; | ||
} | ||
String alias = aliases.get(0); | ||
|
||
Optional<ProblemModel> maybeProblemModel = problemDao.selectBySlug(problemSlug); | ||
if (maybeProblemModel.isEmpty()) { | ||
return; | ||
} | ||
String problemJid = maybeProblemModel.get().jid; | ||
|
||
Optional<ProblemSetModel> maybeProblemSetModel = problemSetDao.selectByJid(toProblemSetJid); | ||
if (maybeProblemSetModel.isEmpty()) { | ||
return; | ||
} | ||
|
||
List<ProblemSetProblemModel> problemSetProblemModels = problemSetProblemDao.selectAllByProblemJid(problemJid); | ||
if (!problemSetProblemModels.isEmpty()) { | ||
for (ProblemSetProblemModel model : problemSetProblemModels) { | ||
model.problemSetJid = toProblemSetJid; | ||
model.alias = alias; | ||
problemSetProblemDao.update(model); | ||
} | ||
} else { | ||
ProblemSetProblemModel model = new ProblemSetProblemModel(); | ||
model.problemSetJid = toProblemSetJid; | ||
model.alias = alias; | ||
model.problemJid = problemJid; | ||
model.type = ProblemType.PROGRAMMING.name(); | ||
problemSetProblemDao.insert(model); | ||
} | ||
|
||
Optional<ChapterProblemModel> maybeChapterProblemModel = chapterProblemDao.selectByProblemJid(problemJid); | ||
maybeChapterProblemModel.ifPresent(chapterProblemDao::delete); | ||
|
||
programmingSubmissionDao.updateContainerJid(problemJid, toProblemSetJid); | ||
} | ||
} |
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