Search This Blog

Tuesday, October 9

Creation of a Custom Navigation Connector in SAP Enterprise Portal

A default navigation connector called a Roles connector is supplied with the SAP Enterprise portal. This navigation connector retrieves navigation nodes based on the roles that are assigned to the user. These navigation nodes are then visible in navigation iviews. It is possible to create a custom navigation connector. Using custom navigation connector, you can retrieve and display navigation nodes as per custom requirements. So in addition to the nodes which are retrieved by roles connector, more navigation nodes can be retrieved for the logged in user using a custom navigation connector. There are 3 steps to create a custom navigation connector. A navigation connector is packaged in a portal application (PAR file).

·         Create Navigation connector node
·         Create navigation connector
·         Register Navigation connector

Create Navigation Connector Node
Create a class that extends AbstractNavigationConnectorNode. Each object of this class is a Navigation node. There is a method called listBindings() in this class. Implement this method. This method returns javax.naming.NamingEnumeration of nodes related to the current node. Nodes or set of nodes that can be available for the current node are Children of the current node, first child of the current node, dynamic navigation iviews for the current node, drag and relate targets of the current node etc.  So listBinding() method should be implemented in to return relevant set of nodes. An example implementation is shown below

1.  public NamingEnumeration listBindings(String binding, String mode,
2.                Hashtable filterParameters)
3.                        throws NamingException {
5.      if (mode.equals(NAVIGATION_GET_CHILDREN))
6.          return new NavigationEnum(childrenBindings);
7.      if (mode.equals(NAVIGATION_GET_RELATED_SEE_ALSO))
8.          return new NavigationEnum(SeeAlsoNodeBindings);
9.      if (mode.equals(NAVIGATION_GET_RELATED_DR_TARGETS))
10.        return new NavigationEnum(TargetNodeBindings);
11.    if (mode.equals(NAVIGATION_GET_FIRST_CHILD)){
12.        return new NavigationEnum(
13.            Collections.singletonList(childrenBindings.get(0)));
14.    }
15.    else
17.throw new NamingException("Unknown mode named "+mode);

Create navigation connector
Create a class that extends AbstractNavigationConnector. Methods available in this class aregetInitialNodes(),getNode()getNodes()getNodeByQuickLink(),getConnectorCacheDiscriminators()These methods need to be implemented.
Example of getInitialNodes() implementation is given below
1.  public NamingEnumeration getInitialNodes(Hashtable environment) {
2.      if (isUserInJavaDeveloperRole(environment))
3.          return new NavigationEnum(initialNodes);
4.      else
5.          return NavigationEnum.EMPTY_ENUM;
6.  }
getNode() returns a InavigationConnectorNode. getNodes() returns a javax.naming.NamingEnumeration of INavigationConnectorNode objects.
Example of getNodes() implementation is shown below
1.  public NamingEnumeration getNodes(
2.              Hashtable environment, Vector connectorNodeURLs) {
3.      myConnectorNode node;
5.      int size = connectorNodeURLs.size();
6.      List nodeBindings = new ArrayList(size);
8.      for (int i = 0; i < size; i++) {
9.          node = (myConnectorNode) getNode(
10.                        environment, (String) connectorNodeURLs.get(i));
11.        if (node != null) nodeBindings.add(
12.                        new Binding(node.getName(), node));
13.    }
15.    return new NavigationEnum(nodeBindings);

Register Navigation connector
Create a portal service which implements IService. In the Init() method of the service, create an instance of INavigationConnector class.
1.  public void init(IServiceContext serviceContext) {
2.      mm_serviceContext = serviceContext;
3.      myConnector = new myConnector();
4.  }

Register the navigation connector in the afterInit() method of the connector.
1.  public void afterInit() {
2.      INavigationConnectorRegistration service =
3.          (INavigationConnectorRegistration)
4.              getContext().getService(INavigationService.KEY);
5.      if (service != null) {
6.          service.registerConnector(
7.              NAV_FILE_CONNECTOR_PREFIX, myConnector);
8.      }
9.  }