Esempio n. 1
0
  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());
    }
  }
Esempio n. 2
0
  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());
    }
  }
Esempio n. 3
0
  public List<EventDTO> getAllEventsOfManager(Long id) {
    Manager man = em.find(Manager.class, id);

    if (man != null) {
      List<Event> events = new ArrayList<>();
      events = man.getEvents();
      return eventsToDTOs(events);
    }
    return null;
  }
Esempio n. 4
0
 public void updateManager(Long id, String username, String password, String name, String email)
     throws EntityDoesNotExistsException, MyConstraintViolationException,
         EntityAlreadyExistsException {
   try {
     Manager manager = em.find(Manager.class, id);
     if (manager == null) {
       throw new EntityDoesNotExistsException("There is no manager with that id.");
     }
     List<Manager> Managers =
         (List<Manager>) em.createNamedQuery("getAllManagers").getResultList();
     for (Manager m : Managers) {
       if (username.equals(m.getUserName()) && !m.getId().equals(manager.getId())) {
         throw new EntityAlreadyExistsException("That username already exists.");
       }
     }
     manager.setUsername(username);
     manager.setPassword(password);
     manager.setName(name);
     manager.setEmail(email);
     em.merge(manager);
   } catch (EntityDoesNotExistsException | EntityAlreadyExistsException e) {
     throw e;
   } catch (ConstraintViolationException e) {
     throw new MyConstraintViolationException(Utils.getConstraintViolationMessages(e));
   } catch (Exception e) {
     throw new EJBException(e.getMessage());
   }
 }
Esempio n. 5
0
 public List<EventDTO> getManagerEvents(Long managerId) throws EntityDoesNotExistsException {
   try {
     Manager manager = em.find(Manager.class, managerId);
     if (manager == null) {
       throw new EntityDoesNotExistsException("Manager does not exists.");
     }
     return eventsToDTOs(manager.getEvents());
   } catch (EntityDoesNotExistsException e) {
     throw e;
   } catch (Exception e) {
     throw new EJBException(e.getMessage());
   }
 }
Esempio n. 6
0
 public ManagerDTO getManager(String username) {
   try {
     Manager manager = new Manager();
     List<Manager> managers =
         (List<Manager>) em.createNamedQuery("getAllManagers").getResultList();
     for (Manager m : managers) {
       if (username.equals(m.getName())) {
         manager = m;
         return managerToDTO(manager);
       }
     }
   } catch (Exception e) {
     throw new EJBException(e.getMessage());
   }
   return null;
 }
Esempio n. 7
0
 ManagerDTO managerToDTO(Manager manager) {
   return new ManagerDTO(
       manager.getId(), manager.getUserName(), null, manager.getName(), manager.getEmail());
 }