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

How to get OperationHistory of the stream programmatically using RTC api?

Hello Team,
Usecase:
We are actually planning to clean up some of the Streams in the Project area ( 40+).
to do this activity, we would like to have a report showing which streams are actively working(Some operation happening in the Stream) or which are not( Operations done few months back like Changeset deliver,,,)

In Eclipse Client, we can see this using Operation History option, which gives me operations currently happening in the Stream. But doing this for all the 40+ streams is difficult.

So could you please support how to achieve this use case using RTC API?


Thanks in advance!!

1

1 vote

Comments

You have asked your question Dec 13th. You could edit that if you wanted to. Please do not spam the forum with duplicate questions. I closed the older one for this time.

@Ralph Schoon, Apologies for the same but there seems some problem with jazz forum, like i was trying to delete my earlier question but it was not getting deleted, may be next time i will keep this thing in my mind, but anyway can you please help me with the above query ?

Don't worry Rajat. I have seen such delete issues myself. Also, sometimes you ask a question once and somehow it has a twin.

I have not looked into that particular API.


Accepted answer

Permanent link
Note: This is not official API, however here is the way to retrieve the same information that would be shown in the Operation History view in Eclipse:


ParmsGetWorkspaceHistory parms = new ParmsGetWorkspaceHistory();
parms.workspaceId = uuidOfStream;
parms.includeDetails = false; // We don't care about all the details, only the time really....
parms.maxResultSize = 1; // We just need the most recent operation entry

IScmRichClientRestService scmService = (IScmRichClientRestService) ((IClientLibraryContext) repository).getServiceInterface(IScmRichClientRestService.class);
ScmWorkspaceHistory workspaceHistory = scmService.postGetWorkspaceHistory(parms);
if (workspaceHistory.getHistoryEntries().size() > 0) {
   ScmWorkspaceHistoryEntry entry = (ScmWorkspaceHistoryEntry) workspaceHistory.getHistoryEntries().get(0);
   date = entry.getDate(); // This is the date of the last operation against this stream....
}
Ralph Schoon selected this answer as the correct answer

1 vote

Comments
ScmWorkspaceHistory workspaceHistory = scmService.postGetWorkspaceHistory(parms);
this line gives error ,saying Parms is compatible.

By "compatible" do you mean "incompatible"?
Can you provide the actual error message + stack trace?

1 vote

 Hello David ,


Thanks for the snippet .It is working fine.

I need support in finding details of components which gets affected with delivery operation.

Example: When user delivers 3 change sets to 3 different component. From above snippet ,I get info on how many comments get affected but not the details of which components.  

Hello David,
I am using below snippet

ParmsGetWorkspaceHistory parms = new ParmsGetWorkspaceHistory();
parms.workspaceId = uuidOfStream;

commmented these two params // parms.includeDetails = false; // We don't care about all the details, only the time really....// parms.maxResultSize = 1; Result of history entries is coming for around last 6 months but not fully since the stream is created.What am I missing to set ? or How can I  get all operation entries  (since beginning of streams)

For identifying the components:
-->ScmWorkspaceHistory .getHistoryEntries() to give ScmWorkspaceHistoryEntry
-->ScmWorkspaceHistoryEntry.getDescription() to give ScmWorkspaceOperationDescription 
-->ScmComponentOperationDescription.getComponent() to identify the component

For getting the entire history:
IScmRichClientRestService.postGetWorkspaceHistory() will not return the entire history as that may be too large. To get all the data you will need to make multiple calls, paging through the results. If the return value has ScmWorkspaceHistory.getNextPage() non-null and non-empty, then you pass that along as an argument using ParmsGetWorkspaceHistory.pageToken to get subsequent pages.

1 vote

Hello David,

thank you so much for earlier comment.
ParmsGetWorkspaceHistory parms = new ParmsGetWorkspaceHistory();
parms.workspaceId = uuidOfStream;
while(workspaceHistory.getNextPage() !=null) {
parms.pageToken=workspaceHistory.getNextPage();
      ScmWorkspaceHistory workspaceHistory = scmService.postGetWorkspaceHistory(parms); 
}
I am still not getting full history entries. What am I using it wrongly from your description?

Hello David,


Support here, would be very much helpful and appreciate it.

To clarify, workspaceHistory.getHistoryEntries() is non-empty for the first page, but it is empty for the 2nd page?

Also, it's hard for me to confirm that your stream has more than 512 'changes' to it (perhaps they all do fit within the 1st page). What type of changes are you missing? (perhaps you are expecting a change type that is not actually included in the operation history)

1 vote

 workspaceHistory.getHistoryEntries() is non-empty for the first page but for second page also it is non empty. 


In the Streams which are one or two year old ,I have all entries in first page itself.In this case it is totally fine. But for two streams which are older than 3 years. They have more entries. In these streams after fetching entries of second page if I run the code , it gets same 2nd page entries. So in total I am getting 1024 entries after that, second page entries gets repeated.

workspaceHistory.getNextPage(); value remains constant 1586880172836, does it indicate something.? 

Are you sure in the code you are using that you are getting the getNextPage() from the correct workspaceHistory instance?

1 vote

In particular, the code you pasted above has an issue with variable shadowing...

1 vote

while(workspaceHistory.getNextPage() !=null) {
parms.pageToken=workspaceHistory.getNextPage();
  workspaceHistory = scmService.postGetWorkspaceHistory(parms); // read the entries using workspaceHistory object
} thanks for hint, there was  variable shadowing. Now my code works perfectly fine and retrieves complete History entries. I highly appreciate  your support and being patient with my queries :) 

Glad you resolved it.
Please click 'Mark this answer as the accepted answer'.

1 vote

 For identifying the components:
-->ScmWorkspaceHistory .getHistoryEntries() to give ScmWorkspaceHistoryEntry 
-->ScmWorkspaceHistoryEntry.getDescription() to give ScmWorkspaceOperationDescription 

How to get  ScmComponentOperationDescription from ScmWorkspaceOperationDescription  object seems to not direct
-->ScmComponentOperationDescription.getComponent() to identify the component

It's literally the first method in the ScmWorkspaceOperationDescription.java file. Please spend a bit of effort looking through the classes to see what's available :)

ScmWorkspaceOperationDescription desc = workspaceHistoryEntry.getDescription();
List<ScmComponentOperationDescription> componentOperations = desc.getComponentDescriptions();


ScmWorkspaceOperationDescription wsOpDesc =entry.getDescription(); List<ScmComponentOperationDescription> compOpDesc =wsOpDesc.getComponentDescriptions();
          for (Iterator<ScmComponentOperationDescription> it = compOpDesc.iterator(); it.hasNext();) {
            ScmComponentOperationDescription compDesc= it.next();
            System.out.println(compDesc.getComponent().getName());
          }
    Earlier I had tried wsOpDesc.getComponentDescriptions(); this, as it was returning just List  ,I thought it may not be the type, ScmComponentOperationDescription. so asked you.  I checked for around 4 streams , all of them give null value for entry.getDescription();  it is bit surprising , how can it be null in 4 streams :(. this blocks me further getting any component details. Does it indicate something wrong with stream ?

It seems likely that you have not set the ParmsGetWorkspaceHistory.includeDetails to true.

In the above thread you only indicate that you comment out the includeDetails parameter, which is equivalent to setting it to false.

Hallo Andrew Niefer,

Thanks for support  it worked. 
Further more , I am trying to get change set details such as modified files etc. As of now i could changeset basic info such author, comment and UUID. How can get file level info from ScmWorkspaceHistoryChangeSetImpl object ?
List changeSets=compDesc.getAddedChangeSets();
 for(Iterator<ScmWorkspaceHistoryChangeSetImpl> its=changeSets.iterator(); its.hasNext();) {
             ScmWorkspaceHistoryChangeSetImpl cs=its.next();
             System.out.println(cs.getComment());
             System.out.println(cs.getItemId());
            System.out.println(cs.getAuthorName());           
           }

showing 5 of 19 show 14 more comments

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
× 13

Question asked: Dec 16 '19, 5:37 a.m.

Question was seen: 1,698 times

Last updated: Nov 16 '20, 4:19 a.m.

Confirmation Cancel Confirm