Beispiel #1
0
  @Override
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    Session session = RequestAdapter.getSession(request);

    TaskDAOIf taskDAO = DAOFactory.TaskDAOIf(session);
    Task task = taskDAO.getTask(Util.parseInteger(request.getParameter("taskid"), 0));
    if (task == null) {
      request.setAttribute("title", "Aufgabe nicht gefunden");
      request.getRequestDispatcher("MessageView").forward(request, response);
      return;
    }

    // check Lecture Participation
    ParticipationDAOIf participationDAO = DAOFactory.ParticipationDAOIf(session);
    Participation participation =
        participationDAO.getParticipation(
            RequestAdapter.getUser(request), task.getTaskGroup().getLecture());
    if (participation == null
        || participation.getRoleType().compareTo(ParticipationRole.ADVISOR) != 0) {
      response.sendError(HttpServletResponse.SC_FORBIDDEN, "insufficient rights");
      return;
    }

    if (task.getDeadline().after(Util.correctTimezone(new Date()))
        || task.getShowPoints() != null) {
      request.setAttribute("title", "Ungültige Anfrage");
      request.getRequestDispatcher("MessageView").forward(request, response);
      return;
    }

    Transaction tx = session.beginTransaction();
    session.lock(task, LockMode.UPGRADE);
    if (request.getParameter("mail") != null) {
      for (Submission submission : task.getSubmissions()) {
        for (Participation submitterParticipation : submission.getSubmitters()) {
          if (submission.getPoints() != null && submission.getPoints().getPointsOk()) {
            // HACK hardcoded URL
            MailSender.sendMail(
                submitterParticipation.getUser().getFullEmail(),
                "Bewertung erfolgt",
                "Hallo "
                    + submitterParticipation.getUser().getFullName()
                    + ",\n\neine Ihrer Abgaben wurde bewertet.\n\nEinsehen: <https://si.in.tu-clausthal.de/submissionsystem/servlets/ShowTask?taskid="
                    + task.getTaskid()
                    + ">.\n\n-- \nReply is not possible.");
          }
        }
      }
    }
    task.setShowPoints(task.getDeadline());
    session.saveOrUpdate(task);
    tx.commit();

    response.sendRedirect(response.encodeRedirectURL("ShowTask?taskid=" + task.getTaskid()));
  }
Beispiel #2
0
  @Override
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    Session session = RequestAdapter.getSession(request);
    SubmissionDAOIf submissionDAO = DAOFactory.SubmissionDAOIf(session);
    Submission submission =
        submissionDAO.getSubmission(Util.parseInteger(request.getParameter("sid"), 0));
    if (submission == null) {
      request.setAttribute("title", "Abgabe nicht gefunden");
      request.getRequestDispatcher("MessageView").forward(request, response);
      return;
    }

    Task task = submission.getTask();

    // check Lecture Participation
    ParticipationDAOIf participationDAO = DAOFactory.ParticipationDAOIf(session);
    Participation participation =
        participationDAO.getParticipation(
            RequestAdapter.getUser(request), submission.getTask().getTaskGroup().getLecture());
    if (participation == null
        || participation.getRoleType().compareTo(ParticipationRole.TUTOR) < 0) {
      response.sendError(HttpServletResponse.SC_FORBIDDEN, "insufficient rights");
      return;
    }

    if ((task.getDeadline().before(Util.correctTimezone(new Date()))
            || (task.isShowTextArea() == false && "-".equals(task.getFilenameRegexp())))
        && request.getParameter("points") != null) {
      PointsDAOIf pointsDAO = DAOFactory.PointsDAOIf(session);
      String publicComment = "";
      if (request.getParameter("publiccomment") != null) {
        publicComment = request.getParameter("publiccomment").trim();
      }
      String internalComment = "";
      if (request.getParameter("internalcomment") != null) {
        internalComment = request.getParameter("internalcomment").trim();
      }
      PointStatus pointStatus = PointStatus.NICHT_ABGENOMMEN;
      if ("failed".equals(request.getParameter("pointsstatus"))) {
        pointStatus = PointStatus.ABGENOMMEN_FAILED;
      } else if ("ok".equals(request.getParameter("pointsstatus"))) {
        pointStatus = PointStatus.ABGENOMMEN;
      } else if ("nbewertet".equals(request.getParameter("pointsstatus"))) {
        pointStatus = PointStatus.NICHT_BEWERTET;
      }
      Transaction tx = session.beginTransaction();
      Integer duplicate = null;
      if (request.getParameter("isdupe") != null
          && Util.parseInteger(request.getParameter("duplicate"), -1) >= 0) {
        duplicate = Util.parseInteger(request.getParameter("duplicate"), -1);
      }
      // attention: quite similar code in MarkEmptyTask
      if (task.getPointCategories().size() > 0) {
        pointsDAO.createPoints(
            request.getParameterMap(),
            submission,
            participation,
            publicComment,
            internalComment,
            pointStatus,
            duplicate);
      } else {
        pointsDAO.createPoints(
            Util.convertToPoints(request.getParameter("points")),
            submission,
            participation,
            publicComment,
            internalComment,
            pointStatus,
            duplicate);
      }
      tx.commit();
      String groupAdding = "";
      if (request.getParameter("group") != null
          && Util.parseInteger(request.getParameter("group"), 0) > 0) {
        groupAdding = "&amp;groupid=" + Util.parseInteger(request.getParameter("group"), 0);
      }
      response.sendRedirect(
          response.encodeRedirectURL(
              "ShowSubmission?sid=" + submission.getSubmissionid() + groupAdding));
      return;
    }

    if (Util.parseInteger(request.getParameter("partnerid"), 0) > 0) {
      Transaction tx = session.beginTransaction();
      Participation partnerParticipation =
          participationDAO.getParticipation(
              Util.parseInteger(request.getParameter("partnerid"), 0));
      if (submission.getSubmitters().size() < task.getMaxSubmitters()
          && partnerParticipation != null
          && partnerParticipation.getLecture().getId() == task.getTaskGroup().getLecture().getId()
          && submissionDAO.getSubmissionLocked(task, partnerParticipation.getUser()) == null) {
        submission.getSubmitters().add(partnerParticipation);
        session.update(submission);
        tx.commit();
        response.sendRedirect(
            response.encodeRedirectURL("ShowSubmission?sid=" + submission.getSubmissionid()));
        return;
      }
      tx.rollback();
      PrintWriter out = response.getWriter();
      Template template = TemplateFactory.getTemplate(request, response);
      template.printTemplateHeader("Ungültige Anfrage");
      out.println(
          "<div class=mid>Der ausgewählte Partner hat bereits eine eigene Abgabe initiiert oder es wurden insgesamt zu viele Partner ausgewählt.</div>");
      template.printTemplateFooter();
      return;
    }

    request.setAttribute("submission", submission);
    request.setAttribute(
        "submittedFiles",
        Util.listFilesAsRelativeStringList(
            new File(
                new ContextAdapter(getServletContext()).getDataPath().getAbsolutePath()
                    + System.getProperty("file.separator")
                    + task.getTaskGroup().getLecture().getId()
                    + System.getProperty("file.separator")
                    + task.getTaskid()
                    + System.getProperty("file.separator")
                    + submission.getSubmissionid()
                    + System.getProperty("file.separator"))));
    request.getRequestDispatcher("ShowSubmissionView").forward(request, response);
  }