It's all about the answers!

Ask a question

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


0
1
Kishore Kushwaha (623) | asked Feb 05 '15, 9:11 a.m.

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

Comments
Evan Hughes commented Feb 05 '15, 11:52 a.m. | edited Feb 05 '15, 11:53 a.m.
JAZZ DEVELOPER

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. 


Kishore Kushwaha commented Feb 06 '15, 12:18 a.m.

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

One answer



permanent link
Kishore Kushwaha (623) | answered Feb 06 '15, 12:17 a.m.
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.


Comments
Geoffrey Clemm commented Feb 06 '15, 12:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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"?


Kishore Kushwaha commented Feb 06 '15, 12:50 a.m. | edited Feb 06 '15, 1:02 a.m.

 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???


Evan Hughes commented Feb 06 '15, 12:19 p.m.
JAZZ DEVELOPER

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 to post your answer.