Search in sources :

Example 81 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, File file) throws IOException {
    KalendarRenderWrapper calendarWrapper = null;
    Calendar calendar = calendarManager.readCalendar(file);
    if (calendar != null) {
        String calendarID = getImportedCalendarID(identity, calendarName);
        File calendarFile = calendarManager.getCalendarFile(type, calendarID);
        if (!file.renameTo(calendarFile)) {
            Files.copy(file.toPath(), calendarFile.toPath());
        }
        importedCalendarDao.createImportedCalendar(identity, calendarName, calendarID, type, null, new Date());
        calendarWrapper = calendarManager.getImportedCalendar(identity, calendarID);
        calendarWrapper.setDisplayName(calendarName);
        calendarWrapper.setPrivateEventsVisible(true);
    }
    return calendarWrapper;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) Calendar(net.fortuna.ical4j.model.Calendar) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) File(java.io.File) Date(java.util.Date)

Example 82 with KalendarRenderWrapper

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

the class ImportCalendarManager method getImportedCalendarsForIdentity.

/**
 * Get imported calendars for a user.
 * @param ureq
 * @return
 */
public List<KalendarRenderWrapper> getImportedCalendarsForIdentity(Identity identity, boolean reload) {
    // initialize the calendars list
    List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
    if (calendarModule.isEnabled() && calendarModule.isEnablePersonalCalendar()) {
        long timestamp = System.currentTimeMillis();
        List<ImportedCalendar> importedCalendars = importedCalendarDao.getImportedCalendars(identity);
        KalendarEventFilter filter = new KalendarEventFilter(identity, importedCalendars);
        for (ImportedCalendar importedCalendar : importedCalendars) {
            try {
                if (reload) {
                    reloadImportCalendar(importedCalendar, timestamp, filter);
                }
                String calendarId = importedCalendar.getCalendarId();
                KalendarRenderWrapper calendarWrapper = calendarManager.getImportedCalendar(identity, calendarId);
                calendarWrapper.setDisplayName(importedCalendar.getDisplayName());
                calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
                calendarWrapper.setImported(true);
                CalendarUserConfiguration config = calendarManager.findCalendarConfigForIdentity(calendarWrapper.getKalendar(), identity);
                if (config != null) {
                    calendarWrapper.setConfiguration(config);
                }
                calendars.add(calendarWrapper);
            } catch (Exception e) {
                log.error("Cannot read an imported file", e);
            }
        }
        Collections.sort(calendars, KalendarComparator.getInstance());
    }
    return calendars;
}
Also used : ImportedCalendar(org.olat.commons.calendar.model.ImportedCalendar) ArrayList(java.util.ArrayList) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) IOException(java.io.IOException)

Example 83 with KalendarRenderWrapper

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

the class UserCalendarWebService method getCalendar.

private KalendarRenderWrapper getCalendar(UserRequest ureq, String calendarId) {
    int typeIndex = calendarId.indexOf('_');
    if (typeIndex <= 0 || (typeIndex + 1 >= calendarId.length())) {
        return null;
    }
    CalendarModule calendarModule = CoreSpringFactory.getImpl(CalendarModule.class);
    if (!calendarModule.isEnabled()) {
        return null;
    }
    String type = calendarId.substring(0, typeIndex);
    String id = calendarId.substring(typeIndex + 1);
    KalendarRenderWrapper wrapper = null;
    if ("group".equals(type) && calendarModule.isEnableGroupCalendar()) {
        Long groupId = Long.parseLong(id);
        BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        BusinessGroup group = bgs.loadBusinessGroup(groupId);
        if (bgs.isIdentityInBusinessGroup(ureq.getIdentity(), group)) {
            CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
            wrapper = collaborationManager.getCalendar(group, ureq, false);
        }
    } else if ("course".equals(type) && (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar())) {
        Long courseId = Long.parseLong(id);
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(ureq.getIdentity());
        ienv.setRoles(ureq.getUserSession().getRoles());
        ICourse course = CourseFactory.loadCourse(courseId);
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        wrapper = CourseCalendars.getCourseCalendarWrapper(ureq, userCourseEnv, null);
    } else if ("user".equals(type) && calendarModule.isEnablePersonalCalendar()) {
        if (id.equals(ureq.getIdentity().getName())) {
            wrapper = getPersonalCalendar(ureq.getIdentity());
        } else if (isAdmin(ureq.getHttpReq())) {
            Identity identity = BaseSecurityManager.getInstance().findIdentityByName(id);
            wrapper = getPersonalCalendar(identity);
        }
    }
    return wrapper;
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BusinessGroupService(org.olat.group.BusinessGroupService) CalendarModule(org.olat.commons.calendar.CalendarModule) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) CollaborationManager(org.olat.collaboration.CollaborationManager)

Example 84 with KalendarRenderWrapper

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

the class UserCalendarWebService method getCalendarWebService.

@Path("{calendarId}")
public CalWebService getCalendarWebService(@PathParam("calendarId") String calendarId, @PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    UserRequest ureq = getUserRequest(httpRequest);
    if (ureq.getIdentity() == null || !ureq.getUserSession().isAuthenticated()) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    } else if (!ureq.getIdentity().getKey().equals(identityKey) && !isAdmin(httpRequest)) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
    KalendarRenderWrapper calendar = getCalendar(ureq, calendarId);
    if (calendar == null) {
        throw new WebApplicationException(Response.serverError().status(Status.NOT_FOUND).build());
    } else if (!hasReadAccess(calendar)) {
        throw new WebApplicationException(Response.serverError().status(Status.UNAUTHORIZED).build());
    }
    return new CalWebService(calendar);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Path(javax.ws.rs.Path)

Example 85 with KalendarRenderWrapper

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

the class UserCalendarWebService method getCalendars.

@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCalendars(@PathParam("identityKey") Long identityKey, @Context HttpServletRequest httpRequest) {
    UserRequest ureq = getUserRequest(httpRequest);
    if (ureq.getIdentity() == null || !ureq.getUserSession().isAuthenticated()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    } else if (!ureq.getIdentity().getKey().equals(identityKey) && !isAdmin(httpRequest)) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    CollectCalendars visitor = new CollectCalendars();
    getCalendars(visitor, ureq);
    List<KalendarRenderWrapper> wrappers = visitor.getWrappers();
    CalendarVO[] voes = new CalendarVO[wrappers.size()];
    int count = 0;
    for (KalendarRenderWrapper wrapper : wrappers) {
        voes[count++] = new CalendarVO(wrapper, hasWriteAccess(wrapper));
    }
    return Response.ok(voes).build();
}
Also used : KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) RestSecurityHelper.getUserRequest(org.olat.restapi.security.RestSecurityHelper.getUserRequest) UserRequest(org.olat.core.gui.UserRequest) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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