Skip to content
Snippets Groups Projects
Commit ad3d322f authored by Faisal Hameed's avatar Faisal Hameed
Browse files

Fising squid:S2970, squid:S1192, squid:S1488, squid:UselessParenthesesCheck

parent 44b591f5
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ public class BaseEntity {
}
public boolean isNew() {
return (this.id == null);
return this.id == null;
}
}
......@@ -42,6 +42,7 @@ import org.springframework.web.servlet.ModelAndView;
@Controller
public class OwnerController {
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
private final ClinicService clinicService;
......@@ -59,13 +60,13 @@ public class OwnerController {
public String initCreationForm(Map<String, Object> model) {
Owner owner = new Owner();
model.put("owner", owner);
return "owners/createOrUpdateOwnerForm";
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}
@RequestMapping(value = "/owners/new", method = RequestMethod.POST)
public String processCreationForm(@Valid Owner owner, BindingResult result) {
if (result.hasErrors()) {
return "owners/createOrUpdateOwnerForm";
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
} else {
this.clinicService.saveOwner(owner);
return "redirect:/owners/" + owner.getId();
......@@ -107,13 +108,13 @@ public class OwnerController {
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
Owner owner = this.clinicService.findOwnerById(ownerId);
model.addAttribute(owner);
return "owners/createOrUpdateOwnerForm";
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
}
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.POST)
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId) {
if (result.hasErrors()) {
return "owners/createOrUpdateOwnerForm";
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
} else {
owner.setId(ownerId);
this.clinicService.saveOwner(owner);
......
......@@ -28,6 +28,7 @@ import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Collection;
/**
......@@ -39,6 +40,7 @@ import java.util.Collection;
@RequestMapping("/owners/{ownerId}")
public class PetController {
private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
private final ClinicService clinicService;
@Autowired
......@@ -53,8 +55,7 @@ public class PetController {
@ModelAttribute("owner")
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
Owner owner = this.clinicService.findOwnerById(ownerId);
return owner;
return this.clinicService.findOwnerById(ownerId);
}
@InitBinder("owner")
......@@ -72,7 +73,7 @@ public class PetController {
Pet pet = new Pet();
owner.addPet(pet);
model.put("pet", pet);
return "pets/createOrUpdatePetForm";
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
}
@RequestMapping(value = "/pets/new", method = RequestMethod.POST)
......@@ -82,7 +83,7 @@ public class PetController {
}
if (result.hasErrors()) {
model.put("pet", pet);
return "pets/createOrUpdatePetForm";
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
} else {
owner.addPet(pet);
this.clinicService.savePet(pet);
......@@ -94,14 +95,14 @@ public class PetController {
public String initUpdateForm(@PathVariable("petId") int petId, ModelMap model) {
Pet pet = this.clinicService.findPetById(petId);
model.put("pet", pet);
return "pets/createOrUpdatePetForm";
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
}
@RequestMapping(value = "/pets/{petId}/edit", method = RequestMethod.POST)
public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
if (result.hasErrors()) {
model.put("pet", pet);
return "pets/createOrUpdatePetForm";
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
} else {
owner.addPet(pet);
this.clinicService.savePet(pet);
......
......@@ -31,23 +31,25 @@ import org.springframework.validation.Validator;
*/
public class PetValidator implements Validator {
private static final String REQUIRED = "required";
@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");
errors.rejectValue("name", REQUIRED, REQUIRED);
}
// type validation
if (pet.isNew() && pet.getType() == null) {
errors.rejectValue("type", "required", "required");
errors.rejectValue("type", REQUIRED, REQUIRED);
}
// birth date validation
if (pet.getBirthDate() == null) {
errors.rejectValue("birthDate", "required", "required");
errors.rejectValue("birthDate", REQUIRED, REQUIRED);
}
}
......
......@@ -62,7 +62,7 @@ public abstract class AbstractClinicServiceTests {
assertThat(owners.size()).isEqualTo(2);
owners = this.clinicService.findOwnerByLastName("Daviss");
assertThat(owners.isEmpty());
assertThat(owners.isEmpty()).isTrue();
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment