It's all about the answers!

Ask a question

How to retrieve the project area of a java file?

yaoben lu (56181) | asked Aug 31 '09, 3:14 a.m.
Hi all!

I have implemented it with Jazz 1.x version. But in 2.0 version some of the interfaces have been changed, my former code doesn't work now.

Here is my former code.

IProjectAreaHandle prjArea = null;
ISharingDescriptor shareDesc = shareable.getShare().getSharingDescriptor();

ITeamRepository repos = getTeamRepository(shareDesc);
IItemManager im = repos.itemManager();
IComponentHandle compRef = shareDesc.getComponent();
IComponent comp = (IComponent) im.fetchCompleteItem(compRef, IItemManager.DEFAULT, null);

// get owning team area & project area
IAuditableHandle compOwner = comp.getOwner();

if (compOwner instanceof ITeamAreaHandle) {
ITeamArea teamArea = (ITeamArea) im.fetchCompleteItem((ITeamAreaHandle)compOwner, IItemManager.DEFAULT, null);
prjArea = teamArea.getProjectArea();

IAuditableHandle compOwner = comp.getOwner();

In RTC 2.0, there is no getOwner() method. So, my plugin couldn't find out the project area of a java file.
Could anyone tell me how to modify the code to get the project area in RTC 2.0.

11 answers

permanent link
SEC Servizi (97123257) | answered Aug 29 '12, 6:31 a.m.
edited Aug 29 '12, 6:32 a.m.
Ok, we got it:
IScmService scmService = (IScmService) ((IClientLibraryContext) repo).getServiceInterface(IScmService.class);
IComponentHandle componentH = cs.getComponent();
ComponentOwnerHandle componentOwnerH = scmService.getComponentOwnerRecord((ComponentHandle) componentH);
ComponentOwner componentOwner = (ComponentOwner) repo.itemManager().fetchCompleteItem(componentOwnerH, IItemManager.DEFAULT, null);

permanent link
SEC Servizi (97123257) | answered Aug 29 '12, 3:52 a.m.
edited Aug 29 '12, 3:54 a.m.
We are trying to do a similar controll: we would check if the change-set was associated to a work-item of the same project area.
Our snippet code is:
ITeamRepository repo = ...
IWorkItemReferences wiReferences = ...
List<IReference> refList = wiReferences.getReferences(ILinkTypeRegistry.INSTANCE.getLinkType("").getSourceEndPointDescriptor());
for (IReference ref : refList) {
 IChangeSet cs = (IChangeSet) repo.itemManager().fetchCompleteItem(ref.resolve(), IItemManager.DEFAULT, null);
 IComponent component = (IComponent) repo.itemManager().fetchCompleteItem(cs.getComponent(), IItemManager.DEFAULT, null);
 IItem owner = (IItem) component.getOwner();
 // ... 
Such a method "IComponent#getOwner()" does not exist, but the information there is as an internal... How can we get the value?
Thanks in advance.

permanent link
Nick Edgar (6.5k711) | answered Sep 15 '09, 9:33 a.m.
Ah, sorry about the confusion. You're right, it should be targetConnection.getOwner().

permanent link
yaoben lu (56181) | answered Sep 15 '09, 2:58 a.m.
Hi Nick,
your solution works, but there is a little mistake in your code, it should be IAuditableHandle ownerHandle = targetConnection.getOwner();

So it didn't work at first!

Thanks Nikc and Michele~~

permanent link
yaoben lu (56181) | answered Sep 14 '09, 11:14 p.m.
It is really nice to see both of your replies. I have tried both ways you offered.

To Michele:
I have debuged on the IAuditable object, unfortunately I find it is null. So there is no way to get access to the project area via it. So I wonder if there is anything wrong with my invoking.
IWorkspace workspace = (IWorkspace) im.fetchCompleteItem(workspaceHandle, IItemManager.DEFAULT, null);
IAuditableHandle handle = workspace.getProcessAreaScope();

Anyway, I really appreciate you offer.

To Nick:
I copy your code into my code, right after
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection&#40;workspaceHandle, null&#41;;

But the getOwner() still returns an IContributorHandle(). I am confused...

permanent link
Nick Edgar (6.5k711) | answered Sep 14 '09, 12:54 p.m.
Yaoben, in your code snippet you're fetching the owner of the workspace, which will always be an IContributorHandle. You should instead look up the current flow target from the workspace's flow table, check that the target is a stream, and get the owner from it.

IFlowEntry currentFlowEntry = workspaceConnection.getFlowTable&#40;&#41;.getCurrentDeliverFlow&#40;&#41;;
if &#40;currentFlowEntry != null&#41; &#123;
IWorkspaceHandle targetHandle = &#40;IWorkspaceHandle&#41; currentFlowEntry.getFlowNode&#40;&#41;;
IWorkspaceConnection targetConnection = workspaceManager.getWorkspaceConnection&#40;targetHandle, null&#41;;
if &#40;targetConnection.isStream&#40;&#41;&#41; &#123;
IAuditableHandle ownerHandle = workspaceConnection.getOwner&#40;&#41;;

Nick Edgar
RTC Build component lead

permanent link
Michele Pegoraro (1.8k14117103) | answered Sep 14 '09, 7:53 a.m.
Have you tried with IWorkspace.getProcessAreaScope()?
It gives you an IAuditableHandle which I think could be a IProjectAreaHandle or an IProcessAreaHandle. In this case you can fetch the item and than use IProcessArea-&gt;getProjectArea().

The only thing is that you have to debug on the IAuditableHandle to see what it could be.

permanent link
yaoben lu (56181) | answered Sep 14 '09, 6:11 a.m.
I have tried this way.

IWorkspaceHandle workspaceHandle = &#40;IWorkspaceHandle&#41;shareDesc.getConnectionHandle&#40;&#41;;

ITeamRepository repos = getTeamRepository&#40;shareDesc&#41;;
IItemManager im = repos.itemManager&#40;&#41;;

IWorkspace workspace = &#40;IWorkspace&#41; im.fetchCompleteItem&#40;workspaceHandle, IItemManager.DEFAULT, null&#41;;
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager&#40;repos&#41;;
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection&#40;workspaceHandle, null&#41;;
IAuditableHandle compOwner = workspaceConnection.getOwner&#40;&#41;;

the getOwner() returns an IContributorHandle(not ITeamAreaHandle), so I still can't get the project area...

permanent link
Nick Edgar (6.5k711) | answered Sep 10 '09, 9:07 a.m.
Yes, that's possible. But note that users may change their current flow target to some other stream than their main development stream (for example, someone in the release engineer role delivering changes to a weekly integration stream). Also, the current flow target may be another workspace, not a stream, or it may have no flow targets.

permanent link
yaoben lu (56181) | answered Sep 09 '09, 11:10 p.m.
The owner of a component wasn't necessarily the workspace in any case in 1.0 (e.g. it could have been the stream, or some other workspace).

ISharingDescriptor has:
public IContextHandle getConnectionHandle()
the result of which can be cast down to IWorkspaceHandle.

IBaselineHandle also extends IContextHandle, but we don't currently allow loading directly from a baseline or baseline set (aka snapshot).

This still doesn't give you the project area though. Workspaces aren't necessarily tied to a particular project area -- they're owned by individuals, and may load components from various streams. Streams are typically scoped to a project or team area, though. A workspace may flow to/from multiple streams, though, possibly in different project areas. A workspace may also have no flow targets.

It would help to know more about what you're trying to do.

Nick Edgar
RTC Build component lead

What i am trying to do is to relate a source code file to a work item, just like the Jazz check-in &amp; deliver. First of all, I am trying to get the file's related project area, so I can create work item in this area.
Can the IFile--IShareable--IWorkspace--Stream--IProjcetArea be a possible solution?
Best regards!

Your answer

Register or to post your answer.