Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to download files from RTC server by java application

I want to write an application by plain Java API.
The application should be able to access our project server,and download source file or document which my colleagues finished from server to local computer's appointed folder.

Now,The application which I finished can access the server and get work items.But I can't download source file or document.

Does RTC's plain Java API provide some method that can satisfy my requirement?(I have searched,but I did not get any answer)

0 votes



2 answers

Permanent link
You can find below source code that we use to load all files from a workspace. If you use builds and don't have a specific purpose, you should prefer to use JBE.


public static void loadComponents(IWorkspaceConnection workspace) throws TeamRepositoryException, FileNotFoundException {
List components = teamRepository.itemManager().fetchCompleteItems(workspace.getComponents(), IItemManager.DEFAULT, null);
for (Iterator<IComponent> it = components.iterator(); it.hasNext();) {
IComponent component = it.next();
String loadComp = component.getName() + " Ykleniyor";
log.println(loadComp);
String loadComponentAct = buildClient.startBuildActivity(buildRequest.getBuildResult(), loadComp, loadComponentsAct, false, monitor);
loadComponentFileTree(workspace, component, workspace.configuration(component), null, "", monitor);
}
}


private static void loadComponentFileTree(IWorkspaceConnection workspace,
IComponent component, IConfiguration configuration, IFolderHandle parent, String indent, IProgressMonitor monitor) throws TeamRepositoryException, FileNotFoundException {
Map<String> children = null;
if(parent == null) {
children = configuration.childEntriesForRoot(null);
} else {
children = configuration.childEntries(parent, null);
}
if(children != null) {
for (String name : children.keySet()) {
String subIndent = indent + "\\" + name;

IVersionableHandle item = children.get(name);
if(item instanceof IFolderHandle)
{
File folderPath = new File(localWorkspace.getAbsolutePath()+subIndent);
folderPath.mkdirs();
}
else if(item instanceof IFileItemHandle)
{
IFileItem fileItem = (IFileItem) SCMPlatform.getWorkspaceManager(teamRepository).versionableManager().fetchCompleteState(item, null);
IFileContent fileContent = fileItem.getContent();
File outputFile = new File(localWorkspace.getAbsolutePath() + subIndent);
if(!outputFile.getParentFile().exists())
outputFile.getParentFile().mkdirs();
OutputStream output = new FileOutputStream(outputFile.getAbsolutePath());
SCMPlatform.getContentManager(teamRepository).retrieveContent(item, fileContent, output, monitor);
}
}
}
}



I want to write an application by plain Java API.
The application should be able to access our project server,and download source file or document which my colleagues finished from server to local computer's appointed folder.

Now,The application which I finished can access the server and get work items.But I can't download source file or document.

Does RTC's plain Java API provide some method that can satisfy my requirement?(I have searched,but I did not get any answer)

1 vote

Comments

thank you very much!

You can find below source code that we use to load all files from a workspace. If you use builds and don't have a specific purpose, you should prefer to use JBE.


public static void loadComponents(IWorkspaceConnection workspace) throws TeamRepositoryException, FileNotFoundException {
List components = teamRepository.itemManager().fetchCompleteItems(workspace.getComponents(), IItemManager.DEFAULT, null);

for (Iterator<IComponent> it = components.iterator(); it.hasNext();) {
IComponent component = it.next();
String loadComp = component.getName() + " Ykleniyor";
log.println(loadComp);
String loadComponentAct = buildClient.startBuildActivity(buildRequest.getBuildResult(), loadComp, loadComponentsAct, false, monitor);
loadComponentFileTree(workspace, component, workspace.configuration(component), null, "", monitor);
}
}




private static void loadComponentFileTree(IWorkspaceConnection workspace,
IComponent component, IConfiguration configuration, IFolderHandle parent, String indent, IProgressMonitor monitor) throws TeamRepositoryException, FileNotFoundException {
Map<String> children = null;
if(parent == null) {
children = configuration.childEntriesForRoot(null);
} else {
children = configuration.childEntries(parent, null);
}
if(children != null) {
for (String name : children.keySet()) {
String subIndent = indent + "\" + name;


IVersionableHandle item = children.get(name);
if(item instanceof IFolderHandle)
{
File folderPath = new File(localWorkspace.getAbsolutePath()+subIndent);
folderPath.mkdirs();
}
else if(item instanceof IFileItemHandle)
{
IFileItem fileItem = (IFileItem) SCMPlatform.getWorkspaceManager(teamRepository).versionableManager().fetchCompleteState(item, null);
IFileContent fileContent = fileItem.getContent();
File outputFile = new File(localWorkspace.getAbsolutePath() + subIndent);
if(!outputFile.getParentFile().exists())
outputFile.getParentFile().mkdirs();
OutputStream output = new FileOutputStream(outputFile.getAbsolutePath());
SCMPlatform.getContentManager(teamRepository).retrieveContent(item, fileContent, output, monitor);
}
}
}
}


Permanent link
Please have a look at http://thescmlounge.blogspot.de/2013/08/getting-your-stuff-using-rtc-sdk-to-zip.html for some more explanations.

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938
× 1,202
× 169
× 57

Question asked: Oct 17 '11, 5:03 a.m.

Question was seen: 10,246 times

Last updated: Dec 16 '13, 11:52 a.m.

Confirmation Cancel Confirm