Search in sources :

Example 6 with KalendarRenderWrapper

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

the class CalendarTest method startup.

@Before
public void startup() {
    if (id1 == null) {
        id1 = JunitTestHelper.createAndPersistIdentityAsUser("cal-1-" + UUID.randomUUID().toString());
    }
    if (id2 == null) {
        id2 = JunitTestHelper.createAndPersistIdentityAsUser("cal-2-" + UUID.randomUUID().toString());
    }
    if (course1 == null) {
        // create a course with a calendar
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course1 = CoursesWebService.createEmptyCourse(id1, "Cal course", "Cal course", config);
        dbInstance.commit();
        ICourse course = CourseFactory.loadCourse(course1.getResourceableId());
        CourseConfig courseConfig = course.getCourseEnvironment().getCourseConfig();
        Assert.assertTrue(courseConfig.isCalendarEnabled());
        KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course);
        Calendar cal = Calendar.getInstance();
        for (int i = 0; i < 10; i++) {
            Date begin = cal.getTime();
            cal.add(Calendar.HOUR_OF_DAY, 1);
            Date end = cal.getTime();
            KalendarEvent event = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test " + i, begin, end);
            calendarManager.addEventTo(calendarWrapper.getKalendar(), event);
            cal.add(Calendar.DATE, 1);
        }
        cal = Calendar.getInstance();
        cal.add(Calendar.MONTH, -1);
        Date begin2 = cal.getTime();
        cal.add(Calendar.HOUR_OF_DAY, 1);
        Date end2 = cal.getTime();
        KalendarEvent event2 = new KalendarEvent(UUID.randomUUID().toString(), null, "Unit test 2", begin2, end2);
        calendarManager.addEventTo(calendarWrapper.getKalendar(), event2);
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course1, false);
        entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
        repositoryService.addRole(id1, entry, GroupRoles.participant.name());
        dbInstance.commit();
    }
    if (course2 == null) {
        // create a course with a calendar
        CourseConfigVO config = new CourseConfigVO();
        config.setCalendar(Boolean.TRUE);
        course2 = CoursesWebService.createEmptyCourse(id2, "Cal course - 2", "Cal course - 2", config);
        dbInstance.commit();
        KalendarRenderWrapper calendarWrapper = calendarManager.getCourseCalendar(course2);
        Assert.assertNotNull(calendarWrapper);
        RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course2, false);
        entry = repositoryManager.setAccess(entry, RepositoryEntry.ACC_USERS, false);
        dbInstance.commit();
    }
}
Also used : CourseConfigVO(org.olat.restapi.support.vo.CourseConfigVO) Calendar(java.util.Calendar) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) CourseConfig(org.olat.course.config.CourseConfig) Before(org.junit.Before)

Example 7 with KalendarRenderWrapper

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

the class CourseWebService method getCourseCalendarWebService.

@Path("calendar")
public CalWebService getCourseCalendarWebService(@Context HttpServletRequest request) {
    CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
    if (calendarModule.isEnabled() && (calendarModule.isEnableCourseToolCalendar() || calendarModule.isEnableCourseElementCalendar()) && course.getCourseConfig().isCalendarEnabled()) {
        UserRequest ureq = getUserRequest(request);
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(ureq.getIdentity());
        ienv.setRoles(ureq.getUserSession().getRoles());
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        KalendarRenderWrapper wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
        return new CalWebService(wrapper);
    }
    return null;
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CalWebService(org.olat.commons.calendar.restapi.CalWebService) CalendarModule(org.olat.commons.calendar.CalendarModule) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path)

Example 8 with KalendarRenderWrapper

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

the class CourseCalendarPeekViewController method init.

private void init(UserRequest ureq, CalCourseNode courseNode, UserCourseEnvironment courseEnv, NodeEvaluation ne) {
    CourseCalendars myCal = CourseCalendars.createCourseCalendarsWrapper(ureq, getWindowControl(), courseEnv, ne);
    Date refDate;
    ModuleConfiguration config = courseNode.getModuleConfiguration();
    if (CalEditController.getAutoDate(config)) {
        refDate = new Date();
    } else {
        refDate = CalEditController.getStartDate(config);
        if (refDate == null)
            refDate = new Date();
    }
    List<KalendarEvent> nextEvents = new ArrayList<KalendarEvent>();
    for (KalendarRenderWrapper calendar : myCal.getCalendars()) {
        Kalendar cal = calendar.getKalendar();
        Collection<KalendarEvent> events = cal.getEvents();
        for (KalendarEvent event : events) {
            if (refDate.compareTo(event.getBegin()) <= 0) {
                nextEvents.add(event);
            }
        }
    }
    Collections.sort(nextEvents, new KalendarEventComparator());
    List<KalendarEvent> nextThreeEvents = nextEvents.subList(0, Math.min(3, nextEvents.size()));
    TableGuiConfiguration tableConfig = new TableGuiConfiguration();
    tableConfig.setTableEmptyMessage(translate("calendar.noEvents"));
    tableConfig.setDisplayTableHeader(false);
    tableConfig.setCustomCssClass("o_portlet_table");
    tableConfig.setDisplayRowCount(false);
    tableConfig.setPageingEnabled(false);
    tableConfig.setDownloadOffered(false);
    tableConfig.setSortingEnabled(false);
    removeAsListenerAndDispose(tableController);
    tableController = new TableController(tableConfig, ureq, getWindowControl(), getTranslator());
    listenTo(tableController);
    // dummy header key, won't be used since setDisplayTableHeader is set to
    // false
    tableController.addColumnDescriptor(new DefaultColumnDescriptor("calendar.date", 0, null, ureq.getLocale()));
    tableController.addColumnDescriptor(new DefaultColumnDescriptor("calendar.subject", 1, null, ureq.getLocale(), ColumnDescriptor.ALIGNMENT_LEFT));
    tableController.setTableDataModel(new CourseCalendarPeekViewModel(nextThreeEvents, getTranslator()));
}
Also used : ModuleConfiguration(org.olat.modules.ModuleConfiguration) TableController(org.olat.core.gui.components.table.TableController) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Date(java.util.Date) Kalendar(org.olat.commons.calendar.model.Kalendar) TableGuiConfiguration(org.olat.core.gui.components.table.TableGuiConfiguration) DefaultColumnDescriptor(org.olat.core.gui.components.table.DefaultColumnDescriptor)

Example 9 with KalendarRenderWrapper

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

the class CourseCalendars method getCourseCalendarWrapper.

/**
 * Return only the course calendar without any group calendar
 * @param ureq
 * @param wControl
 * @param ores
 * @param ne
 * @return
 */
public static KalendarRenderWrapper getCourseCalendarWrapper(UserRequest ureq, UserCourseEnvironment courseEnv, NodeEvaluation ne) {
    CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
    // add course calendar
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseEnvironment().getCourseResourceableId());
    KalendarRenderWrapper courseKalendarWrapper = calendarManager.getCourseCalendar(course);
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    Identity identity = ureq.getIdentity();
    Roles roles = ureq.getUserSession().getRoles();
    boolean isPrivileged = !courseEnv.isCourseReadOnly() && (roles.isOLATAdmin() || courseEnv.isAdmin() || (ne != null && ne.isCapabilityAccessible(CalCourseNode.EDIT_CONDITION_ID)) || RepositoryManager.getInstance().isInstitutionalRessourceManagerFor(identity, roles, cgm.getCourseEntry()));
    if (isPrivileged) {
        courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
        courseKalendarWrapper.setPrivateEventsVisible(true);
    } else {
        courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
        courseKalendarWrapper.setPrivateEventsVisible(courseEnv.isAdmin() || courseEnv.isCoach() || courseEnv.isParticipant());
    }
    CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(courseKalendarWrapper.getKalendar(), ureq.getIdentity());
    if (config != null) {
        courseKalendarWrapper.setConfiguration(config);
    }
    return courseKalendarWrapper;
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) CalendarManager(org.olat.commons.calendar.CalendarManager) 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) Identity(org.olat.core.id.Identity)

Example 10 with KalendarRenderWrapper

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

the class CourseCalendarController method addCalendars.

private void addCalendars(List<BusinessGroup> groups, boolean isOwner, LinkProvider linkProvider, List<KalendarRenderWrapper> calendars) {
    CollaborationToolsFactory collabFactory = CollaborationToolsFactory.getInstance();
    for (BusinessGroup bGroup : groups) {
        CollaborationTools collabTools = collabFactory.getOrCreateCollaborationTools(bGroup);
        if (!collabTools.isToolEnabled(CollaborationTools.TOOL_CALENDAR))
            continue;
        KalendarRenderWrapper groupCalendarWrapper = calendarManager.getGroupCalendar(bGroup);
        groupCalendarWrapper.setPrivateEventsVisible(true);
        // set calendar access
        int iCalAccess = CollaborationTools.CALENDAR_ACCESS_OWNERS;
        Long lCalAccess = collabTools.lookupCalendarAccess();
        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 = calendarManager.findCalendarConfigForIdentity(groupCalendarWrapper.getKalendar(), getIdentity());
        if (config != null) {
            groupCalendarWrapper.setConfiguration(config);
        }
        groupCalendarWrapper.setLinkProvider(linkProvider);
        calendars.add(groupCalendarWrapper);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CollaborationToolsFactory(org.olat.collaboration.CollaborationToolsFactory)

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