How to get a component by component and a projectArea in plain java api
4 answers
IWorkspaceManager#
findComponents(java.lang.String namePattern,
IAuditableHandle owner,
boolean exact,
org.eclipse.core.runtime.IProgressMonitor progressMonitor)
throws TeamRepositoryException
You can use the #findComponents(*) call to get a list of components matching your conditions. IProcessClientService and IProcessItemService both have ways to get an item handle for your project area but it's easier to get a handle if you are working with item IDs.
Comments
1 vote
showing 5 of 8
show 3 more comments
You again use the Workspacemanager to find all streams:
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY
.newInstance().setKind(IWorkspaceSearchCriteria.STREAMS);
List<IWorkspaceHandle> streams = wm.findWorkspaces(criteria, Integer.MAX_VALUE,
monitor);
IWorkspaceManager wm = SCMPlatform.getWorkspaceManager(teamRepository);
IWorkspaceSearchCriteria criteria = IWorkspaceSearchCriteria.FACTORY
.newInstance().setKind(IWorkspaceSearchCriteria.STREAMS);
List<IWorkspaceHandle> streams = wm.findWorkspaces(criteria, Integer.MAX_VALUE,
monitor);
Hi Ralph,
Can I add search criteria like owner is my project area or my project area's team areas. My code is here I get all streams and than fetch it all search owner one by one. Is there a easy way to be?
Can I add search criteria like owner is my project area or my project area's team areas. My code is here I get all streams and than fetch it all search owner one by one. Is there a easy way to be?
IWorkspaceSearchCriteria wsSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
wsSearchCriteria.setKind(IWorkspaceSearchCriteria.STREAMS);
List<IWorkspaceHandle> streamHandleList = wm.findWorkspaces(wsSearchCriteria, Integer.MAX_VALUE, monitor);
for(int i=0; i<streamHandleList.size(); i++)
{
IWorkspace stream = (IWorkspace) repo.itemManager().fetchCompleteItem(streamHandleList.get(i), IItemManager.DEFAULT, monitor);
IAuditableHandle ownerItem = stream.getOwner();
if(ownerItem instanceof IProjectAreaHandle)
{
IProjectAreaHandle pah = (IProjectAreaHandle) ownerItem;
IProjectArea pa = (IProjectArea) repo.itemManager().fetchCompleteItem(pah, IItemManager.DEFAULT, monitor);
if(pa == jazzUtil.getProjectArea())
{
streamNameList.add(stream.getName());
}
}
else if(ownerItem instanceof ITeamAreaHandle)
{
ITeamAreaHandle tah = (ITeamAreaHandle) ownerItem;
ITeamArea ta = (ITeamArea) repo.itemManager().fetchCompleteItem(tah, IItemManager.DEFAULT, monitor);
IProjectAreaHandle pah = ta.getProjectArea();
IProjectArea pa = (IProjectArea) repo.itemManager().fetchCompleteItem(pah, IItemManager.DEFAULT, monitor);
if(pa == jazzUtil.getProjectArea())
{
streamNameList.add(stream.getName());
}
}
I have a utility to copy a project to another server. it does streams and workspaces, and can select workspaces for specific users (src= source system, dest = destination system)
here is the code to find workspaces for the non-archived users in a spacified list (by email address)
IContributor srcwkspace_owner = (IContributor) srcauditableClient.fetchCurrentAuditable(srcowner, ItemProfile.createProfile(IContributor.ITEM_TYPE, new String[] {
IContributor.ARCHIVED_PROPERTY,
IContributor.NAME_PROPERTY,
IContributor.EMAIL_ADDRESS_PROPERTY }), null);
// only for non-archived users
if (!srcwkspace_owner.isArchived())
{
// if no selection list (everyone), or the user is in the selection list (the select few)
// copy their workspaces
if (userworkspaces.isEmpty()
|| userworkspaces.get(srcwkspace_owner.getEmailAddress().toLowerCase()) != null)
{
IWorkspaceSearchCriteria workspacesearchcriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
// say we want workspaces
workspacesearchcriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES);
// for THIS user
workspacesearchcriteria.setExactOwnerName(srcwkspace_owner.getName());
// get the list
List<IWorkspaceHandle> user_workspacehandles = (List<IWorkspaceHandle>) srcmgr.findWorkspaces(workspacesearchcriteria, IWorkspaceManager.MAX_QUERY_SIZE, null);
here is the code to find workspaces for the non-archived users in a spacified list (by email address)
IContributor srcwkspace_owner = (IContributor) srcauditableClient.fetchCurrentAuditable(srcowner, ItemProfile.createProfile(IContributor.ITEM_TYPE, new String[] {
IContributor.ARCHIVED_PROPERTY,
IContributor.NAME_PROPERTY,
IContributor.EMAIL_ADDRESS_PROPERTY }), null);
// only for non-archived users
if (!srcwkspace_owner.isArchived())
{
// if no selection list (everyone), or the user is in the selection list (the select few)
// copy their workspaces
if (userworkspaces.isEmpty()
|| userworkspaces.get(srcwkspace_owner.getEmailAddress().toLowerCase()) != null)
{
IWorkspaceSearchCriteria workspacesearchcriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
// say we want workspaces
workspacesearchcriteria.setKind(IWorkspaceSearchCriteria.WORKSPACES);
// for THIS user
workspacesearchcriteria.setExactOwnerName(srcwkspace_owner.getName());
// get the list
List<IWorkspaceHandle> user_workspacehandles = (List<IWorkspaceHandle>) srcmgr.findWorkspaces(workspacesearchcriteria, IWorkspaceManager.MAX_QUERY_SIZE, null);