It's all about the answers!

Ask a question

How to find a workspace by name


Pietro Bottino (35614) | asked Apr 18 '16, 4:36 p.m.
Hello,

I need a help. I found several examples, but only for "client-side".

My advisor is "server-side" and I need to find a workspace by name. I'll set the UUDI in a build definition property on the request.

Already tried to use "IRepositoryItemService", "IScmService", but I don't found a "findWorkspacesByName" method.

Can anybody help me?


Comments
Donald Nong commented Apr 18 '16, 11:42 p.m.

Are you referring a "repository workspace"?


Ralph Schoon commented Apr 19 '16, 2:58 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

In https://rsjazz.wordpress.com/2013/09/24/managing-workspaces-streams-and-components-using-the-plain-java-client-libraries/ I use the workspace manager and findWorkspaces(). Not sure if this is available in the server API.


Pietro Bottino commented Apr 19 '16, 8:01 a.m.

Thanks Donald and Ralph.

Donald,
yes, I refer to the "repository workspace".

Ralph,
I already read this article, but in the server API I don't found a "workspace manager".

Accepted answer


permanent link
Michele Pegoraro (1.8k14118103) | answered Apr 19 '16, 4:42 a.m.
Hi, on server side you need to use the IScmQueryService.findWorkspaces method using a IWorkspaceSearchCriteria.

In the IWorkspaceSearchCriteria you can set the type of the workspace (IWorkspaceSearchCriteria.STREAMS or WORKSPACE or ALL), the name (exact or partial) and the owner.

You can obtain a IWorkspaceSearchCriteria object using its own factory.

Michele.
Pietro Bottino selected this answer as the correct answer

Comments
Pietro Bottino commented Apr 19 '16, 8:57 a.m. | edited Apr 19 '16, 10:31 a.m.

Thanks by answer Michele.

Currently I'm trying to use the IWorkspaceSearchCriteria, but I don't know how to execute the "search". In the client API has a "findWorkspaces" and in the server API I don't found a similar method.


Pietro Bottino commented Apr 19 '16, 9:38 a.m.

I used the IScmQueryService and worked.

I'll post the code.

One other answer



permanent link
Pietro Bottino (35614) | answered Apr 19 '16, 9:41 a.m.
edited Apr 19 '16, 9:44 a.m.
I resolved this question.

Below is the used code:

private UUID getWorkspaceUUIDFromName(String workspaceName) throws TeamRepositoryException {
	
                
	
        IWorkspaceSearchCriteria search = IWorkspaceSearchCriteria.FACTORY.newInstance();
	
        search.setExactName(workspaceName);        
	
        
	
        IScmQueryService service = getService(IScmQueryService.class);
	
        ItemQueryResult foundWorkspace = service.findWorkspaces(search, 10, null);
	
        
	
        if (foundWorkspace != null) {
	
            IWorkspaceHandle workspaceHandle = (IWorkspaceHandle) foundWorkspace.getItemHandles().get(0);
	
            return workspaceHandle.getItemId();
	
        }
	
        
	
        return null;
	
    }
	

Your answer


Register or 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.