Search in sources :

Example 1 with ActivityFeedEntity

use of org.alfresco.repo.domain.activities.ActivityFeedEntity in project alfresco-remote-api by Alfresco.

the class RepoService method getActivities.

public List<Activity> getActivities(String personId, String siteId, boolean excludeUser, boolean excludeOthers) {
    List<ActivityFeedEntity> feedEntities = activityService.getUserFeedEntries(personId, siteId, excludeUser, excludeOthers, 0);
    List<Activity> activities = new ArrayList<Activity>(feedEntities.size());
    for (ActivityFeedEntity entity : feedEntities) {
        String siteNetwork = entity.getSiteNetwork();
        Pair<String, String> pair = splitSiteNetwork(siteNetwork);
        siteId = pair.getFirst();
        String networkId = pair.getSecond();
        String postDateStr = PublicApiDateFormat.getDateFormat().format(entity.getPostDate());
        Activity activity = new Activity(entity.getId(), networkId, siteId, entity.getFeedUserId(), entity.getPostUserId(), postDateStr, entity.getActivityType(), parseActivitySummary(entity));
        activities.add(activity);
    }
    return activities;
}
Also used : ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.api.tests.client.data.Activity) ActivityFeedEntity(org.alfresco.repo.domain.activities.ActivityFeedEntity)

Example 2 with ActivityFeedEntity

use of org.alfresco.repo.domain.activities.ActivityFeedEntity in project alfresco-remote-api by Alfresco.

the class ActivitiesImpl method getUserActivities.

public CollectionWithPagingInfo<Activity> getUserActivities(String personId, final Parameters parameters) {
    personId = people.validatePerson(personId);
    Paging paging = parameters.getPaging();
    String siteId = parameters.getParameter("siteId");
    String who = parameters.getParameter("who");
    ActivityWho activityWho = null;
    if (who != null) {
        try {
            activityWho = ActivityWho.valueOf(who);
        } catch (IllegalArgumentException e) {
            throw new InvalidArgumentException("Parameter who should be one of " + Arrays.toString(ActivityWho.values()));
        }
    }
    if (siteId != null && !siteId.equals("")) {
        SiteInfo siteInfo = sites.validateSite(siteId);
        if (siteInfo == null) {
            // site does not exist
            throw new EntityNotFoundException(siteId);
        }
        // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
        siteId = siteInfo.getShortName();
    }
    try {
        PagingResults<ActivityFeedEntity> activities = null;
        if (activityWho == null) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, false, false, -1, Util.getPagingRequest(paging));
        } else if (activityWho.equals(ActivityWho.me)) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, false, true, -1, Util.getPagingRequest(paging));
        } else if (activityWho.equals(ActivityWho.others)) {
            activities = activityService.getPagedUserFeedEntries(personId, siteId, true, false, -1, Util.getPagingRequest(paging));
        } else {
            throw new InvalidArgumentException("Who argument is invalid.");
        }
        List<ActivityFeedEntity> feedEntities = activities.getPage();
        List<Activity> ret = new ArrayList<Activity>(feedEntities.size());
        for (ActivityFeedEntity entity : feedEntities) {
            String feedSiteId = getSiteId(entity.getSiteNetwork());
            String networkId = tenantService.getDomain(entity.getSiteNetwork());
            Activity activity = new Activity(entity.getId(), networkId, feedSiteId, entity.getFeedUserId(), entity.getPostUserId(), entity.getPostDate(), entity.getActivityType(), getActivitySummary(entity));
            ret.add(activity);
        }
        return CollectionWithPagingInfo.asPaged(paging, ret, activities.hasMoreItems(), activities.getTotalResultCount().getFirst());
    } catch (JSONException e) {
        throw new AlfrescoRuntimeException("", e);
    }
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) Activity(org.alfresco.rest.api.model.Activity) JSONException(org.json.JSONException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActivityFeedEntity(org.alfresco.repo.domain.activities.ActivityFeedEntity) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

ArrayList (java.util.ArrayList)2 ActivityFeedEntity (org.alfresco.repo.domain.activities.ActivityFeedEntity)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 Activity (org.alfresco.rest.api.model.Activity)1 Activity (org.alfresco.rest.api.tests.client.data.Activity)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1 JSONException (org.json.JSONException)1