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);
}
}
}
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);
}
}
}
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);
}
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");
}
}
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));
}
}
Aggregations