It's all about the answers!

Ask a question

Get the owner and visibility of Component through API


Yung-Hsiang Chan (34613) | asked Nov 20 '14, 12:13 a.m.
edited Nov 20 '14, 12:16 a.m.
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!


Accepted answer


permanent link
SEC Servizi (94622545) | answered Nov 20 '14, 4:02 a.m.
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

One other answer



permanent link
Yung-Hsiang Chan (34613) | answered Nov 20 '14, 4:14 a.m.
edited Nov 20 '14, 4:15 a.m.
 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!

Comments
SEC Servizi commented Nov 20 '14, 11:00 a.m.

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 to post your answer.