Finding A Process Area Using its Name


There is a question on Jazz.net right now about how to fins a RTC team area by its name. I happened to have the code on my disk, so I think its worth showing it here.

License

The post contains published code, so our lawyers reminded me to state that the code in this post is derived from examples from Jazz.net as well as the RTC SDK. The usage of code from that example source code is governed by this license. Therefore this code is governed by this license. I found a section relevant to source code at the and of the license. Please also remember, as stated in the disclaimer, that this code comes with the usual lack of promise or guarantee. Enjoy!

Just Starting With Extending RTC?

If you just get started with extending Rational Team Concert, or create API based automation, start with the post Learning To Fly: Getting Started with the RTC Java API’s and follow the linked resources.

You should be able to use the following code in this environment and get your own automation or extension working.

How the Code Works

The code in this post is client API.

The code below accepts a string as input parameter. It then converts it into an URI that is used to find the element. See the documentation for how the URI path segment should look like:

	/**
	 * Returns the process area for the given URI. URIs have been chosen for
	 * future extensibility. Currently only hierarchical URIs are supported.
	 * Only the path segment of the hierarchical URI is considered. The first
	 * segment should be the name of a project area, the following segments
	 * should be the names of team areas.
	 *

* The returned area is managed by the item manager. * * @param areaURI the URI * @param properties the list of required process area properties; use * ALL_PROPERTIES to retrieve a complete item. * @param monitor a progress monitor or null * @return the process area for the given URI or null * @throws TeamRepositoryException in case this operation fails * @throws org.eclipse.core.runtime.OperationCanceledException in case this * operation has been canceled * @LongOp This is a long operation; it may block indefinitely; must not be * called from a responsive thread. */ IProcessArea findProcessArea(URI areaURI, Collection properties, IProgressMonitor monitor) throws TeamRepositoryException;

The code below works for project areas. However, if you add the segments for the team area hierarchy, it also works for team areas. Here an example of how to create the URI.

       URI newTeamAreaURI = URI.create(projectAreaName + "/" + newTeamAreaName);

The utility code below does this for only the project area, but could be extended to team areas. It would be necessary to know the hierarchy, if searching in a team area hierarchy.

/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2014. All Rights Reserved. 
 *
 * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *******************************************************************************/
package com.ibm.js.team.api.tools.process;

import java.net.URI;

import com.ibm.js.team.api.tools.core.URIUtils;
import com.ibm.team.process.client.IProcessClientService;
import com.ibm.team.process.common.IProjectArea;
import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.common.TeamRepositoryException;

public class ProcessAreaUtil {

	public static IProjectArea findProjectArea(ITeamRepository repository,
			URI targetProjectAreaName) throws TeamRepositoryException {
		IProcessClientService processClient = (IProcessClientService) repository
				.getClientLibrary(IProcessClientService.class);
		IProjectArea projectArea = (IProjectArea) processClient
				.findProcessArea(targetProjectAreaName, null, null);
		return projectArea;
	}

	public static IProjectArea findProjectArea(ITeamRepository repository,
			String targetProjectAreaName) throws TeamRepositoryException {
		return findProjectArea(repository,
				URIUtils.getUriFromString(targetProjectAreaName));
	}
}

The tool URIUtils looks as below:

/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2012. All Rights Reserved. 
 *
 * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 *******************************************************************************/
package com.ibm.js.team.api.tools.core;

import java.net.URI;

public class URIUtils {
	public static URI getUriFromString(String name) {
		return URI.create(name.replaceAll(" ", "%20"));
	}

	public static String getStringFromUri(URI uri) {
		return uri.toString().replaceAll("%20", " ");
	}
}

Advertisements

About rsjazz

Hi, my name is Ralph. I work for IBM and help colleagues and customers with adopting the Jazz technologies.
This entry was posted in Jazz, RTC, RTC Automation, RTC Extensibility and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s