Skip to main content

Remove Reviewer from a Principal

The following code sample illustrates how to remove a review from a principal.


Code Sample

See the C++ environment settings for details on setting the project environment.


<cpp_admin_principal_reviewer_remove.cpp>
/*****************************************************************************************
*
* cpp_admin_principal_reviewer_remove.cpp
*
*
******************************************************************************************/

#include<string>
#include<iostream>
#include "teagent.h"
#include "teconnection.h"
#include "teexception.h"
#include "teauthuserctx.h"
#include "teauthwinctx.h"
#include "teobject.h"
#include "teadmin.h"
#include "tewinprincipal.h"
#include "teldapprincipal.h"
#include "teadmin_acl.h"
#include "teacl_template.h"

using namespace ERUCES;
using namespace std;

int main()
{
string strServer = "localhost";
long nPort = 8888;
string strAdminUser = "admin";
string strAdminPswd = "password1A";

try
{
// Connect to server
auto_ptr<TEConnection> conn = TEConnection::createInstance(TEConnection::SecureConnection);
conn->open(strServer, nPort, strAdminUser, strAdminPswd);
cout << "Connected to " << strServer << " as " << strAdminUser << endl << endl;

TEAdmin admin;
admin.attachConnection(conn.operator->());

// Get the principalID to be removed.
TEUserAndPasswordInfo user2;
user2.setUserName("testuser2");
admin.getPrincipal(user2, user2);
int id2Remove = user2.getPrincipalId();

TEUserAndPasswordInfo user;
user.setUserName("testuser");
admin.getPrincipal(user, user);

cout << "User ID = " << user.getPrincipalId() << endl;
cout << "User Name = " << user.getUserName() << endl << endl;

// List reviewer IDs and pick up the principalID to be removed.
TEObjectContainer cont;
user.getReviewerIds(cont);
cout << "Before removing a review, number of reviewers = " << cont.size() << endl;
int i;
bool isFound = false;
for (i=0; i < cont.size(); ++i)
{
int principalID = ((TEUInt32*)cont[i])->getValue();
if (principalID == id2Remove) {
isFound = true;
}
cout << "\tReviewer's principalId: " << principalID << endl;
}

if(!isFound) {
cout << "The required reviewer is not in the list." << endl;
goto FailureExit;
}

// Remove reviewer
user.removeReviewer(id2Remove);
admin.updatePrincipal(user); // Update principal in the server.
cout << "Review was removed from the principal." << endl;

// List reviewer IDs after removing a review
admin.getPrincipal(user, user);
user.getReviewerIds(cont);
cout << endl;
cout << "After removing a review, number of reviewers = " << cont.size() << endl;
for (i=0; i < cont.size(); ++i)
{
int principalID = ((TEUInt32*)cont[i])->getValue();
cout << "\tReviewer's principalId: " << principalID << endl;
}

FailureExit:

admin.detachConnection();

// Disconnect from server
conn->close();
cout << endl << "Disconnected from " << strServer << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages().c_str() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}
Output
Connected to localhost as admin

User ID = 3004
User Name = testuser

Before removing a review, number of reviewers = 1
Reviewer's principalId: 3007
Review was removed from the principal.

After removing a review, number of reviewers = 0

Disconnected from localhost
Press any key to continue