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