@Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    Contact newContact = addContact();

    Contact existingContact = _persistence.fetchByPrimaryKey(newContact.getPrimaryKey());

    Assert.assertEquals(existingContact, newContact);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Contact contact = _persistence.create(pk);

    Assert.assertNotNull(contact);

    Assert.assertEquals(contact.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    Contact newContact = addContact();

    _persistence.remove(newContact);

    Contact existingContact = _persistence.fetchByPrimaryKey(newContact.getPrimaryKey());

    Assert.assertNull(existingContact);
  }
  protected void updateExpandoAttributes(User user, LDAPUser ldapUser) throws Exception {

    ExpandoBridge userExpandoBridge = user.getExpandoBridge();

    populateExpandoAttributes(userExpandoBridge, ldapUser.getUserExpandoAttributes());

    Contact contact = user.getContact();

    ExpandoBridge contactExpandoBridge = contact.getExpandoBridge();

    populateExpandoAttributes(contactExpandoBridge, ldapUser.getContactExpandoAttributes());
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    Contact newContact = addContact();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newContact.getPrimaryKey());

    Map<Serializable, Contact> contacts = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, contacts.size());
    Assert.assertEquals(newContact, contacts.get(newContact.getPrimaryKey()));
  }
  @Indexable(type = IndexableType.DELETE)
  @Override
  public Contact deleteContact(Contact contact) throws SystemException {

    // Contact

    contactPersistence.remove(contact);

    // Addresses

    addressLocalService.deleteAddresses(
        contact.getCompanyId(), Contact.class.getName(), contact.getContactId());

    // Email addresses

    emailAddressLocalService.deleteEmailAddresses(
        contact.getCompanyId(), Contact.class.getName(), contact.getContactId());

    // Phone

    phoneLocalService.deletePhones(
        contact.getCompanyId(), Contact.class.getName(), contact.getContactId());

    // Website

    websiteLocalService.deleteWebsites(
        contact.getCompanyId(), Contact.class.getName(), contact.getContactId());

    return contact;
  }
Ejemplo n.º 7
0
  @Override
  protected void doDelete(Object obj) throws Exception {
    User user = (User) obj;

    deleteDocument(user.getCompanyId(), user.getUserId());

    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(Contact.class);

    Contact contact = new ContactImpl();

    contact.setContactId(user.getContactId());
    contact.setCompanyId(user.getCompanyId());

    indexer.delete(contact);
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    Contact newContact = addContact();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Contact.class, _dynamicQueryClassLoader);

    dynamicQuery.add(RestrictionsFactoryUtil.eq("contactId", newContact.getContactId()));

    List<Contact> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Contact existingContact = result.get(0);

    Assert.assertEquals(existingContact, newContact);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    Contact newContact = addContact();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newContact.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, Contact> contacts = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, contacts.size());
    Assert.assertEquals(newContact, contacts.get(newContact.getPrimaryKey()));
  }
  public int compareTo(Contact contact) {
    long primaryKey = contact.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    Contact newContact = addContact();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(Contact.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("contactId"));

    Object newContactId = newContact.getContactId();

    dynamicQuery.add(RestrictionsFactoryUtil.in("contactId", new Object[] {newContactId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingContactId = result.get(0);

    Assert.assertEquals(existingContactId, newContactId);
  }
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }

    Contact contact = null;

    try {
      contact = (Contact) obj;
    } catch (ClassCastException cce) {
      return false;
    }

    long primaryKey = contact.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    Contact newContact1 = addContact();
    Contact newContact2 = addContact();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newContact1.getPrimaryKey());
    primaryKeys.add(newContact2.getPrimaryKey());

    Map<Serializable, Contact> contacts = _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, contacts.size());
    Assert.assertEquals(newContact1, contacts.get(newContact1.getPrimaryKey()));
    Assert.assertEquals(newContact2, contacts.get(newContact2.getPrimaryKey()));
  }
Ejemplo n.º 14
0
  private static void _updateAdminUser(
      HttpServletRequest request, UnicodeProperties unicodeProperties) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    Company company = CompanyLocalServiceUtil.getCompanyById(themeDisplay.getCompanyId());

    String emailAddress =
        ParamUtil.getString(
            request,
            "adminEmailAddress",
            PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + StringPool.AT + company.getMx());

    PropsValues.ADMIN_EMAIL_FROM_ADDRESS = emailAddress;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_ADDRESS, emailAddress);

    ScreenNameGenerator screenNameGenerator = ScreenNameGeneratorFactory.getInstance();

    String screenName =
        GetterUtil.getString(PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX, "test");

    try {
      screenName = screenNameGenerator.generate(0, 0, emailAddress);
    } catch (Exception e) {
    }

    String firstName =
        ParamUtil.getString(request, "adminFirstName", PropsValues.DEFAULT_ADMIN_FIRST_NAME);
    String lastName =
        ParamUtil.getString(request, "adminLastName", PropsValues.DEFAULT_ADMIN_LAST_NAME);

    FullNameGenerator fullNameGenerator = FullNameGeneratorFactory.getInstance();

    String fullName = fullNameGenerator.getFullName(firstName, null, lastName);

    PropsValues.ADMIN_EMAIL_FROM_NAME = fullName;

    unicodeProperties.put(PropsKeys.ADMIN_EMAIL_FROM_NAME, fullName);

    User user = null;

    try {
      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String greeting =
          LanguageUtil.format(
              themeDisplay.getLocale(), "welcome-x", StringPool.SPACE + fullName, false);

      Contact contact = user.getContact();

      Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

      birthdayCal.setTime(contact.getBirthday());

      int birthdayMonth = birthdayCal.get(Calendar.MONTH);
      int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
      int birthdayYear = birthdayCal.get(Calendar.YEAR);

      user =
          UserLocalServiceUtil.updateUser(
              user.getUserId(),
              StringPool.BLANK,
              StringPool.BLANK,
              StringPool.BLANK,
              false,
              user.getReminderQueryQuestion(),
              user.getReminderQueryAnswer(),
              screenName,
              emailAddress,
              user.getFacebookId(),
              user.getOpenId(),
              themeDisplay.getLanguageId(),
              user.getTimeZoneId(),
              greeting,
              user.getComments(),
              firstName,
              user.getMiddleName(),
              lastName,
              contact.getPrefixId(),
              contact.getSuffixId(),
              contact.isMale(),
              birthdayMonth,
              birthdayDay,
              birthdayYear,
              contact.getSmsSn(),
              contact.getAimSn(),
              contact.getFacebookSn(),
              contact.getIcqSn(),
              contact.getJabberSn(),
              contact.getMsnSn(),
              contact.getMySpaceSn(),
              contact.getSkypeSn(),
              contact.getTwitterSn(),
              contact.getYmSn(),
              contact.getJobTitle(),
              null,
              null,
              null,
              null,
              null,
              new ServiceContext());
    } catch (NoSuchUserException nsue) {
      UserLocalServiceUtil.addDefaultAdminUser(
          themeDisplay.getCompanyId(),
          screenName,
          emailAddress,
          themeDisplay.getLocale(),
          firstName,
          StringPool.BLANK,
          lastName);

      user = UserLocalServiceUtil.getUserByEmailAddress(themeDisplay.getCompanyId(), emailAddress);

      String defaultAdminEmailAddress =
          PropsValues.DEFAULT_ADMIN_EMAIL_ADDRESS_PREFIX + "@" + PropsValues.COMPANY_DEFAULT_WEB_ID;

      if (!emailAddress.equals(defaultAdminEmailAddress)) {
        User testUser =
            UserLocalServiceUtil.fetchUserByEmailAddress(
                themeDisplay.getCompanyId(), defaultAdminEmailAddress);

        if (testUser != null) {
          UserLocalServiceUtil.updateStatus(
              testUser.getUserId(), WorkflowConstants.STATUS_INACTIVE);
        }
      }
    }

    user = UserLocalServiceUtil.updatePasswordReset(user.getUserId(), true);

    HttpSession session = request.getSession();

    session.setAttribute(WebKeys.EMAIL_ADDRESS, emailAddress);
    session.setAttribute(WebKeys.SETUP_WIZARD_PASSWORD_UPDATED, true);
    session.setAttribute(WebKeys.USER_ID, user.getUserId());
  }
  protected void updateLDAPUser(User ldapUser, Contact ldapContact, User user)
      throws PortalException, SystemException {

    Contact contact = user.getContact();

    ldapContact.setAimSn(GetterUtil.getString(contact.getAimSn()));
    ldapContact.setFacebookSn(GetterUtil.getString(contact.getFacebookSn()));
    ldapContact.setIcqSn(GetterUtil.getString(contact.getIcqSn()));
    ldapContact.setJabberSn(GetterUtil.getString(contact.getJabberSn()));
    ldapContact.setMale(GetterUtil.getBoolean(contact.getMale()));
    ldapContact.setMsnSn(GetterUtil.getString(contact.getMsnSn()));
    ldapContact.setMySpaceSn(GetterUtil.getString(contact.getMySpaceSn()));
    ldapContact.setPrefixId(GetterUtil.getInteger(contact.getPrefixId()));
    ldapContact.setSkypeSn(GetterUtil.getString(contact.getSkypeSn()));
    ldapContact.setSmsSn(GetterUtil.getString(contact.getSmsSn()));
    ldapContact.setSuffixId(GetterUtil.getInteger(contact.getSuffixId()));
    ldapContact.setTwitterSn(GetterUtil.getString(contact.getTwitterSn()));
    ldapContact.setYmSn(GetterUtil.getString(contact.getYmSn()));

    ldapUser.setComments(GetterUtil.getString(user.getComments()));
    ldapUser.setGreeting(GetterUtil.getString(user.getGreeting()));
    ldapUser.setJobTitle(GetterUtil.getString(user.getJobTitle()));
    ldapUser.setLanguageId(GetterUtil.getString(user.getLanguageId()));
    ldapUser.setMiddleName(GetterUtil.getString(user.getMiddleName()));
    ldapUser.setOpenId(GetterUtil.getString(user.getOpenId()));
    ldapUser.setTimeZoneId(GetterUtil.getString(user.getTimeZoneId()));
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public Contact addContact(
      long userId,
      String className,
      long classPK,
      String emailAddress,
      String firstName,
      String middleName,
      String lastName,
      int prefixId,
      int suffixId,
      boolean male,
      int birthdayMonth,
      int birthdayDay,
      int birthdayYear,
      String smsSn,
      String aimSn,
      String facebookSn,
      String icqSn,
      String jabberSn,
      String msnSn,
      String mySpaceSn,
      String skypeSn,
      String twitterSn,
      String ymSn,
      String jobTitle)
      throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);
    Date birthday =
        PortalUtil.getDate(
            birthdayMonth, birthdayDay, birthdayYear, ContactBirthdayException.class);
    Date now = new Date();

    validate(className, classPK);

    long contactId = counterLocalService.increment();

    Contact contact = contactPersistence.create(contactId);

    contact.setCompanyId(user.getCompanyId());
    contact.setUserId(user.getUserId());
    contact.setUserName(user.getFullName());
    contact.setCreateDate(now);
    contact.setModifiedDate(now);
    contact.setClassName(className);
    contact.setClassPK(classPK);
    contact.setEmailAddress(emailAddress);
    contact.setFirstName(firstName);
    contact.setMiddleName(middleName);
    contact.setLastName(lastName);
    contact.setPrefixId(prefixId);
    contact.setSuffixId(suffixId);
    contact.setMale(male);
    contact.setBirthday(birthday);
    contact.setSmsSn(smsSn);
    contact.setAimSn(aimSn);
    contact.setFacebookSn(facebookSn);
    contact.setIcqSn(icqSn);
    contact.setJabberSn(jabberSn);
    contact.setMsnSn(msnSn);
    contact.setMySpaceSn(mySpaceSn);
    contact.setSkypeSn(skypeSn);
    contact.setTwitterSn(twitterSn);
    contact.setYmSn(ymSn);
    contact.setJobTitle(jobTitle);

    contactPersistence.update(contact);

    return contact;
  }
Ejemplo n.º 17
0
  protected User updateUser(User user, Userinfo userinfo) throws Exception {
    String emailAddress = userinfo.getEmail();
    String firstName = userinfo.getGivenName();
    String lastName = userinfo.getFamilyName();
    boolean male = Validator.equals(userinfo.getGender(), "male");

    if (emailAddress.equals(user.getEmailAddress())
        && firstName.equals(user.getFirstName())
        && lastName.equals(user.getLastName())
        && (male == user.isMale())) {

      return user;
    }

    Contact contact = user.getContact();

    Calendar birthdayCal = CalendarFactoryUtil.getCalendar();

    birthdayCal.setTime(contact.getBirthday());

    int birthdayMonth = birthdayCal.get(Calendar.MONTH);
    int birthdayDay = birthdayCal.get(Calendar.DAY_OF_MONTH);
    int birthdayYear = birthdayCal.get(Calendar.YEAR);

    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    List<UserGroupRole> userGroupRoles = null;
    long[] userGroupIds = null;

    ServiceContext serviceContext = new ServiceContext();

    if (!StringUtil.equalsIgnoreCase(emailAddress, user.getEmailAddress())) {

      UserLocalServiceUtil.updateEmailAddress(
          user.getUserId(), StringPool.BLANK, emailAddress, emailAddress);
    }

    UserLocalServiceUtil.updateEmailAddressVerified(user.getUserId(), true);

    return UserLocalServiceUtil.updateUser(
        user.getUserId(),
        StringPool.BLANK,
        StringPool.BLANK,
        StringPool.BLANK,
        false,
        user.getReminderQueryQuestion(),
        user.getReminderQueryAnswer(),
        user.getScreenName(),
        emailAddress,
        0,
        user.getOpenId(),
        user.getLanguageId(),
        user.getTimeZoneId(),
        user.getGreeting(),
        user.getComments(),
        firstName,
        user.getMiddleName(),
        lastName,
        contact.getPrefixId(),
        contact.getSuffixId(),
        male,
        birthdayMonth,
        birthdayDay,
        birthdayYear,
        contact.getSmsSn(),
        contact.getAimSn(),
        contact.getFacebookSn(),
        contact.getIcqSn(),
        contact.getJabberSn(),
        contact.getMsnSn(),
        contact.getMySpaceSn(),
        contact.getSkypeSn(),
        contact.getTwitterSn(),
        contact.getYmSn(),
        contact.getJobTitle(),
        groupIds,
        organizationIds,
        roleIds,
        userGroupRoles,
        userGroupIds,
        serviceContext);
  }
 private Contact createContact4User(User newUser) throws SystemException {
   Contact contact = ContactLocalServiceUtil.createContact(CounterLocalServiceUtil.increment());
   contact.setCompanyId(newUser.getCompanyId());
   contact.setCreateDate(new Date());
   contact.setUserName(newUser.getScreenName());
   contact.setUserId(newUser.getUserId());
   contact.setModifiedDate(new Date());
   contact.setFirstName("contact-" + contact.getContactId());
   contact.setLastName("contact-" + contact.getContactId());
   contact.setMiddleName("contact-" + contact.getContactId());
   contact.setBirthday(new Date());
   return ContactLocalServiceUtil.addContact(contact);
 }
Ejemplo n.º 19
0
  @Override
  public boolean contains(
      PermissionChecker permissionChecker, long userId, long[] organizationIds, String actionId) {

    if ((actionId.equals(ActionKeys.DELETE)
            || actionId.equals(ActionKeys.IMPERSONATE)
            || actionId.equals(ActionKeys.PERMISSIONS)
            || actionId.equals(ActionKeys.UPDATE))
        && PortalUtil.isOmniadmin(userId)
        && !permissionChecker.isOmniadmin()) {

      return false;
    }

    try {
      User user = null;

      if (userId != ResourceConstants.PRIMKEY_DNE) {
        user = UserLocalServiceUtil.getUserById(userId);

        Contact contact = user.getContact();

        if (permissionChecker.hasOwnerPermission(
                permissionChecker.getCompanyId(),
                User.class.getName(),
                userId,
                contact.getUserId(),
                actionId)
            || (permissionChecker.getUserId() == userId)) {

          return true;
        }
      }

      if (permissionChecker.hasPermission(0, User.class.getName(), userId, actionId)) {

        return true;
      }

      if (user == null) {
        return false;
      }

      if (organizationIds == null) {
        organizationIds = user.getOrganizationIds();
      }

      for (long organizationId : organizationIds) {
        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        if (OrganizationPermissionUtil.contains(
            permissionChecker, organization, ActionKeys.MANAGE_USERS)) {

          if (permissionChecker.getUserId() == user.getUserId()) {
            return true;
          }

          Group organizationGroup = organization.getGroup();

          // Organization administrators can only manage normal users.
          // Owners can only manage normal users and administrators.

          if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
              user.getUserId(),
              organizationGroup.getGroupId(),
              RoleConstants.ORGANIZATION_OWNER,
              true)) {

            continue;
          } else if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                  user.getUserId(),
                  organizationGroup.getGroupId(),
                  RoleConstants.ORGANIZATION_ADMINISTRATOR,
                  true)
              && !UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                  permissionChecker.getUserId(),
                  organizationGroup.getGroupId(),
                  RoleConstants.ORGANIZATION_OWNER,
                  true)) {

            continue;
          }

          return true;
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
  @Override
  protected void doVerify() throws Exception {
    List<User> users = UserLocalServiceUtil.getNoContacts();

    if (_log.isDebugEnabled()) {
      _log.debug("Processing " + users.size() + " users with no contacts");
    }

    Date now = new Date();

    for (User user : users) {
      if (_log.isDebugEnabled()) {
        _log.debug("Creating contact for user " + user.getUserId());
      }

      long contactId = CounterLocalServiceUtil.increment();

      Contact contact = ContactLocalServiceUtil.createContact(contactId);

      Company company = CompanyLocalServiceUtil.getCompanyById(user.getCompanyId());

      contact.setCompanyId(user.getCompanyId());
      contact.setUserId(user.getUserId());
      contact.setUserName(StringPool.BLANK);
      contact.setCreateDate(now);
      contact.setModifiedDate(now);
      contact.setAccountId(company.getAccountId());
      contact.setParentContactId(ContactConstants.DEFAULT_PARENT_CONTACT_ID);
      contact.setFirstName(user.getFirstName());
      contact.setMiddleName(user.getMiddleName());
      contact.setLastName(user.getLastName());
      contact.setPrefixId(0);
      contact.setSuffixId(0);
      contact.setJobTitle(user.getJobTitle());

      ContactLocalServiceUtil.updateContact(contact);

      user.setContactId(contactId);

      UserLocalServiceUtil.updateUser(user);
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Contacts verified for users");
    }

    users = UserLocalServiceUtil.getNoGroups();

    if (_log.isDebugEnabled()) {
      _log.debug("Processing " + users.size() + " users with no groups");
    }

    for (User user : users) {
      if (_log.isDebugEnabled()) {
        _log.debug("Creating group for user " + user.getUserId());
      }

      GroupLocalServiceUtil.addGroup(
          user.getUserId(),
          User.class.getName(),
          user.getUserId(),
          null,
          null,
          0,
          StringPool.SLASH + user.getScreenName(),
          false,
          true,
          null);
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Groups verified for users");
    }
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static Contact toModel(ContactSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    Contact model = new ContactImpl();

    model.setContactId(soapModel.getContactId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setClassNameId(soapModel.getClassNameId());
    model.setClassPK(soapModel.getClassPK());
    model.setAccountId(soapModel.getAccountId());
    model.setParentContactId(soapModel.getParentContactId());
    model.setEmailAddress(soapModel.getEmailAddress());
    model.setFirstName(soapModel.getFirstName());
    model.setMiddleName(soapModel.getMiddleName());
    model.setLastName(soapModel.getLastName());
    model.setPrefixId(soapModel.getPrefixId());
    model.setSuffixId(soapModel.getSuffixId());
    model.setMale(soapModel.getMale());
    model.setBirthday(soapModel.getBirthday());
    model.setSmsSn(soapModel.getSmsSn());
    model.setAimSn(soapModel.getAimSn());
    model.setFacebookSn(soapModel.getFacebookSn());
    model.setIcqSn(soapModel.getIcqSn());
    model.setJabberSn(soapModel.getJabberSn());
    model.setMsnSn(soapModel.getMsnSn());
    model.setMySpaceSn(soapModel.getMySpaceSn());
    model.setSkypeSn(soapModel.getSkypeSn());
    model.setTwitterSn(soapModel.getTwitterSn());
    model.setYmSn(soapModel.getYmSn());
    model.setEmployeeStatusId(soapModel.getEmployeeStatusId());
    model.setEmployeeNumber(soapModel.getEmployeeNumber());
    model.setJobTitle(soapModel.getJobTitle());
    model.setJobClass(soapModel.getJobClass());
    model.setHoursOfOperation(soapModel.getHoursOfOperation());

    return model;
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public Contact updateContact(
      long contactId,
      String emailAddress,
      String firstName,
      String middleName,
      String lastName,
      int prefixId,
      int suffixId,
      boolean male,
      int birthdayMonth,
      int birthdayDay,
      int birthdayYear,
      String smsSn,
      String aimSn,
      String facebookSn,
      String icqSn,
      String jabberSn,
      String msnSn,
      String mySpaceSn,
      String skypeSn,
      String twitterSn,
      String ymSn,
      String jobTitle)
      throws PortalException, SystemException {

    Date birthday =
        PortalUtil.getDate(
            birthdayMonth, birthdayDay, birthdayYear, ContactBirthdayException.class);

    Contact contact = contactPersistence.findByPrimaryKey(contactId);

    contact.setModifiedDate(new Date());
    contact.setEmailAddress(emailAddress);
    contact.setFirstName(firstName);
    contact.setMiddleName(middleName);
    contact.setLastName(lastName);
    contact.setPrefixId(prefixId);
    contact.setSuffixId(suffixId);
    contact.setMale(male);
    contact.setBirthday(birthday);
    contact.setSmsSn(smsSn);
    contact.setAimSn(aimSn);
    contact.setFacebookSn(facebookSn);
    contact.setIcqSn(icqSn);
    contact.setJabberSn(jabberSn);
    contact.setMsnSn(msnSn);
    contact.setMySpaceSn(mySpaceSn);
    contact.setSkypeSn(skypeSn);
    contact.setTwitterSn(twitterSn);
    contact.setYmSn(ymSn);
    contact.setJobTitle(jobTitle);

    contactPersistence.update(contact);

    return contact;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Contact newContact = _persistence.create(pk);

    newContact.setMvccVersion(RandomTestUtil.nextLong());

    newContact.setCompanyId(RandomTestUtil.nextLong());

    newContact.setUserId(RandomTestUtil.nextLong());

    newContact.setUserName(RandomTestUtil.randomString());

    newContact.setCreateDate(RandomTestUtil.nextDate());

    newContact.setModifiedDate(RandomTestUtil.nextDate());

    newContact.setClassNameId(RandomTestUtil.nextLong());

    newContact.setClassPK(RandomTestUtil.nextLong());

    newContact.setAccountId(RandomTestUtil.nextLong());

    newContact.setParentContactId(RandomTestUtil.nextLong());

    newContact.setEmailAddress(RandomTestUtil.randomString());

    newContact.setFirstName(RandomTestUtil.randomString());

    newContact.setMiddleName(RandomTestUtil.randomString());

    newContact.setLastName(RandomTestUtil.randomString());

    newContact.setPrefixId(RandomTestUtil.nextLong());

    newContact.setSuffixId(RandomTestUtil.nextLong());

    newContact.setMale(RandomTestUtil.randomBoolean());

    newContact.setBirthday(RandomTestUtil.nextDate());

    newContact.setSmsSn(RandomTestUtil.randomString());

    newContact.setFacebookSn(RandomTestUtil.randomString());

    newContact.setJabberSn(RandomTestUtil.randomString());

    newContact.setSkypeSn(RandomTestUtil.randomString());

    newContact.setTwitterSn(RandomTestUtil.randomString());

    newContact.setEmployeeStatusId(RandomTestUtil.randomString());

    newContact.setEmployeeNumber(RandomTestUtil.randomString());

    newContact.setJobTitle(RandomTestUtil.randomString());

    newContact.setJobClass(RandomTestUtil.randomString());

    newContact.setHoursOfOperation(RandomTestUtil.randomString());

    _contacts.add(_persistence.update(newContact));

    Contact existingContact = _persistence.findByPrimaryKey(newContact.getPrimaryKey());

    Assert.assertEquals(existingContact.getMvccVersion(), newContact.getMvccVersion());
    Assert.assertEquals(existingContact.getContactId(), newContact.getContactId());
    Assert.assertEquals(existingContact.getCompanyId(), newContact.getCompanyId());
    Assert.assertEquals(existingContact.getUserId(), newContact.getUserId());
    Assert.assertEquals(existingContact.getUserName(), newContact.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingContact.getCreateDate()),
        Time.getShortTimestamp(newContact.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingContact.getModifiedDate()),
        Time.getShortTimestamp(newContact.getModifiedDate()));
    Assert.assertEquals(existingContact.getClassNameId(), newContact.getClassNameId());
    Assert.assertEquals(existingContact.getClassPK(), newContact.getClassPK());
    Assert.assertEquals(existingContact.getAccountId(), newContact.getAccountId());
    Assert.assertEquals(existingContact.getParentContactId(), newContact.getParentContactId());
    Assert.assertEquals(existingContact.getEmailAddress(), newContact.getEmailAddress());
    Assert.assertEquals(existingContact.getFirstName(), newContact.getFirstName());
    Assert.assertEquals(existingContact.getMiddleName(), newContact.getMiddleName());
    Assert.assertEquals(existingContact.getLastName(), newContact.getLastName());
    Assert.assertEquals(existingContact.getPrefixId(), newContact.getPrefixId());
    Assert.assertEquals(existingContact.getSuffixId(), newContact.getSuffixId());
    Assert.assertEquals(existingContact.getMale(), newContact.getMale());
    Assert.assertEquals(
        Time.getShortTimestamp(existingContact.getBirthday()),
        Time.getShortTimestamp(newContact.getBirthday()));
    Assert.assertEquals(existingContact.getSmsSn(), newContact.getSmsSn());
    Assert.assertEquals(existingContact.getFacebookSn(), newContact.getFacebookSn());
    Assert.assertEquals(existingContact.getJabberSn(), newContact.getJabberSn());
    Assert.assertEquals(existingContact.getSkypeSn(), newContact.getSkypeSn());
    Assert.assertEquals(existingContact.getTwitterSn(), newContact.getTwitterSn());
    Assert.assertEquals(existingContact.getEmployeeStatusId(), newContact.getEmployeeStatusId());
    Assert.assertEquals(existingContact.getEmployeeNumber(), newContact.getEmployeeNumber());
    Assert.assertEquals(existingContact.getJobTitle(), newContact.getJobTitle());
    Assert.assertEquals(existingContact.getJobClass(), newContact.getJobClass());
    Assert.assertEquals(existingContact.getHoursOfOperation(), newContact.getHoursOfOperation());
  }
  protected Contact addContact() throws Exception {
    long pk = RandomTestUtil.nextLong();

    Contact contact = _persistence.create(pk);

    contact.setMvccVersion(RandomTestUtil.nextLong());

    contact.setCompanyId(RandomTestUtil.nextLong());

    contact.setUserId(RandomTestUtil.nextLong());

    contact.setUserName(RandomTestUtil.randomString());

    contact.setCreateDate(RandomTestUtil.nextDate());

    contact.setModifiedDate(RandomTestUtil.nextDate());

    contact.setClassNameId(RandomTestUtil.nextLong());

    contact.setClassPK(RandomTestUtil.nextLong());

    contact.setAccountId(RandomTestUtil.nextLong());

    contact.setParentContactId(RandomTestUtil.nextLong());

    contact.setEmailAddress(RandomTestUtil.randomString());

    contact.setFirstName(RandomTestUtil.randomString());

    contact.setMiddleName(RandomTestUtil.randomString());

    contact.setLastName(RandomTestUtil.randomString());

    contact.setPrefixId(RandomTestUtil.nextLong());

    contact.setSuffixId(RandomTestUtil.nextLong());

    contact.setMale(RandomTestUtil.randomBoolean());

    contact.setBirthday(RandomTestUtil.nextDate());

    contact.setSmsSn(RandomTestUtil.randomString());

    contact.setFacebookSn(RandomTestUtil.randomString());

    contact.setJabberSn(RandomTestUtil.randomString());

    contact.setSkypeSn(RandomTestUtil.randomString());

    contact.setTwitterSn(RandomTestUtil.randomString());

    contact.setEmployeeStatusId(RandomTestUtil.randomString());

    contact.setEmployeeNumber(RandomTestUtil.randomString());

    contact.setJobTitle(RandomTestUtil.randomString());

    contact.setJobClass(RandomTestUtil.randomString());

    contact.setHoursOfOperation(RandomTestUtil.randomString());

    _contacts.add(_persistence.update(contact));

    return contact;
  }