/** * Copies user contact and sets specified owner for copy. Needed for possibility perform deep copy of user. * @param contact contact to be copied * @param owner user which will be set as copy owner * * @return copy of specified user contact */ @VisibleForTesting static UserContact copyUserContact(UserContact contact, JCUser owner) { if (contact == null) { throw new IllegalArgumentException("User contact should not be null"); } UserContact copy = new UserContact(contact.getValue(), contact.getType()); copy.setOwner(owner); copy.setId(contact.getId()); copy.setUuid(contact.getUuid()); return copy; }
UserContact contact = contactContainer.getId() == null ? null : this.getDao().getContactById(contactContainer.getId()); if (contact != null && contact.getOwner().getId() == user.getId()) { contact.setValue(contactContainer.getValue()); contact.setType(actualType); } else { contact = new UserContact(contactContainer.getValue(), actualType); user.addContact(contact);
public static UserContact getDefaultUserContact() { UserContactType type = new UserContactType(); UserContact contact = new UserContact("value", type); contact.setOwner(ObjectsFactory.getDefaultUser()); return contact; }
/** * Check if contact exist in list of contact dto's * @param userContact user contact * @param contacts list of edited contacts * @return contact exist in list */ private boolean contactExistInListWithNotEmptyValue(UserContact userContact, List<UserContactContainer> contacts) { for (UserContactContainer contact : contacts) { if (contact.getId() != null && contact.getValue() != null && userContact.getId() == contact.getId()) { return true; } } return false; } }
/** * @param contact user contact */ public void addContact(UserContact contact) { contact.setOwner(this); this.getContacts().add(contact); }