Search in sources :

Example 91 with KalendarEvent

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

the class CalendarTest method putCalendarEvent.

@Test
public void putCalendarEvent() 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 = getCourseCalendar(vos, course2);
    Assert.assertNotNull(calendar);
    // 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.getCourseCalendar(course2);
    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();
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) Calendar(java.util.Calendar) CalendarVO(org.olat.commons.calendar.restapi.CalendarVO) HttpResponse(org.apache.http.HttpResponse) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 92 with KalendarEvent

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

the class CalendarTest method testPostCalendarEvents.

@Test
public void testPostCalendarEvents() 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);
    assertTrue(vos != null && !vos.isEmpty());
    CalendarVO calendar = getCourseCalendar(vos, course2);
    Assert.assertNotNull(calendar);
    // 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();
    HttpPost postEventMethod = conn.createPost(eventUri, MediaType.APPLICATION_JSON);
    conn.addJsonEntity(postEventMethod, event);
    HttpResponse postEventResponse = conn.execute(postEventMethod);
    assertEquals(200, postEventResponse.getStatusLine().getStatusCode());
    // check if the event is saved
    KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
    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();
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpGet(org.apache.http.client.methods.HttpGet) Calendar(java.util.Calendar) CalendarVO(org.olat.commons.calendar.restapi.CalendarVO) HttpResponse(org.apache.http.HttpResponse) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 93 with KalendarEvent

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

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

Example 94 with KalendarEvent

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

the class EventsModel method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == tableController) {
        if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
            TableEvent te = (TableEvent) event;
            String actionid = te.getActionId();
            if (actionid.equals(CMD_LAUNCH)) {
                int rowid = te.getRowId();
                KalendarEvent kalendarEvent = ((EventsModel) tableController.getTableDataModel()).getObject(rowid);
                String resourceUrl = "[HomeSite:" + ureq.getIdentity().getKey() + "][calendar:0]" + BusinessControlFactory.getInstance().getContextEntryStringForDate(kalendarEvent.getBegin());
                BusinessControl bc = BusinessControlFactory.getInstance().createFromString(resourceUrl);
                WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(bc, getWindowControl());
                NewControllerFactory.getInstance().launch(ureq, bwControl);
            }
        }
    }
}
Also used : TableEvent(org.olat.core.gui.components.table.TableEvent) BusinessControl(org.olat.core.id.context.BusinessControl) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) WindowControl(org.olat.core.gui.control.WindowControl)

Example 95 with KalendarEvent

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

the class ICalFileCalendarManagerTest method synchronizeCalendarFrom.

@Test
public void synchronizeCalendarFrom() throws ValidationException, IOException {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("s1-");
    Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
    String eventId1 = "id-not-managed-event";
    // 1. Add a standard event, not managed
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MILLISECOND, 0);
    Date start = calendar.getTime();
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    Date end = calendar.getTime();
    KalendarEvent notManagedEvent = new KalendarEvent(eventId1, null, "testEvent", start, end);
    calendarManager.addEventTo(cal, notManagedEvent);
    // 2. Synchronize with a first calendar
    Kalendar baseCalendar = calendarManager.createCalendar("user", "first-sync");
    String eventIdManaged1 = "managed-event-1";
    KalendarEvent managedEvent1 = new KalendarEvent(eventIdManaged1, null, "managedEvent", start, end);
    baseCalendar.addEvent(managedEvent1);
    String eventIdManaged2 = "managed-event-2";
    KalendarEvent managedEvent2 = new KalendarEvent(eventIdManaged2, null, "managedEvent", start, end);
    baseCalendar.addEvent(managedEvent2);
    ByteArrayOutputStream os1 = new ByteArrayOutputStream();
    new CalendarOutputter(false).output(calendarManager.buildCalendar(baseCalendar), os1);
    InputStream in1 = new ByteArrayInputStream(os1.toByteArray());
    calendarManager.synchronizeCalendarFrom(in1, "http://localhost:8080/unittest", cal);
    in1.close();
    // 3. Synchronize with a second calendar
    Kalendar resyncCalendar = calendarManager.createCalendar("user", "first-sync");
    KalendarEvent managedEvent1Alt = new KalendarEvent(eventIdManaged1, null, "managedEvent resync", start, end);
    resyncCalendar.addEvent(managedEvent1Alt);
    String eventIdManaged3 = "managed-event-3";
    KalendarEvent managedEvent3 = new KalendarEvent(eventIdManaged3, null, "managedEvent 3", start, end);
    resyncCalendar.addEvent(managedEvent3);
    ByteArrayOutputStream os2 = new ByteArrayOutputStream();
    new CalendarOutputter(false).output(calendarManager.buildCalendar(resyncCalendar), os2);
    InputStream in2 = new ByteArrayInputStream(os2.toByteArray());
    calendarManager.synchronizeCalendarFrom(in2, "http://localhost:8080/unittest", cal);
    in2.close();
    emptyCalendarCache();
    // check
    Kalendar synchedCal = calendarManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent notManagedEvent1 = synchedCal.getEvent(eventId1, null);
    Assert.assertNotNull(notManagedEvent1);
    Assert.assertEquals("testEvent", notManagedEvent1.getSubject());
    KalendarEvent event1 = synchedCal.getEvent(eventIdManaged1, null);
    Assert.assertNotNull(event1);
    Assert.assertEquals("managedEvent resync", event1.getSubject());
    KalendarEvent event2 = synchedCal.getEvent(eventIdManaged2, null);
    Assert.assertNull(event2);
    KalendarEvent event3 = synchedCal.getEvent(eventIdManaged3, null);
    Assert.assertNotNull(event3);
    Assert.assertEquals("managedEvent 3", event3.getSubject());
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) Identity(org.olat.core.id.Identity) Date(java.util.Date) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) 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