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
Nick Edgar (6.5k711) | answered Sep 09 '09, 3:19 p.m.
JAZZ DEVELOPER
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.

Regards,
Nick Edgar
RTC Build component lead

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.

Regards,
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 & 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!

permanent link
Nick Edgar (6.5k711) | answered Sep 10 '09, 9:07 a.m.
JAZZ DEVELOPER
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 14 '09, 6:11 a.m.
I have tried this way.

IWorkspaceHandle workspaceHandle = (IWorkspaceHandle)shareDesc.getConnectionHandle();

ITeamRepository repos = getTeamRepository(shareDesc);
IItemManager im = repos.itemManager();

IWorkspace workspace = (IWorkspace) im.fetchCompleteItem(workspaceHandle, IItemManager.DEFAULT, null);
IWorkspaceManager workspaceManager = SCMPlatform.getWorkspaceManager(repos);
IWorkspaceConnection workspaceConnection = workspaceManager.getWorkspaceConnection(workspaceHandle, null);
IAuditableHandle compOwner = workspaceConnection.getOwner();


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

permanent link
Michele Pegoraro (1.8k14119103) | 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->getProjectArea().

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

permanent link
Nick Edgar (6.5k711) | answered Sep 14 '09, 12:54 p.m.
JAZZ DEVELOPER
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.
Try:

IFlowEntry currentFlowEntry = workspaceConnection.getFlowTable().getCurrentDeliverFlow();
if (currentFlowEntry != null) {
IWorkspaceHandle targetHandle = (IWorkspaceHandle) currentFlowEntry.getFlowNode();
IWorkspaceConnection targetConnection = workspaceManager.getWorkspaceConnection(targetHandle, null);
if (targetConnection.isStream()) {
IAuditableHandle ownerHandle = workspaceConnection.getOwner();
...
}
}


Regards,
Nick Edgar
RTC Build component lead

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(workspaceHandle, null);

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

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
Nick Edgar (6.5k711) | answered Sep 15 '09, 9:33 a.m.
JAZZ DEVELOPER
Ah, sorry about the confusion. You're right, it should be targetConnection.getOwner().

permanent link
SEC Servizi (97123860) | 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("com.ibm.team.filesystem.workitems.change_set").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.

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.