Difference between revisions of "Portal Context"

From Gcube Wiki
Jump to: navigation, search
(Introduction)
Line 11: Line 11:
 
* the user (authorisation) token for that scope (infrastructure context).
 
* the user (authorisation) token for that scope (infrastructure context).
  
Apart from that, '''portal context''' provides contextual information about the gCube Gateway your webapp/portlet is running on, for instance you can:
+
Apart from that, '''portal context''' provides your application with contextual information about the gCube Gateway your webapp/portlet is running on, for instance you can:
  
 
* retrieve the list of Virtual Organizations available on a given portal;
 
* retrieve the list of Virtual Organizations available on a given portal;
Line 28: Line 28:
 
</source>
 
</source>
  
== PortalContext ==
+
== PortalContext Usage/Examples==
  
A new instance of the manager can be retrieved by invoking
+
First, get an instance of the PortalContext by invoking the static method PortalContext.getConfiguration();
  
 
<source lang="java">
 
<source lang="java">
Line 36: Line 36:
 
</source>
 
</source>
  
Now it allows you to retrieve:
+
Some of the useful methods available:
  
* The name of the gateway and its URL
+
* Get the current username of the current user:
 +
 
 +
<source lang="java">
 +
import org.gcube.common.portal;
 +
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
 +
...
 +
PortalContext pContext = PortalContext.getConfiguration();
 +
String username = pContext.getCurrentUser(httpServletRequest).getUsername();
 +
 
 +
</source>
 +
 
 +
* Get the user object (GCubeUser, see https://wiki.gcube-system.org/gcube/UserManagement_Core#UserManager_APIs) of the current user:
 +
 
 +
<source lang="java">
 +
import org.gcube.common.portal;
 +
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
 +
...
 +
PortalContext pContext = PortalContext.getConfiguration();
 +
GCubeUser theUser = pContext.getCurrentUser(httpServletRequest).getUsername();
 +
 
 +
</source>
 +
 
 +
 
 +
* Get name of the gateway and its URL
  
 
<source lang="java">
 
<source lang="java">
Line 50: Line 73:
 
</source>
 
</source>
  
* The landing page path of the current Site e.g. "/group/i-marine"
+
* Get landing page path of the current VRE or VO e.g. "/group/i-marine"
  
 
<source lang="java">
 
<source lang="java">

Revision as of 14:50, 14 November 2016

Introduction

The gCube Portal Manager is a component all portlets need to use to get the portal context where they are running into & to get the centralised email manager for sending emails from your application.

What is a portal context?

It is the component you must use to (programmatically) get:

  • the current user identifier using your webapp/portlet;
  • the current scope (infrastructure context) the user is currently working;
  • the user (authorisation) token for that scope (infrastructure context).

Apart from that, portal context provides your application with contextual information about the gCube Gateway your webapp/portlet is running on, for instance you can:

  • retrieve the list of Virtual Organizations available on a given portal;
  • retrieve the configured senders of emails sent by the portal;
  • retrieve the gateway name.

Maven Dependency

In order to use it in your project, add the following dependency to the project's pom.xml file

<dependency>
	<groupId>org.gcube.common.portal</groupId>
	<artifactId>portal-manager</artifactId>
	<scope>provided</scope>
</dependency>

PortalContext Usage/Examples

First, get an instance of the PortalContext by invoking the static method PortalContext.getConfiguration();

PortalContext instance = PortalContext.getConfiguration();

Some of the useful methods available:

  • Get the current username of the current user:
import org.gcube.common.portal;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
...
PortalContext pContext = PortalContext.getConfiguration();
String username = pContext.getCurrentUser(httpServletRequest).getUsername();
import org.gcube.common.portal;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
...
PortalContext pContext = PortalContext.getConfiguration();
GCubeUser theUser = pContext.getCurrentUser(httpServletRequest).getUsername();


  • Get name of the gateway and its URL
package org.gcube.common.portal;
...
// get the gateway name given the HttpServletRequest
String gatewayName = instance.getGatewayName(request);
 
// get the gateway url given the HttpServletRequest
String gatewayUrl = instance.getGatewayUrl(request);
  • Get landing page path of the current VRE or VO e.g. "/group/i-marine"
package org.gcube.common.portal;
...
// get the landing page path of the current Site e.g. "/group/i-marine"
String landingPagePath = instance.getSiteLandingPagePath(request);


  • mail sender for the current site
// get the current site email's sender (used when notifications are sent, for example), given the HttpServletRequest 
String sender = instance.getSenderEmail(request);
  • the name of the current infrastructure in which the client is running
package org.gcube.common.portal;
....
// get the current infrastructure name
String infrastructureName = instance.getInfrastructureName();
  • retrieve the list of VOs
// get the VOs
List<String> listVo = instance.getVOs();

Centralised Email Manager

The constructor expects the following parameters:

public EmailNotification(String recipient, String subject, String body, HttpServletRequest httpServletRequest)

once the object is instantiated just use the public void sendEmail() method to add the email to queue. The email will be delivered within minutes.

How to use it:

package org.gcube.common.portal.mailing;
 
//instanciate
EmailNotification mailToSend = new EmailNotification(
					email , 
					subject, 
					emailText, 
					request);
//send
mailToSend sendEmail();