// //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; }
@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; }