use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method updateEventAlreadyInSync.
/**
* @see org.olat.commons.calendar.CalendarManager#updateEventFrom(org.olat.commons.calendar.model.Kalendar, org.olat.commons.calendar.model.KalendarEvent)
*/
@Override
public boolean updateEventAlreadyInSync(final Kalendar cal, final KalendarEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
CoordinatorManager.getInstance().getCoordinator().getSyncer().assertAlreadyDoInSyncFor(calOres);
Kalendar reloadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
if (StringHelper.containsNonWhitespace(kalendarEvent.getRecurrenceRule())) {
Date oldBegin = kalendarEvent.getImmutableBegin();
Date oldEnd = kalendarEvent.getImmutableEnd();
KalendarEvent originalEvent = reloadedCal.getEvent(kalendarEvent.getID(), null);
Date newBegin = kalendarEvent.getBegin();
Date newEnd = kalendarEvent.getEnd();
long beginDiff = newBegin.getTime() - oldBegin.getTime();
long endDiff = newEnd.getTime() - oldEnd.getTime();
java.util.Calendar cl = java.util.Calendar.getInstance();
cl.setTime(originalEvent.getBegin());
cl.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
kalendarEvent.setBegin(cl.getTime());
cl.setTime(originalEvent.getEnd());
cl.add(java.util.Calendar.MILLISECOND, (int) endDiff);
kalendarEvent.setEnd(cl.getTime());
List<KalendarEvent> exEvents = new ArrayList<>();
List<KalendarEvent> allEvents = reloadedCal.getEvents();
for (KalendarEvent event : allEvents) {
if (event.getID().equals(kalendarEvent.getID()) && StringHelper.containsNonWhitespace(event.getRecurrenceID())) {
exEvents.add(event);
}
}
if (exEvents.size() > 0) {
for (KalendarEvent exEvent : exEvents) {
try {
reloadedCal.removeEvent(exEvent);
String recurrenceId = exEvent.getRecurrenceID();
RecurrenceId recurId = new RecurrenceId(recurrenceId, tz);
Date currentRecurrence = recurId.getDate();
java.util.Calendar calc = java.util.Calendar.getInstance();
calc.clear();
calc.setTime(currentRecurrence);
if (beginDiff > 0) {
calc.add(java.util.Calendar.MILLISECOND, (int) beginDiff);
}
Date newRecurrenceDate = calc.getTime();
boolean allDay = kalendarEvent.isAllDayEvent();
RecurrenceId newRecurId;
if (allDay) {
newRecurId = new RecurrenceId(tz);
newRecurId.setDate(CalendarUtils.createDate(newRecurrenceDate));
} else {
String startString = CalendarUtils.formatRecurrenceDate(newRecurrenceDate, false);
newRecurId = new RecurrenceId(startString, tz);
}
exEvent.setRecurrenceID(newRecurId.getValue());
reloadedCal.addEvent(exEvent);
} catch (ParseException e) {
log.error("", e);
}
}
}
}
// remove old event
reloadedCal.removeEvent(kalendarEvent);
kalendarEvent.resetImmutableDates();
// add changed event
reloadedCal.addEvent(kalendarEvent);
boolean successfullyPersist = persistCalendar(reloadedCal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return successfullyPersist;
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method removeOccurenceOfEvent.
@Override
public boolean removeOccurenceOfEvent(final Kalendar cal, final KalendarRecurEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
String uid = kalendarEvent.getID();
Date occurenceDate = kalendarEvent.getBegin();
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
rootEvent.addRecurrenceExc(kalendarEvent.getBegin());
for (KalendarEvent kEvent : loadedCal.getEvents()) {
if (uid.equals(kEvent.getID()) && kEvent.getOccurenceDate() != null && occurenceDate.equals(kEvent.getOccurenceDate())) {
loadedCal.removeEvent(kEvent);
}
}
boolean successfullyPersist = persistCalendar(loadedCal);
return new Boolean(successfullyPersist);
}
});
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return removeSuccessful.booleanValue();
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method updateCalendar.
@Override
public boolean updateCalendar(final Kalendar cal, final Kalendar importedCal) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean updatedSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
Map<KalendarEventKey, KalendarEvent> uidToEvent = new HashMap<>();
for (KalendarEvent event : cal.getEvents()) {
if (StringHelper.containsNonWhitespace(event.getID())) {
uidToEvent.put(new KalendarEventKey(event), event);
}
}
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
for (KalendarEvent importedEvent : importedCal.getEvents()) {
KalendarEventKey uid = new KalendarEventKey(importedEvent);
if (uidToEvent.containsKey(uid)) {
// remove old event
loadedCal.removeEvent(importedEvent);
// add changed event
loadedCal.addEvent(importedEvent);
} else {
loadedCal.addEvent(importedEvent);
}
}
boolean successfullyPersist = persistCalendar(cal);
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return new Boolean(successfullyPersist);
}
});
return updatedSuccessful.booleanValue();
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method createKalendar.
protected Kalendar createKalendar(String type, String calendarID, Calendar calendar) {
Kalendar cal = new Kalendar(calendarID, type);
for (Iterator<?> iter = calendar.getComponents().iterator(); iter.hasNext(); ) {
Object comp = iter.next();
if (comp instanceof VEvent) {
VEvent vevent = (VEvent) comp;
KalendarEvent calEvent = getKalendarEvent(vevent);
cal.addEvent(calEvent);
} else if (comp instanceof VTimeZone) {
log.info("createKalendar: VTimeZone Component is not supported and will not be added to calender");
log.debug("createKalendar: VTimeZone=" + comp);
} else {
log.warn("createKalendar: unknown Component=" + comp);
}
}
return cal;
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class CalendarTest method testPutPersonalCalendarEvents.
@Test
public void testPutPersonalCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id2.getName(), "A6B7C8"));
URI calUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").build();
HttpGet calMethod = conn.createGet(calUri, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(calMethod);
assertEquals(200, response.getStatusLine().getStatusCode());
List<CalendarVO> vos = parseArray(response);
assertNotNull(vos);
assertTrue(2 <= vos.size());
CalendarVO calendar = getUserCalendar(vos);
// create an event
EventVO event = new EventVO();
Calendar cal = Calendar.getInstance();
event.setBegin(cal.getTime());
cal.add(Calendar.HOUR_OF_DAY, 1);
event.setEnd(cal.getTime());
String subject = UUID.randomUUID().toString();
event.setSubject(subject);
URI eventUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").path(calendar.getId()).path("event").build();
HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
conn.addJsonEntity(putEventMethod, event);
HttpResponse putEventResponse = conn.execute(putEventMethod);
assertEquals(200, putEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(putEventResponse.getEntity());
// check if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(id2);
Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
boolean found = false;
for (KalendarEvent savedEvent : savedEvents) {
if (subject.equals(savedEvent.getSubject())) {
found = true;
}
}
Assert.assertTrue(found);
conn.shutdown();
}
Aggregations