It's all about the answers!

Ask a question

How to fetch all the files and folders from the component.


Anurag Patel (21366) | asked Oct 14 '17, 2:07 a.m.
edited Oct 14 '17, 6:36 a.m.

 Hi,


I am trying to fetch the files and folders from the components using java api.
Can we fetch directly files of the components using java server api.
I am able to fetch workspace/stream and component using server api and trying to fetch the Files and folders inside the componets. 

Can any one help for getting the Files and folders.


Thanks in advance.

Accepted answer


permanent link
Luca Martinucci (1.0k396112) | answered Oct 15 '17, 9:00 a.m.

I have done that with plain Java API, not with server API, but I suppose that, once you've got the workspace/stream and the component you have done most of the job.
Basically, you have to retrieve a IWorkspaceConnection from the workspace, and the to get a IConfiguration from the WS connection.
Then you retrieve the "children" (that is, folders and files) of the configuration by cycling over them.
Here are some code snippets (remember, for plain Java API, you should adapt them to server API):

static Hashtable<IVersionableHandle, IComponent> rawFilesHash = new Hashtable<IVersionableHandle, IComponent>();
getRawFilesList(repo, wm, wHandle, component, null, monitor);

private static void getRawFilesList(ITeamRepository repo, IWorkspaceManager wm, IWorkspaceHandle wHandle,
        IComponent component, IFolderHandle parent, IProgressMonitor monitor) throws TeamRepositoryException {       
     IWorkspace workspace = (IWorkspace) repo.itemManager().fetchCompleteItem(wHandle, IItemManager.DEFAULT, null);
        IWorkspaceConnection wsConn = wm.getWorkspaceConnection(workspace, null);
        IConfiguration configuration = wsConn.configuration((IComponentHandle)component.getItemHandle());
           Map <String, IVersionableHandle> children = null;
           if (parent == null) {
               children = configuration.childEntriesForRoot(null);
           } else {
               children = configuration.childEntries(parent, null);
           }
           if (children != null) {
               for (String name : children.keySet()) {
                   IVersionableHandle item = children.get(name);
                      if (item instanceof IFolderHandle) {
                          getRawFilesList(repo, wm, wHandle, component, (IFolderHandle)item, monitor);
                      } else {
                          if (item instanceof IFileItemHandle) {
                              if (!rawFilesList.contains(item)) {
                                     rawFilesList.add(item);
                                     rawFilesHash.put(item, component);     
                              }
                          }
                      }     
                  }
           }
}

Anurag Patel selected this answer as the correct answer

One other answer



permanent link
Ralph Schoon (63.2k33646) | answered Oct 16 '17, 5:33 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.