Exemple #1
0
  public void saveToEdit(Gym gym) {
    Assert.notNull(gym);
    Assert.isTrue(actorService.checkAuthority("ADMIN"), "Only an admin can save gyms");

    Collection<ServiceEntity> services;
    Collection<ServiceEntity> servicesPreSave;
    ServiceEntity fitness;

    servicesPreSave = new ArrayList<ServiceEntity>();

    fitness = serviceService.findOneByName("Fitness");
    if (gym.getServices() == null) {
      gym.setServices(new ArrayList<ServiceEntity>());
    }
    gym.addService(fitness);

    if (gym.getId() != 0) {
      Gym gymPreSave;
      Collection<Booking> bookings;
      Collection<FeePayment> feePayments;
      Collection<Comment> comments;

      gymPreSave = gymRepository.findOne(gym.getId());

      bookings = gymPreSave.getBookings();
      feePayments = gymPreSave.getFeePayments();
      comments = gymPreSave.getComments();
      servicesPreSave = new ArrayList<ServiceEntity>(gymPreSave.getServices());

      Assert.isTrue(
          gym.getBookings().containsAll(bookings) && gym.getBookings().size() == bookings.size());
      Assert.isTrue(
          gym.getFeePayments().containsAll(feePayments)
              && gym.getFeePayments().size() == feePayments.size());
      Assert.isTrue(
          gym.getComments().containsAll(comments) && gym.getComments().size() == comments.size());
    }
    services = gym.getServices();

    gym = this.save(gym);

    for (ServiceEntity service : services) {
      if (!servicesPreSave.contains(service)) {
        service.addGym(gym);
        serviceService.save(service);
      }
    }

    for (ServiceEntity service : servicesPreSave) {
      if (!services.contains(service)) {
        service.removeGym(gym);
        serviceService.save(service);
      }
    }
  }
Exemple #2
0
  public Gym create() {
    Assert.isTrue(actorService.checkAuthority("ADMIN"), "Only an admin can create gyms");

    Gym result;
    Collection<ServiceEntity> services;
    Collection<Comment> comments;
    Collection<FeePayment> feePayments;
    Collection<Booking> bookings;

    services = new ArrayList<>();
    feePayments = new ArrayList<>();
    comments = new ArrayList<>();
    bookings = new ArrayList<>();

    result = new Gym();

    result.setServices(services);
    result.setFeePayments(feePayments);
    result.setComments(comments);
    result.setBookings(bookings);

    return result;
  }