@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; }
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); }
@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 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); }
@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()); }