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

How to retrieve the latest ChangeSet/UUID/version-number of a project/file (residing on Jazz server) along with its contents and then locate that project/file from that version-number


Hi All,

I am just started understanding on RTC Java Plain libraray 5.0.2. Also I am very much familiar about the SVN functionality.

I want to know :----

How to retrieve the latest ChangeSet/UUID/version-number of a project/file (residing on Jazz server) along with its contents and then locate that project/file from that version-number by using Java code.

I am using this code to locate a file by its name only....
private static IVersionableHandle findFile(IFolderHandle root,
IConfiguration iconfig, String fileName, IProgressMonitor monitor)
throws TeamRepositoryException
{

String fileNamePath[] = { fileName };
IVersionableHandle filePathHandle = null;

// Check if file at this folder level
filePathHandle = iconfig.resolvePath(root, fileNamePath, monitor);
if (filePathHandle != null)
{
return filePathHandle;
}

// Check this file sub folders
@SuppressWarnings("unchecked")
Map<String, IVersionableHandle> childEntries = iconfig.childEntries(root, monitor);
for (Map.Entry<String, IVersionableHandle> next : childEntries.entrySet())
{
IVersionableHandle nextVersionable = next.getValue();
if (nextVersionable instanceof IFolderHandle)
{
filePathHandle = findFile((IFolderHandle)nextVersionable, iconfig, fileName, monitor);
if (filePathHandle != null)
{
//System.out.println("Found file " + fileName);
break;
}
}
}
return filePathHandle;
}

public static String readFileContent(IWorkspaceHandle streamHandle,
IComponentHandle componentHandle, ITeamRepository repo,
String fileName, IProgressMonitor monitor)
throws TeamRepositoryException, IOException
{
IFileItem fileItem = null;
IFileContentManager contentManager = FileSystemCore.getContentManager(repo);
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repo);

IWorkspaceConnection streamConnection = workspaceManager.getWorkspaceConnection(streamHandle, monitor);

// Find file handle
IConfiguration iconfig = (IConfiguration)streamConnection.configuration(componentHandle);
//IFolderHandle root = iconfig.completeRootFolder(monitor);
IFolderHandle root = iconfig.rootFolderHandle(monitor);
System.out.println("********************* Searching for file " + fileName);
IVersionableHandle filePathHandle = findFile(root, iconfig, fileName, monitor);

// Check if file found
if (filePathHandle == null)
{
throw new FileNotFoundException("********************** File not found.");
}
else
{
System.out.println("*********************** Found file: " + fileName);
}

// Fetch file complete item
IVersionable filePath = (IVersionable)iconfig.fetchCompleteItem(filePathHandle, monitor);
if (filePath.hasFullState())
{
fileItem = (IFileItem)filePath.getFullState();
}
else
{
throw new TeamRepositoryException("Could not find file item");
}

// Get file content
IFileContent content = fileItem.getContent();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
contentManager.retrieveContent(fileItem, content, outputStream, monitor);

String readContent = null;
readContent = outputStream.toString("UTF-8");
System.out.println("Contents of " + filePath.getName() + "++++++++++++++++++++++++++++++++++++++++++++.");
System.out.println(readContent);
return readContent;
}

Thanks in advance

1

0 votes

Comments

Can you tell me more about your use case? 


RTC doesn't have a notion of the "latest" version of a file. Files can exist in multiple streams/workspaces, so there's only the notion of the current state of a file in a specific stream/workspace. The code you've posted looks like it can find the current version of a file in a workspace, so I don't think I understand what you're trying to do. 

 Hi Evan, please see the more details of my problem below.



One answer

Permanent link
Thanks for understanding the problem.
Actually in an application, I can fetch/chekout the source of a project/file (inside a project) with a particular revision number by using SVNKit APIs very easily

The same this I want to do for RTC by using Rational Team Concert Java API download: https://jazz.net/downloads/rational-team-concert/releases/5.0.2?p=allDownloads.

Now I am able to do the following task by Java code as:
- Get a list of all projects under a work-space of Jass server for a particular user
- Get a full sources checkout of any project

But I need to do the following more:
- How to see and fetch, if there is any update on that project, which I have already checked-out or known by the name
- And how to see/get, if there is any update in source of a text-file, committed by other developers of that project.

Please tell, if this is possible by Java code similar to SVN functionality.

0 votes

Comments

A couple of comments:
- The server does not track checkouts ... that is tracked by the client with the sandbox containing the checkout.   The server does track "locks" ("reserved checkouts"), so you could ask the server about those.
- When you say "updates committed by other developers", do you mean "are there any incoming changes to that file from the stream identified as the current flow target of the workspace"?

 Yes, exactly I mean "are there any incoming changes to that file from the stream identified as the current flow target of the workspace"?


One more point, Suppose I load a particular file into my local sandbox, then I deleted that file from my local workspace/sandbox, And  other developer checked-in the changes into the same file, so How to get that file previous contents ignoring the latest state updated by someone else???

What's your goal? Why are you trying to do this? I ask because the tasks you are describing seem very similar to subcommands available in the CLI. 


- Get a list of all projects under a work-space of Jass server for a particular user
- Get a full sources checkout of any project
Can you achieve the same thing by loading the user's repository workspace? What are you going to do with the full source after you get it?


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
× 12,019
× 1,700
× 383

Question asked: Feb 05 '15, 9:11 a.m.

Question was seen: 4,659 times

Last updated: Feb 06 '15, 12:19 p.m.

Confirmation Cancel Confirm