It's all about the answers!

Ask a question

Get files referred in a change set via REST APIs


Debdoot Mukherjee (512118) | asked Jun 21 '10, 10:39 a.m.
Hi,

Is there a way to get the contents of a project in Jazz source control whose files can be found in a RTC change set via RTC/OSLC REST APIs?

From oslc_cm:ChangeRequest I can navigate to a scm:ChangeSet associated with it.
For example, here is a snapshot of a scm:ChangeSet obtained via a GET on

https://localhost:9443/jazz/resource/itemOid/com.ibm.team.scm.ChangeSet/_IrrpoXz5Ed-hkKjk2Khljw?_mediaType=text/xml

<scm>
<stateId>_IxVlt3z5Ed-hkKjk2Khljw</stateId>
<immutable>true</immutable>
<contextId>_Dp6kMdwTEd2jUupDpQV1Rw</contextId>
<modified>2010-06-21T05:52:12.187Z</modified>
<mergePredecessor>
<predecessor>_IvQiEXz5Ed-hkKjk2Khljw</predecessor>
<active>false</active>
<comment>Testing ChangeSets</comment>
<lastUpdatedDate>2010-06-21T05:52:12.125Z</lastUpdatedDate>
<modifiedBy>
<changes>
<internalId>_IuEPQnz5Ed-hkKjk2Khljw</internalId>
<kind>2</kind>
<before>_76M7OXz4Ed-hkKjk2Khljw</before>
<after>_ItwtRHz5Ed-hkKjk2Khljw</after>
<item>
</changes>
<component>
<owner>
<xComponentLink>
</scm>


However, I cannot navigate to access the component or the item of type "filesystem:FileItemHandle". Is this possible by using REST APIs?


Thanks in advance,
Debdoot

9 answers



permanent link
John Scott (11) | answered Jun 21 '12, 11:48 a.m.
I was getting an error when using an IItemManager too. IVersionableManager (which appears quite similar) works:

ITeamRepository repository = ...

IVersionableManager versionableManager = SCMPlatform.getWorkspaceManager(repository).versionableManager();

IChange change = ...

IFileItem beforeState = (IFileItem) versionableManager.fetchCompleteState(change.beforeState(), null);
IFileItem afterState = (IFileItem) versionableManager.fetchCompleteState(change.afterState(), null);

I found this in an example in a post over at http://jazzlab.net/jazz/tip/8568

permanent link
Martin Gompertz (48611) | answered Dec 18 '11, 11:32 a.m.
Hi,

We're moving from a change control system which allows SQL query access to configuration and file change history.

In RTC, can this be queried via REST? I've checked the RTC Java API classes and REST interfaces. It looks like the facilities are not there in Java.

It looks like there are more possibilities if using REST, but I've only found examples of searching for work items. I've not found any examples of querying SCM so far.

These are examples of what we need:

- Show all file changes in a given work item.
- Show all file changes for a given file, for its whole life.
- For each file change listed, show the first baseline that included the file change.

Is it possible to get the above in a report format?

Is it possible to do SPARQL of SCM change history via REST? Are there any examples out there? If not this method, then what method can be used to get versatile access to the data?

Thanks!!

Martin

permanent link
S M (8622023) | answered Dec 09 '11, 11:59 a.m.
@pkomar: Could you explain a little bit more about

.../service/com.ibm.team.filesystem.service.internal.rest.IFilesystemContentService

Where exactly is this located? Do I just have to put http://localhost:9443/jts/ before?

permanent link
Marcel de Koster (6) | answered Jun 07 '11, 3:25 a.m.
Hi there,

Sorry to also ask the same question, but I'm struggling with it for a while now and can't seem to find a solution to get the file info for a change set. I have the IVersionableHandle, but no way to get the file or change info:

- Who changed the file
- What is the file name
- What is the file path

I do not need the contents of the file, only the info above.

Whould appriciate any anwer.
Regards,
Marcel de Koster

Hi there,

I have a similar query about the RTC java API. I thought this wouid be simple (it works for other *Handles) but I can't obtain an IFileItem from a FileItemHandleImpl:


// "change" is an IChange I have obtained from a ChangeSet.changes() call
IFileItem fileItem = teamRepository.itemManager().fetchCompleteItem(change.item(), 1, JazzCommonDelegate.getProgressMonitor());


When this code is executed, an "Error: com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl cannot be cast to com.ibm.team.repository.common.IManagedItemHandle" is thrown. It seems from debugging that this is happening internal to the fetchCompleteItem(...) call.

This method works for all the other times I've tried to get an Item from its Handle. Am I doing something wrong?

Hope you can help.

TIA.

Cheers, Andrew

permanent link
Andrew Harmel-Law (14612218) | answered Nov 01 '10, 7:20 a.m.
Hi there,

I have a similar query about the RTC java API. I thought this wouid be simple (it works for other *Handles) but I can't obtain an IFileItem from a FileItemHandleImpl:


// "change" is an IChange I have obtained from a ChangeSet.changes() call
IFileItem fileItem = teamRepository.itemManager().fetchCompleteItem(change.item(), 1, JazzCommonDelegate.getProgressMonitor());


When this code is executed, an "Error: com.ibm.team.filesystem.common.internal.impl.FileItemHandleImpl cannot be cast to com.ibm.team.repository.common.IManagedItemHandle" is thrown. It seems from debugging that this is happening internal to the fetchCompleteItem(...) call.

This method works for all the other times I've tried to get an Item from its Handle. Am I doing something wrong?

Hope you can help.

TIA.

Cheers, Andrew

permanent link
Debdoot Mukherjee (512118) | answered Jul 01 '10, 1:49 p.m.
Thanks for your replies.

We chose to use the Java APIs to do the following:

Starting from a change set, find all projects whose files are present in the change set and then download such projects.

Primarily we used the following services:
com.ibm.team.scm.common.IScmService
com.ibm.team.scm.service.IServerSideVersionedContentService

The following code is used to recursively traverse a project folder to download it from Jazz SCM

private void createLocalDump(IFolderHandle fHandle, ServiceConfigurationProvider configProvider, String parent) throws TeamRepositoryException, IOException{
IScmService scmService = getService(IScmService.class);
IServerSideVersionedContentService serverVCService = getService(IServerSideVersionedContentService.class);
FolderEntryReport[] feRpts = scmService.configurationChildEntriesMultiple(configProvider,
new IFolderHandle[]{fHandle}, null, null);

for(FolderEntryReport feRpt : feRpts){
Map map = feRpt.getEntries();
for(String child: (Set<String>)map.keySet()){
System.out.println(child);
IVersionableHandle vhandle = (IVersionableHandle) map.get(child);
if(vhandle instanceof IFolderHandle){
String childDir = parent + "/" + child;
new File(childDir).mkdirs();
createLocalDump((IFolderHandle)vhandle,configProvider,childDir);
}
else if(vhandle instanceof IFileItemHandle){
IFileItem fileItem = (IFileItem)getVersionable(vhandle);
ContentHash ch = ((IFileItem)fileItem).getContent().getHash();
FileOutputStream fos = new FileOutputStream(new File(parent + "/" +
fileItem.getName()));
serverVCService.fetchContent(fileItem, ch, fos);
fos.close();
}
}
}
}


We could not find any direct API to obtain the WorkspaceId from a change set.
We parsed this information from the url field LinkDTO objects reachable from WorkItemDTO objects obtained through IWorkItemRestService.

Here's some preliminary information:

This specifies the UUID of the versionable (folder, file or symbolic link)
<internalId>_IuEPQnz5Ed-hkKjk2Khljw</internalId>


These specify the states of the versionable
<before>_76M7OXz4Ed-hkKjk2Khljw</before>

<after>_ItwtRHz5Ed-hkKjk2Khljw</after>


If the versionable is a file item then it has content.

In RTC 3.0 (and probably RTC 2.0.0.2) , I believe that you can GET the content from the IFilesystemContentService, which lives at:
.../service/com.ibm.team.filesystem.service.internal.rest.IFilesystemContentService


It's header comment explains:
/**

* Content service for Filesystem, which returns the contents of files given a
* URIs of the form:
* .../{workspaceItemId}/{componentItemId}/{fileNameOrFilePath}?itemId={fileItemId}&stateId={fileStateId}
*
* The {fileNameOrFilePath} segment(s) are there only to cause the browser to offer an appropriate
* file name on save.
*/


At the moment, I don't have any advice about how to get a workspaceItemId or the relevant componentItemId, though it might be the value of
<contextId>_Dp6kMdwTEd2jUupDpQV1Rw</contextId>
.

Shortly, I'll add another reply explaining how to use the oslc-scm capabilities that are being added to RTC 3.0

permanent link
Paul Komar (421) | answered Jul 01 '10, 10:48 a.m.
Here's some preliminary information:

This specifies the UUID of the versionable (folder, file or symbolic link)
<internalId>_IuEPQnz5Ed-hkKjk2Khljw</internalId>


These specify the states of the versionable
<before>_76M7OXz4Ed-hkKjk2Khljw</before>

<after>_ItwtRHz5Ed-hkKjk2Khljw</after>


If the versionable is a file item then it has content.

In RTC 3.0 (and probably RTC 2.0.0.2) , I believe that you can GET the content from the IFilesystemContentService, which lives at:
.../service/com.ibm.team.filesystem.service.internal.rest.IFilesystemContentService


It's header comment explains:
/**

* Content service for Filesystem, which returns the contents of files given a
* URIs of the form:
* .../{workspaceItemId}/{componentItemId}/{fileNameOrFilePath}?itemId={fileItemId}&stateId={fileStateId}
*
* The {fileNameOrFilePath} segment(s) are there only to cause the browser to offer an appropriate
* file name on save.
*/


At the moment, I don't have any advice about how to get a workspaceItemId or the relevant componentItemId, though it might be the value of
<contextId>_Dp6kMdwTEd2jUupDpQV1Rw</contextId>
.

Shortly, I'll add another reply explaining how to use the oslc-scm capabilities that are being added to RTC 3.0

permanent link
Michael Valenta (3.7k3) | answered Jun 23 '10, 1:26 p.m.
FORUM MODERATOR / JAZZ DEVELOPER
If the versionable represents a file, it will be an instance of an
IFileItem which has a content object associated with it. You can get a
stream to the contents from the content object.

Michael

debdootm wrote:
Even with Java APIs, I am struggling to write code to download
contents of a project, files in which may be a part of a change set
that I have a handle to.

IChangeSet cs =
getChangeSet(changeSetUuId);
if(cs.changes().size() > 0){
IChange chng =
(IChange)cs.changes().get(0);
IVersionableHandle chngObj = chng.afterState();
IVersionable versionable = getVersionable(chngObj);
}


In the above code, how do I get the contents of the item:
"versionable"?

By tracing the GET requests made by Web UI, I find that the
IFileContentService can help us fetch versioned file items. What is
the best way to programmatically mimic this service?

Thanks in advance,

Debdoot

debdootmwrote:
Hi,
Is there a way to get the contents of a project in Jazz source
control whose files can be found in a RTC change set
via RTC/OSLC REST APIs?
From oslc_cm:ChangeRequest I can navigate to a scm:ChangeSet
associated with it.
For example, here is a snapshot of a scm:ChangeSet obtained via a
GET on

https://localhost:9443/jazz/resource/itemOid/com.ibm.team.scm.ChangeSet/_IrrpoXz5Ed-hkKjk2Khljw?_mediaType=text/xml

scm
stateId>_IxVlt3z5Ed-hkKjk2Khljw</stateId>true</immutable>_Dp6kMdwTEd2jUupDpQV1Rw</contextId>2010-06-21T05:52:12.187Z</modified>_IvQiEXz5Ed-hkKjk2Khljw</predecessor>false</active>Testing ChangeSets</comment>2010-06-21T05:52:12.125Z</lastUpdatedDate>_IuEPQnz5Ed-hkKjk2Khljw</internalId>2</kind>_76M7OXz4Ed-hkKjk2Khljw</before>_ItwtRHz5Ed-hkKjk2Khljw</after>


However, I cannot navigate to access the component or the item of
type "filesystem:FileItemHandle". Is this possible by using
REST APIs?

Thanks in advance,
Debdoot

permanent link
Debdoot Mukherjee (512118) | answered Jun 23 '10, 8:50 a.m.
Even with Java APIs, I am struggling to write code to download contents of a project, files in which may be a part of a change set that I have a handle to.

 IChangeSet cs = getChangeSet(changeSetUuId);

if(cs.changes().size() > 0){
IChange chng = (IChange)cs.changes().get(0);
IVersionableHandle chngObj = chng.afterState();
IVersionable versionable = getVersionable(chngObj);
}


In the above code, how do I get the contents of the item: "versionable"?

By tracing the GET requests made by Web UI, I find that the IFileContentService can help us fetch versioned file items. What is the best way to programmatically mimic this service?

Thanks in advance,

Debdoot

Hi,

Is there a way to get the contents of a project in Jazz source control whose files can be found in a RTC change set via RTC/OSLC REST APIs?

From oslc_cm:ChangeRequest I can navigate to a scm:ChangeSet associated with it.
For example, here is a snapshot of a scm:ChangeSet obtained via a GET on

https://localhost:9443/jazz/resource/itemOid/com.ibm.team.scm.ChangeSet/_IrrpoXz5Ed-hkKjk2Khljw?_mediaType=text/xml

<scm>
<stateId>_IxVlt3z5Ed-hkKjk2Khljw</stateId>
<immutable>true</immutable>
<contextId>_Dp6kMdwTEd2jUupDpQV1Rw</contextId>
<modified>2010-06-21T05:52:12.187Z</modified>
<mergePredecessor>
<predecessor>_IvQiEXz5Ed-hkKjk2Khljw</predecessor>
<active>false</active>
<comment>Testing ChangeSets</comment>
<lastUpdatedDate>2010-06-21T05:52:12.125Z</lastUpdatedDate>
<modifiedBy>
<changes>
<internalId>_IuEPQnz5Ed-hkKjk2Khljw</internalId>
<kind>2</kind>
<before>_76M7OXz4Ed-hkKjk2Khljw</before>
<after>_ItwtRHz5Ed-hkKjk2Khljw</after>
<item>
</changes>
<component>
<owner>
<xComponentLink>
</scm>


However, I cannot navigate to access the component or the item of type "filesystem:FileItemHandle". Is this possible by using REST APIs?


Thanks in advance,
Debdoot

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.