Search code examples
ibm-sbt

How can I get ActivityNodes from a Section?


I'm trying to get all the activities from a section in a community Activity.

First I loop over all the activities:

ActivityList allActivities = service.getAllActivities();
for(Activity activity : allActivities) {
    if("community_activity".equals(activity.getEntryType())) {
    ...

For every community activities I loop over the ActivityNodes:

ActivityNodeList activityNodesFromActivity = service.getActivityNodes(activity.getActivityId());            
    for (ActivityNode activityNode : activityNodesFromActivity) {
    ...

So far so good. But because some of the activities can be Sections, I want to loop over them once more to get their 'child' activities.

ActivityNodeList activityNodesFromSection = service.getActivityNodes(activityNode.getActivityId());

Now I get 403 errors for these requests:

<error xmlns="http://www.ibm.com/xmlns/prod/sn">
    <code/>
    <message>
        Identifier: LCFED1E22083D5412BB4A4E5ABB1D26B10 Request denied
    </message>
    <displaymessage/>
    <errortype/>
    <trace>
        java.lang.Exception: Identifier: LCFED1E22083D5412BB4A4E5ABB1D26B10 Request denied
    </trace>
</error>

Because of that the SBT loses the OAuth token and I have to login again on SmartCloud and grand access.

Is there another/better way to get the activities from a section in a community activity?

btw: I'm using the second last version of the SBT: 1.0.0.20140125-1133


Solution

  • try this approach...

    You can extend the base "extends ActivityService"

    /**
    * Method to get Activity nodes from Section
    * 
    * @param includeSelf 
    * @param nodeUuid
    * @param sectionId
    * @return ActivityNodeList
    * @throws ActivityServiceException
    */
    public ActivityNodeList getActivityNodesInSection(String nodeUuid, String sectionId boolean includeSelf) throws ActivityServiceException {
    
    private String sectionUri = "/activities/service/atom2/descendants";
    
    if (null == activityId ){
    throw new ActivityServiceException(null, "Null activityId");
    }
    
    /**
     * Includes section node, if it's true
     */
    String include = "no";
    if(includeSelf){
       include = "yes";
    }
    
    try {
    Map<String, String> params = new HashMap<String, String>();
    params.put("nodeUuid", activityId);
    params.put("includeSelf", include);
    params.put("section", sectionId);
    
    
             return (ActivityNodeList) getEntities(sectionUri, params, new ActivityNodeFeedHandler(this));
    } catch (Exception e) {
    throw new ActivityServiceException(e);
    }
    }
    

    then the function you call - in your case, nodeUuid and sectionid should be the same.