Skip to Content

EWS Modules run Portal Applications similar to standard Portal iViews. In Nir’s post you can get informed about how to integrate your existing portal applications or iViews as modules in the workspaces as is.

However you can also take advantage of the various EWS APIs to enhance your modules with additional capabilities related to the EWS environment they will be running in.

EWS public APIs are provided inside the tc~workspaces~api_api.jar .

In order to start your development and access the APIs from your development environment you should add:

  • The appropriate reference to your projects Java build path (classpath).
  • A private sharing reference in your applications portalapp.xml to tc~workspaces~api:

    <application-config>

                   <property name=”SharingReference value=”tc~workspaces~api” />

          </application-config>

/wp-content/uploads/2012/12/pic1_167191.jpg

EWS APIs:  Accessing Module Context

Now you are ready to start developing.  As a first step in using the EWS API for modules, you might want to obtain access to the Module Context object and the various Workspace services. A ModuleContext represents the runtime context associated with a specific module instance allowing access to relevant data about the running user, the module itself and the containing Workspace.  For more info follow the code sample bellow:

     import com.sap.workspaces.module.IModuleContext;

     import com.sap.workspaces.module.ModuleHelper;

     import com.sap.workspaces.workspace.Type;

     import com.sap.workspaces.module.IModuleID;

     import com.sap.workspaces.workspace.IIdentifier;

     //Get the module context object with the current request object

     IModuleContext moduleContext = ModuleHelper.getModuleContext(request);

     //the current user

     IUser user = moduleContext.getUser();

    

     //The locale associated with the current request/user

     Locale locale = moduleContext.getLocale();

     //The value of a property residing on the module instance

     String propValue = moduleContext.getProperty(“PROPERTY_ID”)

     //The module instance’s unique identifier

     IModuleID moduleId = moduleContext.getModuleID();

     //The module instance ID

     String moduleInctanceId = moduleId.getInstanceID();

     // the module template ID

     String mouleTemplateId = moduleId.getTemplateID();

     //The unique identifier of the containing workspace instance

     IIdentifier workspaceIdentifier = moduleId.getWorkspaceID();

     //Enumeration of the workspace types ( Type.PERSONAL, Type.SHARED )

     Type workspaceType = workspaceIdentifier.getType();

     //Returns the workspace ID

     String workspaceId = workspaceIdentifier.getID();

You can obtain the containing Workspace itself (IWorkspace) through the IModuleContext  object:

     //Gets workspace factory for workspace information and operation

     IWorkspacesRuntime workspaceRuntime = RuntimeFactory.getWorkspacesRuntime();

    

     IWorkspaceFactory workspaceFactory =

    (IWorkspaceFactory)workspaceRuntime.getService(IWorkspaceFactory.class);

     //Get the workspace object

     IWorkspace workspace =     

          workspaceFactory.getWorkspace(moduleContext.getUser(), workspaceIdentifier);


     //The member list of the workspace

     IMemberList memberList = workspace.getMemberList();

     //The title of the workspace

     String workspaceTitle = workspace.getName();

     //The description of the workspace

     String workspaceDescription = workspace.getDescription();

     //The workspace status (Status.CLOSED / PUBLISHED / PENDING / DRAFT)

     Status workspaceStatus = workspace.getStatus();

EWS APIs:  Detecting the Users Workspace Role

You may want to implement different behavior of you application depending on the current user’s role and permissions in the workspace.  For instance, enable certain user actions for Workspace Managers and disable them for Workspace Members. The EWS API provides a possibility to detect the user’s role as illustrated in the following example:

     // Get the workspace in which this module is running

     IModuleContext moduleContext = ModuleHelper.getModuleContext(request);

    

     IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)                               RuntimeFactory.getWorkspacesRuntime().getService(IWorkspaceFactory.class);

    

     IIdentifier workspaceIdentifier = moduleContext.getModuleID().getWorkspaceID();

    

     IWorkspace workspace =     
          workspaceFactory.getWorkspace(moduleContext.getUser() ,workspaceIdentifier);

     //Get the Workspaces Member List object

     IMemberList memberList = workspace.getMemberList();

     //Check if the user is manager in this workspace

     boolean isManager = memberList.isManager(request.getUser());

     //Get the owner user of this workspace

     IUser ownerUser = (IUser) memberList.getOwner();

     // Check if the user is member in this workspace

     IRole memberRole = memberList.getRole(WorkspaceRole.MEMBER);

     boolean isMember = memberRole.isUserInRole(request.getUser());

     // Check if the user is manager in this workspace

     IRole memberRole = memberList.getRole(WorkspaceRole.MANAGER);

     boolean isManager = memberRole.isUserInRole(request.getUser());


Now you’re ready to develop or extend your existing portal applications into EWS module templates aware and responsive to their Workspace runtime environment. For a deeper dive into these topics and additional functionalities available through the EWS public API refer to the official SAP documentation.

Go back to: A Deep Dive into SAP NetWeaver Portal, Enterprise Workspaces (Main TOC blog)

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply