@Override public void execute(Event<UIWeekView> event) throws Exception { UIWeekView calendarview = event.getSource(); String eventId = event.getRequestContext().getRequestParameter(OBJECTID); String calendarId = event.getRequestContext().getRequestParameter(eventId + CALENDARID); String calType = event.getRequestContext().getRequestParameter(eventId + CALTYPE); String startTime = event.getRequestContext().getRequestParameter(eventId + START_TIME); String finishTime = event.getRequestContext().getRequestParameter(eventId + FINISH_TIME); Boolean isOccur = false; if (!Utils.isEmpty(event.getRequestContext().getRequestParameter(eventId + ISOCCUR))) { isOccur = Boolean.parseBoolean(event.getRequestContext().getRequestParameter(eventId + ISOCCUR)); } String recurId = null; if (isOccur) recurId = event.getRequestContext().getRequestParameter(eventId + RECURID); try { String username = CalendarUtils.getCurrentUser(); CalendarEvent eventCalendar = null; if (isOccur && !Utils.isEmpty(recurId)) { eventCalendar = calendarview.getRecurrenceMap().get(eventId).get(recurId); } else { eventCalendar = calendarview.getDataMap().get(eventId); } if (eventCalendar != null) { CalendarService calendarService = CalendarUtils.getCalendarService(); Calendar calBegin = calendarview.getInstanceTempCalendar(); Calendar calEnd = calendarview.getInstanceTempCalendar(); long unit = 15 * 60 * 1000; calBegin.setTimeInMillis((Long.parseLong(startTime) / unit) * unit); eventCalendar.setFromDateTime(calBegin.getTime()); calEnd.setTimeInMillis((Long.parseLong(finishTime) / unit) * unit); eventCalendar.setToDateTime(calEnd.getTime()); if (eventCalendar.getToDateTime().before(eventCalendar.getFromDateTime())) { return; } org.exoplatform.calendar.service.Calendar calendar = null; if (CalendarUtils.PRIVATE_TYPE.equals(calType)) { calendar = calendarService.getUserCalendar(username, calendarId); } else if (CalendarUtils.SHARED_TYPE.equals(calType)) { if (calendarService.getSharedCalendars(username, true) != null) calendar = calendarService.getSharedCalendars(username, true).getCalendarById(calendarId); } else if (CalendarUtils.PUBLIC_TYPE.equals(calType)) { calendar = calendarService.getGroupCalendar(calendarId); } if (calendar == null) { event .getRequestContext() .getUIApplication() .addMessage(new ApplicationMessage("UICalendars.msg.have-no-calendar", null, 1)); } else { if ((CalendarUtils.SHARED_TYPE.equals(calType) && !CalendarUtils.canEdit( calendarview.getApplicationComponent(OrganizationService.class), Utils.getEditPerUsers(calendar), username)) || (CalendarUtils.PUBLIC_TYPE.equals(calType) && !CalendarUtils.canEdit( calendarview.getApplicationComponent(OrganizationService.class), calendar.getEditPermission(), username))) { event .getRequestContext() .getUIApplication() .addMessage( new ApplicationMessage( "UICalendars.msg.have-no-permission-to-edit-event", null, 1)); calendarview.refresh(); event.getRequestContext().addUIComponentToUpdateByAjax(calendarview.getParent()); return; } // if it's a 'virtual' occurrence if (isOccur && !Utils.isEmpty(recurId)) { List<CalendarEvent> listEvent = new ArrayList<CalendarEvent>(); listEvent.add(eventCalendar); calendarService.updateOccurrenceEvent( calendarId, calendarId, calType, calType, listEvent, username); } else { if (calType.equals(CalendarUtils.PRIVATE_TYPE)) { calendarService.saveUserEvent(username, calendarId, eventCalendar, false); } else if (calType.equals(CalendarUtils.SHARED_TYPE)) { calendarService.saveEventToSharedCalendar( username, calendarId, eventCalendar, false); } else if (calType.equals(CalendarUtils.PUBLIC_TYPE)) { calendarService.savePublicEvent(calendarId, eventCalendar, false); } } calendarview.setLastUpdatedEventId(eventId); calendarview.refresh(); UIMiniCalendar uiMiniCalendar = calendarview .getAncestorOfType(UICalendarPortlet.class) .findFirstComponentOfType(UIMiniCalendar.class); event.getRequestContext().addUIComponentToUpdateByAjax(uiMiniCalendar); event.getRequestContext().addUIComponentToUpdateByAjax(calendarview.getParent()); } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Fail to save the event to the calendar", e); } return; } }