It's all about the answers!

Ask a question

How to get a component by component and a projectArea in plain java api


silencehill wu (5022632) | asked Aug 26 '13, 5:39 a.m.

I am writing using plain java to find a component.

I only have a project area name and a component name as argument.

How shoud I write api to get the component or component list.

4 answers



permanent link
sam detweiler (12.5k6195201) | answered May 12 '16, 7:53 a.m.
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);

permanent link
Hakki Bozkurt (1631228) | answered May 12 '16, 5:20 a.m.
edited May 12 '16, 6:22 a.m.
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?

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());
}
}

Comments
1
Ralph Schoon commented May 13 '16, 3:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I think you can add such search criteria, there are likely examples in the SDK. I have no examples.


permanent link
Ralph Schoon (63.1k33646) | answered Sep 02 '13, 2:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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);


permanent link
Tim Mok (6.6k38) | answered Aug 26 '13, 10:30 a.m.
JAZZ DEVELOPER
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
silencehill wu commented Aug 26 '13, 11:30 a.m.

I think the answer can not resolve my problem.

At first, the findComponents has a argument named owner, but in my request, I only know the component is in a stream of my project area, but the project area maybe not the owner of the component, maybe the owner of component is a team area of project area. So if I pass project area as argument, the component will not be found out.




Tim Mok commented Aug 26 '13, 11:42 a.m.
JAZZ DEVELOPER

You don't have to give it a project area and if you don't know the owner then that's the best you can do with the query conditions.


silencehill wu commented Aug 26 '13, 8:45 p.m.

The project area is not the owner of this component, but it is under this project area.

From view of RTC client, I can see the component in a stream of this project area. So I really need get the component under this project area. If I don't pass project area, how can I avoid this api get the component with same name in another project area.


Geoffrey Clemm commented Aug 26 '13, 10:26 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A component has a global name ... it does not have different names depending on where it is used.   Any component can be added to any stream (if the user has read access to the component, and write access to the stream).   There is no concept in RTC of a component being "under" a project area.   A component can be owned by a (single) project area, and it can be used by an arbitrary number of streams or workspaces.


silencehill wu commented Aug 26 '13, 11:24 p.m.

I got the component concept. 

But why the component can be display in a stream of a project area?

Dose project Area really unuseful in API to find a component unless project area is owner of component?


1
Tim Mok commented Aug 27 '13, 8:44 a.m.
JAZZ DEVELOPER

The component shows in the stream because it is in that configuration. The project area owns the stream (or one of the project area's teams owns it) so it shows there. If you are looking at the "Components" node under a project area then that means the project area or one of its teams owns the component.

If the project area is the owner then you can specify that in the #findComponents(*) call. It sounds like you're thinking of the stream's owner, which isn't useful for finding your component. It would be better to find the stream and then find the component in it. However at this point, it seems like you want the component's configuration and not the component handle itself.


silencehill wu commented Sep 01 '13, 12:29 p.m.

So I have to get the stream, and then loop components in a streams,  Do you have any idea to get the component in a stream by one api?


Tim Mok commented Sep 03 '13, 8:31 a.m.
JAZZ DEVELOPER

IWorkspaceConnection#getComponents() returns a list of IComponentHandle. You may want to mention your overall goal. The component handle at this point isn't particularly significant because you could have retrieved it with the component search mentioned above. The component handle itself isn't going to provide any specific information about existing in the stream. You likely would want the component's configuration to get anything significant.

showing 5 of 8 show 3 more comments

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.