Search in sources :

Example 86 with KalendarEvent

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);
    }
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity)

Example 87 with KalendarEvent

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);
    }
}
Also used : Util(org.olat.core.util.Util) LectureParticipantSummary(org.olat.modules.lecture.LectureParticipantSummary) LectureBlockRollCallSearchParameters(org.olat.modules.lecture.LectureBlockRollCallSearchParameters) Date(java.util.Date) I18nManager(org.olat.core.util.i18n.I18nManager) RepositoryEntryRef(org.olat.repository.RepositoryEntryRef) LectureBlockAuditLog(org.olat.modules.lecture.LectureBlockAuditLog) Autowired(org.springframework.beans.factory.annotation.Autowired) IdentityRef(org.olat.basesecurity.IdentityRef) MailContextImpl(org.olat.core.util.mail.MailContextImpl) RepositoryEntryLectureConfiguration(org.olat.modules.lecture.RepositoryEntryLectureConfiguration) Locale(java.util.Locale) GroupDAO(org.olat.basesecurity.manager.GroupDAO) Map(java.util.Map) Group(org.olat.basesecurity.Group) LectureBlockToGroup(org.olat.modules.lecture.LectureBlockToGroup) LectureBlockStatistics(org.olat.modules.lecture.model.LectureBlockStatistics) MailTemplate(org.olat.core.util.mail.MailTemplate) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) OLog(org.olat.core.logging.OLog) Translator(org.olat.core.gui.translator.Translator) LectureBlock(org.olat.modules.lecture.LectureBlock) LectureBlockWithTeachers(org.olat.modules.lecture.model.LectureBlockWithTeachers) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) Set(java.util.Set) LectureBlockImpl(org.olat.modules.lecture.model.LectureBlockImpl) UUID(java.util.UUID) AggregatedLectureBlocksStatistics(org.olat.modules.lecture.model.AggregatedLectureBlocksStatistics) Collectors(java.util.stream.Collectors) VelocityContext(org.apache.velocity.VelocityContext) MailManager(org.olat.core.util.mail.MailManager) LectureService(org.olat.modules.lecture.LectureService) List(java.util.List) Identity(org.olat.core.id.Identity) ParticipantAndLectureSummary(org.olat.modules.lecture.model.ParticipantAndLectureSummary) IdentityImpl(org.olat.basesecurity.IdentityImpl) MailContext(org.olat.core.util.mail.MailContext) LectureBlockIdentityStatistics(org.olat.modules.lecture.model.LectureBlockIdentityStatistics) Settings(org.olat.core.helpers.Settings) MailBundle(org.olat.core.util.mail.MailBundle) LectureBlockAndRollCall(org.olat.modules.lecture.model.LectureBlockAndRollCall) Action(org.olat.modules.lecture.LectureBlockAuditLog.Action) HashMap(java.util.HashMap) CalendarManagedFlag(org.olat.commons.calendar.CalendarManagedFlag) Reason(org.olat.modules.lecture.Reason) RepositoryEntry(org.olat.repository.RepositoryEntry) LecturesBlockSearchParameters(org.olat.modules.lecture.model.LecturesBlockSearchParameters) ArrayList(java.util.ArrayList) Kalendar(org.olat.commons.calendar.model.Kalendar) HashSet(java.util.HashSet) Calendar(java.util.Calendar) Service(org.springframework.stereotype.Service) StringHelper(org.olat.core.util.StringHelper) LectureBlockRollCall(org.olat.modules.lecture.LectureBlockRollCall) RepositoryEntryDAO(org.olat.repository.manager.RepositoryEntryDAO) LectureBlockToTeacher(org.olat.modules.lecture.model.LectureBlockToTeacher) CalendarManager(org.olat.commons.calendar.CalendarManager) LectureBlockRef(org.olat.modules.lecture.LectureBlockRef) LectureBlockStatus(org.olat.modules.lecture.LectureBlockStatus) LectureStatisticsSearchParameters(org.olat.modules.lecture.model.LectureStatisticsSearchParameters) Formatter(org.olat.core.util.Formatter) MailerResult(org.olat.core.util.mail.MailerResult) LectureAdminController(org.olat.modules.lecture.ui.LectureAdminController) LectureModule(org.olat.modules.lecture.LectureModule) Iterator(java.util.Iterator) LectureBlockRollCallRef(org.olat.modules.lecture.LectureBlockRollCallRef) File(java.io.File) UserManager(org.olat.user.UserManager) DB(org.olat.core.commons.persistence.DB) BusinessGroup(org.olat.group.BusinessGroup) DeletableGroupData(org.olat.group.DeletableGroupData) LectureRollCallStatus(org.olat.modules.lecture.LectureRollCallStatus) Tracing(org.olat.core.logging.Tracing) ConfigurationHelper(org.olat.modules.lecture.ui.ConfigurationHelper) UserDataDeletable(org.olat.user.UserDataDeletable) LectureBlock(org.olat.modules.lecture.LectureBlock) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Map(java.util.Map) HashMap(java.util.HashMap)

Example 88 with KalendarEvent

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;
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent)

Example 89 with KalendarEvent

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);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent)

Example 90 with KalendarEvent

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()));
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) HttpResponse(org.apache.http.HttpResponse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Aggregations

KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)172 Date (java.util.Date)80 Kalendar (org.olat.commons.calendar.model.Kalendar)68 Test (org.junit.Test)48 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)46 Identity (org.olat.core.id.Identity)46 ArrayList (java.util.ArrayList)42 Calendar (java.util.Calendar)40 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)34 CalendarManager (org.olat.commons.calendar.CalendarManager)32 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 File (java.io.File)16 ExDate (net.fortuna.ical4j.model.property.ExDate)16 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 URL (java.net.URL)12 KalendarRecurEvent (org.olat.commons.calendar.model.KalendarRecurEvent)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12