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

IWorkSpaceHandle on a server side plugin

Hi guys

I was wondering, which is the way to retrieve an instance of this object in an OperationParticipant context of a work item save.

0 votes

Comments

I don't understand your question. What does an IWorkspaceHandle have anything to do with a work item? Please provide some sample code.

Pheraps my question was not crystal clear.
I'm doing a Server Side Operation Participant on a work item save.

So in the beginning I just have a SaveParameter that refers to the work item and the service that I can reach with AbstracScmService.getService().
The work item is linked with a change set so I can have the changeset component.

From this point going on, how I can have the workspacehandle of where this changeset is lying.
Thanks any suggestions.

Please attach the code that you have so far.

Also note that change sets do not have to reside in a workspace. They may have been suspended or discarded in which case they are not part of any workspace.

In this case i'm sure that the changeset reside in a workspace.
The code is really long so I just attach the way to retrieve the changeset

ILinkService linkService = getService(ILinkService.class);
        ILinkServiceLibrary linkServiceLibrary = (ILinkServiceLibrary) linkService
                .getServiceLibrary(ILinkServiceLibrary.class);

        IReference workItemReference = linkServiceLibrary.referenceFactory()

                .createReferenceToItem(workItem);
        
        ILinkCollection linkCollection = linkServiceLibrary.findLinksByTarget(
                ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID,
                workItemReference).getAllLinksFromHereOn();

        List<IChangeSetHandle> changeSetHandles = new ArrayList<IChangeSetHandle>();

        for (ILink link : linkCollection) {

            // Change set links should be item references
            IChangeSetHandle changeSetHandle = (IChangeSetHandle) link
                    .getSourceRef().resolve();
            changeSetHandles.add(changeSetHandle);
        }.
IItem[] changeSets = this.getService(IRepositoryItemService.class)
                .fetchItems(changeSetHandles.toArray(new IChangeSetHandle[0]),
                        IRepositoryItemService.COMPLETE);

If needed I also have the ProjectAreaHandle retrieved from the workItem connected to that changeset, but i don't know ho to resolve the ProjectAreaHandle to a ProjectArea

IWorkItem workItem = (IWorkItem) saveParameter.getNewState();
        IProjectAreaHandle projectAreaHandle = workItem.getProjectArea();



Accepted answer

Permanent link
You need to get the direct IReference and query its extra information. That is a way to do it. However, keep in mind that this extra information may or may not be present in the link. This extra information also does not guarantee that this particular change set is in this workspace. Also of course note that a change set can be in multiple workspaces. There is no way of knowing that this workspace is the one "you want".

IReference workItemReference = linkServiceLibrary.referenceFactory().createReferenceToItem(workItemHandle);
ILinkQueryPage page = linkService.findLinksByTarget(ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID, workItemReference);
for (ILink link : page.getLinks()) {
IReference reference = link.getSourceRef();
String extraInfo = reference.getExtraInfo();
if (extraInfo != null) {
int index = extraInfo.indexOf('=');
if (index != -1) {
IWorkspaceHandle workspace = (IWorkspaceHandle) IWorkspace.ITEM_TYPE.createItemHandle(UUID.valueOf(extraInfo.substring(index + 1)), null);
// do work...
}
}
}
Marco Gianfico selected this answer as the correct answer

2 votes

Comments

Thanks Remy for your answer.
Just few question to understand better. Is linkService on line 2 an instance of ILinkServiceLibrary? The same object the you use above to find workitemreference?

Yes, it is an ILinkServiceLibrary.

Thanks Remy, it seems to work well, I got
extrainfo: Workspace=_ir5fIDUIEeSD1IdFVDHgIw


One other answer

Permanent link
To resolve an item see https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ and other examples on the blog that use hadles and resolve the item (almost all examples have to).

(ITeamArea) teamRepository.itemManager()
	.fetchCompleteItem(handle, IItemManager.REFRESH, monitor);

Another way to resolve Items -if they are IAuditables.

workItemCommon.getAuditableCommon().resolveAuditable(processAreaHandle,
ItemProfile.PROCESS_AREA_DEFAULT,monitor);


0 votes

Comments

for who is interested in I got the workItemCommon as service of the abstractService

AbstractService.getService(IWorkItemCommon.class)

@ralph: Why ItemProfile.PROCESS_AREA_DEFAULT and not ItemProfile.PROJECT_AREA_DEFAULT?

Please read the blog(s) they explain these things.I did them to not have to answer everything over and over.

Use the Item profiles you think need. The profiles select more or less data.

Thanks Ralph. If you have suggestions also on how to reach the workspace handle would be great.

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
× 10,937

Question asked: Sep 09 '14, 11:57 a.m.

Question was seen: 3,501 times

Last updated: Sep 12 '14, 8:57 a.m.

Confirmation Cancel Confirm