Search in sources :

Example 1 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.

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 2 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.

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 3 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.

the class EventsModel method getMatchingEvents.

private List<KalendarEvent> getMatchingEvents(UserRequest ureq, WindowControl wControl) {
    Date startDate = new Date();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + 7);
    Date endDate = cal.getTime();
    List<KalendarEvent> events = new ArrayList<>();
    List<KalendarRenderWrapper> calendars = personalCalendarManager.getListOfCalendarWrappers(ureq, wControl);
    for (Iterator<KalendarRenderWrapper> iter = calendars.iterator(); iter.hasNext(); ) {
        KalendarRenderWrapper calendarWrapper = iter.next();
        boolean readOnly = (calendarWrapper.getAccess() == KalendarRenderWrapper.ACCESS_READ_ONLY) && !calendarWrapper.isImported();
        List<KalendarEvent> eventsWithinPeriod = calendarManager.getEvents(calendarWrapper.getKalendar(), startDate, endDate, true);
        for (KalendarEvent event : eventsWithinPeriod) {
            // skip non-public events
            if (readOnly && event.getClassification() != KalendarEvent.CLASS_PUBLIC) {
                continue;
            }
            events.add(event);
        }
    }
    // sort events
    Collections.sort(events, new Comparator<KalendarEvent>() {

        public int compare(KalendarEvent arg0, KalendarEvent arg1) {
            Date begin0 = arg0.getBegin();
            Date begin1 = arg1.getBegin();
            return begin0.compareTo(begin1);
        }
    });
    if (events.size() > MAX_EVENTS)
        events = events.subList(0, MAX_EVENTS);
    return events;
}
Also used : Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date)

Example 4 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.

the class CourseCalendarTest method setUp.

/**
 * SetUp is called before each test.
 */
@Before
public void setUp() throws Exception {
    super.setUp();
    try {
        // create course and persist as OLATResourceImpl
        auth1 = JunitTestHelper.createAndPersistIdentityAsUser("rest-course-cal-one");
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course1 = CoursesWebService.createEmptyCourse(auth1, "course calendar", "course with calendar for REST API testing", config);
        dbInstance.commit();
        ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
        Assert.assertTrue(course.getCourseConfig().isCalendarEnabled());
        CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
        KalendarRenderWrapper calendarWrapper = calManager.getCourseCalendar(course);
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 2; i++) {
            Date begin = cal.getTime();
            cal.add(Calendar.HOUR_OF_DAY, 1);
            Date end = cal.getTime();
            String eventId = UUID.randomUUID().toString();
            KalendarEvent event = new KalendarEvent(eventId, null, "Unit test " + i, begin, end);
            calManager.addEventTo(calendarWrapper.getKalendar(), event);
            cal.add(Calendar.DATE, 1);
        }
    } catch (Exception e) {
        log.error("Exception in setUp(): " + e);
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) CalendarManager(org.olat.commons.calendar.CalendarManager) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Before(org.junit.Before)

Example 5 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.

the class CourseCalendarTest method deleteCalendarEvent.

@Test
public void deleteCalendarEvent() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(auth1.getName(), "A6B7C8"));
    // create an event if the event is saved
    KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course1);
    Calendar cal = Calendar.getInstance();
    Date begin = cal.getTime();
    cal.add(Calendar.HOUR_OF_DAY, 1);
    String id = UUID.randomUUID().toString();
    KalendarEvent kalEvent = new KalendarEvent(id, null, "Subject (" + id + ")", begin, cal.getTime());
    calendarManager.addEventTo(calendarWrapper.getKalendar(), kalEvent);
    // check if the event exists
    URI uri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").path("events").build();
    HttpGet method = conn.createGet(uri, MediaType.APPLICATION_JSON, true);
    HttpResponse response = conn.execute(method);
    assertEquals(200, response.getStatusLine().getStatusCode());
    List<EventVO> vos = parseEventArray(response.getEntity().getContent());
    assertNotNull(vos);
    boolean found = false;
    for (EventVO vo : vos) {
        if (id.equals(vo.getId())) {
            found = true;
        }
    }
    assertTrue(found);
    // delete the event
    URI eventUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").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 really deleted
    KalendarRenderWrapper reloadedCalendarWrapper = calendarManager.getCourseCalendar(course1);
    Collection<KalendarEvent> savedEvents = reloadedCalendarWrapper.getKalendar().getEvents();
    for (KalendarEvent savedEvent : savedEvents) {
        Assert.assertFalse(savedEvent.getID().equals(kalEvent.getID()));
    }
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) Calendar(java.util.Calendar) HttpGet(org.apache.http.client.methods.HttpGet) 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) EventVO(org.olat.commons.calendar.restapi.EventVO) 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