return clazz.equals(Phone.class);
}
public void validate(Object obj, Errors errors) {
//use regular phone
CustomerPhone cPhone = (CustomerPhone) obj;
if (!errors.hasErrors()) {
//check for duplicate phone number
List<CustomerPhone> phones = customerPhoneService.readAllCustomerPhonesByCustomerId(cPhone.getCustomer().getId());
String phoneNum = cPhone.getPhone().getPhoneNumber();
String phoneName = cPhone.getPhoneName();
Long phoneId = cPhone.getPhone().getId();
Long customerPhoneId = cPhone.getId();
boolean foundPhoneIdForUpdate = false;
boolean foundCustomerPhoneIdForUpdate = false;
for (CustomerPhone existingPhone : phones) {
//validate that the phoneId passed for an editPhone scenario exists for this user
if(phoneId != null && !foundPhoneIdForUpdate){
if(existingPhone.getPhone().getId().equals(phoneId)){
foundPhoneIdForUpdate = true;
}
}
//validate that the customerPhoneId passed for an editPhone scenario exists for this user
if(customerPhoneId != null && !foundCustomerPhoneIdForUpdate){
if(existingPhone.getId().equals(customerPhoneId)){
foundCustomerPhoneIdForUpdate = true;
}
}
if(existingPhone.getId().equals(cPhone.getId())){
continue;
}
if(phoneNum.equals(existingPhone.getPhone().getPhoneNumber())){
errors.pushNestedPath("phone");