Search in sources :

Example 21 with Event

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

the class EventServiceImpl method addRecurrentEventsByDays.

@Override
@Transactional
public void addRecurrentEventsByDays(Event event, int periodicity, int endType, int repetitionsNumber, LocalDate endDate) {
    Event lastEvent = event;
    if (endType == RecurrenceConfigurationRepository.END_TYPE_REPET) {
        int repeated = 0;
        while (repeated != repetitionsNumber) {
            Event copy = eventRepo.copy(lastEvent, false);
            copy.setParentEvent(event);
            copy.setStartDateTime(copy.getStartDateTime().plusDays(periodicity));
            copy.setEndDateTime(copy.getEndDateTime().plusDays(periodicity));
            lastEvent = eventRepo.save(copy);
            repeated++;
        }
    } else {
        while (lastEvent.getStartDateTime().plusDays(periodicity).isBefore(endDate.atStartOfDay().plusDays(1))) {
            Event copy = eventRepo.copy(lastEvent, false);
            copy.setParentEvent(event);
            copy.setStartDateTime(copy.getStartDateTime().plusDays(periodicity));
            copy.setEndDateTime(copy.getEndDateTime().plusDays(periodicity));
            lastEvent = eventRepo.save(copy);
        }
    }
}
Also used : Event(com.axelor.apps.crm.db.Event) Transactional(com.google.inject.persist.Transactional)

Example 22 with Event

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

the class EventServiceImpl method addRecurrentEventsByWeeks.

@Override
@Transactional
public void addRecurrentEventsByWeeks(Event event, int periodicity, int endType, int repetitionsNumber, LocalDate endDate, Map<Integer, Boolean> daysCheckedMap) {
    List<DayOfWeek> dayOfWeekList = daysCheckedMap.keySet().stream().sorted().map(DayOfWeek::of).collect(Collectors.toList());
    Duration duration = Duration.between(event.getStartDateTime(), event.getEndDateTime());
    Event lastEvent = event;
    BiFunction<Integer, LocalDateTime, Boolean> breakCondition;
    if (endType == RecurrenceConfigurationRepository.END_TYPE_REPET) {
        breakCondition = (iteration, dateTime) -> iteration >= repetitionsNumber;
    } else {
        breakCondition = (iteration, dateTime) -> dateTime.toLocalDate().isAfter(endDate);
    }
    boolean loop = true;
    for (int iteration = 0; loop; ++iteration) {
        if (iteration > ITERATION_LIMIT) {
            throw new TooManyIterationsException(iteration);
        }
        LocalDateTime nextStartDateTime = lastEvent.getStartDateTime().plusWeeks(periodicity - 1L);
        for (DayOfWeek dayOfWeek : dayOfWeekList) {
            nextStartDateTime = nextStartDateTime.with(TemporalAdjusters.next(dayOfWeek));
            if (breakCondition.apply(iteration, nextStartDateTime)) {
                loop = false;
                break;
            }
            Event copy = eventRepo.copy(lastEvent, false);
            copy.setParentEvent(event);
            copy.setStartDateTime(nextStartDateTime);
            copy.setEndDateTime(nextStartDateTime.plus(duration));
            lastEvent = eventRepo.save(copy);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DayOfWeek(java.time.DayOfWeek) TooManyIterationsException(org.apache.commons.math3.exception.TooManyIterationsException) Event(com.axelor.apps.crm.db.Event) Duration(java.time.Duration) Transactional(com.google.inject.persist.Transactional)

Example 23 with Event

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

the class EventController method assignToMeEvent.

@SuppressWarnings("rawtypes")
public void assignToMeEvent(ActionRequest request, ActionResponse response) {
    EventRepository eventRepository = Beans.get(EventRepository.class);
    if (request.getContext().get("id") != null) {
        Event event = eventRepository.find((Long) request.getContext().get("id"));
        event.setUser(AuthUtils.getUser());
        Beans.get(EventService.class).saveEvent(event);
    } else if (!((List) request.getContext().get("_ids")).isEmpty()) {
        for (Event event : eventRepository.all().filter("id in ?1", request.getContext().get("_ids")).fetch()) {
            event.setUser(AuthUtils.getUser());
            Beans.get(EventService.class).saveEvent(event);
        }
    }
    response.setReload(true);
}
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) List(java.util.List)

Example 24 with Event

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

the class EventController method checkRights.

public void checkRights(ActionRequest request, ActionResponse response) {
    Event event = request.getContext().asType(Event.class);
    User user = AuthUtils.getUser();
    List<Long> calendarIdlist = Beans.get(CalendarService.class).showSharedCalendars(user);
    if (calendarIdlist.isEmpty() || !calendarIdlist.contains(event.getCalendar().getId())) {
        response.setAttr("meetingGeneralPanel", "readonly", "true");
        response.setAttr("addGuestsPanel", "readonly", "true");
        response.setAttr("meetingAttributesPanel", "readonly", "true");
        response.setAttr("meetingLinkedPanel", "readonly", "true");
    }
}
Also used : User(com.axelor.auth.db.User) Event(com.axelor.apps.crm.db.Event) CalendarService(com.axelor.apps.crm.service.CalendarService)

Example 25 with Event

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

the class EventController method computeFromCalendar.

public void computeFromCalendar(ActionRequest request, ActionResponse response) {
    Event event = request.getContext().asType(Event.class);
    LOG.debug("event : {}", event);
    if (event.getStartDateTime() != null && event.getEndDateTime() != null) {
        Duration duration = DurationTool.computeDuration(event.getStartDateTime(), event.getEndDateTime());
        response.setValue("duration", DurationTool.getSecondsDuration(duration));
    }
}
Also used : Event(com.axelor.apps.crm.db.Event) Duration(java.time.Duration)

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