Search in sources :

Example 31 with CalendarUserConfiguration

use of org.olat.commons.calendar.model.CalendarUserConfiguration in project OpenOLAT by OpenOLAT.

the class HomeCalendarManager method getListOfCalendarWrappers.

@Override
public List<KalendarRenderWrapper> getListOfCalendarWrappers(UserRequest ureq, WindowControl wControl) {
    if (!calendarModule.isEnabled()) {
        return new ArrayList<KalendarRenderWrapper>();
    }
    Identity identity = ureq.getIdentity();
    List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
    Map<CalendarKey, CalendarUserConfiguration> configMap = calendarManager.getCalendarUserConfigurationsMap(ureq.getIdentity());
    appendPersonalCalendar(identity, calendars, configMap);
    appendGroupCalendars(identity, calendars, configMap);
    appendCourseCalendars(ureq, wControl, calendars, configMap);
    // reload every hour
    List<KalendarRenderWrapper> importedCalendars = importCalendarManager.getImportedCalendarsForIdentity(identity, true);
    for (KalendarRenderWrapper importedCalendar : importedCalendars) {
        importedCalendar.setPrivateEventsVisible(true);
    }
    calendars.addAll(importedCalendars);
    return calendars;
}
Also used : CalendarKey(org.olat.commons.calendar.model.CalendarKey) ArrayList(java.util.ArrayList) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 32 with CalendarUserConfiguration

use of org.olat.commons.calendar.model.CalendarUserConfiguration in project OpenOLAT by OpenOLAT.

the class HomeCalendarManager method appendCourseCalendars.

private void appendCourseCalendars(UserRequest ureq, WindowControl wControl, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
        // add course calendars
        List<Object[]> resources = getCourses(ureq.getIdentity());
        Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());
        Set<Long> duplicates = new HashSet<>();
        for (Object[] resource : resources) {
            RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
            if (duplicates.contains(courseEntry.getKey())) {
                continue;
            }
            duplicates.add(courseEntry.getKey());
            String role = (String) resource[1];
            Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
            try {
                ICourse course = CourseFactory.loadCourse(courseEntry);
                if (isCourseCalendarEnabled(course)) {
                    // calendar course aren't enabled per default but course node of type calendar are always possible
                    // REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled()) continue;
                    // add course calendar
                    KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course);
                    boolean isPrivileged = GroupRoles.owner.name().equals(role) || editoredResources.contains(courseEntry.getOlatResource());
                    if (isPrivileged) {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
                    } else {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
                    }
                    if (role != null && (GroupRoles.owner.name().equals(role) || GroupRoles.coach.name().equals(role) || GroupRoles.participant.name().equals(role))) {
                        courseCalendarWrapper.setPrivateEventsVisible(true);
                    }
                    CalendarUserConfiguration config = configMap.get(courseCalendarWrapper.getCalendarKey());
                    if (config != null) {
                        courseCalendarWrapper.setConfiguration(config);
                    }
                    courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl));
                    calendars.add(courseCalendarWrapper);
                }
            } catch (CorruptedCourseException e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Corrupted course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            } catch (Exception e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Cannor read calendar of course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            }
        }
    }
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CorruptedCourseException(org.olat.course.CorruptedCourseException) CorruptedCourseException(org.olat.course.CorruptedCourseException) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) HashSet(java.util.HashSet)

Example 33 with CalendarUserConfiguration

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

the class CalendarUserConfigurationDAOTest method getCalendarUserConfigurations.

@Test
public void getCalendarUserConfigurations() {
    Identity user = JunitTestHelper.createAndPersistIdentityAsRndUser("Cal-2");
    String calendarId = UUID.randomUUID().toString();
    Kalendar calendar = new Kalendar(calendarId, CalendarManager.TYPE_COURSE);
    CalendarUserConfiguration config = calendarDao.createCalendarUserConfiguration(calendar, user);
    dbInstance.commit();
    Assert.assertNotNull(config);
    // retrieve
    List<CalendarUserConfiguration> configList = calendarDao.getCalendarUserConfigurations(user);
    Assert.assertNotNull(configList);
    Assert.assertEquals(1, configList.size());
    Assert.assertEquals(config, configList.get(0));
    // paranoia check
    CalendarUserConfiguration loadedConfig = configList.get(0);
    Assert.assertNotNull(loadedConfig.getCreationDate());
    Assert.assertNotNull(loadedConfig.getLastModified());
    Assert.assertEquals(config.getKey(), loadedConfig.getKey());
    Assert.assertEquals(calendarId, loadedConfig.getCalendarId());
    Assert.assertEquals(CalendarManager.TYPE_COURSE, loadedConfig.getType());
    Assert.assertEquals(user, loadedConfig.getIdentity());
    Assert.assertTrue(loadedConfig.isVisible());
    Assert.assertTrue(loadedConfig.isInAggregatedFeed());
}
Also used : Kalendar(org.olat.commons.calendar.model.Kalendar) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 34 with CalendarUserConfiguration

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

the class UserInfoMainController method doOpenCalendar.

private WeeklyCalendarController doOpenCalendar(UserRequest ureq) {
    removeAsListenerAndDispose(calendarController);
    KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(chosenIdentity);
    CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), getIdentity());
    if (config != null) {
        calendarWrapper.setConfiguration(config);
    }
    calendarWrapper.setPrivateEventsVisible(chosenIdentity.equals(ureq.getIdentity()));
    if (chosenIdentity.equals(ureq.getIdentity())) {
        calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
    } else {
        calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
    }
    List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
    calendars.add(calendarWrapper);
    OLATResourceable ores = OresHelper.createOLATResourceableType(CMD_CALENDAR);
    WindowControl bwControl = addToHistory(ureq, ores, null);
    OLATResourceable callerOres = OresHelper.createOLATResourceableInstance(chosenIdentity.getName(), chosenIdentity.getKey());
    calendarController = new WeeklyCalendarController(ureq, bwControl, calendars, WeeklyCalendarController.CALLER_PROFILE, callerOres, false);
    listenTo(calendarController);
    return calendarController;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) WeeklyCalendarController(org.olat.commons.calendar.ui.WeeklyCalendarController) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) WindowControl(org.olat.core.gui.control.WindowControl)

Example 35 with CalendarUserConfiguration

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

the class CalendarUserConfigurationDAO method createCalendarUserConfiguration.

/**
 * Create and persist an user configuration
 * @param calendar
 * @param identity
 * @param token
 * @param aggregated
 * @param visible
 * @return
 */
public CalendarUserConfiguration createCalendarUserConfiguration(Kalendar calendar, Identity identity, String token, boolean aggregated, boolean visible) {
    CalendarUserConfiguration config = new CalendarUserConfiguration();
    config.setCreationDate(new Date());
    config.setLastModified(config.getCreationDate());
    config.setCalendarId(calendar.getCalendarID());
    config.setType(calendar.getType());
    config.setToken(token);
    config.setIdentity(identity);
    config.setInAggregatedFeed(aggregated);
    config.setVisible(visible);
    dbInstance.getCurrentEntityManager().persist(config);
    return config;
}
Also used : CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) Date(java.util.Date)

Aggregations

CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)46 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)24 Kalendar (org.olat.commons.calendar.model.Kalendar)12 Identity (org.olat.core.id.Identity)12 ArrayList (java.util.ArrayList)10 BusinessGroup (org.olat.group.BusinessGroup)10 CalendarKey (org.olat.commons.calendar.model.CalendarKey)8 Test (org.junit.Test)6 CalendarManager (org.olat.commons.calendar.CalendarManager)6 CorruptedCourseException (org.olat.course.CorruptedCourseException)6 ICourse (org.olat.course.ICourse)6 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 CollaborationTools (org.olat.collaboration.CollaborationTools)4 CollaborationToolsFactory (org.olat.collaboration.CollaborationToolsFactory)4 Roles (org.olat.core.id.Roles)4 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 File (java.io.File)2 URISyntaxException (java.net.URISyntaxException)2