Example usage for com.liferay.portal.kernel.webdav WebDAVRequest getPermissionChecker

List of usage examples for com.liferay.portal.kernel.webdav WebDAVRequest getPermissionChecker

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.webdav WebDAVRequest getPermissionChecker.

Prototype

public PermissionChecker getPermissionChecker();

Source Link

Usage

From source file:it.smc.calendar.sync.caldav.LiferayCalDAVStorageImpl.java

License:Open Source License

@Override
public List<Resource> getResources(WebDAVRequest webDAVRequest) throws WebDAVException {

    try {//from ww  w. j a  v a2  s. c  o  m
        String[] pathArray = webDAVRequest.getPathArray();

        // calendar resource collection request

        CalendarResource calendarResource;

        if (CalDAVUtil.isPrincipalRequest(webDAVRequest)) {
            long userid = GetterUtil.getLong(pathArray[2]);
            User user = null;

            try {
                user = UserServiceUtil.getUserById(userid);
            } catch (Exception e) {
                if (_log.isWarnEnabled()) {
                    _log.warn(e);
                }
            }

            if (user == null) {
                throw new WebDAVException("No user were found with id " + pathArray[2]);
            }

            calendarResource = CalendarResourceLocalServiceUtil
                    .fetchCalendarResource(PortalUtil.getClassNameId(User.class), user.getPrimaryKey());
        } else {
            String calendarResourceGUID = pathArray[0];

            calendarResource = CalendarResourceLocalServiceUtil.fetchCalendarResourceByUuidAndCompanyId(
                    calendarResourceGUID, webDAVRequest.getCompanyId());
        }

        if (calendarResource == null) {
            throw new WebDAVException("No calendar resource were found");
        }

        CalendarResourcePermission.check(webDAVRequest.getPermissionChecker(), calendarResource,
                ActionKeys.VIEW);

        if (CalDAVUtil.isCalendarRequest(webDAVRequest)) {
            return toCalendarBookingResources(webDAVRequest);
        } else {
            return toCalendarResources(webDAVRequest, calendarResource);
        }
    } catch (Exception e) {
        throw new WebDAVException(e);
    }
}

From source file:it.smc.calendar.sync.caldav.LiferayCalDAVStorageImpl.java

License:Open Source License

protected List<Resource> toCalendarBookingResources(WebDAVRequest webDAVRequest)
        throws PortalException, SystemException {

    Calendar calendar = (Calendar) getResource(webDAVRequest).getModel();

    List<CalendarBooking> calendarBookings = CalendarUtil
            .getCalendarBookings(webDAVRequest.getPermissionChecker(), calendar, null, null);

    List<Resource> resources = new ArrayList<Resource>();

    for (CalendarBooking calendarBooking : calendarBookings) {
        resources.add(toResource(webDAVRequest, calendarBooking));
    }// w ww  . ja  v  a 2s . c o  m

    return resources;
}

From source file:it.smc.calendar.sync.caldav.LiferayCalDAVStorageImpl.java

License:Open Source License

protected List<Resource> toCalendarResources(WebDAVRequest webDAVRequest, CalendarResource calendarResource)
        throws PortalException, SystemException {

    List<Calendar> calendars;

    if (CalDAVUtil.isIOS(webDAVRequest) || CalDAVUtil.isMacOSX(webDAVRequest)) {

        calendars = CalendarUtil.getAllCalendars(webDAVRequest.getPermissionChecker());
    } else {//www  .j a  v  a  2 s . c o  m
        calendars = CalendarUtil.getCalendarResourceCalendars(calendarResource);
    }

    List<Resource> resources = new ArrayList<Resource>();

    for (Calendar calendar : calendars) {
        resources.add(toResource(webDAVRequest, calendar));
    }

    return resources;
}

From source file:it.smc.calendar.sync.caldav.methods.ReportMethodImpl.java

License:Open Source License

@Override
protected void addResponse(WebDAVStorage storage, WebDAVRequest webDAVRequest, Resource resource,
        Set<QName> props, Element multistatusElement, long depth) throws Exception {

    List<CalendarBooking> calendarBookings = null;

    List<Node> hrefNodes = CalDAVRequestThreadLocal.getRequestDocument()
            .selectNodes("//*[local-name()='href']");

    if ((hrefNodes.size() > 0) && CalDAVUtil.isCalendarBookingRequest(webDAVRequest)) {

        calendarBookings = new ArrayList<CalendarBooking>();

        CalendarBooking calendarBooking;

        for (Node hrefNode : hrefNodes) {
            calendarBooking = CalDAVUtil.getCalendarBookingFromURL(hrefNode.getText());

            if (calendarBooking != null) {
                calendarBookings.add(calendarBooking);
            }/*w ww.j av a  2 s. c o  m*/
        }
    } else {
        Calendar calendar = (Calendar) resource.getModel();

        Date startDate = null;
        Date endDate = null;

        Element timeRangeElement = CalDAVUtil.getReportDateFilter();

        if ((timeRangeElement != null) && (timeRangeElement.attribute("start") != null)) {

            String startDateStr = timeRangeElement.attribute("start").getValue();

            startDate = new net.fortuna.ical4j.model.Date(startDateStr);
        }

        if ((timeRangeElement != null) && (timeRangeElement.attribute("end") != null)) {

            String endDateStr = timeRangeElement.attribute("end").getValue();

            endDate = new net.fortuna.ical4j.model.Date(endDateStr);
        }

        calendarBookings = CalendarUtil.getCalendarBookings(webDAVRequest.getPermissionChecker(), calendar,
                startDate, endDate);
    }

    for (CalendarBooking calendarBooking : calendarBookings) {
        try {
            addCalendarBookingData(webDAVRequest, resource, calendarBooking, multistatusElement);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn(e);
            }
        }
    }
}