public void unrollManagerInEvent(Long managerId, Long eventId) throws EntityDoesNotExistsException, ManagerNotEnrolledException { try { Event event = em.find(Event.class, eventId); if (event == null) { throw new EntityDoesNotExistsException("There is no event with that id."); } Manager manager = em.find(Manager.class, managerId); if (manager == null) { throw new AttendantNotEnrolledException("There is no manager with that id."); } if (!event.getManagers().contains(manager)) { throw new ManagerNotEnrolledException("Manager is not enrolled in that event."); } event.removeManager(manager); manager.removeEvent(event); } catch (EntityDoesNotExistsException | ManagerNotEnrolledException e) { throw e; } catch (Exception e) { throw new EJBException(e.getMessage()); } }
public void enrollManagerInEvent(Long managerId, Long eventId) throws EntityDoesNotExistsException, ManagerEnrolledException { System.out.println("Eeeeeeeeevent ID: "); try { Manager manager = em.find(Manager.class, managerId); if (manager == null) { throw new EntityDoesNotExistsException("There is no manager with that id."); } Event event = em.find(Event.class, eventId); if (event == null) { throw new EntityDoesNotExistsException("There is no event with that id."); } if (event.getManagers().contains(manager)) { throw new ManagerEnrolledException("Manager is already enrolled in that event."); } event.addManager(manager); manager.addEvent(event); } catch (EntityDoesNotExistsException | ManagerEnrolledException e) { throw e; } catch (Exception e) { throw new EJBException(e.getMessage()); } }
public List<ManagerDTO> getEnrolledManagersInEvents(Long id) throws EntityDoesNotExistsException { try { Event event = em.find(Event.class, id); if (event == null) { throw new EntityDoesNotExistsException("There is no event with that id."); } List<Manager> managers = (List<Manager>) event.getManagers(); return managersToDTOs(managers); } catch (EntityDoesNotExistsException e) { throw e; } catch (Exception e) { throw new EJBException(e.getMessage()); } }
EventDTO eventToDTO(Event event) { EventDTO eventDTO = new EventDTO( event.getId(), event.getName(), event.getDescription(), event.getStartDate(), event.getFinishDate()); eventDTO.setOpenForEnroll(event.isOpenForEnroll()); eventDTO.setOpenForPresence(event.isOpenForPresence()); eventDTO.setPassword(event.getPassword()); return eventDTO; }
public List<ManagerDTO> getUnrolledManagersInEvents(Long id) throws EntityDoesNotExistsException { try { Event event = em.find(Event.class, id); if (event == null) { throw new EntityDoesNotExistsException("There is no event with that id."); } // nao sei se este código está correcto?? List<Manager> managers = (List<Manager>) em.createNamedQuery("getAllEventManagers") .setParameter("eventId", event.getId()) .getResultList(); // ----------------------------------------------------------------------------------------- List<Manager> enrolled = em.find(Event.class, id).getManagers(); managers.removeAll(enrolled); return managersToDTOs(managers); } catch (EntityDoesNotExistsException e) { throw e; } catch (Exception e) { throw new EJBException(e.getMessage()); } }