public User getContact(String email, String firstName, String lastName, long ownerId) {
return getContact(email, firstName, lastName, null, null, get(ownerId));
}
public User getContact(String email, String firstName, String lastName, Long langId, String tzId, User owner) {
User to = null;
try {
to = em.createNamedQuery("getContactByEmailAndUser", User.class)
.setParameter("email", email).setParameter("type", User.Type.contact).setParameter("ownerId", owner.getUser_id()).getSingleResult();
} catch (Exception e) {
//no-op
}
if (to == null) {
to = new User();
to.setType(Type.contact);
String login = owner.getUser_id() + "_" + email; //UserId prefix is used to ensure unique login
to.setLogin(login.length() < getMinLoginLength(cfgDao) ? UUID.randomUUID().toString() : login);
to.setFirstname(firstName);
to.setLastname(lastName);
to.setLanguage_id(null == langId ? owner.getLanguage_id() : langId);
to.setOwnerId(owner.getUser_id());
to.setAdresses(new Address());
to.getAdresses().setEmail(email);
to.setTimeZoneId(null == tzId ? owner.getTimeZoneId() : tzId);
}
return to;
}