Search in sources :

Example 1 with PagingFollowingResults

use of org.alfresco.service.cmr.subscriptions.PagingFollowingResults in project alfresco-remote-api by Alfresco.

the class UserFeedRetrieverWebScript method executeImpl.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    // retrieve requested format
    String format = req.getFormat();
    if (format == null || format.length() == 0) {
        format = getDescription().getDefaultFormat();
    }
    // process extension
    String extensionPath = req.getExtensionPath();
    String[] extParts = extensionPath == null ? new String[1] : extensionPath.split("/");
    String feedUserId = null;
    if (extParts.length == 1) {
        feedUserId = extParts[0];
    } else if (extParts.length > 1) {
        throw new AlfrescoRuntimeException("Unexpected extension: " + extensionPath);
    }
    // process arguments
    // optional
    String siteId = req.getParameter(PARAM_SITE_ID);
    // optional
    String exclThisUserStr = req.getParameter(PARAM_EXCLUDE_THIS_USER);
    // optional
    String exclOtherUsersStr = req.getParameter(PARAM_EXCLUDE_OTHER_USERS);
    // optional
    String onlyFollowingStr = req.getParameter(PARAM_ONLY_FOLLOWING);
    // optional
    String activityFilterStr = req.getParameter(PARAM_ACTIVITY_FILTER);
    boolean exclThisUser = false;
    if ((exclThisUserStr != null) && (exclThisUserStr.equalsIgnoreCase("true") || exclThisUserStr.equalsIgnoreCase("t"))) {
        exclThisUser = true;
    }
    boolean exclOtherUsers = false;
    if ((exclOtherUsersStr != null) && (exclOtherUsersStr.equalsIgnoreCase("true") || exclOtherUsersStr.equalsIgnoreCase("t"))) {
        exclOtherUsers = true;
    }
    Set<String> userFilter = null;
    if ((onlyFollowingStr != null) && (onlyFollowingStr.equalsIgnoreCase("true") || onlyFollowingStr.equalsIgnoreCase("t"))) {
        userFilter = new HashSet<String>();
        if (subscriptionService.isActive()) {
            PagingFollowingResults following = subscriptionService.getFollowing(AuthenticationUtil.getRunAsUser(), new PagingRequest(-1, null));
            if (following.getPage() != null) {
                for (String userName : following.getPage()) {
                    userFilter.add(this.userNamesAreCaseSensitive ? userName : userName.toLowerCase());
                }
            }
        }
    }
    Set<String> activityFilter = null;
    if (activityFilterStr != null) {
        activityFilter = new HashSet<String>();
        String[] activities = activityFilterStr.split(",");
        for (String s : activities) {
            if (s.trim().length() > 0) {
                activityFilter.add(s.trim());
            }
        }
        if (activityFilter.size() == 0) {
            activityFilter = null;
        }
    }
    if ((feedUserId == null) || (feedUserId.length() == 0)) {
        feedUserId = AuthenticationUtil.getFullyAuthenticatedUser();
    }
    // atom     -> atomentry
    if (format.equals("atomfeed") || format.equals("atom")) {
        format = "atomentry";
    }
    Map<String, Object> model = new HashMap<String, Object>();
    try {
        List<String> feedEntries = activityService.getUserFeedEntries(feedUserId, siteId, exclThisUser, exclOtherUsers, userFilter, activityFilter);
        if (format.equals(FeedTaskProcessor.FEED_FORMAT_JSON)) {
            model.put("feedEntries", feedEntries);
            model.put("siteId", siteId);
        } else {
            List<Map<String, Object>> activityFeedModels = new ArrayList<Map<String, Object>>();
            try {
                for (String feedEntry : feedEntries) {
                    activityFeedModels.add(JSONtoFmModel.convertJSONObjectToMap(feedEntry));
                }
            } catch (JSONException je) {
                throw new AlfrescoRuntimeException("Unable to get user feed entries: " + je.getMessage());
            }
            model.put("feedEntries", activityFeedModels);
            model.put("feedUserId", feedUserId);
        }
    } catch (AccessDeniedException ade) {
        status.setCode(Status.STATUS_UNAUTHORIZED);
        logger.warn("Unable to get user feed entries for '" + feedUserId + "' - currently logged in as '" + AuthenticationUtil.getFullyAuthenticatedUser() + "'");
        return null;
    }
    return model;
}
Also used : AccessDeniedException(org.alfresco.repo.security.permissions.AccessDeniedException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) PagingFollowingResults(org.alfresco.service.cmr.subscriptions.PagingFollowingResults) PagingRequest(org.alfresco.query.PagingRequest) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with PagingFollowingResults

use of org.alfresco.service.cmr.subscriptions.PagingFollowingResults in project alfresco-remote-api by Alfresco.

the class SubscriptionServiceFollowersGet method executeImpl.

@SuppressWarnings("unchecked")
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException {
    PagingFollowingResults result = subscriptionService.getFollowers(userId, createPagingRequest(req));
    JSONObject obj = new JSONObject();
    obj.put("people", getUserArray(result.getPage()));
    obj.put("hasMoreItems", result.hasMoreItems());
    if (result.getTotalResultCount() != null) {
        obj.put("totalCount", result.getTotalResultCount().getFirst());
    }
    return obj;
}
Also used : JSONObject(org.json.simple.JSONObject) PagingFollowingResults(org.alfresco.service.cmr.subscriptions.PagingFollowingResults)

Example 3 with PagingFollowingResults

use of org.alfresco.service.cmr.subscriptions.PagingFollowingResults in project alfresco-remote-api by Alfresco.

the class SubscriptionServiceFollowingGet method executeImpl.

@SuppressWarnings("unchecked")
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException {
    PagingFollowingResults result = subscriptionService.getFollowing(userId, createPagingRequest(req));
    JSONObject obj = new JSONObject();
    obj.put("people", getUserArray(result.getPage()));
    obj.put("hasMoreItems", result.hasMoreItems());
    if (result.getTotalResultCount() != null) {
        obj.put("totalCount", result.getTotalResultCount().getFirst());
    }
    return obj;
}
Also used : JSONObject(org.json.simple.JSONObject) PagingFollowingResults(org.alfresco.service.cmr.subscriptions.PagingFollowingResults)

Aggregations

PagingFollowingResults (org.alfresco.service.cmr.subscriptions.PagingFollowingResults)3 JSONObject (org.json.simple.JSONObject)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 PagingRequest (org.alfresco.query.PagingRequest)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 JSONException (org.json.JSONException)1