Example usage for org.apache.commons.validator.routines EmailValidator getInstance

List of usage examples for org.apache.commons.validator.routines EmailValidator getInstance

Introduction

In this page you can find the example usage for org.apache.commons.validator.routines EmailValidator getInstance.

Prototype

public static EmailValidator getInstance() 

Source Link

Document

Returns the Singleton instance of this validator.

Usage

From source file:org.apache.rave.portal.web.validator.UserProfileValidator.java

private boolean isInvalidEmailAddress(String emailAddress) {
    return !EmailValidator.getInstance().isValid(emailAddress);
}

From source file:org.berkholz.vcard2fritzXML.EMail.java

/**
 * Validate a mail address.//from   w  ww  . j a v  a  2  s.c o m
 * 
 * @param email Mail address as String representation.
 * @return True if mail address is valid, otherwise false.
 */
public static boolean validateEmail(String email) {
    if (email.isEmpty()) {
        // if no mail is in the contact, we accept an empty string
        return true;
    } else {
        // Get an EmailValidator
        EmailValidator validator = EmailValidator.getInstance();

        // Validate an email address
        return validator.isValid(email);
    }
}

From source file:org.businessmanager.web.controller.page.contact.ContactEditController.java

private boolean validateInput() {
    boolean isValid = true;

    if (bean.getFirstname() == null || bean.getFirstname().isEmpty()) {
        addMessage(FacesMessage.SEVERITY_WARN, "editcontact_warn_no_firstname");
        isValid = false;/*  w w w .  j  av a  2s. com*/
    }

    if (bean.getLastname() == null || bean.getLastname().isEmpty()) {
        addMessage(FacesMessage.SEVERITY_WARN, "editcontact_warn_no_lastname");
        isValid = false;
    }

    for (ContactItemBean item : getEmailList()) {
        if (item.getValue() != null && !EmailValidator.getInstance().isValid(item.getValue())) {
            addExtendedMessage(FacesMessage.SEVERITY_WARN, "editcontact_warn_invalid_mail",
                    "(" + item.getValue() + ")");
            isValid = false;
        }
    }

    return isValid;
}

From source file:org.catrobat.jira.adminhelper.rest.UserRest.java

@PUT
@Path("/createUser")
@Consumes(MediaType.APPLICATION_JSON)//w w  w  .j a va 2s . c o  m
public Response createUser(final JsonUser jsonUser, @Context HttpServletRequest request) {
    Response unauthorized = checkPermission(request);
    if (unauthorized != null) {
        return unauthorized;
    }

    if (jsonUser.getFirstName() == null || jsonUser.getLastName() == null || jsonUser.getUserName() == null
            || !EmailValidator.getInstance().isValid(jsonUser.getEmail())) {
        return Response.serverError().entity("Please check all input fields.").build();
    }

    UserManager userManager = ComponentAccessor.getUserManager();
    if (userManager.getUserByName(jsonUser.getUserName()) != null) {
        return Response.serverError().entity("User already exists!").build();
    }

    JsonConfig config = new JsonConfig(configService);

    try {
        UserTemplate user = new UserTemplate(jsonUser.getUserName(), config.getUserDirectoryId());
        user.setFirstName(jsonUser.getFirstName());
        user.setLastName(jsonUser.getLastName());
        user.setEmailAddress(jsonUser.getEmail());
        user.setDisplayName(jsonUser.getFirstName() + " " + jsonUser.getLastName());
        user.setActive(true);
        String password = RandomStringUtils.random(16, 0, 0, true, true, null, new SecureRandom());
        PasswordCredential credential = new PasswordCredential(password);
        directoryManager.addUser(config.getUserDirectoryId(), user, credential);
        sendEmail(jsonUser.getFirstName(), jsonUser.getUserName(), jsonUser.getEmail(), password);
    } catch (DirectoryNotFoundException e) {
        e.printStackTrace();
        return Response.serverError().entity("User-Directory was not found. Please check the settings!")
                .build();
    } catch (InvalidCredentialException e) {
        e.printStackTrace();
        return Response.serverError().entity("User's credential do not meet requirements of directory.")
                .build();
    } catch (InvalidUserException e) {
        e.printStackTrace();
        return Response.serverError().entity("Required user properties are not given.").build();
    } catch (UserAlreadyExistsException e) {
        e.printStackTrace();
        return Response.serverError().entity("User already exists in this directory!").build();
    } catch (OperationFailedException e) {
        e.printStackTrace();
        return Response.serverError().entity("Operation failed on directory implementation.").build();
    } catch (DirectoryPermissionException e) {
        e.printStackTrace();
        return Response.serverError().entity("Not enough permissions to create user in directory").build();
    }

    ApplicationUser jiraUser = userManager.getUserByName(jsonUser.getUserName());
    if (jiraUser == null) {
        return Response.serverError().entity("User creation failed.").build();
    }

    ExtendedPreferences extendedPreferences = userPreferencesManager.getExtendedPreferences(jiraUser);
    try {
        extendedPreferences.setText(GITHUB_PROPERTY, jsonUser.getGithubName());
    } catch (AtlassianCoreException e) {
        e.printStackTrace();
    }

    // User just needs to be added to default github team if desired
    Response response = addUserToGithubAndJiraGroups(jsonUser, jiraUser, config);
    if (response != null && response.getStatus() == Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) {
        return response;
    }

    return Response.ok().build();
}

From source file:org.cherchgk.actions.security.SignUpAction.java

@Override
public String execute() throws Exception {
    String login = ActionContextHelper.getRequestParameterValue("login");
    String email = ActionContextHelper.getRequestParameterValue("email");
    String password = ActionContextHelper.getRequestParameterValue("password");
    String password2 = ActionContextHelper.getRequestParameterValue("password2");

    boolean validationResult = true;

    if ((login == null) || "".equals(login)) {
        addActionError("    ?");
        validationResult = false;//  w  ww.j ava2 s. co  m
    } else {
        if (securityService.getUserByName(login) != null) {
            addActionError(
                    " ?    ??");
            validationResult = false;
        }
    }

    if (!EmailValidator.getInstance().isValid(email)) {
        addActionError("  ? ? ");
        validationResult = false;
    } else {
        if (securityService.getUserByEmail(email) != null) {
            addActionError(
                    " ?  ? ?   ?");
            validationResult = false;
        }
    }

    if ((password == null) || "".equals(password)) {
        addActionError("    ?");
        validationResult = false;
    }

    if ((password != null) && !password.equals(password2)) {
        addActionError(
                "      ?");
        validationResult = false;
    }

    if (!validationResult) {
        return Action.ERROR;
    }

    try {
        securityService.registerNewUser(login, password, email);
        addActionMessage(
                "? ?  ?   ? ? ? .");
    } catch (Exception ex) {
        addActionError("??  ?.");
        return Action.ERROR;
    }

    return Action.SUCCESS;
}

From source file:org.clebi.subscribers.model.Email.java

@Override
public boolean isValid() {
    return EmailValidator.getInstance().isValid(email);
}

From source file:org.codehaus.griffon.runtime.validation.constraints.EmailConstraint.java

@Override
protected void processValidate(@Nonnull Object target, Object propertyValue, @Nonnull Errors errors) {
    if (!email) {
        return;/*from  w w  w .  ja  va  2  s.  co  m*/
    }

    EmailValidator emailValidator = EmailValidator.getInstance();
    Object[] args = new Object[] { constraintPropertyName, constraintOwningClass, propertyValue };

    String value = propertyValue.toString();
    if (isBlank(value)) {
        return;
    }

    if (!emailValidator.isValid(value)) {
        rejectValue(target, errors, DEFAULT_INVALID_EMAIL_MESSAGE_CODE, VALIDATION_DSL_NAME + INVALID_SUFFIX,
                args);
    }
}

From source file:org.daybreak.emailler.utils.ExcelPipeline.java

@Override
public void process(ResultItems resultItems, Task task) {
    String link = null;//w w w .ja  v a2  s  . c  o  m
    Object emails = null;
    for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
        if ("emails".equals(entry.getKey())) {
            emails = entry.getValue();
        } else if ("link".equals(entry.getKey())) {
            link = entry.getValue().toString();
        }
    }

    if (link != null && emails != null) {
        if (emails instanceof Iterable) {
            for (Object emailItem : (Iterable) emails) {
                if (EmailValidator.getInstance().isValid(emailItem.toString())) {
                    final EmailAddress emailAdress = EmailFilter
                            .filter(new EmailAddress(emailItem.toString().toLowerCase()), crawler);
                    if (StringUtils.isNotEmpty(emailAdress.getDomain())) {
                        EAExistenceVerifier.verify(preyService, crawler, emailAdress.getAddress().toLowerCase(),
                                link);
                    }
                }
            }
        } else if (emails instanceof String) {
            if (EmailValidator.getInstance().isValid((String) emails)) {
                final EmailAddress emailAdress = EmailFilter
                        .filter(new EmailAddress(((String) emails).toLowerCase()), crawler);
                if (StringUtils.isNotEmpty(emailAdress.getDomain())) {
                    EAExistenceVerifier.verify(preyService, crawler, emailAdress.getAddress().toLowerCase(),
                            link);
                }
            }
        }
    }
}

From source file:org.duracloud.notification.AmazonNotificationFactory.java

@Override
public Emailer getEmailer(String fromAddress) {
    if (null == fromAddress || !EmailValidator.getInstance().isValid(fromAddress)) {
        String msg = "fromAddress not valid notification: " + fromAddress;
        log.error(msg);// w  w  w . j  a  va2 s. c  om
        throw new IllegalArgumentException(msg);
    }

    if (null == emailService) {
        String msg = "Emailer service !initialized.";
        log.error(msg);
        throw new DuraCloudRuntimeException(msg);
    }

    Emailer emailer = emailerMap.get(fromAddress);
    if (null == emailer) {
        emailer = new AmazonEmailer(emailService, fromAddress);
        emailerMap.put(fromAddress, emailer);
    }

    return emailer;
}

From source file:org.entirej.ejinvoice.forms.customer.CustomerContactsFormActionProcessor.java

@Override
public void executeActionCommand(EJForm form, String blockName, String command, EJScreenType screenType)
        throws EJActionProcessorException {
    EJRecord record = form.getBlock(blockName).getFocusedRecord();

    if (F_CUSTOMER_CONTACTS.AC_QUERY_CONTACTS.equals(command)) {
        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.ID).executeQuery();
    } else if (F_CUSTOMER_CONTACTS.AC_ADD_NEW_CONTACT.equals(command)) {
        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID).clear(true);
        EJRecord insertRecord = form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID)
                .getFocusedRecord();/*from w w  w  . j  a  va 2  s.c o m*/

        Integer customerId = (Integer) form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_TOOLBAR.ID)
                .getFocusedRecord().getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_TOOLBAR.I_CUSTOMER_ID);
        if (customerId != null) {
            insertRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_ID, customerId);
        }

        insertRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_INSERT_PAGE_TITLE,
                "Create a new Customer Contact");
        form.showStackedCanvasPage(F_CUSTOMER_CONTACTS.C_MAIN_STACK,
                F_CUSTOMER_CONTACTS.C_MAIN_STACK_PAGES.INSERT);
        form.setFormParameter(F_CUSTOMER_CONTACTS.P_IN_EDIT_MODE, true);
    } else if (F_CUSTOMER_CONTACTS.AC_DELETE_CUSTOMER_CONTACT.equals(command)) {
        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.ID)
                .askToDeleteCurrentRecord("Are you sure you want to delete this contact?");
    } else if (F_CUSTOMER_CONTACTS.AC_EDIT_CONTACT.equals(command)) {
        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID).clear(true);
        EJRecord editRecord = form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID).getFocusedRecord();

        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_UPDATE_PAGE_TITLE,
                (record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_FIRST_NAME) + " "
                        + record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_FIRST_NAME))
                        + " - Edit");

        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_CONTACT_TYPES_ID));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_VALUE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_CONTACT_TYPE));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_EMAIL,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_EMAIL));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_FIRST_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_FIRST_NAME));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_LAST_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_LAST_NAME));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_MOBILE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_MOBILE));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_PHONE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_PHONE));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_SALUTATIONS_ID));
        editRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID_VALUE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_SALUTATION));

        form.showStackedCanvasPage(F_CUSTOMER_CONTACTS.C_MAIN_STACK,
                F_CUSTOMER_CONTACTS.C_MAIN_STACK_PAGES.EDIT);
        form.setFormParameter(F_CUSTOMER_CONTACTS.P_IN_EDIT_MODE, true);
    } else if (F_CUSTOMER_CONTACTS.AC_EDIT_SAVE.equals(command)) {
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_ID);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_EMAIL);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_LAST_NAME);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID);

        Integer contactTypeId = (Integer) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_ID);
        String email = (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_EMAIL);
        String lastName = (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_LAST_NAME);
        Integer salutationId = (Integer) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID);

        boolean error = false;
        if (contactTypeId == null) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_ID,
                    "Please choose a contact type");
        }
        if (email == null || email.trim().length() == 0) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_EMAIL, "Please enter a valid email address");
        }
        if (lastName == null || lastName.trim().length() == 0) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_LAST_NAME, "Please enter a last name");
        }
        if (salutationId == null) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_MOBILE, "Please choose a salutation");
        }
        if (error) {
            throw new EJActionProcessorException();
        }
        EJRecord baseRecord = form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.ID).getFocusedRecord();

        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_CONTACT_TYPES_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_ID));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_EMAIL,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_EMAIL));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_FIRST_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_FIRST_NAME));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_LAST_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_LAST_NAME));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_MOBILE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_MOBILE));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_PHONE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_PHONE));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_SALUTATIONS_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID));

        CustomerContact customerContact = (CustomerContact) baseRecord.getBlockServicePojo();

        customerContact.setContactType(
                (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_VALUE));
        customerContact.setSalutation(
                (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID_VALUE));
        baseRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_DISPLAY_TEXT,
                customerContact.getDisplayText());

        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.ID).updateRecord(baseRecord);
        form.saveChanges();

        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID).clear(true);

        form.showStackedCanvasPage(F_CUSTOMER_CONTACTS.C_MAIN_STACK,
                F_CUSTOMER_CONTACTS.C_MAIN_STACK_PAGES.MAIN);
        form.setFormParameter(F_CUSTOMER_CONTACTS.P_IN_EDIT_MODE, false);
    } else if (F_CUSTOMER_CONTACTS.AC_INSERT_SAVE.equals(command)) {
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_ID);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_EMAIL);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_LAST_NAME);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_SALUTATIONS_ID);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CONTACT_TYPES_ID);

        Integer customerId = (Integer) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_ID);
        Integer contactTypeId = (Integer) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CONTACT_TYPES_ID);
        Integer salutationsId = (Integer) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_SALUTATIONS_ID);
        String contactLastName = (String) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_LAST_NAME);
        String email = (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_EMAIL);

        boolean error = false;

        if (customerId == null) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_ID, "Please choose a customer");
        }
        if (contactTypeId == null) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CONTACT_TYPES_ID,
                    "Please choose a type for the default contact");
        }
        if (salutationsId == null) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_SALUTATIONS_ID,
                    "Please enter a salutation for the default contact");
        }
        if (contactLastName == null) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_LAST_NAME,
                    "Please enter a last name for the default contact");
        }
        if (!EmailValidator.getInstance().isValid(email)) {
            error = true;
            setError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                    F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_EMAIL,
                    "The email address you have entered is not a valid email address");
        }

        if (error) {
            throw new EJApplicationException();
        }
        Integer companyId = (Integer) form.getApplicationLevelParameter(EJ_PROPERTIES.P_COMPANY_ID).getValue();
        EJRecord newRecord = form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.ID).createRecord();

        int idSeqNextval = PKSequenceService.getPKSequence(form.getConnection());
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_ID, idSeqNextval);
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_COMPANY_ID, companyId);
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_CONTACT_TYPES_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CONTACT_TYPES_ID));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_CUSTOMER_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_ID));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_CUSTOMER_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_NAME));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_EMAIL, email);
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_FIRST_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_FIRST_NAME));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_LAST_NAME,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_LAST_NAME));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_MOBILE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_MOBILE));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_PHONE,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_PHONE));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_SALUTATIONS_ID,
                record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_SALUTATIONS_ID));
        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_COMPANY_ID, companyId);

        CustomerContact customerContact = (CustomerContact) newRecord.getBlockServicePojo();
        customerContact.setCustomerName(
                (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_NAME));
        customerContact.setContactType(
                (String) record.getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CONTACT_TYPES_VALUE));
        customerContact.setSalutation((String) record
                .getValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_SALUTATIONS_ID_VALUE));

        newRecord.setValue(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.I_DISPLAY_TEXT,
                customerContact.getDisplayText());

        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS.ID).insertRecord(newRecord);
        form.saveChanges();
        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID).clear(true);
        form.showStackedCanvasPage(F_CUSTOMER_CONTACTS.C_MAIN_STACK,
                F_CUSTOMER_CONTACTS.C_MAIN_STACK_PAGES.MAIN);
        form.setFormParameter(F_CUSTOMER_CONTACTS.P_IN_EDIT_MODE, false);
    } else if (F_CUSTOMER_CONTACTS.AC_EDIT_CANCEL.equals(command)) {
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_CONTACT_TYPES_ID);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_EMAIL);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_LAST_NAME);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.I_SALUTATIONS_ID);

        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_EDIT.ID).clear(true);
        form.showStackedCanvasPage(F_CUSTOMER_CONTACTS.C_MAIN_STACK,
                F_CUSTOMER_CONTACTS.C_MAIN_STACK_PAGES.MAIN);
        form.setFormParameter(F_CUSTOMER_CONTACTS.P_IN_EDIT_MODE, false);
    } else if (F_CUSTOMER_CONTACTS.AC_INSERT_CANCEL.equals(command)) {
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CUSTOMER_ID);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_EMAIL);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_LAST_NAME);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_SALUTATIONS_ID);
        clearError(form, F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID,
                F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.I_CONTACT_TYPES_ID);

        form.getBlock(F_CUSTOMER_CONTACTS.B_CUSTOMER_CONTACTS_INSERT.ID).clear(true);
        form.showStackedCanvasPage(F_CUSTOMER_CONTACTS.C_MAIN_STACK,
                F_CUSTOMER_CONTACTS.C_MAIN_STACK_PAGES.MAIN);
        form.setFormParameter(F_CUSTOMER_CONTACTS.P_IN_EDIT_MODE, false);
    }

}