コード例 #1
0
ファイル: GymService.java プロジェクト: DPIRPSG/DP8Entrega
  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);
      }
    }
  }
コード例 #2
0
ファイル: GymService.java プロジェクト: DPIRPSG/DP8Entrega
  public Collection<ArrayList<Integer>> numbersOfCustomersByGym(Collection<Gym> gyms) {
    Collection<ArrayList<Integer>> result;
    Integer customerNumber;
    ArrayList<Integer> result2;

    result = new ArrayList<ArrayList<Integer>>();

    for (Gym gym : gyms) {
      result2 = new ArrayList<Integer>();
      customerNumber = customerService.numbersOfCustomersByGym(gym.getId());
      result2.add(gym.getId());
      result2.add(customerNumber);
      result.add(result2);
    }

    return result;
  }
コード例 #3
0
ファイル: GymService.java プロジェクト: DPIRPSG/DP8Entrega
  public void delete(Gym gym) {
    Assert.notNull(gym);
    Assert.isTrue(gym.getId() != 0);
    Assert.isTrue(actorService.checkAuthority("ADMIN"), "Only an admin can delete gyms");
    Assert.isTrue(gym.getFeePayments().isEmpty());
    Assert.isTrue(gym.getBookings().isEmpty());
    Assert.isTrue(gym.getComments().isEmpty());

    Collection<ServiceEntity> services;

    services = serviceService.findAll();

    for (ServiceEntity service : services) {
      service.removeGym(gym);
      serviceService.save(service);
    }

    gymRepository.delete(gym);
  }