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!
Accepted answer
You should use the repo service com.ibm.team.scm.common.IScmService:
IScmService scmService = ...Cheers.
IRepositoryItemService itemService = ...
IComponentHandle componentH = ...
ComponentOwnerHandle componentOwnerH = scmService.getComponentOwnerRecord((ComponentHandle) componentH);
ComponentOwner componentOwner = (ComponentOwner) itemService.fetchItem(componentOwnerH, IRepositoryItemService.COMPLETE);
IAuditableHandle ownerH = componentOwner.getOwner();
One other answer
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!