Search in sources :

Example 1 with EventReminder

use of com.axelor.apps.crm.db.EventReminder in project axelor-open-suite by axelor.

the class BatchEventReminder method markEventReminderProcess.

protected void markEventReminderProcess() {
    if (!stop) {
        int i = 0;
        List<? extends EventReminder> eventReminderList = eventReminderRepo.all().fetch();
        for (EventReminder eventReminder : eventReminderList) {
            try {
                eventReminder = eventReminderRepo.find(eventReminder.getId());
                Integer eventStatusSelect = eventReminder.getEvent().getStatusSelect();
                boolean eventIsNotFinished = eventStatusSelect == EventRepository.STATUS_PLANNED || eventStatusSelect == EventRepository.STATUS_NOT_STARTED || eventStatusSelect == EventRepository.STATUS_ON_GOING || eventStatusSelect == EventRepository.STATUS_PENDING;
                if (!eventReminder.getIsReminded() && isExpired(eventReminder) && eventIsNotFinished) {
                    updateEventReminder(eventReminder);
                    i++;
                }
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get(IExceptionMessage.BATCH_EVENT_REMINDER_1), eventReminderRepo.find(eventReminder.getId()).getEvent().getSubject()), e), ExceptionOriginRepository.CRM, batch.getId());
                incrementAnomaly();
                LOG.error("Bug(Anomalie) généré(e) pour le rappel de l'évènement {}", eventReminderRepo.find(eventReminder.getId()).getEvent().getSubject());
            } finally {
                if (i % 1 == 0) {
                    JPA.clear();
                }
            }
        }
    }
}
Also used : EventReminder(com.axelor.apps.crm.db.EventReminder) AxelorException(com.axelor.exception.AxelorException)

Example 2 with EventReminder

use of com.axelor.apps.crm.db.EventReminder in project axelor-open-suite by axelor.

the class BatchEventReminder method generateMessageProcess.

protected void generateMessageProcess() {
    MessageRepository messageRepo = Beans.get(MessageRepository.class);
    if (!stop) {
        int i = 0;
        Query q = JPA.em().createQuery(" SELECT er FROM EventReminder as er WHERE er.isReminded = true and ?1 MEMBER OF er.batchSet");
        q.setParameter(1, batch);
        @SuppressWarnings("unchecked") List<EventReminder> eventReminderList = q.getResultList();
        for (EventReminder eventReminder : eventReminderList) {
            try {
                eventReminder = eventReminderRepo.find(eventReminder.getId());
                Message message = messageServiceCrmImpl.createMessage(eventReminder.getEvent());
                // Send reminder to owner of the reminder in any case
                if (eventReminder.getUser().getPartner() != null && eventReminder.getUser().getPartner().getEmailAddress() != null) {
                    message.addToEmailAddressSetItem(eventReminder.getUser().getPartner().getEmailAddress());
                } else if (eventReminder.getUser().getEmail() != null) {
                    message.addToEmailAddressSetItem(findOrCreateEmailAddress(eventReminder.getUser().getEmail(), "[" + eventReminder.getUser().getEmail() + "]"));
                } else {
                    messageRepo.remove(message);
                    throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CRM_CONFIG_USER_EMAIL), eventReminder.getUser().getName());
                }
                // Also send to attendees if needed
                if (EventReminderRepository.ASSIGN_TO_ALL.equals(eventReminder.getAssignToSelect()) && eventReminder.getEvent().getAttendees() != null) {
                    for (ICalendarUser iCalUser : eventReminder.getEvent().getAttendees()) {
                        if (iCalUser.getUser() != null && iCalUser.getUser().getPartner() != null) {
                            message.addToEmailAddressSetItem(iCalUser.getUser().getPartner().getEmailAddress());
                        } else {
                            message.addToEmailAddressSetItem(findOrCreateEmailAddress(iCalUser.getEmail(), iCalUser.getName()));
                        }
                    }
                }
                message = Beans.get(MessageService.class).sendByEmail(message);
            } catch (Exception e) {
                TraceBackService.trace(new Exception(String.format(I18n.get("Event") + " %s", eventRepo.find(eventReminder.getEvent().getId()).getSubject()), e), ExceptionOriginRepository.CRM, batch.getId());
                incrementAnomaly();
                LOG.error("Bug(Anomalie) généré(e) pour l'évènement {}", eventRepo.find(eventReminder.getEvent().getId()).getSubject());
            } finally {
                if (i % 1 == 0) {
                    JPA.clear();
                }
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) EventReminder(com.axelor.apps.crm.db.EventReminder) Query(javax.persistence.Query) IExceptionMessage(com.axelor.apps.crm.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) MessageRepository(com.axelor.apps.message.db.repo.MessageRepository) AxelorException(com.axelor.exception.AxelorException)

Example 3 with EventReminder

use of com.axelor.apps.crm.db.EventReminder in project axelor-open-suite by axelor.

the class EventController method deleteReminder.

@Transactional(rollbackOn = { Exception.class })
public void deleteReminder(ActionRequest request, ActionResponse response) {
    try {
        EventReminderRepository eventReminderRepository = Beans.get(EventReminderRepository.class);
        EventReminder eventReminder = eventReminderRepository.find((long) request.getContext().get("id"));
        eventReminderRepository.remove(eventReminder);
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : EventReminderRepository(com.axelor.apps.crm.db.repo.EventReminderRepository) EventReminder(com.axelor.apps.crm.db.EventReminder) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Aggregations

EventReminder (com.axelor.apps.crm.db.EventReminder)3 AxelorException (com.axelor.exception.AxelorException)3 ICalendarUser (com.axelor.apps.base.db.ICalendarUser)1 EventReminderRepository (com.axelor.apps.crm.db.repo.EventReminderRepository)1 IExceptionMessage (com.axelor.apps.crm.exception.IExceptionMessage)1 Message (com.axelor.apps.message.db.Message)1 MessageRepository (com.axelor.apps.message.db.repo.MessageRepository)1 Transactional (com.google.inject.persist.Transactional)1 Query (javax.persistence.Query)1