@Override
  protected void handleGet(
      PageContext pageContext, Template template, VelocityContext templateContext)
      throws ServletException, IOException {
    IDAOSession f;
    try {
      DAOFactory df = (DAOFactory) FactoryRegistrar.getFactory(DAOFactory.class);
      f = df.getInstance();
    } catch (FactoryException e) {
      throw new ServletException("dao init error", e);
    }

    // Get assignmentId
    String assignmentString = pageContext.getParameter("assignment");
    if (assignmentString == null) {
      throw new ServletException("No assignment parameter given");
    }
    Long assignmentId = Long.valueOf(pageContext.getParameter("assignment"));

    // Ascertain sorting - TODO more sorting
    StaffDeadlineRevisionsQuerySortingType sortingType = null;
    if (pageContext.getParameter("sorting") != null) {
      if (pageContext.getParameter("sorting").equals("deadline_asc")) {
        sortingType = StaffDeadlineRevisionsQuerySortingType.DEADLINE_ASCENDING;
        templateContext.put("sorting", "deadline_asc");
      } else if (pageContext.getParameter("sorting").equals("deadline_desc")) {
        sortingType = StaffDeadlineRevisionsQuerySortingType.DEADLINE_DESCENDING;
        templateContext.put("sorting", "deadline_desc");
      } else if (pageContext.getParameter("sorting").equals("student_id_asc")) {
        sortingType = StaffDeadlineRevisionsQuerySortingType.STUDENT_ID_ASCENDING;
        templateContext.put("sorting", "student_id_asc");
      } else if (pageContext.getParameter("sorting").equals("student_id_desc")) {
        sortingType = StaffDeadlineRevisionsQuerySortingType.STUDENT_ID_DESCENDING;
        templateContext.put("sorting", "student_id_desc");
      }
    } else {
      sortingType = StaffDeadlineRevisionsQuerySortingType.NONE;
      templateContext.put("sorting", "");
    }

    // Render page
    try {
      f.beginTransaction();

      IStaffInterfaceQueriesDAO staffInterfaceQueriesDAO = f.getStaffInterfaceQueriesDAOInstance();
      IAssignmentDAO assignmentDao = f.getAssignmentDAOInstance();
      Assignment assignment = assignmentDao.retrievePersistentEntity(assignmentId);

      if (!staffInterfaceQueriesDAO.isStaffModuleAccessAllowed(
          pageContext.getSession().getPersonBinding().getId(), assignment.getModuleId())) {
        f.abortTransaction();
        throw new ServletException("permission denied");
      }

      IModuleDAO moduleDao = f.getModuleDAOInstance();
      Module module = moduleDao.retrievePersistentEntity(assignment.getModuleId());

      Collection<StaffDeadlineRevisionsQueryResult> result =
          staffInterfaceQueriesDAO.performStaffDeadlineRevisionsQuery(sortingType, assignmentId);

      f.endTransaction();

      // TODO: localisation
      templateContext.put("greet", pageContext.getSession().getPersonBinding().getChosenName());
      templateContext.put("module", module);
      templateContext.put("assignment", assignment);
      templateContext.put("deadlineRevisions", result);

      pageContext.renderTemplate(template, templateContext);
    } catch (DAOException e) {
      f.abortTransaction();
      throw new ServletException("dao exception", e);
    }
  }
예제 #2
0
  @Override
  protected void handleGet(
      PageContext pageContext, Template template, VelocityContext templateContext)
      throws ServletException, IOException {
    IDAOSession f;
    try {
      DAOFactory df = (DAOFactory) FactoryRegistrar.getFactory(DAOFactory.class);
      f = df.getInstance();
    } catch (FactoryException e) {
      throw new ServletException("dao init error", e);
    }

    // Ascertain sorting
    IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType sortingType = null;
    if (pageContext.getParameter("sorting") != null) {
      if (pageContext.getParameter("sorting").equals("assignment_count_asc")) {
        sortingType =
            IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.ASSIGNMENT_COUNT_ASCENDING;
        templateContext.put("sorting", "assignment_count_asc");
      } else if (pageContext.getParameter("sorting").equals("assignment_count_desc")) {
        sortingType =
            IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.ASSIGNMENT_COUNT_DESCENDING;
        templateContext.put("sorting", "assignment_count_desc");
      } else if (pageContext.getParameter("sorting").equals("student_count_asc")) {
        sortingType =
            IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.STUDENT_COUNT_ASCENDING;
        templateContext.put("sorting", "student_count_asc");
      } else if (pageContext.getParameter("sorting").equals("student_count_desc")) {
        sortingType =
            IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.STUDENT_COUNT_DESCENDING;
        templateContext.put("sorting", "student_count_desc");
      } else if (pageContext.getParameter("sorting").equals("model_id_asc")) {
        sortingType = IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.MODEL_ID_ASCENDING;
        templateContext.put("sorting", "model_id_asc");
      } else if (pageContext.getParameter("sorting").equals("model_id_desc")) {
        sortingType = IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.MODEL_ID_DESCENDING;
        templateContext.put("sorting", "model_id_desc");
      }
    } else {
      sortingType = IStaffInterfaceQueriesDAO.StaffModulesQuerySortingType.MODEL_ID_DESCENDING;
      templateContext.put("sorting", "model_id_desc");
    }

    // Render page
    try {
      f.beginTransaction();

      IStaffInterfaceQueriesDAO dao = f.getStaffInterfaceQueriesDAOInstance();
      Collection<StaffModulesQueryResult> result =
          dao.performStaffModulesQuery(
              sortingType, pageContext.getSession().getPersonBinding().getId());

      f.endTransaction();

      // TODO: localisation
      templateContext.put("greet", pageContext.getSession().getPersonBinding().getChosenName());
      templateContext.put("modules", result);

      // loading plugins' entry pages (if present)
      Collection<? extends IStaffPluginEntryLink> extraLinkProviders =
          Lookup.getDefault().lookupAll(IStaffPluginEntryLink.class);
      if (!extraLinkProviders.isEmpty()) {
        List<String> labels = new LinkedList<String>();
        List<String> links = new LinkedList<String>();
        for (IStaffPluginEntryLink link : extraLinkProviders) {
          labels.add(link.getLinkLabel());
          links.add(pageContext.getPageUrl(StaffPageFactory.SITE_NAME, link.getPageName()));
        }
        templateContext.put("extraLinks", links);
        templateContext.put("extraLabels", labels);
      }

      pageContext.renderTemplate(template, templateContext);
    } catch (DAOException e) {
      f.abortTransaction();
      throw new ServletException("dao exception", e);
    }
  }