Ejemplo n.º 1
0
  @Override
  public Boolean execute(OnlineSectioningServer server, OnlineSectioningHelper helper) {
    for (Long offeringId : getOfferingIds()) {
      helper
          .getAction()
          .addOther(
              OnlineSectioningLog.Entity.newBuilder()
                  .setUniqueId(offeringId)
                  .setType(OnlineSectioningLog.Entity.EntityType.OFFERING));

      List<Long> studentIds =
          (List<Long>)
              helper
                  .getHibSession()
                  .createQuery(
                      "select distinct cr.courseDemand.student.uniqueId from CourseRequest cr "
                          + "where cr.courseOffering.instructionalOffering.uniqueId = :offeringId")
                  .setLong("offeringId", offeringId)
                  .list();
      studentIds.addAll(
          helper
              .getHibSession()
              .createQuery(
                  "select distinct e.student.uniqueId from StudentClassEnrollment e "
                      + "where e.courseOffering.instructionalOffering.uniqueId = :offeringId and e.courseRequest is null")
              .setLong("offeringId", offeringId)
              .list());
      /*
      List<Long> studentIds = (List<Long>)helper.getHibSession().createQuery(
      		"select distinct s.uniqueId from Student s " +
      		"left outer join s.classEnrollments e " +
      		"left outer join s.courseDemands d left outer join d.courseRequests r left outer join r.courseOffering co " +
      		"where e.courseOffering.instructionalOffering.uniqueId = :offeringId or " +
      		"co.instructionalOffering.uniqueId = :offeringId").setLong("offeringId", offeringId).list();
      */

      Lock lock = server.lockOffering(offeringId, studentIds, name());
      try {
        helper.beginTransaction();
        try {
          reloadOffering(server, helper, offeringId);

          helper.commitTransaction();
        } catch (Exception e) {
          helper.rollbackTransaction();
          if (e instanceof SectioningException) throw (SectioningException) e;
          throw new SectioningException(MSG.exceptionUnknown(e.getMessage()), e);
        }
      } finally {
        lock.release();
      }
    }
    return true;
  }
Ejemplo n.º 2
0
  @Override
  public Boolean execute(OnlineSectioningServer server, OnlineSectioningHelper helper) {
    StudentSectioningStatus status =
        (hasStatus()
            ? (StudentSectioningStatus)
                helper
                    .getHibSession()
                    .createQuery("from StudentSectioningStatus where reference = :ref")
                    .setString("ref", getStatus())
                    .uniqueResult()
            : null);
    for (Long studentId : getStudentIds()) {
      Lock lock = server.lockStudent(studentId, null, name());
      try {
        XStudent student = server.getStudent(studentId);
        helper.beginTransaction();
        try {
          Student dbStudent = StudentDAO.getInstance().get(studentId, helper.getHibSession());
          if (student != null && dbStudent != null) {

            OnlineSectioningLog.Action.Builder action =
                helper.addAction(this, server.getAcademicSession());
            action.setStudent(
                OnlineSectioningLog.Entity.newBuilder()
                    .setUniqueId(student.getStudentId())
                    .setExternalId(student.getExternalId())
                    .setName(student.getName()));
            if (status != null) {
              action.addOther(
                  OnlineSectioningLog.Entity.newBuilder()
                      .setUniqueId(status.getUniqueId())
                      .setName(status.getLabel())
                      .setExternalId(status.getReference())
                      .setType(OnlineSectioningLog.Entity.EntityType.OTHER));
            }

            student.setStatus(getStatus());
            dbStudent.setSectioningStatus(status);
            helper.getHibSession().saveOrUpdate(dbStudent);
            server.update(student, false);
          }
          helper.commitTransaction();
        } catch (Exception e) {
          helper.rollbackTransaction();
          if (e instanceof SectioningException) throw (SectioningException) e;
          throw new SectioningException(MSG.exceptionUnknown(e.getMessage()), e);
        }

      } finally {
        lock.release();
      }
    }
    return true;
  }
  @Override
  public FilterRpcResponse execute(
      SectioningStatusFilterRpcRequest request, SessionContext context) {
    try {
      boolean online = "true".equals(request.getOption("online"));

      if (context.isAuthenticated()) {
        request.setOption("user", context.getUser().getExternalUserId());
        if (context.getUser().getCurrentAuthority() != null
            && context.getUser().getCurrentAuthority().hasRight(Right.ConsentApproval))
          request.setOption("approval", "true");
      }

      if (online) {
        Long sessionId = getStatusPageSessionId(context);

        OnlineSectioningServer server =
            solverServerService
                .getOnlineStudentSchedulingContainer()
                .getSolver(sessionId.toString());
        if (server == null) throw new SectioningException(MSG.exceptionBadSession());

        context.checkPermission(
            server.getAcademicSession().getUniqueId(), "Session", Right.SchedulingDashboard);
        request.setSessionId(server.getAcademicSession().getUniqueId());

        return server.execute(
            server.createAction(SectioningStatusFilterAction.class).forRequest(request),
            currentUser(context));
      } else {
        OnlineSectioningServer server = studentSectioningSolverService.getSolver();
        if (server == null) throw new SectioningException(MSG.exceptionNoSolver());

        context.checkPermission(
            server.getAcademicSession().getUniqueId(),
            "Session",
            Right.StudentSectioningSolverDashboard);
        request.setSessionId(server.getAcademicSession().getUniqueId());

        return server.execute(
            server.createAction(SectioningStatusFilterAction.class).forRequest(request),
            currentUser(context));
      }
    } catch (PageAccessException e) {
      throw e;
    } catch (SectioningException e) {
      throw e;
    } catch (Exception e) {
      sLog.error(e.getMessage(), e);
      throw new SectioningException(MSG.exceptionUnknown(e.getMessage()), e);
    }
  }