Search in sources :

Example 1 with KalendarRenderWrapper

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

the class HomeCalendarManager method addCalendars.

/**
 * Append the calendars of a list of groups. The groups must have their calendar tool
 * enabled, this routine doesn't check it.
 * @param ureq
 * @param groups
 * @param isOwner
 * @param calendars
 */
private void addCalendars(List<BusinessGroup> groups, boolean isOwner, boolean isParticipant, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    Map<Long, Long> groupKeyToAccess = CoreSpringFactory.getImpl(CollaborationManager.class).lookupCalendarAccess(groups);
    for (BusinessGroup bGroup : groups) {
        try {
            KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
            groupCalendarWrapper.setPrivateEventsVisible(true);
            // set calendar access
            int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
            Long lCalAccess = groupKeyToAccess.get(bGroup.getKey());
            if (lCalAccess != null) {
                iCalAccess = lCalAccess.intValue();
            }
            if (iCalAccess == CollaborationTools.CALENDAR_ACCESS_OWNERS && !isOwner) {
                groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
            } else {
                groupCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
            }
            CalendarUserConfiguration config = configMap.get(groupCalendarWrapper.getCalendarKey());
            if (config != null) {
                groupCalendarWrapper.setConfiguration(config);
            }
            if (isOwner || isParticipant) {
                groupCalendarWrapper.setPrivateEventsVisible(true);
            }
            calendars.add(groupCalendarWrapper);
        } catch (Exception e) {
            log.error("Cannot read calendar of group: " + bGroup, e);
        }
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CollaborationManager(org.olat.collaboration.CollaborationManager) CorruptedCourseException(org.olat.course.CorruptedCourseException)

Example 2 with KalendarRenderWrapper

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

the class HomeCalendarManager method appendPersonalCalendar.

private void appendPersonalCalendar(Identity identity, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    // get the personal calendar
    if (calendarModule.isEnablePersonalCalendar()) {
        try {
            KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(identity);
            calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
            calendarWrapper.setPrivateEventsVisible(true);
            CalendarUserConfiguration config = configMap.get(calendarWrapper.getCalendarKey());
            if (config != null) {
                calendarWrapper.setConfiguration(config);
            }
            calendars.add(calendarWrapper);
        } catch (Exception e) {
            log.error("Cannot read personal calendar of: " + identity, e);
        }
    }
}
Also used : CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CorruptedCourseException(org.olat.course.CorruptedCourseException)

Example 3 with KalendarRenderWrapper

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

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

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

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