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

How to retrieve the project area of a java file?

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.

0 votes



11 answers

Permanent link
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

0 votes


Permanent link
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!

0 votes


Permanent link
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.

0 votes


Permanent link
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...

0 votes


Permanent link
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.

0 votes


Permanent link
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

0 votes


Permanent link
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...

0 votes


Permanent link
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~~

0 votes


Permanent link
Ah, sorry about the confusion. You're right, it should be targetConnection.getOwner().

0 votes


Permanent link
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.

0 votes

1–15 items
page 1of 1 pagesof 2 pages

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,926

Question asked: Aug 31 '09, 3:14 a.m.

Question was seen: 12,569 times

Last updated: Aug 29 '12, 6:32 a.m.

Confirmation Cancel Confirm