Example #1
0
  @Override
  public boolean approveElective(int[] electiveIds) {

    try {
      for (int id : electiveIds) {
        Elective elective = entityManager.find(Elective.class, id);
        if (elective == null) {
          return false;
        }
        elective.setProposed("1");
        entityManager.persist(elective);
      }
    } catch (EntityExistsException e) {
      e.printStackTrace();
      entityManager.getTransaction().rollback();
      return false;
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      entityManager.getTransaction().rollback();
      return false;
    } catch (TransactionRequiredException e) {
      e.printStackTrace();
      entityManager.getTransaction().rollback();
      return false;
    }
    return true;
  }
Example #2
0
  @Override
  public boolean setTaughtElectives(int[] electiveId) {

    // entityManager.getTransaction().begin();
    for (int i : electiveId) {
      Elective ele = entityManager.find(Elective.class, i);
      ele.setTaught((short) 1);
      try {
        entityManager.persist(ele);
      } catch (EntityExistsException e) {
        e.printStackTrace();
        return false;
      } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return false;
      } catch (TransactionRequiredException e) {
        e.printStackTrace();
        return false;
      }
    }

    //        try {
    //            entityManager.getTransaction().commit();
    //        } catch (RollbackException e) {
    //            e.printStackTrace();
    //            return false;
    //        }
    return true;
  }
Example #3
0
  @Override
  public boolean isTaught(int electiveId) {

    try {
      Elective elective = entityManager.find(Elective.class, electiveId);
      return (elective != null && elective.getTaught() != null && elective.getTaught() == 1)
          ? true
          : false;
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
      return false;
    }
  }
Example #4
0
  @Override
  public boolean assignStudentElectives(Collection<StudentElectiveDTO> studentElective) {

    for (StudentElectiveDTO studentElectiveDTO : studentElective) {
      Student student = entityManager.find(Student.class, studentElectiveDTO.getCPR());
      Elective elective = entityManager.find(Elective.class, studentElectiveDTO.getElective_id());
      student.addElective(elective);
      elective.addStudent(student);
      entityManager.persist(elective);
      entityManager.persist(student);
    }

    return true;
  }
Example #5
0
  //    //Returns all the electives proposed by students and teachears!
  //    @Override
  //    public Collection<ElectiveDTO> getProposedElectives() {
  //        ArrayList< ElectiveDTO> electiveDTOs = new ArrayList<>();
  //        Query query = entityManager.createNamedQuery("Elective.findAll");
  //        List<Elective> electives = query.getResultList();
  //        for (Elective e : electives) {
  //            if (e.getProposed().equals("0")) {
  //                electiveDTOs.add(new ElectiveDTO(e.getElectiveId(), e.getTitle(),
  // e.getDescription(), e.getCreationDate(), e.getProposed()));
  //            }
  //        }
  //        return electiveDTOs;
  //    }
  // Returns electives that has been approved by the head of program to go for the first round
  @Override
  public Collection<ElectiveFirstDTO> getFirstRndElectives() {

    ArrayList<ElectiveFirstDTO> electiveDTOs = new ArrayList<>();
    Query query = entityManager.createNamedQuery("Elective.findByProposed");
    Query q1, q2;
    query.setParameter("proposed", "1");
    List<Elective> electives = query.getResultList();

    int firstPriorityCount;
    int secondPriorityCount;

    for (Elective e : electives) {
      if (e.getPool() == null) {
        q1 = entityManager.createNamedQuery("FirstRoundVote.count_priority1");
        q1.setParameter("elective", e);
        firstPriorityCount = Integer.parseInt(q1.getSingleResult().toString());

        q2 = entityManager.createNamedQuery("FirstRoundVote.count_priority2");
        q2.setParameter("elective", e);
        secondPriorityCount = Integer.parseInt(q2.getSingleResult().toString());
        electiveDTOs.add(
            new ElectiveFirstDTO(
                e.getElectiveId(),
                e.getTitle(),
                e.getDescription(),
                e.getCreationDate(),
                e.getProposed(),
                firstPriorityCount,
                secondPriorityCount));
      }
    }
    return electiveDTOs;
  }
Example #6
0
  @Override
  public Collection<ElectiveSecondDTO> getSecondRndElectivesB() {

    ArrayList<ElectiveSecondDTO> electiveDTOsB = new ArrayList<>();
    Query query = entityManager.createNamedQuery("Elective.findByPool");
    query.setParameter("pool", "b");
    List<Elective> electives = query.getResultList();

    for (Elective e : electives) {
      electiveDTOsB.add(
          new ElectiveSecondDTO(
              e.getElectiveId(),
              e.getTitle(),
              e.getDescription(),
              e.getCreationDate(),
              e.getProposed(),
              e.getPool()));
    }

    return electiveDTOsB;
  }