public void addVisit(Visit visit) { getVisitsInternal().add(visit); visit.setPetId(this.getId()); }
@Override public void validate(Object obj, Errors errors) { Pet pet = (Pet) obj; String name = pet.getName(); // name validation if (!StringUtils.hasLength(name)) { errors.rejectValue("name", REQUIRED, REQUIRED); } // type validation if (pet.isNew() && pet.getType() == null) { errors.rejectValue("type", REQUIRED, REQUIRED); } // birth date validation if (pet.getBirthDate() == null) { errors.rejectValue("birthDate", REQUIRED, REQUIRED); } }
/** * Return the Pet with the given name, or null if none found for this Owner. * * @param name to test * @return true if pet name is already in use */ public Pet getPet(String name, boolean ignoreNew) { name = name.toLowerCase(); for (Pet pet : getPetsInternal()) { if (!ignoreNew || !pet.isNew()) { String compName = pet.getName(); compName = compName.toLowerCase(); if (compName.equals(name)) { return pet; } } } return null; }
@RequestMapping(value = "/owner/{ownerId}/getVisits", method = RequestMethod.GET) public ResponseEntity<List<Visit>> getOwnerVisits(@PathVariable int ownerId){ List<Pet> petList = this.owners.findById(ownerId).getPets(); List<Visit> visitList = new ArrayList<Visit>(); petList.forEach(pet -> visitList.addAll(pet.getVisits())); return new ResponseEntity<List<Visit>>(visitList, HttpStatus.OK); } }
public List<Visit> getVisits() { List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal()); PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false)); return Collections.unmodifiableList(sortedVisits); }