Login Name,User Name,Email,Role
orna.rabinovitz,Orna Rabinovitz,orna.rabinovitz@rci.rogers.com,STManager
madhava.reddy,Madhava Reddy,madhava.reddy@rci.rogers.com,STTester
nikhil.srivastava,Nikhil Srivastava,nikhil.srivastava@rci.rogers.com,STTester
These 3 Roles in this sample, being STManager, STLead and STTester, are already exist in CQ. The following Perl script will create a new user in CQ and set their:
- UserID and Password (empty)
- Full Name and Email Address
- LDAP enabled.
- Group
#!/usr/local/pure/releases/ClearQuestClient.2001.03.00/sun5/bin/cqperl
use Text::CSV;
$csv = Text::CSV->new();
open (AMDOCSUserInfo, "< C:\\Rogers2009\\ExportImport\\amdocs-users-cq.csv");
use CQPerlExt;
- Create a Rational ClearQuest admin session
- Logon as admin
- Get the database object
die "Unable to get database!\n" unless $dbObj;
#Get the group "STManager" object
$groupSTManager = $adminSession->GetGroup( "STManager" );
$groupSTManagerName = $groupSTManager->GetName();
print ("STManager:$groupSTManagerName\n");
#Get the group "STLead" object
$groupSTLead = $adminSession->GetGroup( "STLead" );
#Get the group "STTester" object
$groupSTTester = $adminSession->GetGroup( "STTester" );
$n = 0;
while (
#discard the first line of Request file
if ($n == 0) { $n++; next; }
my ($line) = $_;
chomp($line);
print "$line\n";
$status = $csv->parse($line); # parse a CSV string into fields
@columns = $csv->fields(); # get the parsed fields
# Login Name,User Name,Email,Role
$loginName = $columns[0];
$userName = $columns[1];
$emailAddress = $columns[2];
$roleName = $columns[3];
print ("$columns[0];$columns[1];$columns[2];$columns[3];\n");
eval {
# Create the user object
$newUserObj = $adminSession->CreateUser( $loginName );
die "Unable to create the user!\n" unless $newUserObj;
};
if ($@ =~ /is already in use/) {
next;
}
# Set the new user's password to secret
$newUserObj->SetPassword("");
$newUserObj->SetFullName($userName);
$newUserObj->SetEmail($emailAddress);
# $newUserObj->SetLDAPAuthentication($userName);
$newUserObj->SubscribeDatabase($dbObj);
# Add user to Group
#$groupSTTester->AddUser($newUserObj);
if ($roleName eq "STManager"){
$groupSTManager->AddUser($newUserObj);
}
elsif ($roleName eq "STLead"){
$groupSTLead->AddUser($newUserObj);
}
elsif ($roleName eq "STTester"){
$groupSTTester->AddUser($newUserObj);
}
}
- All done.