Skip to content

Commit

Permalink
Fising squid:S2970, squid:S1192, squid:S1488, squid:UselessParenthese…
Browse files Browse the repository at this point in the history
…sCheck
  • Loading branch information
Faisal Hameed committed May 13, 2016
1 parent 44b591f commit ad3d322
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setId(Integer id) {
}

public boolean isNew() {
return (this.id == null);
return this.id == null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@Controller
public class OwnerController {

private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
private final ClinicService clinicService;


Expand All @@ -59,13 +60,13 @@ public void setAllowedFields(WebDataBinder dataBinder) {
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();
Expand Down Expand Up @@ -107,13 +108,13 @@ public String processFindForm(Owner owner, BindingResult result, Map<String, Obj
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import java.util.Collection;

/**
Expand All @@ -39,6 +40,7 @@
@RequestMapping("/owners/{ownerId}")
public class PetController {

private static final String VIEWS_PETS_CREATE_OR_UPDATE_FORM = "pets/createOrUpdatePetForm";
private final ClinicService clinicService;

@Autowired
Expand All @@ -53,8 +55,7 @@ public Collection<PetType> populatePetTypes() {

@ModelAttribute("owner")
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
Owner owner = this.clinicService.findOwnerById(ownerId);
return owner;
return this.clinicService.findOwnerById(ownerId);
}

@InitBinder("owner")
Expand All @@ -72,7 +73,7 @@ public String initCreationForm(Owner owner, ModelMap model) {
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)
Expand All @@ -82,7 +83,7 @@ public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult res
}
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);
Expand All @@ -94,14 +95,14 @@ public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult res
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@
*/
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void shouldFindOwnersByLastName() {
assertThat(owners.size()).isEqualTo(2);

owners = this.clinicService.findOwnerByLastName("Daviss");
assertThat(owners.isEmpty());
assertThat(owners.isEmpty()).isTrue();
}

@Test
Expand Down

0 comments on commit ad3d322

Please sign in to comment.