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; }
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); }
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; }
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); } } }