20
20
21
21
import jakarta .validation .Valid ;
22
22
23
+ import org .slf4j .Logger ;
24
+ import org .slf4j .LoggerFactory ;
23
25
import org .springframework .data .domain .Page ;
24
26
import org .springframework .data .domain .PageRequest ;
25
27
import org .springframework .data .domain .Pageable ;
28
+ import org .springframework .samples .petclinic .clm .ClmController ;
26
29
import org .springframework .stereotype .Controller ;
27
30
import org .springframework .ui .Model ;
28
31
import org .springframework .validation .BindingResult ;
@@ -49,6 +52,7 @@ class OwnerController {
49
52
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm" ;
50
53
51
54
private final OwnerRepository owners ;
55
+ private static final Logger logger = LoggerFactory .getLogger (OwnerController .class );
52
56
53
57
public OwnerController (OwnerRepository clinicService ) {
54
58
this .owners = clinicService ;
@@ -61,7 +65,12 @@ public void setAllowedFields(WebDataBinder dataBinder) {
61
65
62
66
@ ModelAttribute ("owner" )
63
67
public Owner findOwner (@ PathVariable (name = "ownerId" , required = false ) Integer ownerId ) {
64
- return ownerId == null ? new Owner () : this .owners .findById (ownerId );
68
+ if (ownerId == null ) {
69
+ logger .info ("OwnerId NULL" );
70
+ return new Owner ();
71
+ }
72
+
73
+ return this .owners .findById (ownerId );
65
74
}
66
75
67
76
@ GetMapping ("/owners/new" )
@@ -74,6 +83,7 @@ public String initCreationForm(Map<String, Object> model) {
74
83
@ PostMapping ("/owners/new" )
75
84
public String processCreationForm (@ Valid Owner owner , BindingResult result , RedirectAttributes redirectAttributes ) {
76
85
if (result .hasErrors ()) {
86
+ logger .error ("Error Creating New Owner; Validation Failed" );
77
87
redirectAttributes .addFlashAttribute ("error" , "There was an error in creating the owner." );
78
88
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM ;
79
89
}
@@ -143,6 +153,7 @@ public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model mo
143
153
public String processUpdateOwnerForm (@ Valid Owner owner , BindingResult result , @ PathVariable ("ownerId" ) int ownerId ,
144
154
RedirectAttributes redirectAttributes ) {
145
155
if (result .hasErrors ()) {
156
+ logger .error ("Error Updating Owner; Validation Failed" );
146
157
redirectAttributes .addFlashAttribute ("error" , "There was an error in updating the owner." );
147
158
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM ;
148
159
}
0 commit comments