Search in sources :

Example 6 with ICalendarUser

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

the class ICalendarEventManagementRepository method save.

@Override
public ICalendarEvent save(ICalendarEvent entity) {
    User creator = entity.getCreatedBy();
    if (creator == null) {
        creator = AuthUtils.getUser();
    }
    if (entity.getOrganizer() == null && creator != null) {
        if (creator.getPartner() != null && creator.getPartner().getEmailAddress() != null) {
            String email = creator.getPartner().getEmailAddress().getAddress();
            if (email != null) {
                ICalendarUser organizer = Beans.get(ICalendarUserRepository.class).all().filter("self.email = ?1 AND self.user.id = ?2", email, creator.getId()).fetchOne();
                if (organizer == null) {
                    organizer = new ICalendarUser();
                    organizer.setEmail(email);
                    organizer.setName(creator.getFullName());
                    organizer.setUser(creator);
                }
                entity.setOrganizer(organizer);
            }
        }
    }
    entity.setSubjectTeam(entity.getSubject());
    if (entity.getVisibilitySelect() == ICalendarEventRepository.VISIBILITY_PRIVATE) {
        entity.setSubjectTeam(I18n.get("Available"));
        if (entity.getDisponibilitySelect() == ICalendarEventRepository.DISPONIBILITY_BUSY) {
            entity.setSubjectTeam(I18n.get("Busy"));
        }
    }
    return super.save(entity);
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) User(com.axelor.auth.db.User)

Example 7 with ICalendarUser

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

the class ICalendarEventServiceImpl method addEmailGuest.

@Override
public List<ICalendarUser> addEmailGuest(EmailAddress email, ICalendarEvent event) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, MessagingException, IOException, ICalendarException, ParseException {
    if (email != null) {
        if (event.getAttendees() == null || !event.getAttendees().stream().anyMatch(x -> email.getAddress().equals(x.getEmail()))) {
            ICalendarUser calUser = new ICalendarUser();
            calUser.setEmail(email.getAddress());
            calUser.setName(email.getName());
            if (email.getPartner() != null) {
                calUser.setUser(userRepository.all().filter("self.partner.id = ?1", email.getPartner().getId()).fetchOne());
            }
            event.addAttendee(calUser);
        }
    }
    return event.getAttendees();
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser)

Example 8 with ICalendarUser

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

the class EventServiceImpl method manageFollowers.

@Override
@Transactional
public void manageFollowers(Event event) {
    MailFollowerRepository mailFollowerRepo = Beans.get(MailFollowerRepository.class);
    List<MailFollower> followers = mailFollowerRepo.findAll(event);
    List<ICalendarUser> attendeesSet = event.getAttendees();
    if (followers != null)
        followers.forEach(x -> mailFollowerRepo.remove(x));
    mailFollowerRepo.follow(event, event.getUser());
    if (attendeesSet != null) {
        for (ICalendarUser user : attendeesSet) {
            if (user.getUser() != null) {
                mailFollowerRepo.follow(event, user.getUser());
            } else {
                MailAddress mailAddress = Beans.get(MailAddressRepository.class).findOrCreate(user.getEmail(), user.getName());
                mailFollowerRepo.follow(event, mailAddress);
            }
        }
    }
}
Also used : PartnerService(com.axelor.apps.base.service.PartnerService) Inject(com.google.inject.Inject) BiFunction(java.util.function.BiFunction) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Lead(com.axelor.apps.crm.db.Lead) Function(java.util.function.Function) EmailAddress(com.axelor.apps.message.db.EmailAddress) ICalendarService(com.axelor.apps.base.ical.ICalendarService) Transactional(com.google.inject.persist.Transactional) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) Strings(com.google.common.base.Strings) Event(com.axelor.apps.crm.db.Event) AxelorException(com.axelor.exception.AxelorException) Duration(java.time.Duration) Map(java.util.Map) IExceptionMessage(com.axelor.apps.crm.exception.IExceptionMessage) I18n(com.axelor.i18n.I18n) RecurrenceConfiguration(com.axelor.apps.crm.db.RecurrenceConfiguration) MailFollower(com.axelor.mail.db.MailFollower) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) LeadRepository(com.axelor.apps.crm.db.repo.LeadRepository) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) Collectors(java.util.stream.Collectors) TooManyIterationsException(org.apache.commons.math3.exception.TooManyIterationsException) MessageService(com.axelor.apps.message.service.MessageService) EventRepository(com.axelor.apps.crm.db.repo.EventRepository) List(java.util.List) Beans(com.axelor.inject.Beans) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) RecurrenceConfigurationRepository(com.axelor.apps.crm.db.repo.RecurrenceConfigurationRepository) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Address(com.axelor.apps.base.db.Address) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) MailAddressRepository(com.axelor.mail.db.repo.MailAddressRepository) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) Partner(com.axelor.apps.base.db.Partner) MailAddress(com.axelor.mail.db.MailAddress) User(com.axelor.auth.db.User) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) MailAddress(com.axelor.mail.db.MailAddress) MailFollower(com.axelor.mail.db.MailFollower) MailAddressRepository(com.axelor.mail.db.repo.MailAddressRepository) Transactional(com.google.inject.persist.Transactional)

Example 9 with ICalendarUser

use of com.axelor.apps.base.db.ICalendarUser 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)9 ICalendarUserRepository (com.axelor.apps.base.db.repo.ICalendarUserRepository)3 EmailAddress (com.axelor.apps.message.db.EmailAddress)3 EmailAddressRepository (com.axelor.apps.message.db.repo.EmailAddressRepository)3 User (com.axelor.auth.db.User)3 LocalDateTime (java.time.LocalDateTime)3 IExceptionMessage (com.axelor.apps.crm.exception.IExceptionMessage)2 AxelorException (com.axelor.exception.AxelorException)2 Transactional (com.google.inject.persist.Transactional)2 OffsetDateTime (java.time.OffsetDateTime)2 DateTime (net.fortuna.ical4j.model.DateTime)2 DtEnd (net.fortuna.ical4j.model.property.DtEnd)2 DtStart (net.fortuna.ical4j.model.property.DtStart)2 Address (com.axelor.apps.base.db.Address)1 ICalendarEvent (com.axelor.apps.base.db.ICalendarEvent)1 Partner (com.axelor.apps.base.db.Partner)1 PartnerRepository (com.axelor.apps.base.db.repo.PartnerRepository)1 ICalendarService (com.axelor.apps.base.ical.ICalendarService)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 Event (com.axelor.apps.crm.db.Event)1