Advertisement
Guest User

Untitled

a guest
Jan 7th, 2013
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. @Override
  2. @Transactional(readOnly = true)
  3. public Set<Location> getAllLocationDescendants(Location location, Set<Location> descendants) {
  4. if (descendants == null)
  5. descendants = new HashSet<Location>();
  6.  
  7. if (location != null) {
  8. Set<Location> childLocations = location.getChildLocations();
  9. for (Location childLocation : childLocations) {
  10. descendants.add(childLocation);
  11. getAllLocationDescendants(childLocation, descendants);
  12. }
  13. }
  14.  
  15. return descendants;
  16. }
  17.  
  18. @Override
  19. @Transactional(readOnly = true)
  20. public List<Appointment> getAppointmentsByConstraints(Date fromDate, Date toDate, Location location, Provider provider,
  21. AppointmentType type, String status) throws APIException {
  22.  
  23. List<Appointment> appointments = appointmentDAO.getAppointmentsByConstraints(fromDate, toDate, provider, type,
  24. status);
  25.  
  26. List<Appointment> appointmentsInLocation = new LinkedList<Appointment>();
  27.  
  28. Set<Location> relevantLocations = getAllLocationDescendants(location, null);
  29. relevantLocations.add(location);
  30.  
  31. for (Appointment appointment : appointments) {
  32. boolean satisfyingConstraints = true;
  33.  
  34. //Filter by location
  35. if (location != null) {
  36. if (relevantLocations.contains(appointment.getTimeSlot().getAppointmentBlock().getLocation()))
  37. appointmentsInLocation.add(appointment);
  38. } else
  39. appointmentsInLocation.add(appointment);
  40.  
  41. }
  42.  
  43. return appointmentsInLocation;
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement