It's all about the answers!

Ask a question

How to download files from RTC server by java application


jiang haoran (1622) | asked Oct 17 '11, 5:03 a.m.
retagged Dec 16 '13, 11:52 a.m. by David Lafreniere (4.8k7)
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)

2 answers



permanent link
Mehmet Ali Aydın (6133) | answered Oct 17 '11, 9:10 a.m.
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)

Comments
jiang haoran commented Oct 21 '11, 2:57 a.m. | edited Dec 02 '13, 4:16 a.m.

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
Ralph Schoon (63.5k33646) | answered Dec 02 '13, 5:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please have a look at http://thescmlounge.blogspot.de/2013/08/getting-your-stuff-using-rtc-sdk-to-zip.html for some more explanations.

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.