Java Code Examples for org.springframework.samples.petclinic.model.Pet#isNew()

The following examples show how to use org.springframework.samples.petclinic.model.Pet#isNew() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PetValidator.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@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");
    }
}
 
Example 2
Source File: PetValidator.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: PetValidator.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
public void validate(Pet pet, Errors errors) {
    String name = pet.getName();
    // name validaation
    if (!StringUtils.hasLength(name)) {
        errors.rejectValue("name", "required", "required");
    } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
        errors.rejectValue("name", "duplicate", "already exists");
    }
    
    // type valication
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", "required", "required");
    }
    
 // type valication
    if (pet.getBirthDate()==null) {
        errors.rejectValue("birthDate", "required", "required");
    }
}
 
Example 4
Source File: PetValidator.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
public void validate(Pet pet, Errors errors) {
    String name = pet.getName();
    // name validaation
    if (!StringUtils.hasLength(name)) {
        errors.rejectValue("name", "required", "required");
    } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
        errors.rejectValue("name", "duplicate", "already exists");
    }
    
    // type valication
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", "required", "required");
    }
    
 // type valication
    if (pet.getBirthDate()==null) {
        errors.rejectValue("birthDate", "required", "required");
    }
}
 
Example 5
Source File: PetController.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@RequestMapping(value = "/pets/new", method = RequestMethod.POST)
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
    if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null){
        result.rejectValue("name", "duplicate", "already exists");
    }
    if (result.hasErrors()) {
        model.put("pet", pet);
        return "pets/createOrUpdatePetForm";
    } else {
        owner.addPet(pet);
        this.clinicService.savePet(pet);
        return "redirect:/owners/{ownerId}";
    }
}
 
Example 6
Source File: JdbcPetRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public void save(Pet pet) throws DataAccessException {
    if (pet.isNew()) {
        Number newKey = this.insertPet.executeAndReturnKey(
            createPetParameterSource(pet));
        pet.setId(newKey.intValue());
    } else {
        this.namedParameterJdbcTemplate.update(
            "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
                "owner_id=:owner_id WHERE id=:id",
            createPetParameterSource(pet));
    }
}
 
Example 7
Source File: PetController.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@RequestMapping(value = "/pets/new", method = RequestMethod.POST)
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
    if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null){
        result.rejectValue("name", "duplicate", "already exists");
    }
    if (result.hasErrors()) {
        model.put("pet", pet);
        return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
    } else {
        owner.addPet(pet);
        this.clinicService.savePet(pet);
        return "redirect:/owners/{ownerId}";
    }
}
 
Example 8
Source File: JdbcPetRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public void save(Pet pet) throws DataAccessException {
    if (pet.isNew()) {
        Number newKey = this.insertPet.executeAndReturnKey(
            createPetParameterSource(pet));
        pet.setId(newKey.intValue());
    } else {
        this.namedParameterJdbcTemplate.update(
            "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
                "owner_id=:owner_id WHERE id=:id",
            createPetParameterSource(pet));
    }
}
 
Example 9
Source File: JdbcPetRepositoryImpl.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
public void save(Pet pet) throws DataAccessException {
    if (pet.isNew()) {
        Number newKey = this.insertPet.executeAndReturnKey(
                createPetParameterSource(pet));
        pet.setId(newKey.intValue());
    } else {
        this.namedParameterJdbcTemplate.update(
                "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
                        "owner_id=:owner_id WHERE id=:id",
                createPetParameterSource(pet));
    }
}
 
Example 10
Source File: JdbcPetRepositoryImpl.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void save(Pet pet) throws DataAccessException {
    if (pet.isNew()) {
        Number newKey = this.insertPet.executeAndReturnKey(
                createPetParameterSource(pet));
        pet.setId(newKey.intValue());
    } else {
        this.namedParameterJdbcTemplate.update(
                "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
                        "owner_id=:owner_id WHERE id=:id",
                createPetParameterSource(pet));
    }
}