Creating OBN Links
The OBN service
helps you create a user interface for displaying valid OBN links for the
current user. When a link is selected, a WD action can be triggered to perform
the OBN navigation by calling WDPortalNavigation.navigateToObject(), as described in Navigating with
OBN.
To obtain a
reference to the service, whose interface is IUserLocaleOBN, add the following Web Dynpro sharing
reference:
PORTAL:sap.com/com.sap.portal.unification.objectbasednavigationservice
For more
information about calling portal services, see Calling Portal
Services.
Tasks
The OBN service
enables you find out which operations for a specific business object, if any,
are valid for the current user, or whether there are any valid navigation
targets for a specific business object, operation and user.
Checking a Business
Object
The following shows
how to check if a specific user has permission to any of the operations of a
specific business object:
// Get a reference to the OBN service
IUserObjectBasedNavigation obnService =(IUserObjectBasedNavigation)
WDPortalUtils.getServiceReference(IUserObjectBasedNavigation.KEY);
// Get the current user
IUser user = null;
try {
user = WDClientUser.getCurrentUser().getSAPUser();
} catch (WDUMException e) {
wdComponentAPI.getMessageManager().reportException(
"Failed to get current user: " + e.getLocalizedMessage(), true);
}
// Define the system and the business object
String system = "MySystem";
String bo = "customer";
// Call the service
boolean hasValidDefaultOperation = obn.isTargetExist(system, bo, user);
|
Use this function
to check whether to offer a specific operation OBN link to the current
user.
Checking an Operation
The following shows
how to check if a specific user has permission to any navigation targets
assigned to a specific operation of a specific business object:
// Get a reference to the OBN service
IUserObjectBasedNavigation obnService =(IUserObjectBasedNavigation)
WDPortalUtils.getServiceReference(IUserObjectBasedNavigation.KEY);
// Get the current user
IUser user = null;
try {
user = WDClientUser.getCurrentUser().getSAPUser();
} catch (WDUMException e) {
wdComponentAPI.getMessageManager().reportException(
"Failed to get current user: " + e.getLocalizedMessage(), true);
}
// Define the system, the business object and the operation
String system = "MySystem";
String bo = "customer";
String operation "Display";
// Call the service
boolean operationHasValidTarget =
isTargetExistsForOperation(system, bo, operation, user);
|
Getting a List of Valid Operations
The following shows
how to get the valid operations for the current user:
// Get a reference to the OBN service
IUserObjectBasedNavigation obnService = (IUserObjectBasedNavigation)
WDPortalUtils.getServiceReference(IUserObjectBasedNavigation.KEY);
// Get the current user
IUser user = null;
try {
user = WDClientUser.getCurrentUser().getSAPUser();
} catch (WDUMException e) {
wdComponentAPI.getMessageManager().reportException(
"Failed to get current user: " + e.getLocalizedMessage(), true);
}
// Define the system and the business object
String system = "MySystem";
String bo = "customer";
// Get the list of valid operations
List operations = obn.getTargets(system, bo, user);
// Fill
a context node with the operation information
dynamically.
// The list can be displayed in a DropDownByIndex control.
IMyTestView.IOperationsElement newOperation = null;
for (Iterator iter = operations.iterator(); iter.hasNext();) {
IOBNTarget target = (IOBNTarget) iter.next();
newOperation = wdContext.nodeOperations().createOperationsElement();
newOperation.setCaption(target.getOperationFriendlyName());
newOperation.setName(target.getOperationName());
wdContext.nodeOperations().addElement(newOperation);
}
|