@Override public String toString() { return this.getName(); }
/** * 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) { return getPet(name, false); }
@Override public String print(PetType petType, Locale locale) { return petType.getName(); }
@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); } }
@Override public String toString() { return new ToStringCreator(this) .append("id", this.getId()) .append("new", this.isNew()) .append("lastName", this.getLastName()) .append("firstName", this.getFirstName()) .append("address", this.address) .append("city", this.city) .append("telephone", this.telephone) .toString(); } }
public void addPet(Pet pet) { if (pet.isNew()) { getPetsInternal().add(pet); } pet.setOwner(this); }
public void addVisit(Visit visit) { getVisitsInternal().add(visit); visit.setPetId(this.getId()); }
/** * 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 int getNrOfSpecialties() { return getSpecialtiesInternal().size(); }
public List<Pet> getPets() { List<Pet> sortedPets = new ArrayList<>(getPetsInternal()); PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedPets); }
public List<Visit> getVisits() { List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal()); PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false)); return Collections.unmodifiableList(sortedVisits); }
@Override public String toString() { return this.getName(); }
public void addSpecialty(Specialty specialty) { getSpecialtiesInternal().add(specialty); }
@Override public PetType parse(String text, Locale locale) throws ParseException { Collection<PetType> findPetTypes = this.pets.findPetTypes(); for (PetType type : findPetTypes) { if (type.getName().equals(text)) { return type; } } throw new ParseException("type not found: " + text, 0); }
@Override public String toString() { return this.getName(); }
@XmlElement public List<Specialty> getSpecialties() { List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedSpecs); }