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

Get the owner and visibility of Component through API

Hi, I want to get the owner and visibility of Component through API.

There is a api for setting the owner and visibility for Component like below.

workspaceManager.setComponentOwnerAndVisibility(IComponentHandle ch, IAuditableHandle ah, IReadScope pscope, monitor);

But there is no API for querying.

I've found there is a class ComponentOwner  and ComponentOwnerQueryModel in com.ibm.team.scm.common.internal.ComponentOwner.

I tried like below.

ComponentOwnerQueryModel componentOwnerQueryModel = ComponentOwnerQueryModel.ROOT;

// create a query for ComponentOwner
IItemQuery query = IItemQuery.FACTORY
.newInstance(componentOwnerQueryModel);
;
// allocate space for the parameter
IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[] { query
.newItemHandleArg() };
// the query filter
IPredicate filter = ((ComponentOwnerQueryModel) componentOwnerQueryModel)
.component()._in(itemHandleArgs);

// 1 parameter required
IItemQueryPage queryPage = RTCService
.iTeamBuildClient().queryItems(query,
new Object[] { iComponent },
IQueryService.ITEM_QUERY_MAX_PAGE_SIZE,
null);

if (queryPage.getResultSize() == 1) {
ComponentOwner componentOwner = (ComponentOwner) RTCService
.itemManager().fetchCompleteItem(
(ComponentOwnerHandle) queryPage
.getItemHandles().get(0),
IItemManager.DEFAULT, null);
System.out.println(componentOwner.getOwner()
.toString());
}
}

But I got an error message: com.ibm.team.repository.common.PermissionDeniedException: Remote queries are not allowed for the application-managed item type "com.ibm.team.scm#ComponentOwner"

how can i get this object?

Thanks!


1 vote


Accepted answer

Permanent link
You should use the repo service com.ibm.team.scm.common.IScmService:
IScmService scmService = ...
IRepositoryItemService itemService = ...
IComponentHandle componentH = ...
ComponentOwnerHandle componentOwnerH = scmService.getComponentOwnerRecord((ComponentHandle) componentH);
ComponentOwner componentOwner = (ComponentOwner) itemService.fetchItem(componentOwnerH, IRepositoryItemService.COMPLETE);
IAuditableHandle ownerH = componentOwner.getOwner();
Cheers.
Yung-Hsiang Chan selected this answer as the correct answer

2 votes


One other answer

Permanent link
 I then found another way to do this.

List<IAuditableHandle> iAuditableHandles = RTCService.workspaceManager().findOwnersForComponents(components, null);
But I am not sure that the order of this list whether is equal to the list returned by getComponents().

Maybe the above solutions is better. 
Thanks!

1 vote

Comments

According to com.ibm.team.scm.service.internal.query.ScmQueryService#findComponentOwners, used as implementor for com.ibm.team.scm.client.IWorkspaceManager#findOwnersForComponents, the owners list will get the same order of the components list.

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,938
× 19

Question asked: Nov 20 '14, 12:13 a.m.

Question was seen: 4,834 times

Last updated: Nov 20 '14, 11:00 a.m.

Confirmation Cancel Confirm