List available user databases
About this task
The following example uses the CqProvider.doGeDbSetList() method to obtain a list of all the Rational ClearQuest database sets known to the provider. (A database set is sometimes called a configuration or a schema repository.) By accessing each of those database sets, a complete list of databases accessible to the user is obtained.
In this example, each user database is identified by a combination of its database set name (CqDbSet.DISPLAY_NAME) and its user database name (CqUserDb.DISPLAY_NAME). This is the canonical way to identify a user database in the Rational ClearQuest CM API. The complete location syntax for a user database is cq.userdb:<db-set>/<user-db>.
public static void main(String[] args) throws Exception
{
try {
CqProvider provider = Utilities.getProvider().cqProvider();
System.out.println("CM API Library...\n"
+ provider.stpProductInfo(null));
System.out.println("ClearQuest Adaptor...\n"
+ provider.stpProductInfo(Domain.CLEAR_QUEST));
// Iterate over the database sets known to the provider
for (CqDbSet set : provider.doGetDbSetList(DB_PROPS)) {
// Skip database set if user doesn't have access
if (set.getResourceError() != null)
continue;
// Identify the user databases to which the user is subscribed
for (CqUserDb userDb: set.getCurrentUser().getSubscribedDatabases()) {
CqProductInfo info = (CqProductInfo)userDb.getProductInfo();
System.out.println (userDb.getUserFriendlyLocation().getRepo()
+ ": " + info.getFullProductVersion() +
" (" + info.getStageLabel()+ ", OMREV "
+ (info.getObjectModelVersionMajor()*100
+ info.getObjectModelVersionMinor()) + ")");
}
}
} catch(Throwable ex) {
ex.printStackTrace();
} finally {
System.exit(0); // to terminate Swing threads
}
}
/** Properties to be displayed for subscribed user databases */
static final PropertyRequest DB_PROPS =
new PropertyRequest(CqDbSet.CURRENT_USER
.nest(CqUser.SUBSCRIBED_DATABASES
.nest(CqUserDb.USER_FRIENDLY_LOCATION,
CqUserDb.PRODUCT_INFO)));
}
static ResourceList<CqUserDb> getUserDbList(CqProvider provider,
PropertyRequest feedback)
throws WvcmException
{
PropertyRequest wantedProps =
new PropertyRequest(CqDbSet.CURRENT_USER
.nest(CqUser.SUBSCRIBED_DATABASES.nest(feedback)));
ResourceList<CqUserDb> result = provider.resourceList();
for (CqDbSet set : provider.doGetDbSetList(wantedProps)) {
if (set.getResourceError() == null)
result.addAll(set.getCurrentUser().getSubscribedDatabases());
}
return result;
}
The only interaction with the Rational ClearQuest application occurs during the invocation of the CqProvider.doGetDbSetList method at the start of the outer loop. The DB_PROPS nested property request used in that invocation forces Rational ClearQuest to log the user into each database set it knows about and obtain from that database set a list of the user databases to which that user is subscribed.
As this method executes, the Callback object given to the provider will be invoked for each database set to obtain the user identity and password for that database set. If the user cannot provide the proper credentials for a given database set, the failed-login exception is stored in the resource-error field of the returned proxy. A non-null value in this field is the standard way to inform the client that a resource in a list of resources could not be accessed to satisfy a property request.
Results
Lesson checkpoint
- How to use Rational ClearQuest CM API to get accessible user databases.
- About CqUserDb objects.