use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class LectureServiceImpl method unsyncInternalCalendar.
/*
private void unsyncParticipantsCalendar(RepositoryEntry entry) {
List<Identity> participants = getParticipants(entry);
unsyncInternalCalendar(entry, participants);
}
*/
private void unsyncInternalCalendar(RepositoryEntry entry, List<Identity> identities) {
String prefix = generateExternalIdPrefix(entry);
for (Identity identity : identities) {
Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_USER, identity.getName());
List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
for (KalendarEvent event : events) {
if (event.getExternalId() != null && event.getExternalId().startsWith(prefix)) {
calendarMgr.removeEventFrom(cal, event);
}
}
lectureParticipantSummaryDao.updateCalendarSynchronization(entry, identity);
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class LectureServiceImpl method fullSyncCourseCalendar.
private void fullSyncCourseCalendar(RepositoryEntry entry) {
List<LectureBlock> blocks = getLectureBlocks(entry);
Map<String, LectureBlock> externalIds = blocks.stream().collect(Collectors.toMap(b -> generateExternalId(b, entry), b -> b));
Kalendar cal = calendarMgr.getCalendar(CalendarManager.TYPE_COURSE, entry.getOlatResource().getResourceableId().toString());
String prefix = generateExternalIdPrefix(entry);
List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
for (KalendarEvent event : events) {
String externalId = event.getExternalId();
if (StringHelper.containsNonWhitespace(externalId) && externalId.startsWith(prefix)) {
if (externalIds.containsKey(externalId)) {
if (updateEvent(externalIds.get(externalId), event)) {
calendarMgr.updateEventFrom(cal, event);
}
externalIds.remove(externalId);
} else {
calendarMgr.removeEventFrom(cal, event);
}
}
}
// add new calendar events
List<KalendarEvent> eventsToAdd = new ArrayList<>();
for (Map.Entry<String, LectureBlock> entryToAdd : externalIds.entrySet()) {
eventsToAdd.add(createEvent(entryToAdd.getValue(), entry));
}
if (eventsToAdd.size() > 0) {
calendarMgr.addEventTo(cal, eventsToAdd);
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class LectureServiceImpl method createEvent.
private KalendarEvent createEvent(LectureBlock lectureBlock, RepositoryEntry entry) {
String eventId = UUID.randomUUID().toString();
String title = lectureBlock.getTitle();
KalendarEvent event = new KalendarEvent(eventId, null, title, lectureBlock.getStartDate(), lectureBlock.getEndDate());
event.setExternalId(generateExternalId(lectureBlock, entry));
event.setLocation(lectureBlock.getLocation());
updateEventDescription(lectureBlock, event);
event.setManagedFlags(CAL_MANAGED_FLAGS);
return event;
}
use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.
the class LectureServiceImpl method unsyncEvent.
private void unsyncEvent(LectureBlock lectureBlock, RepositoryEntry entry, Kalendar cal) {
String externalId = generateExternalId(lectureBlock, entry);
List<KalendarEvent> events = new ArrayList<>(cal.getEvents());
for (KalendarEvent event : events) {
if (externalId.equals(event.getExternalId())) {
calendarMgr.removeEventFrom(cal, event);
}
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class CalendarTest method testDeletePersonalCalendarEvents.
@Test
public void testDeletePersonalCalendarEvents() throws IOException, URISyntaxException {
RestConnection conn = new RestConnection();
assertTrue(conn.login(id2.getName(), "A6B7C8"));
// check if the event is saved
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(id2);
KalendarEvent kalEvent = new KalendarEvent(UUID.randomUUID().toString(), null, "Rendez-vous", new Date(), new Date());
calendarManager.addEventTo(calendarWrapper.getKalendar(), kalEvent);
URI eventUri = UriBuilder.fromUri(getContextURI()).path("users").path(id2.getKey().toString()).path("calendars").path("user_" + calendarWrapper.getKalendar().getCalendarID()).path("events").path(kalEvent.getID()).build();
HttpDelete delEventMethod = conn.createDelete(eventUri, MediaType.APPLICATION_JSON);
HttpResponse delEventResponse = conn.execute(delEventMethod);
assertEquals(200, delEventResponse.getStatusLine().getStatusCode());
EntityUtils.consume(delEventResponse.getEntity());
conn.shutdown();
// check if the event is saved
Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
for (KalendarEvent savedEvent : savedEvents) {
Assert.assertFalse(savedEvent.getID().equals(kalEvent.getID()));
}
}
Aggregations