Search in sources :

Example 11 with PagingRequest

use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.

the class Util method getPagingRequest.

public static PagingRequest getPagingRequest(Paging paging) {
    PagingRequest pagingRequest = new PagingRequest(paging.getSkipCount(), paging.getMaxItems());
    pagingRequest.setRequestTotalCountMax(CannedQueryPageDetails.DEFAULT_PAGE_SIZE);
    return pagingRequest;
}
Also used : PagingRequest(org.alfresco.query.PagingRequest)

Example 12 with PagingRequest

use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.

the class LinksListGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, String linkName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    // Decide on what kind of request they wanted
    String filter = req.getParameter("filter");
    // Tagging?
    boolean tagFiltering = true;
    String tag = req.getParameter("tag");
    if (tag == null || tag.length() == 0) {
        tagFiltering = false;
    }
    // User?
    boolean userFiltering = false;
    String user = null;
    if ("user".equals(filter)) {
        userFiltering = true;
        user = AuthenticationUtil.getFullyAuthenticatedUser();
    }
    // Date?
    boolean dateFiltering = false;
    Date from = null;
    Date to = null;
    if ("recent".equals(filter)) {
        dateFiltering = true;
        Date now = new Date();
        from = new Date(now.getTime() - RECENT_SEARCH_PERIOD_DAYS * ONE_DAY_MS);
        to = new Date(now.getTime() + ONE_DAY_MS);
    }
    // Get the links for the list
    PagingRequest paging = buildPagingRequest(req);
    paging.setRequestTotalCountMax(paging.getSkipCount() + paging.getRequestTotalCountMax());
    PagingResults<LinkInfo> links;
    if (tagFiltering) {
        links = linksService.findLinks(site.getShortName(), user, from, to, tag, paging);
    } else {
        if (userFiltering) {
            links = linksService.listLinks(site.getShortName(), user, paging);
        } else if (dateFiltering) {
            links = linksService.listLinks(site.getShortName(), from, to, paging);
        } else {
            links = linksService.listLinks(site.getShortName(), paging);
        }
    }
    // For each one in our page, grab details of any ignored instances
    List<Map<String, Object>> items = new ArrayList<Map<String, Object>>();
    for (LinkInfo link : links.getPage()) {
        Map<String, Object> result = renderLink(link);
        items.add(result);
    }
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("items", items);
    data.put("pageSize", paging.getMaxItems());
    data.put("startIndex", paging.getSkipCount());
    data.put("itemCount", items.size());
    int total = items.size();
    if (links.getTotalResultCount() != null && links.getTotalResultCount().getFirst() != null) {
        total = links.getTotalResultCount().getFirst();
    }
    data.put("total", total);
    if (total == paging.getRequestTotalCountMax()) {
        data.put("totalRecordsUpper", true);
    } else {
        data.put("totalRecordsUpper", false);
    }
    // We need the container node for permissions checking
    NodeRef container;
    if (links.getPage().size() > 0) {
        container = links.getPage().get(0).getContainerNodeRef();
    } else {
        // Find the container (if it's been created yet)
        container = siteService.getContainer(site.getShortName(), LinksServiceImpl.LINKS_COMPONENT);
        if (container == null) {
            // Brand new site, no write operations on links have happened
            // Fudge it for now with the site itself, the first write call
            // will have the container created
            container = site.getNodeRef();
        }
    }
    // All done
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("data", data);
    model.put("links", container);
    model.put("siteId", site.getShortName());
    model.put("site", site);
    return model;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkInfo(org.alfresco.service.cmr.links.LinkInfo) Date(java.util.Date) PagingRequest(org.alfresco.query.PagingRequest) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with PagingRequest

use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.

the class AbstractGetBlogWebScript method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nonSiteContainer, BlogPostInfo blog, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    // process additional parameters. <index, count>
    PagingRequest pagingReq = parsePagingParams(req);
    pagingReq.setRequestTotalCountMax(pagingReq.getSkipCount() + pagingReq.getRequestTotalCountMax());
    // begin and end date.
    // Legacy note: these dates are URL query parameters in int form.
    Date fromDate = parseDateParam(req, "fromDate");
    Date toDate = parseDateParam(req, "toDate");
    String tag = req.getParameter("tag");
    if (tag == null || tag.length() == 0) {
        tag = null;
    } else {
        // Tags can be full unicode strings, so decode
        tag = URLDecoder.decode(tag);
    }
    // This is a hacky solution to this special case. FIXME
    if (this.getClass().equals(BlogPostsNewGet.class)) {
        // Default is for 'now' minus seven days.
        final long oneDayInMilliseconds = 24 * 60 * 60 * 1000;
        final long sevenDaysInMilliseconds = 7 * oneDayInMilliseconds;
        fromDate = new Date(System.currentTimeMillis() - sevenDaysInMilliseconds);
        // But if there is a numdays parameter then that changes the fromDate
        String numDays = req.getServiceMatch().getTemplateVars().get("numdays");
        if (numDays != null) {
            Integer numDaysInt = Integer.parseInt(numDays);
            fromDate = new Date(System.currentTimeMillis() - (numDaysInt * oneDayInMilliseconds));
        }
    }
    // Fetch and assign the data
    PagingResults<BlogPostInfo> blogPostList = getBlogPostList(site, nonSiteContainer, fromDate, toDate, tag, pagingReq);
    // We need the container for various bits
    NodeRef container = nonSiteContainer;
    if (container == null) {
        // Container mustn't exist yet
        // Fake it with the site for permissions checking reasons
        container = site.getNodeRef();
    }
    if (log.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder();
        msg.append("Retrieved ").append(blogPostList.getPage().size()).append(" blog posts in page.");
        log.debug(msg.toString());
    }
    createFtlModel(req, model, container, pagingReq, blogPostList);
    return model;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) JSONObject(org.json.simple.JSONObject) BlogPostInfo(org.alfresco.service.cmr.blog.BlogPostInfo) PagingRequest(org.alfresco.query.PagingRequest) Date(java.util.Date)

Example 14 with PagingRequest

use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.

the class CalendarEntriesListGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    // Evil format needed for compatibility with old API...
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    // Decide on date ranges and repeating rules
    Date fromDate = parseDate(req.getParameter("from"));
    Date toDate = parseDate(req.getParameter("to"));
    boolean resortNeeded = false;
    boolean repeatingFirstOnly = true;
    String repeatingEvents = req.getParameter("repeating");
    if (repeatingEvents != null) {
        if ("first".equals(repeatingEvents)) {
            repeatingFirstOnly = true;
        } else if ("all".equals(repeatingEvents)) {
            repeatingFirstOnly = false;
            resortNeeded = true;
        }
    }
    // Get the entries for the list
    PagingRequest paging = buildPagingRequest(req);
    PagingResults<CalendarEntry> entries = calendarService.listCalendarEntries(new String[] { site.getShortName() }, fromDate, toDate, paging);
    // For each one in our page, grab details of any ignored instances
    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (CalendarEntry entry : entries.getPage()) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(RESULT_EVENT, entry);
        result.put(RESULT_NAME, entry.getSystemName());
        result.put(RESULT_TITLE, entry.getTitle());
        boolean isAllDay = CalendarEntryDTO.isAllDay(entry);
        boolean removeTimezone = isAllDay && !entry.isOutlook();
        result.put(RESULT_START, removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
        result.put(RESULT_END, removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
        if (isAllDay) {
            long dayLong = 86400000;
            Date newDay = new Date(entry.getEnd().getTime() + dayLong);
            result.put("allDayEnd", newDay);
        }
        String legacyDateFormat = "M/d/yyyy";
        String legacyTimeFormat = "HH:mm";
        result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
        result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
        result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
        result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyTimeFormat));
        result.put("fromDate", entry.getStart());
        result.put("tags", entry.getTags());
        List<ChildAssociationRef> ignores = nodeService.getChildAssocs(entry.getNodeRef(), CalendarModel.TYPE_IGNORE_EVENT, ContentModel.ASSOC_CONTAINS, true);
        List<String> ignoreEvents = new ArrayList<String>();
        List<Date> ignoreEventDates = new ArrayList<Date>();
        for (ChildAssociationRef ref : ignores) {
            Date date = (Date) nodeService.getProperty(ref.getChildRef(), CalendarModel.PROP_IGNORE_EVENT_DATE);
            if (date != null) {
                ignoreEventDates.add(date);
                ignoreEvents.add(formatter.format(date));
            }
        }
        result.put("ignoreEvents", ignoreEvents);
        result.put("ignoreEventDates", ignoreEventDates);
        // For repeating events, push forward if needed
        boolean orderChanged = handleRecurring(entry, result, results, fromDate, toDate, repeatingFirstOnly);
        if (orderChanged) {
            resortNeeded = true;
        }
        // All done with this one
        results.add(result);
    }
    // If they asked for repeating events to be expanded, then do so
    if (resortNeeded) {
        Collections.sort(results, getEventDetailsSorter());
    }
    // All done
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("events", results);
    model.put("siteId", site.getShortName());
    model.put("site", site);
    return model;
}
Also used : CalendarEntry(org.alfresco.service.cmr.calendar.CalendarEntry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Date(java.util.Date) PagingRequest(org.alfresco.query.PagingRequest) JSONObject(org.json.simple.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with PagingRequest

use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.

the class UserCalendarEntriesGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo singleSite, String eventName, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    // Did they restrict by date?
    Date fromDate = parseDate(req.getParameter("from"));
    Date toDate = parseDate(req.getParameter("to"));
    // What should we do about repeating events? First or all?
    boolean repeatingFirstOnly = true;
    String repeatingEvents = req.getParameter("repeating");
    if (repeatingEvents != null) {
        if ("first".equals(repeatingEvents)) {
            repeatingFirstOnly = true;
        } else if ("all".equals(repeatingEvents)) {
            repeatingFirstOnly = false;
        }
    } else {
        // the format of the from date, which differs between uses!
        if (fromDate != null) {
            String fromDateS = req.getParameter("from");
            if (fromDateS.indexOf('-') != -1) {
                // Apparently this is the site calendar dashlet...
                repeatingFirstOnly = true;
            }
            if (fromDateS.indexOf('/') != -1) {
                // This is something else, wants all events in range
                repeatingFirstOnly = false;
            }
        }
    }
    // One site, or all the user's ones?
    List<SiteInfo> sites = new ArrayList<SiteInfo>();
    if (singleSite != null) {
        // Just one
        sites.add(singleSite);
    } else {
        // All their sites (with optional limit)
        int max = 0;
        String strMax = req.getParameter("size");
        if (strMax != null && strMax.length() != 0) {
            max = Integer.parseInt(strMax);
        }
        sites = siteService.listSites(AuthenticationUtil.getRunAsUser(), max);
    }
    // We need to know the Site Names, and the NodeRefs of the calendar containers
    String[] siteShortNames = new String[sites.size()];
    Map<NodeRef, SiteInfo> containerLookup = new HashMap<NodeRef, SiteInfo>();
    for (int i = 0; i < sites.size(); i++) {
        SiteInfo site = sites.get(i);
        siteShortNames[i] = site.getShortName();
        try {
            containerLookup.put(siteService.getContainer(site.getShortName(), CalendarServiceImpl.CALENDAR_COMPONENT), site);
        } catch (AccessDeniedException e) {
        // You can see the site, but not the calendar, so skip it
        // This means you won't have any events in it anyway
        }
    }
    // Get the entries for the list
    PagingRequest paging = buildPagingRequest(req);
    PagingResults<CalendarEntry> entries = calendarService.listCalendarEntries(siteShortNames, fromDate, toDate, paging);
    boolean resortNeeded = false;
    List<Map<String, Object>> results = new ArrayList<Map<String, Object>>();
    for (CalendarEntry entry : entries.getPage()) {
        // Build the object
        Map<String, Object> result = new HashMap<String, Object>();
        boolean isAllDay = CalendarEntryDTO.isAllDay(entry);
        boolean removeTimezone = isAllDay && !entry.isOutlook();
        result.put(RESULT_EVENT, entry);
        result.put(RESULT_NAME, entry.getSystemName());
        result.put(RESULT_TITLE, entry.getTitle());
        result.put("description", entry.getDescription());
        result.put("where", entry.getLocation());
        result.put(RESULT_START, removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone));
        result.put(RESULT_END, removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone));
        String legacyDateFormat = "yyyy-MM-dd";
        String legacyTimeFormat = "HH:mm";
        result.put("legacyDateFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyDateFormat));
        result.put("legacyTimeFrom", removeTimeZoneIfRequired(entry.getStart(), isAllDay, removeTimezone, legacyTimeFormat));
        result.put("legacyDateTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyDateFormat));
        result.put("legacyTimeTo", removeTimeZoneIfRequired(entry.getEnd(), isAllDay, removeTimezone, legacyTimeFormat));
        result.put("duration", buildDuration(entry));
        result.put("tags", entry.getTags());
        result.put("isoutlook", entry.isOutlook());
        result.put("allday", CalendarEntryDTO.isAllDay(entry));
        // Identify the site
        SiteInfo site = containerLookup.get(entry.getContainerNodeRef());
        result.put("site", site);
        result.put("siteName", site.getShortName());
        result.put("siteTitle", site.getTitle());
        // Check the permissions the user has on the entry
        AccessStatus canEdit = permissionService.hasPermission(entry.getNodeRef(), PermissionService.WRITE);
        AccessStatus canDelete = permissionService.hasPermission(entry.getNodeRef(), PermissionService.DELETE);
        result.put("canEdit", (canEdit == AccessStatus.ALLOWED));
        result.put("canDelete", (canDelete == AccessStatus.ALLOWED));
        // Replace nulls with blank strings for the JSON
        for (String key : result.keySet()) {
            if (result.get(key) == null) {
                result.put(key, "");
            }
        }
        // Save this one
        results.add(result);
        // Handle recurring as needed
        boolean orderChanged = handleRecurring(entry, result, results, fromDate, toDate, repeatingFirstOnly);
        if (orderChanged) {
            resortNeeded = true;
        }
    }
    // If the recurring events meant dates changed, re-sort
    if (resortNeeded) {
        Collections.sort(results, getEventDetailsSorter());
    }
    // All done
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("events", results);
    return model;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) HashMap(java.util.HashMap) CalendarEntry(org.alfresco.service.cmr.calendar.CalendarEntry) ArrayList(java.util.ArrayList) Date(java.util.Date) PagingRequest(org.alfresco.query.PagingRequest) AccessStatus(org.alfresco.service.cmr.security.AccessStatus) NodeRef(org.alfresco.service.cmr.repository.NodeRef) JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

PagingRequest (org.alfresco.query.PagingRequest)36 ArrayList (java.util.ArrayList)18 Pair (org.alfresco.util.Pair)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 HashMap (java.util.HashMap)10 JSONObject (org.json.simple.JSONObject)10 Paging (org.alfresco.rest.framework.resource.parameters.Paging)8 Map (java.util.Map)7 Date (java.util.Date)6 UserTransaction (javax.transaction.UserTransaction)6 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)6 AbstractList (java.util.AbstractList)5 FacesContext (javax.faces.context.FacesContext)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 TopicInfo (org.alfresco.service.cmr.discussion.TopicInfo)5 PersonInfo (org.alfresco.service.cmr.security.PersonService.PersonInfo)5 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)4 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)4 HashSet (java.util.HashSet)3 List (java.util.List)3