ContentService usage

Hey all,

I am working on a script that will utilize the ContentService class. In particular, the streamDirectory() method.

My usage is as follows:

def repo = repositoryService.getById(1930)
def callback = new AbstractContentTreeCallback()

Syntax wise, this is correct. However I do not understand how to actually see the data that is returned. The API states that streamDirectory() calls methods for the AbstractContentTreeCallback object I pass in. The streamDirectory() method itself does not return anything.

I think I am not understanding the “callback” terminology in a Java sense. I’ve seen callbacks in javascript but not in Java.

Has anyone been successful with this class before?

1 Like

AbstractContentTreeCallback doesn’t actually do anything, you need to extend it. You might want to start by writing a subclass that calls System.out.println for each method, so you can understand when the methods will be called and what data they get passed.

1 Like

Ahhhhh that makes sense. Thanks Brent.

I will go ahead and try that out and report back.

EDIT: I got it. Added a few methods in my extended class to store data that was returned.

So, here is my updated code:

public class MyContentTreeCallback extends AbstractContentTreeCallback {
    ArrayList<String> files = new ArrayList<String>()
    Logger log;
    ContentTreeSummary fileSummary;
    public MyContentTreeCallback() {
        log = Logger.getLogger("com.onresolve.jira.groovy")
    public void onEnd(@Nonnull ContentTreeSummary summary) {
        fileSummary = summary
        log.debug("hello world")
    public void onStart(@Nonnull ContentTreeContext context) {
       log.debug("hello world")
    public boolean onTreeNode(@Nonnull ContentTreeNode node) {
       String filePath = ""
            for(int i=0;i<node.getPath().getComponents().size();i++){
                //filePath=filePath.substring(0,filePath.length() - 1)
       } else {
       String lastChar = filePath.charAt(filePath.length() - 1)
           filePath=filePath.substring(0,filePath.length() - 1)
       return true;

    public ArrayList<String> getFiles(){
        return files
//further down the file......
def repo = repositoryService.getById(1930)
MyContentTreeCallback callback = new MyContentTreeCallback()

ArrayList<String> repoFiles = callback.getFiles()

Thanks @bplump

1 Like