use of com.axelor.apps.crm.db.Event in project axelor-open-suite by axelor.
the class EventServiceImpl method applyChangesToAll.
@Override
@Transactional
public void applyChangesToAll(Event event) {
Event child = eventRepo.all().filter("self.parentEvent.id = ?1", event.getId()).fetchOne();
Event parent = event.getParentEvent();
Event copyEvent = eventRepo.copy(event, false);
while (child != null) {
child.setSubject(event.getSubject());
child.setCalendar(event.getCalendar());
child.setStartDateTime(child.getStartDateTime().withHour(event.getStartDateTime().getHour()));
child.setStartDateTime(child.getStartDateTime().withMinute(event.getStartDateTime().getMinute()));
child.setEndDateTime(child.getEndDateTime().withHour(event.getEndDateTime().getHour()));
child.setEndDateTime(child.getEndDateTime().withMinute(event.getEndDateTime().getMinute()));
child.setDuration(event.getDuration());
child.setUser(event.getUser());
child.setTeam(event.getTeam());
child.setDisponibilitySelect(event.getDisponibilitySelect());
child.setVisibilitySelect(event.getVisibilitySelect());
child.setDescription(event.getDescription());
child.setPartner(event.getPartner());
child.setContactPartner(event.getContactPartner());
child.setLead(event.getLead());
child.setTypeSelect(event.getTypeSelect());
child.setLocation(event.getLocation());
eventRepo.save(child);
copyEvent = child;
child = eventRepo.all().filter("self.parentEvent.id = ?1", copyEvent.getId()).fetchOne();
}
while (parent != null) {
Event nextParent = parent.getParentEvent();
parent.setSubject(event.getSubject());
parent.setCalendar(event.getCalendar());
parent.setStartDateTime(parent.getStartDateTime().withHour(event.getStartDateTime().getHour()));
parent.setStartDateTime(parent.getStartDateTime().withMinute(event.getStartDateTime().getMinute()));
parent.setEndDateTime(parent.getEndDateTime().withHour(event.getEndDateTime().getHour()));
parent.setEndDateTime(parent.getEndDateTime().withMinute(event.getEndDateTime().getMinute()));
parent.setDuration(event.getDuration());
parent.setUser(event.getUser());
parent.setTeam(event.getTeam());
parent.setDisponibilitySelect(event.getDisponibilitySelect());
parent.setVisibilitySelect(event.getVisibilitySelect());
parent.setDescription(event.getDescription());
parent.setPartner(event.getPartner());
parent.setContactPartner(event.getContactPartner());
parent.setLead(event.getLead());
parent.setTypeSelect(event.getTypeSelect());
parent.setLocation(event.getLocation());
eventRepo.save(parent);
parent = nextParent;
}
}
use of com.axelor.apps.crm.db.Event 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);
}
}
}
}
use of com.axelor.apps.crm.db.Event in project axelor-open-suite by axelor.
the class EventServiceImpl method addRecurrentEventsByYears.
@Override
@Transactional
public void addRecurrentEventsByYears(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().plusYears(periodicity));
copy.setEndDateTime(copy.getEndDateTime().plusYears(periodicity));
lastEvent = eventRepo.save(copy);
repeated++;
}
} else {
while (lastEvent.getStartDateTime().plusYears(periodicity).isBefore(endDate.atStartOfDay().plusYears(1))) {
Event copy = eventRepo.copy(lastEvent, false);
copy.setParentEvent(event);
copy.setStartDateTime(copy.getStartDateTime().plusYears(periodicity));
copy.setEndDateTime(copy.getEndDateTime().plusYears(periodicity));
lastEvent = eventRepo.save(copy);
}
}
}
use of com.axelor.apps.crm.db.Event in project axelor-open-suite by axelor.
the class EventServiceImpl method createEvent.
@Override
public Event createEvent(LocalDateTime fromDateTime, LocalDateTime toDateTime, User user, String description, int type, String subject) {
Event event = new Event();
event.setSubject(subject);
event.setStartDateTime(fromDateTime);
event.setEndDateTime(toDateTime);
event.setUser(user);
event.setTypeSelect(type);
if (!Strings.isNullOrEmpty(description)) {
event.setDescription(description);
}
if (fromDateTime != null && toDateTime != null) {
long duration = Duration.between(fromDateTime, toDateTime).getSeconds();
event.setDuration(duration);
}
return event;
}
use of com.axelor.apps.crm.db.Event in project axelor-open-suite by axelor.
the class EventServiceImpl method addRecurrentEventsByMonths.
@Override
@Transactional
public void addRecurrentEventsByMonths(Event event, int periodicity, int endType, int repetitionsNumber, LocalDate endDate, int monthRepeatType) {
int weekNo = 1 + (event.getStartDateTime().getDayOfMonth() - 1) / 7;
Duration duration = Duration.between(event.getStartDateTime(), event.getEndDateTime());
Event lastEvent = event;
BiFunction<Integer, LocalDateTime, Boolean> breakConditionFunc;
Function<LocalDateTime, LocalDateTime> nextStartDateTimeFunc;
LocalDateTime nextStartDateTime;
if (endType == RecurrenceConfigurationRepository.END_TYPE_REPET) {
breakConditionFunc = (iteration, dateTime) -> iteration >= repetitionsNumber;
} else {
breakConditionFunc = (iteration, dateTime) -> dateTime.toLocalDate().isAfter(endDate);
}
if (monthRepeatType == RecurrenceConfigurationRepository.REPEAT_TYPE_MONTH) {
nextStartDateTimeFunc = dateTime -> dateTime.withDayOfMonth(1).plusMonths(periodicity).withDayOfMonth(event.getStartDateTime().getDayOfMonth());
} else {
nextStartDateTimeFunc = dateTime -> {
LocalDateTime baseNextDateTime = dateTime.withDayOfMonth(1).plusMonths(periodicity);
dateTime = baseNextDateTime.with(TemporalAdjusters.dayOfWeekInMonth(weekNo, event.getStartDateTime().getDayOfWeek()));
if (!dateTime.getMonth().equals(baseNextDateTime.getMonth()) && weekNo > 1) {
dateTime = baseNextDateTime.with(TemporalAdjusters.dayOfWeekInMonth(weekNo - 1, event.getStartDateTime().getDayOfWeek()));
}
return dateTime;
};
}
for (int iteration = 0; ; ++iteration) {
if (iteration > ITERATION_LIMIT) {
throw new TooManyIterationsException(iteration);
}
nextStartDateTime = nextStartDateTimeFunc.apply(lastEvent.getStartDateTime());
if (breakConditionFunc.apply(iteration, nextStartDateTime)) {
break;
}
Event copy = eventRepo.copy(lastEvent, false);
copy.setParentEvent(event);
copy.setStartDateTime(nextStartDateTime);
copy.setEndDateTime(nextStartDateTime.plus(duration));
lastEvent = eventRepo.save(copy);
}
}
Aggregations