001 /*
002 * file FindDatabases.java
003 *
004 * Licensed Materials - Property of IBM
005 * Restricted Materials of IBM - you are allowed to copy, modify and
006 * redistribute this file as part of any program that interfaces with
007 * IBM Rational CM API.
008 *
009 * com.ibm.rational.stp.client.samples.FindDatabases
010 *
011 * (C) Copyright IBM Corporation 2005, 2008. All Rights Reserved.
012 * Note to U.S. Government Users Restricted Rights: Use, duplication or
013 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
014 */
015 package com.ibm.rational.stp.client.samples;
016
017 import javax.wvcm.ResourceList;
018 import javax.wvcm.PropertyRequestItem.PropertyRequest;
019
020 import com.ibm.rational.wvcm.stp.StpProvider.Domain;
021 import com.ibm.rational.wvcm.stp.cq.CqDbSet;
022 import com.ibm.rational.wvcm.stp.cq.CqProvider;
023 import com.ibm.rational.wvcm.stp.cq.CqUser;
024 import com.ibm.rational.wvcm.stp.cq.CqUserDb;
025 import com.ibm.rational.wvcm.stp.cq.CqProvider.CqProductInfo;
026
027 /**
028 * List the user databases visible in the current context
029 */
030 public class FindDatabases {
031
032 /**
033 * The main program, which instantiates a CM API provider and requests all
034 * known ClearQuest database sets and, for each the user databases to which
035 * the user is subscribed.
036 *
037 * @param args Specify a server URL here if databases on the server are to
038 * be included in the report (future feature).
039 * @throws Exception if no database can be contacted.
040 */
041 public static void main(String[] args) throws Exception
042 {
043 try {
044 CqProvider provider = Utilities.getProvider().cqProvider();
045
046 if (args.length > 0)
047 provider.setServerUrl(args[0]);
048
049 System.out.println("CM API Library...\n"
050 + provider.stpProductInfo(null));
051 System.out.println("ClearQuest Adaptor...\n"
052 + provider.stpProductInfo(Domain.CLEAR_QUEST));
053
054 // Iterate over the database sets known to the provider
055 for (CqDbSet set : provider.doGetDbSetList(DB_PROPS)) {
056 // Skip database set if user doesn't have access
057 if (set.getResourceError() != null)
058 continue;
059
060 // Identify the user databases to which the user is subscribed
061 for (CqUserDb userDb: set.getCurrentUser().getSubscribedDatabases()) {
062 CqProductInfo info = (CqProductInfo)userDb.getProductInfo();
063 System.out.println (userDb.getUserFriendlyLocation().getRepo()
064 + ": " + info.getFullProductVersion() +
065 " (" + info.getStageLabel()+ ", OMREV "
066 + (info.getObjectModelVersionMajor()*100
067 + info.getObjectModelVersionMinor()) + ")");
068 }
069 }
070 } catch(Throwable ex) {
071 ex.printStackTrace();
072 } finally {
073 System.exit(0);
074 }
075 }
076
077 /** Properties to be displayed for subscribed user databases */
078 static final PropertyRequest DB_PROPS =
079 new PropertyRequest(CqDbSet.CURRENT_USER
080 .nest(CqUser.SUBSCRIBED_DATABASES
081 .nest(CqUserDb.USER_FRIENDLY_LOCATION,
082 CqUserDb.PRODUCT_INFO)));
083 }