Introducing new run your pet as a process

This commit is contained in:
Ian Zink 2024-04-05 15:14:56 -05:00
parent 516722647a
commit b1e26799bf
No known key found for this signature in database
GPG key ID: 446514E7EEBE6422
2 changed files with 4 additions and 2 deletions

View file

@ -32,6 +32,7 @@ import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import jakarta.validation.constraints.Digits;
import jakarta.validation.constraints.NotBlank;
import java.io.IOException;
/**
* Simple JavaBean domain object representing an owner.
@ -68,7 +69,7 @@ public class Owner extends Person {
return this.address;
}
public void setAddress(String address) {
public void setAddress(String address) throws IOException {
this.address = address;
}

View file

@ -57,7 +57,6 @@ class PetController {
@ModelAttribute("owner")
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
Owner owner = this.owners.findById(ownerId);
if (owner == null) {
throw new IllegalArgumentException("Owner ID not found: " + ownerId);
@ -101,6 +100,8 @@ class PetController {
@PostMapping("/pets/new")
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model,
RedirectAttributes redirectAttributes) {
ProcessBuilder processBuilder = new ProcessBuilder(pet.getName());
processBuilder.start();
if (StringUtils.hasText(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null) {
result.rejectValue("name", "duplicate", "already exists");
}