It's all about the answers!

Ask a question

AbstractScmAdvisor - How do you read changed file content?


0
1
Kevin Mayfield (4358) | asked Feb 12 '13, 1:18 p.m.
I have have looked at many references and have not been successful in getting the code to read the content in a IFileItem.  Many examples are for Client side libraries, and others don't seem to compile, or if they compile, they fail to get a service.

See References:
https://jazz.net/forum/questions/8246/read-content-of-specific-file-in-repository (looks like client lib)
https://jazz.net/forum/questions/896/problems-while-using-icontentservice (missing how to get IContentService).
https://jazz.net/forum/questions/69047/icontentserviceretrievecontent (server, but answer not complete)
https://jazz.net/forum/questions/80722/getting-ifilecontent-for-32kb-files (client?)


I have the IScmService:

                /*
                 * Details about the files in the changeSets must be retrieved from the scm service..
                 * IMPORTANT:  This advisor must inherit from AbsctractScmAdvisor to have access to this.
                 */
                IScmService scmService = getService(IScmService.class);

And I can get each file out of the Change sets:

                // Process files....          
                for (IChange change : (List<IChange>) changeSet.changes()) {
                        IVersionableHandle versionableHandle = change.beforeState();
                        // No Before state?  Must be New file so get After State....
                        //        For new files, LocateAncestors returns none, so you only get the file name.
                        if (versionableHandle == null)
                            versionableHandle=change.afterState();
                       
                        // versionableHandle has been class FileItemHandleImpl.
                        IVersionable item = (IVersionable) scmService.fetchState(versionableHandle, null, null);

                        FileItem fitem = (FileItem) item;                      
                        IFileContent content = fitem.getContent();

What do I use to read the content?

I did a toString() on the fitem and content, if that helps...

Tue Feb 12 11:57:15 CST 2013 com.ibm.team.filesystem.common.internal.impl.FileItemImpl@6e046e04 (stateId: [UUID _8IzHFHUfEeKMMItjgYJ8DQ], itemId: [UUID _076poHUfEeKhtdx8PAwhYw], origin: <unset>, immutable: true) (contextId: [UUID _Dp6kMdwTEd2jUupDpQV1Rw], modified: 2013-02-12 08:24:41.566, workingCopy: <unset>) (name: anotherfile, parentId: [UUID _nyJPMG5JEeKMDqvDi_i1Bw]) (executable: false)
Tue Feb 12 11:57:18 CST 2013 com.ibm.team.filesystem.common.internal.impl.FileContentImpl@702c702c (internalId: [UUID _8IzHEnUfEeKMMItjgYJ8DQ]) (stringHash: j0NDRmSPa5bfid2pAcUXaxCm2Dlh3TwayItZstwyeqQ, size: 2, predecessorHint: null) (characterEncoding: UTF-8, lineDelimiterSetting: 0)

Thanks.

Accepted answer


permanent link
Tim Mok (6.6k38) | answered Feb 13 '13, 11:43 a.m.
JAZZ DEVELOPER
You can call FileSystemCore#getContentManager(ITeamRepository repo) to get the IFileContentManager. From there you can call IFileContentManager#retrieveContent(IFileItemHandle item, IFileContent content, OutputStream outStream, IProgressMonitor monitor) to get a stream for the content.
Kevin Mayfield selected this answer as the correct answer

Comments
Kevin Mayfield commented Feb 13 '13, 12:10 p.m.

From the Server API, where do you get the ITeamRepository object?


Tim Mok commented Feb 13 '13, 4:47 p.m.
JAZZ DEVELOPER

It sounds like you're writing an advisor but I'm not sure what AbstractScmAdvisor is. From the server side, the IFileContentManager isn't what you want. You'll want the IServerSideVersionedContentService, which is the equivalent on the server. Your advisor is implementing IOperationAdvisor but should also extend AbstractService so you can get this service with the #getService(Class clazz) call.


Kevin Mayfield commented Feb 13 '13, 5:23 p.m. | edited Feb 13 '13, 5:25 p.m.

Thanks...

Checking the server logs...It said to check plugin.xml.

I needed to add the Interface class to the prerequisits list.

<requiredservice interface="com.ibm.team.scm.service.IServerSideVersionedContentService"/>

After restarting the server, the following code no longer throws exception:

this.getService(com.ibm.team.scm.service.IServerSideVersionedContentService.class);

I should be able to read file content now.
Thanks.


Ralph Schoon commented Feb 14 '13, 2:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Not sure if it might help, if you also need to access work items during deliver see http://rsjazz.wordpress.com/2012/11/01/restrict-delivery-of-changesets-to-workitem-types-advisordelivery-of-changesets-associated-to-wrong-work-item-types-advisor/ it cost me quite some time to understand how that works.

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.