Search in sources :

Example 1 with ICalendarUserRepository

use of com.axelor.apps.base.db.repo.ICalendarUserRepository in project axelor-open-suite by axelor.

the class ICalendarService method findOrCreateUser.

public ICalendarUser findOrCreateUser(User user) {
    String email = null;
    if (user.getPartner() != null && user.getPartner().getEmailAddress() != null && !Strings.isNullOrEmpty(user.getPartner().getEmailAddress().getAddress())) {
        email = user.getPartner().getEmailAddress().getAddress();
    } else if (!Strings.isNullOrEmpty(user.getEmail())) {
        email = user.getEmail();
    } else {
        return null;
    }
    ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
    ICalendarUser icalUser = null;
    icalUser = repo.all().filter("self.email = ?1 AND self.user.id = ?2", email, user.getId()).fetchOne();
    if (icalUser == null) {
        icalUser = repo.all().filter("self.user.id = ?1", user.getId()).fetchOne();
    }
    if (icalUser == null) {
        icalUser = repo.all().filter("self.email = ?1", email).fetchOne();
    }
    if (icalUser == null) {
        icalUser = new ICalendarUser();
        icalUser.setEmail(email);
        icalUser.setName(user.getFullName());
        EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
        if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
            icalUser.setUser(emailAddress.getPartner().getUser());
        }
    }
    return icalUser;
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) EmailAddress(com.axelor.apps.message.db.EmailAddress) ICalendarUserRepository(com.axelor.apps.base.db.repo.ICalendarUserRepository)

Example 2 with ICalendarUserRepository

use of com.axelor.apps.base.db.repo.ICalendarUserRepository in project axelor-open-suite by axelor.

the class ICalendarService method findOrCreateUser.

protected ICalendarUser findOrCreateUser(Property source, ICalendarEvent event) {
    URI addr = null;
    if (source instanceof Organizer) {
        addr = ((Organizer) source).getCalAddress();
    }
    if (source instanceof Attendee) {
        addr = ((Attendee) source).getCalAddress();
    }
    if (addr == null) {
        return null;
    }
    String email = mailto(addr.toString(), true);
    ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
    ICalendarUser user = null;
    if (source instanceof Organizer) {
        user = repo.all().filter("self.email = ?1", email).fetchOne();
    } else {
        user = repo.all().filter("self.email = ?1 AND self.event.id = ?2", email, event.getId()).fetchOne();
    }
    if (user == null) {
        user = new ICalendarUser();
        user.setEmail(email);
        user.setName(email);
        EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
        if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
            user.setUser(emailAddress.getPartner().getUser());
        }
    }
    if (source.getParameter(Parameter.CN) != null) {
        user.setName(source.getParameter(Parameter.CN).getValue());
    }
    if (source.getParameter(Parameter.PARTSTAT) != null) {
        String role = source.getParameter(Parameter.PARTSTAT).getValue();
        if (role.equals("TENTATIVE")) {
            user.setStatusSelect(ICalendarUserRepository.STATUS_MAYBE);
        } else if (role.equals("ACCEPTED")) {
            user.setStatusSelect(ICalendarUserRepository.STATUS_YES);
        } else if (role.equals("DECLINED")) {
            user.setStatusSelect(ICalendarUserRepository.STATUS_NO);
        }
    }
    return user;
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser) Organizer(net.fortuna.ical4j.model.property.Organizer) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) URI(java.net.URI) Attendee(net.fortuna.ical4j.model.property.Attendee) EmailAddress(com.axelor.apps.message.db.EmailAddress) ICalendarUserRepository(com.axelor.apps.base.db.repo.ICalendarUserRepository)

Aggregations

ICalendarUser (com.axelor.apps.base.db.ICalendarUser)2 ICalendarUserRepository (com.axelor.apps.base.db.repo.ICalendarUserRepository)2 EmailAddress (com.axelor.apps.message.db.EmailAddress)2 EmailAddressRepository (com.axelor.apps.message.db.repo.EmailAddressRepository)2 URI (java.net.URI)1 Attendee (net.fortuna.ical4j.model.property.Attendee)1 Organizer (net.fortuna.ical4j.model.property.Organizer)1