Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

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.

0 votes



4 answers

Permanent link
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.

0 votes

Comments

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.



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.

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.

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.

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?

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.

1 vote

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?

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

Permanent link
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);

0 votes


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

0 votes

Comments

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

1 vote


Permanent link
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);

0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,952

Question asked: Aug 26 '13, 5:39 a.m.

Question was seen: 8,731 times

Last updated: May 13 '16, 3:18 a.m.

Confirmation Cancel Confirm