It's all about the answers!

Ask a question

IWorkSpaceHandle on a server side plugin


Marco Gianfico (2049) | asked Sep 09 '14, 11:57 a.m.
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.

Comments
Remy Suen commented Sep 09 '14, 1:02 p.m.

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


Marco Gianfico commented Sep 10 '14, 4:12 a.m.

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.


Remy Suen commented Sep 10 '14, 8:09 a.m.

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.


Marco Gianfico commented Sep 12 '14, 4:37 a.m. | edited Sep 12 '14, 4:41 a.m.

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);


Marco Gianfico commented Sep 12 '14, 4:41 a.m.

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
Remy Suen (426124) | answered Sep 12 '14, 8:07 a.m.
edited Sep 12 '14, 8:45 a.m.
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

Comments
Marco Gianfico commented Sep 12 '14, 8:40 a.m. | edited Sep 12 '14, 8:41 a.m.

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?


Remy Suen commented Sep 12 '14, 8:46 a.m.

Yes, it is an ILinkServiceLibrary.


Marco Gianfico commented Sep 12 '14, 8:57 a.m.

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

One other answer



permanent link
Ralph Schoon (63.1k33646) | answered Sep 12 '14, 5:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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);



Comments
Marco Gianfico commented Sep 12 '14, 5:41 a.m. | edited Sep 12 '14, 5:59 a.m.

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?


Ralph Schoon commented Sep 12 '14, 6:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


Ralph Schoon commented Sep 12 '14, 6:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


Marco Gianfico commented Sep 12 '14, 7:55 a.m.

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

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.