Search in sources :

Example 26 with Event

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

the class EventController method manageFollowers.

public void manageFollowers(ActionRequest request, ActionResponse response) throws AxelorException {
    try {
        Event event = request.getContext().asType(Event.class);
        event = Beans.get(EventRepository.class).find(event.getId());
        Beans.get(EventService.class).manageFollowers(event);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Event(com.axelor.apps.crm.db.Event) EventService(com.axelor.apps.crm.service.EventService) ICalendarEventService(com.axelor.base.service.ical.ICalendarEventService) AxelorException(com.axelor.exception.AxelorException)

Example 27 with Event

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

the class EventController method deleteThis.

@Transactional
public void deleteThis(ActionRequest request, ActionResponse response) {
    Long eventId = new Long(request.getContext().getParent().get("id").toString());
    EventRepository eventRepository = Beans.get(EventRepository.class);
    Event event = eventRepository.find(eventId);
    Event child = eventRepository.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne();
    if (child != null) {
        child.setParentEvent(event.getParentEvent());
    }
    eventRepository.remove(event);
    response.setCanClose(true);
    response.setReload(true);
}
Also used : Event(com.axelor.apps.crm.db.Event) EventRepository(com.axelor.apps.crm.db.repo.EventRepository) Transactional(com.google.inject.persist.Transactional)

Example 28 with Event

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

the class EventController method saveEventTicketStatusSelect.

public void saveEventTicketStatusSelect(ActionRequest request, ActionResponse response) throws AxelorException {
    Event event = request.getContext().asType(Event.class);
    Event persistEvent = Beans.get(EventRepository.class).find(event.getId());
    persistEvent.setStatusSelect(event.getStatusSelect());
    Beans.get(EventService.class).saveEvent(persistEvent);
}
Also used : Event(com.axelor.apps.crm.db.Event) EventRepository(com.axelor.apps.crm.db.repo.EventRepository) EventService(com.axelor.apps.crm.service.EventService) ICalendarEventService(com.axelor.base.service.ical.ICalendarEventService)

Example 29 with Event

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

the class EventController method computeFromStartDateTime.

public void computeFromStartDateTime(ActionRequest request, ActionResponse response) {
    Event event = request.getContext().asType(Event.class);
    LOG.debug("event : {}", event);
    if (event.getStartDateTime() != null) {
        if (event.getDuration() != null && event.getDuration() != 0) {
            response.setValue("endDateTime", DateTool.plusSeconds(event.getStartDateTime(), event.getDuration()));
        } else if (event.getEndDateTime() != null && event.getEndDateTime().isAfter(event.getStartDateTime())) {
            Duration duration = DurationTool.computeDuration(event.getStartDateTime(), event.getEndDateTime());
            response.setValue("duration", DurationTool.getSecondsDuration(duration));
        } else {
            Duration duration = Duration.ofHours(1);
            response.setValue("duration", DurationTool.getSecondsDuration(duration));
            response.setValue("endDateTime", event.getStartDateTime().plus(duration));
        }
    }
}
Also used : Event(com.axelor.apps.crm.db.Event) Duration(java.time.Duration)

Example 30 with Event

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

the class EventController method changeAll.

@Transactional(rollbackOn = { Exception.class })
public void changeAll(ActionRequest request, ActionResponse response) throws AxelorException {
    Long eventId = new Long(request.getContext().getParent().get("id").toString());
    EventRepository eventRepository = Beans.get(EventRepository.class);
    Event event = eventRepository.find(eventId);
    Event child = eventRepository.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne();
    Event parent = event.getParentEvent();
    child.setParentEvent(null);
    Event eventDeleted = child;
    child = eventRepository.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne();
    while (child != null) {
        child.setParentEvent(null);
        eventRepository.remove(eventDeleted);
        eventDeleted = child;
        child = eventRepository.all().filter("self.parentEvent.id = ?1", eventDeleted.getId()).fetchOne();
    }
    while (parent != null) {
        Event nextParent = parent.getParentEvent();
        eventRepository.remove(parent);
        parent = nextParent;
    }
    RecurrenceConfiguration conf = request.getContext().asType(RecurrenceConfiguration.class);
    RecurrenceConfigurationRepository confRepo = Beans.get(RecurrenceConfigurationRepository.class);
    conf = confRepo.save(conf);
    event.setRecurrenceConfiguration(conf);
    event = eventRepository.save(event);
    if (conf.getRecurrenceType() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_RECURRENCE_TYPE));
    }
    int recurrenceType = conf.getRecurrenceType();
    if (conf.getPeriodicity() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY));
    }
    int periodicity = conf.getPeriodicity();
    if (periodicity < 1) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_PERIODICITY));
    }
    boolean monday = conf.getMonday();
    boolean tuesday = conf.getTuesday();
    boolean wednesday = conf.getWednesday();
    boolean thursday = conf.getThursday();
    boolean friday = conf.getFriday();
    boolean saturday = conf.getSaturday();
    boolean sunday = conf.getSunday();
    Map<Integer, Boolean> daysMap = new HashMap<Integer, Boolean>();
    Map<Integer, Boolean> daysCheckedMap = new HashMap<Integer, Boolean>();
    if (recurrenceType == 2) {
        daysMap.put(DayOfWeek.MONDAY.getValue(), monday);
        daysMap.put(DayOfWeek.TUESDAY.getValue(), tuesday);
        daysMap.put(DayOfWeek.WEDNESDAY.getValue(), wednesday);
        daysMap.put(DayOfWeek.THURSDAY.getValue(), thursday);
        daysMap.put(DayOfWeek.FRIDAY.getValue(), friday);
        daysMap.put(DayOfWeek.SATURDAY.getValue(), saturday);
        daysMap.put(DayOfWeek.SUNDAY.getValue(), sunday);
        for (Integer day : daysMap.keySet()) {
            if (daysMap.get(day)) {
                daysCheckedMap.put(day, daysMap.get(day));
            }
        }
        if (daysMap.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_DAYS_CHECKED));
        }
    }
    int monthRepeatType = conf.getMonthRepeatType();
    int endType = conf.getEndType();
    int repetitionsNumber = 0;
    if (endType == 1) {
        if (conf.getRepetitionsNumber() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_REPETITION_NUMBER));
        }
        repetitionsNumber = conf.getRepetitionsNumber();
        if (repetitionsNumber < 1) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, IExceptionMessage.RECURRENCE_REPETITION_NUMBER);
        }
    }
    LocalDate endDate = Beans.get(AppBaseService.class).getTodayDate(event.getUser() != null ? event.getUser().getActiveCompany() : Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null));
    if (endType == 2) {
        if (conf.getEndDate() == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_END_DATE));
        }
        endDate = conf.getEndDate();
        if (endDate.isBefore(event.getStartDateTime().toLocalDate()) && endDate.isEqual(event.getStartDateTime().toLocalDate())) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RECURRENCE_END_DATE));
        }
    }
    switch(recurrenceType) {
        case 1:
            Beans.get(EventService.class).addRecurrentEventsByDays(event, periodicity, endType, repetitionsNumber, endDate);
            break;
        case 2:
            Beans.get(EventService.class).addRecurrentEventsByWeeks(event, periodicity, endType, repetitionsNumber, endDate, daysCheckedMap);
            break;
        case 3:
            Beans.get(EventService.class).addRecurrentEventsByMonths(event, periodicity, endType, repetitionsNumber, endDate, monthRepeatType);
            break;
        case 4:
            Beans.get(EventService.class).addRecurrentEventsByYears(event, periodicity, endType, repetitionsNumber, endDate);
            break;
        default:
            break;
    }
    response.setCanClose(true);
    response.setReload(true);
}
Also used : AxelorException(com.axelor.exception.AxelorException) HashMap(java.util.HashMap) EventService(com.axelor.apps.crm.service.EventService) ICalendarEventService(com.axelor.base.service.ical.ICalendarEventService) LocalDate(java.time.LocalDate) RecurrenceConfigurationRepository(com.axelor.apps.crm.db.repo.RecurrenceConfigurationRepository) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Event(com.axelor.apps.crm.db.Event) EventRepository(com.axelor.apps.crm.db.repo.EventRepository) RecurrenceConfiguration(com.axelor.apps.crm.db.RecurrenceConfiguration) Transactional(com.google.inject.persist.Transactional)

Aggregations

Event (com.axelor.apps.crm.db.Event)36 Transactional (com.google.inject.persist.Transactional)21 EventRepository (com.axelor.apps.crm.db.repo.EventRepository)11 EventService (com.axelor.apps.crm.service.EventService)7 ICalendarEventService (com.axelor.base.service.ical.ICalendarEventService)7 TrainingRegister (com.axelor.apps.talent.db.TrainingRegister)6 Duration (java.time.Duration)6 AxelorException (com.axelor.exception.AxelorException)5 LocalDateTime (java.time.LocalDateTime)4 RecurrenceConfiguration (com.axelor.apps.crm.db.RecurrenceConfiguration)3 RecurrenceConfigurationRepository (com.axelor.apps.crm.db.repo.RecurrenceConfigurationRepository)3 HashMap (java.util.HashMap)3 TooManyIterationsException (org.apache.commons.math3.exception.TooManyIterationsException)3 Partner (com.axelor.apps.base.db.Partner)2 Lead (com.axelor.apps.crm.db.Lead)2 Training (com.axelor.apps.talent.db.Training)2 TrainingSession (com.axelor.apps.talent.db.TrainingSession)2 TrainingSessionRepository (com.axelor.apps.talent.db.repo.TrainingSessionRepository)2 User (com.axelor.auth.db.User)2 DayOfWeek (java.time.DayOfWeek)2