Search in sources :

Example 76 with KalendarRenderWrapper

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

the class CourseCalendarTest method putCalendarEvent.

@Test
public void putCalendarEvent() throws IOException, URISyntaxException {
    RestConnection conn = new RestConnection();
    assertTrue(conn.login(auth1.getName(), "A6B7C8"));
    // 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("repo").path("courses").path(course1.getResourceableId().toString()).path("calendar").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(course1);
    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 : Calendar(java.util.Calendar) 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 77 with KalendarRenderWrapper

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

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 78 with KalendarRenderWrapper

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

the class ICalFileCalendarManager method getGroupCalendar.

@Override
public KalendarRenderWrapper getGroupCalendar(BusinessGroup businessGroup) {
    Kalendar cal = getCalendar(CalendarManager.TYPE_GROUP, businessGroup.getResourceableId().toString());
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, businessGroup.getName());
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_ORANGE);
    calendarWrapper.setVisible(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 79 with KalendarRenderWrapper

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

the class ICalFileCalendarManager method getCalendarForDeletion.

@Override
public KalendarRenderWrapper getCalendarForDeletion(OLATResourceable resource) {
    String type;
    if ("CourseModule".equals(resource.getResourceableTypeName())) {
        type = CalendarManager.TYPE_COURSE;
    } else {
        type = CalendarManager.TYPE_GROUP;
    }
    Kalendar cal = getCalendar(type, resource.getResourceableId().toString());
    KalendarRenderWrapper calendarWrapper = new KalendarRenderWrapper(cal, "To delete");
    calendarWrapper.setCssClass(KalendarRenderWrapper.CALENDAR_COLOR_GREEN);
    calendarWrapper.setVisible(true);
    return calendarWrapper;
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 80 with KalendarRenderWrapper

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

the class ImportCalendarManager method importCalendar.

public KalendarRenderWrapper importCalendar(Identity identity, String calendarName, String type, String url) throws IOException {
    File tmpFile = new File(WebappHelper.getTmpDir(), UUID.randomUUID() + ".ics");
    try (InputStream in = new URL(url).openStream()) {
        Files.copy(in, tmpFile.toPath());
    } catch (IOException e) {
        throw e;
    }
    KalendarRenderWrapper calendarWrapper = null;
    Calendar calendar = calendarManager.readCalendar(tmpFile);
    if (calendar != null) {
        String calendarID = getImportedCalendarID(identity, calendarName);
        File calendarFile = calendarManager.getCalendarFile(type, calendarID);
        if (!tmpFile.renameTo(calendarFile)) {
            Files.copy(tmpFile.toPath(), calendarFile.toPath());
        }
        importedCalendarDao.createImportedCalendar(identity, calendarName, calendarID, type, url, new Date());
        calendarWrapper = calendarManager.getImportedCalendar(identity, calendarID);
        calendarWrapper.setDisplayName(calendarName);
        calendarWrapper.setPrivateEventsVisible(true);
    }
    return calendarWrapper;
}
Also used : InputStream(java.io.InputStream) ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(net.fortuna.ical4j.model.Calendar) IOException(java.io.IOException) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) URL(java.net.URL) Date(java.util.Date)

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