How to check components in a stream with Server side code
![](http://jazz.net/_images/myphoto/8b8f82855c75402bd970b3b8c6c11b26.jpg)
Hello,
I'm writing an operations advisor that validates an entered Component name on a work item save operation and checks it is associated with a given stream, but have come a bit unstuck with the validation part.
Is there a way using server side code to extract components associated with a specific stream.
The code so far looks like this:
// Check if POM location corresponds to a component name under the named stream
IComponentSearchCriteria compSearchCriteria = IComponentSearchCriteria.FACTORY.newInstance();
compSearchCriteria.setExactName(POMLocation);
ItemQueryResult result = query.findComponents(compSearchCriteria, 10, repomonitor);
List results = result.getItemHandles();
// If list is empty component name doesn't exist so fail
if (results.isEmpty())
{
System.out.println("No items pulled from POM Location check. Check POM location corresponds to a component in this project");
IAdvisorInfo problem5 = collector
.createProblemInfo("Component name/Build POM location entered not found, check it is valid and associated with project area "+
projectAreaName,"Item Number "+itemNumber,PROBLEM_TYPE);
collector.addInfo(problem5);
}
IWorkspaceHandle wshandle = (IWorkspaceHandle) handles.get(0);
ComponentEntry[] centries = service.getComponentEntries(wshandle, repomonitor);
....
I have a workspace handle and can get component entries from it, but how would I tie this in. I can already check that the component name entered is an actual component on RTC successfully, but need to check that the component is also found in the workspace referenced by my handle.
Is there anything I could add to ComponentSearchCriteria to do this.
Thanks for your help,
Kelly
I'm writing an operations advisor that validates an entered Component name on a work item save operation and checks it is associated with a given stream, but have come a bit unstuck with the validation part.
Is there a way using server side code to extract components associated with a specific stream.
The code so far looks like this:
// Check if POM location corresponds to a component name under the named stream
IComponentSearchCriteria compSearchCriteria = IComponentSearchCriteria.FACTORY.newInstance();
compSearchCriteria.setExactName(POMLocation);
ItemQueryResult result = query.findComponents(compSearchCriteria, 10, repomonitor);
List results = result.getItemHandles();
// If list is empty component name doesn't exist so fail
if (results.isEmpty())
{
System.out.println("No items pulled from POM Location check. Check POM location corresponds to a component in this project");
IAdvisorInfo problem5 = collector
.createProblemInfo("Component name/Build POM location entered not found, check it is valid and associated with project area "+
projectAreaName,"Item Number "+itemNumber,PROBLEM_TYPE);
collector.addInfo(problem5);
}
IWorkspaceHandle wshandle = (IWorkspaceHandle) handles.get(0);
ComponentEntry[] centries = service.getComponentEntries(wshandle, repomonitor);
....
I have a workspace handle and can get component entries from it, but how would I tie this in. I can already check that the component name entered is an actual component on RTC successfully, but need to check that the component is also found in the workspace referenced by my handle.
Is there anything I could add to ComponentSearchCriteria to do this.
Thanks for your help,
Kelly
2 answers
![](http://jazz.net/_images/myphoto/8b8f82855c75402bd970b3b8c6c11b26.jpg)
Is there a way using server side code to extract components associated with a specific stream./quote]
It would probably be easiest to iterate across the known components in the stream, rather than getting all components with a given name and checking to see if they're part of the stream you care about.
If' you'd like to go that route, take a look at IScmService#getComponentsForWorkspace().
![](http://jazz.net/_images/myphoto/8b8f82855c75402bd970b3b8c6c11b26.jpg)
Is there a way using server side code to extract components associated with a specific stream./quote]
It would probably be easiest to iterate across the known components in the stream, rather than getting all components with a given name and checking to see if they're part of the stream you care about.
If' you'd like to go that route, take a look at IScmService#getComponentsForWorkspace().
Thanks Evan. That's working much more efficiently now and I'm able to do the check. FYI, the code snippet is now:
// Check if POM location corresponds to a component name under the named stream
IWorkspaceHandle wshandle = (IWorkspaceHandle) handles.get(0);
IComponentHandle[] comphandles = service.getComponentsForWorkspace(wshandle, null);
// If no entries then workspace has no components so fail
if (comphandles.length < 1)
{
System.out.println("No components associated with Stream "+componentName);
IAdvisorInfo problem5 = collector
.createProblemInfo("No components associated with Stream "+componentName
,"Item Number "+itemNumber,PROBLEM_TYPE);
collector.addInfo(problem5);
}
IComponent component = null;
componentFound = false;
IRepositoryItemService itemService = getService(IRepositoryItemService.class);
for (int i = 0; i < comphandles.length; i++)
{
component = (IComponent) itemService.fetchItem(comphandles, IRepositoryItemService.COMPLETE);
if (component.getName().equals(POMLocation))
{
System.out.println("VALIDATESTREAMNAME: MATCHED component in stream to POM Location value "+POMLocation);
componentFound = true;
}
else
{
System.out.println("VALIDATESTREAMNAME: Found component "+component.getName());
}
}
Thanks again for your help