/** * Delete a task * * @param storyId * @param taskId */ public static void delete(Long storyId, long taskId) { Task toDelete = Task.findById(taskId); if (toDelete != null) { toDelete.delete(); } renderJSON(UserMessage.SUCCESSFUL); }
private static void updateElement(Long storyId, JsonElement element) { if (element.isJsonObject()) { JsonObject jsonObject = element.getAsJsonObject(); JsonElement jsonElement = jsonObject.get("id"); if (jsonElement != null) { Task toUpdate = Task.findById(jsonElement.getAsLong()); doUpdate(toUpdate, jsonObject); } } }
/** * Show statistics REQ-7.1, REQ-7.2 * * @param id */ public static void statistics(Long id) { Task task = Task.findById(id); notFoundIfNull(task); Collection<SystemReplyResult> systemReplyStatistics = new SystemReplyStatistics().getStatistics(task); Collection<ContestantResult> contestantStatistics = new ContestantStatistics().getStatistics(task, 10); render(task, systemReplyStatistics, contestantStatistics); }
/** * Remove all evaluations from single solutions of this task * * @param id */ public static void unevaluate(Long id) { Task task = Task.findById(id); notFoundIfNull(task); List<models.Solution> solutions = models.Solution.find("task=?", task).fetch(); for (models.Solution solution : solutions) { solution.unevaluate(); solution.save(); } Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("search_task", task.id); redirect(Router.getFullUrl("admin.Solutions.list", parameters)); }
/** * Check for delete constraints * * @param id */ @Before(only = {"delete"}) public static void beforeDelete(Long id) { Task task = Task.findById(id); notFoundIfNull(task); if (!task.competitions.isEmpty()) { flash.error( "Can't delete task! Is used in " + task.competitions.size() + " competition" + (task.competitions.size() > 1 ? "s" : "") + ": " + task.competitions.get(0).name + (task.competitions.size() > 1 ? ", ..." : "")); redirect(request.controller + ".show", id); } }
/** * Update files before save * * @param id * @param inputData * @param outputData * @param removeOutputData * @throws IOException */ @Before(only = "save") public static void beforeSave( Long id, java.io.File inputData, java.io.File outputData, boolean removeOutputData) throws IOException { models.Task task = models.Task.findById(id); notFoundIfNull(task); if (removeOutputData) { task.deleteOutputData(); } if (inputData != null) { InputFile inputFile = new InputFile(inputData); inputFile.save(); params.put("object.inputData.id", inputFile.getId().toString()); } if (outputData != null) { OutputFile outputFile = new OutputFile(outputData); outputFile.save(); params.put("object.outputData.id", outputFile.getId().toString()); } }
/** * Updates a single task data * * @param storyId * @param taskId * @param body */ public static void update(Long storyId, Long taskId, JsonObject body) { Task toUpdate = Task.findById(taskId); doUpdate(toUpdate, body); renderText(gson.toJson(toUpdate)); }
/** * gets all the tasks for a story * * @param storyId */ public static void byId(long storyId, long taskId) { Task byId = Task.findById(taskId); renderText(gson.toJson(byId)); }