Search in sources :

Example 71 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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 72 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper 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 73 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManagerTest method testCalendarRecurringEventInversed.

/**
 * A recurring event with the start and end date reversed. This error
 * in the calendar cause the whole calendar to crash.
 *
 * @throws URISyntaxException
 * @throws IOException
 */
@Test
public void testCalendarRecurringEventInversed() throws URISyntaxException, IOException {
    Identity test = JunitTestHelper.createAndPersistIdentityAsRndUser("ur1-");
    URL calendarUrl = CalendarImportTest.class.getResource("ReversedRecurringEvent.ics");
    File calendarFile = new File(calendarUrl.toURI());
    String calendarName = UUID.randomUUID().toString().replace("-", "");
    KalendarRenderWrapper importedCalendar = importCalendarManager.importCalendar(test, calendarName, CalendarManager.TYPE_USER, calendarFile);
    List<KalendarEvent> events = importedCalendar.getKalendar().getEvents();
    Assert.assertEquals(1, events.size());
    Calendar cal = Calendar.getInstance();
    cal.set(2018, 03, 10, 10, 00);
    Date startDate = cal.getTime();
    cal.set(2018, 03, 17);
    Date endDate = cal.getTime();
    List<KalendarEvent> recurringEvents = calendarManager.getEvents(importedCalendar.getKalendar(), startDate, endDate, true);
    Assert.assertEquals(0, recurringEvents.size());
}
Also used : Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) URL(java.net.URL) Date(java.util.Date) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 74 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.

the class ICalFileCalendarManagerTest method testListEventsForPeriodWithoutDTEndEvent.

/**
 * Check a NPE
 * @throws IOException
 */
@Test
public void testListEventsForPeriodWithoutDTEndEvent() throws IOException {
    // replace the standard calendar with a forged one
    Identity identity = JunitTestHelper.createAndPersistIdentityAsRndUser("cal-test-1-");
    File calendarFile = calendarManager.getCalendarFile("user", identity.getName());
    if (calendarFile.exists()) {
        calendarFile.delete();
    }
    File newCalendarFile = new File(calendarFile.getParentFile(), calendarFile.getName());
    InputStream in = CalendarImportTest.class.getResourceAsStream("cal_without_dtend.ics");
    FileUtils.copyInputStreamToFile(in, newCalendarFile);
    // to be sure
    emptyCalendarCache();
    // load the calendar
    KalendarRenderWrapper reloadCalWrapper = calendarManager.getPersonalCalendar(identity);
    // check if its the right calendar
    Collection<KalendarEvent> events = reloadCalWrapper.getKalendar().getEvents();
    Assert.assertNotNull(events);
    Assert.assertEquals(1, events.size());
    KalendarEvent event = events.iterator().next();
    Assert.assertEquals("Arbeitszeit: 1-3h", event.getSubject());
    Assert.assertEquals("e73iiu9masoddi4g0vllmi2ht0@google.com", event.getID());
    Assert.assertNull(event.getEnd());
    // test persist
    boolean allOk = calendarManager.persistCalendar(reloadCalWrapper.getKalendar());
    Assert.assertTrue(allOk);
    // an other possible RS
    // within period
    Date periodStart = CalendarUtils.getDate(2010, Calendar.MARCH, 15);
    Date periodEnd = CalendarUtils.getDate(2010, Calendar.MARCH, 20);
    List<KalendarEvent> eventsForPeriod = calendarManager.getEvents(reloadCalWrapper.getKalendar(), periodStart, periodEnd, true);
    Assert.assertNotNull(eventsForPeriod);
    Assert.assertEquals(0, eventsForPeriod.size());
    KalendarEvent eventForPeriod = events.iterator().next();
    Assert.assertEquals("e73iiu9masoddi4g0vllmi2ht0@google.com", eventForPeriod.getID());
    // out of scope
    Date periodStart2 = CalendarUtils.getDate(2008, Calendar.APRIL, 15);
    Date periodEnd2 = CalendarUtils.getDate(2008, Calendar.APRIL, 17);
    List<KalendarEvent> eventsOutOfPeriod = calendarManager.getEvents(reloadCalWrapper.getKalendar(), periodStart2, periodEnd2, true);
    Assert.assertNotNull(eventsOutOfPeriod);
    Assert.assertTrue(eventsOutOfPeriod.isEmpty());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) Date(java.util.Date) CalendarImportTest(org.olat.commons.calendar.CalendarImportTest) Test(org.junit.Test)

Example 75 with KalendarRenderWrapper

use of org.olat.commons.calendar.ui.components.KalendarRenderWrapper in project OpenOLAT by OpenOLAT.

the class CourseCalendarController method getListOfCalendarWrappers.

private List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq) {
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    // add course calendar
    ICourse course = CourseFactory.loadCourse(userCourseEnv.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
    courseKalendarWrapper = calendarManager.getCourseCalendar(course);
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    Roles roles = ureq.getUserSession().getRoles();
    boolean isPrivileged = !userCourseEnv.isCourseReadOnly() && (roles.isOLATAdmin() || userCourseEnv.isAdmin() || repositoryManager.isInstitutionalRessourceManagerFor(getIdentity(), roles, cgm.getCourseEntry()));
    if (isPrivileged) {
        courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
        courseKalendarWrapper.setPrivateEventsVisible(true);
    } else {
        courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
        courseKalendarWrapper.setPrivateEventsVisible(userCourseEnv.isAdmin() || userCourseEnv.isCoach() || userCourseEnv.isParticipant());
    }
    CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(courseKalendarWrapper.getKalendar(), getIdentity());
    if (config != null) {
        courseKalendarWrapper.setConfiguration(config);
    }
    // add link provider
    CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.<ICourse>singletonList(course), ureq, getWindowControl());
    courseKalendarWrapper.setLinkProvider(clpc);
    calendars.add(courseKalendarWrapper);
    // add course group calendars
    // learning groups
    List<BusinessGroup> ownerGroups = cgm.getOwnedBusinessGroups(getIdentity());
    addCalendars(ownerGroups, !userCourseEnv.isCourseReadOnly(), clpc, calendars);
    List<BusinessGroup> attendedGroups = cgm.getParticipatingBusinessGroups(getIdentity());
    for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext(); ) {
        BusinessGroup ownerGroup = ownerGroupsIterator.next();
        if (attendedGroups.contains(ownerGroup))
            attendedGroups.remove(ownerGroup);
    }
    addCalendars(attendedGroups, false, clpc, calendars);
    return calendars;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Aggregations

KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)134 KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)46 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 Identity (org.olat.core.id.Identity)26 Date (java.util.Date)24 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)24 Calendar (java.util.Calendar)22 Kalendar (org.olat.commons.calendar.model.Kalendar)22 ICourse (org.olat.course.ICourse)20 File (java.io.File)18 BusinessGroup (org.olat.group.BusinessGroup)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)14 URL (java.net.URL)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12 CalendarManager (org.olat.commons.calendar.CalendarManager)10 HttpGet (org.apache.http.client.methods.HttpGet)8 UserRequest (org.olat.core.gui.UserRequest)8