Search in sources :

Example 71 with KalendarEvent

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

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)

Example 72 with KalendarEvent

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

the class CourseCalendarTest method putCalendarEvents.

@Test
public void putCalendarEvents() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    Identity admin = BaseSecurityManager.getInstance().findIdentityByName("administrator");
    Assert.assertTrue(conn.login("administrator", "openolat"));
    CourseConfigVO config = new CourseConfigVO();
    config.setCalendar(Boolean.TRUE);
    ICourse course = CoursesWebService.createEmptyCourse(admin, "Course with calendar", "Course with calendar", config);
    dbInstance.commitAndCloseSession();
    // create an event
    EventVO event1 = new EventVO();
    Calendar cal = Calendar.getInstance();
    event1.setBegin(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 1);
    event1.setEnd(cal.getTime());
    String subject1 = UUID.randomUUID().toString();
    event1.setSubject(subject1);
    EventVO event2 = new EventVO();
    event2.setBegin(cal.getTime());
    cal.add(Calendar.HOUR_OF_DAY, 1);
    event2.setEnd(cal.getTime());
    String subject2 = UUID.randomUUID().toString();
    event2.setSubject(subject2);
    EventVO[] newEvents = new EventVO[2];
    newEvents[0] = event1;
    newEvents[1] = event2;
    URI eventUri = UriBuilder.fromUri(getContextURI()).path("repo").path("courses").path(course.getResourceableId().toString()).path("calendar").path("events").build();
    HttpPut putEventMethod = conn.createPut(eventUri, MediaType.APPLICATION_JSON, true);
    conn.addJsonEntity(putEventMethod, newEvents);
    HttpResponse putEventResponse = conn.execute(putEventMethod);
    assertEquals(200, putEventResponse.getStatusLine().getStatusCode());
    EntityUtils.consume(putEventResponse.getEntity());
    // check if the event is saved
    KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
    Collection<KalendarEvent> savedEvents = calendarWrapper.getKalendar().getEvents();
    boolean found1 = false;
    boolean found2 = false;
    for (KalendarEvent savedEvent : savedEvents) {
        if (subject1.equals(savedEvent.getSubject())) {
            found1 = true;
        } else if (subject2.equals(savedEvent.getSubject())) {
            found2 = true;
        }
    }
    Assert.assertTrue(found1);
    Assert.assertTrue(found2);
    conn.shutdown();
}
Also used : Calendar(java.util.Calendar) HttpResponse(org.apache.http.HttpResponse) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) Identity(org.olat.core.id.Identity) EventVO(org.olat.commons.calendar.restapi.EventVO) Test(org.junit.Test)

Example 73 with KalendarEvent

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

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

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

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

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

the class ICalFileCalendarManagerTest method testAddChangeRemoveEvent.

@Test
public void testAddChangeRemoveEvent() {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ical-1-");
    String TEST_EVENT_ID = "id-testAddEvent";
    Kalendar cal = calendarManager.getPersonalCalendar(test).getKalendar();
    // 1. Test Add Event
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 13);
    calendar.set(Calendar.MINUTE, 12);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    Date start = calendar.getTime();
    // 1 hour
    KalendarEvent testEvent = new KalendarEvent(TEST_EVENT_ID, "testEvent", start, 60 * 60 * 1000);
    calendarManager.addEventTo(cal, testEvent);
    // set manager null to force reload of calendar from file-system
    emptyCalendarCache();
    cal = calendarManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent reloadedEvent = cal.getEvent(TEST_EVENT_ID, null);
    Assert.assertNotNull("Could not found added event", reloadedEvent);
    Assert.assertEquals("Added event has wrong subject", testEvent.getSubject(), reloadedEvent.getSubject());
    Assert.assertEquals(start, reloadedEvent.getBegin());
    // calculate and check end date
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    Date end = calendar.getTime();
    Assert.assertEquals(end, reloadedEvent.getEnd());
    Assert.assertFalse(reloadedEvent.isAllDayEvent());
    Assert.assertTrue(reloadedEvent.isToday());
    // 2. Test Change event
    calendar.add(Calendar.HOUR_OF_DAY, 1);
    Date updatedEnd = calendar.getTime();
    reloadedEvent.setSubject("testEvent changed");
    reloadedEvent.setEnd(updatedEnd);
    calendarManager.updateEventFrom(cal, reloadedEvent);
    // set manager null to force reload of calendar from file-system
    emptyCalendarCache();
    cal = calendarManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent updatedEvent = cal.getEvent(TEST_EVENT_ID, null);
    Assert.assertNotNull("Could not found updated event", updatedEvent);
    Assert.assertEquals("Added event has wrong subject", reloadedEvent.getSubject(), updatedEvent.getSubject());
    Assert.assertEquals(start, reloadedEvent.getBegin());
    Assert.assertEquals(updatedEnd, reloadedEvent.getEnd());
    // 3. Test Remove event
    calendarManager.removeEventFrom(cal, updatedEvent);
    emptyCalendarCache();
    cal = calendarManager.getPersonalCalendar(test).getKalendar();
    KalendarEvent removedEvent = cal.getEvent(TEST_EVENT_ID, null);
    assertNull("Found removed event", removedEvent);
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) 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