Search in sources :

Example 1 with UserContact

use of org.apache.openmeetings.db.entity.user.UserContact in project openmeetings by apache.

the class UserContactDao method add.

public UserContact add(Long userId, Long ownerId, boolean pending) {
    try {
        UserContact userContact = new UserContact();
        userContact.setInserted(new Date());
        userContact.setOwner(userDao.get(ownerId));
        userContact.setContact(userDao.get(userId));
        userContact.setPending(pending);
        userContact = update(userContact);
        return userContact;
    } catch (Exception e) {
        log.error("[addUserContact]", e);
    }
    return null;
}
Also used : UserContact(org.apache.openmeetings.db.entity.user.UserContact) Date(java.util.Date)

Example 2 with UserContact

use of org.apache.openmeetings.db.entity.user.UserContact in project openmeetings by apache.

the class ContactsHelper method addUserToContactList.

public static Object addUserToContactList(long userIdToAdd) {
    boolean isContact = get().getBean(UserContactDao.class).isContact(userIdToAdd, getUserId());
    if (isContact) {
        return "error.contact.added";
    }
    UserContact contact = get().getBean(UserContactDao.class).add(userIdToAdd, getUserId(), true);
    User user = contact.getOwner();
    User userToAdd = contact.getContact();
    String subj = user.getFirstname() + " " + user.getLastname() + " " + Application.getString("1193");
    String message = RequestContactTemplate.getEmail(userToAdd, user);
    get().getBean(PrivateMessageDao.class).addPrivateMessage(subj, message, user, userToAdd, userToAdd, true, contact.getId());
    if (userToAdd.getAddress() != null) {
        get().getBean(MailHandler.class).send(userToAdd.getAddress().getEmail(), subj, message);
    }
    return contact;
}
Also used : MailHandler(org.apache.openmeetings.core.mail.MailHandler) User(org.apache.openmeetings.db.entity.user.User) PrivateMessageDao(org.apache.openmeetings.db.dao.user.PrivateMessageDao) UserContact(org.apache.openmeetings.db.entity.user.UserContact) UserContactDao(org.apache.openmeetings.db.dao.user.UserContactDao)

Example 3 with UserContact

use of org.apache.openmeetings.db.entity.user.UserContact in project openmeetings by apache.

the class ContactsHelper method acceptUserContact.

public static Object acceptUserContact(long userContactId) {
    UserContactDao dao = get().getBean(UserContactDao.class);
    UserContact contact = dao.get(userContactId);
    if (contact == null) {
        return "error.contact.denied";
    }
    if (!contact.isPending()) {
        return "error.contact.approved";
    }
    dao.updateContactStatus(userContactId, false);
    contact = dao.get(userContactId);
    User user = contact.getOwner();
    dao.add(user.getId(), getUserId(), false);
    if (user.getAddress() != null) {
        String message = RequestContactConfirmTemplate.getEmail(contact);
        String subj = contact.getContact().getFirstname() + " " + contact.getContact().getLastname() + " " + Application.getString("1198");
        get().getBean(PrivateMessageDao.class).addPrivateMessage(subj, message, contact.getContact(), user, user, false, 0L);
        get().getBean(MailHandler.class).send(user.getAddress().getEmail(), subj, message);
    }
    return userContactId;
}
Also used : MailHandler(org.apache.openmeetings.core.mail.MailHandler) User(org.apache.openmeetings.db.entity.user.User) PrivateMessageDao(org.apache.openmeetings.db.dao.user.PrivateMessageDao) UserContact(org.apache.openmeetings.db.entity.user.UserContact) UserContactDao(org.apache.openmeetings.db.dao.user.UserContactDao)

Example 4 with UserContact

use of org.apache.openmeetings.db.entity.user.UserContact in project openmeetings by apache.

the class TestEmailTemplate method testTemplateGeneration.

@Test
public void testTemplateGeneration() {
    User u = new User();
    u.setLanguageId(rnd.nextInt(30));
    UserContact uc = new UserContact();
    uc.setOwner(u);
    uc.setContact(new User());
    checkTemplate(FeedbackTemplate.getEmail("testuser", "email", "message"));
    checkTemplate(InvitationTemplate.getEmail(u, "testuser", "email", "message"));
    checkTemplate(RegisterUserTemplate.getEmail("testuser", "email", "message"));
    checkTemplate(RequestContactConfirmTemplate.getEmail(uc));
    checkTemplate(RequestContactTemplate.getEmail(u, new User()));
    checkTemplate(ResetPasswordTemplate.getEmail("link"));
}
Also used : User(org.apache.openmeetings.db.entity.user.User) UserContact(org.apache.openmeetings.db.entity.user.UserContact) Test(org.junit.Test)

Example 5 with UserContact

use of org.apache.openmeetings.db.entity.user.UserContact in project openmeetings by apache.

the class BackupImport method importContacts.

/*
	 * ##################### Import User Contacts
	 */
private void importContacts(File f) throws Exception {
    log.info("Private message folder import complete, starting user contacts import");
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);
    registry.bind(User.class, new UserConverter(userDao, userMap));
    List<UserContact> list = readList(serializer, f, "userContacts.xml", "usercontacts", UserContact.class);
    for (UserContact uc : list) {
        Long ucId = uc.getId();
        UserContact storedUC = userContactDao.get(ucId);
        if (storedUC == null && uc.getContact() != null && uc.getContact().getId() != null) {
            uc.setId(null);
            if (uc.getOwner() != null && uc.getOwner().getId() == null) {
                uc.setOwner(null);
            }
            uc = userContactDao.update(uc);
            userContactMap.put(ucId, uc.getId());
        }
    }
}
Also used : UserConverter(org.apache.openmeetings.backup.converter.UserConverter) UserContact(org.apache.openmeetings.db.entity.user.UserContact) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) RegistryStrategy(org.simpleframework.xml.convert.RegistryStrategy) Strategy(org.simpleframework.xml.strategy.Strategy) Registry(org.simpleframework.xml.convert.Registry) Persister(org.simpleframework.xml.core.Persister) Serializer(org.simpleframework.xml.Serializer)

Aggregations

UserContact (org.apache.openmeetings.db.entity.user.UserContact)6 User (org.apache.openmeetings.db.entity.user.User)3 MailHandler (org.apache.openmeetings.core.mail.MailHandler)2 PrivateMessageDao (org.apache.openmeetings.db.dao.user.PrivateMessageDao)2 UserContactDao (org.apache.openmeetings.db.dao.user.UserContactDao)2 Date (java.util.Date)1 UserConverter (org.apache.openmeetings.backup.converter.UserConverter)1 Test (org.junit.Test)1 Serializer (org.simpleframework.xml.Serializer)1 Registry (org.simpleframework.xml.convert.Registry)1 RegistryStrategy (org.simpleframework.xml.convert.RegistryStrategy)1 Persister (org.simpleframework.xml.core.Persister)1 Strategy (org.simpleframework.xml.strategy.Strategy)1