Difference between revisions of "Portal Manager"

From Gcube Wiki
Jump to: navigation, search
(Created page with "__FORCETOC__ == 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 cent...")
 
 
Line 1: Line 1:
 
__FORCETOC__  
 
__FORCETOC__  
 
== Introduction ==
 
== 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.  
+
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. Starting from gCube 4.2, it also allows to retrieve the current user and gCube context (plus some other information), if combined with the [https://wiki.gcube-system.org/gcube/ClientContextLibrary Client Context library].
 
+
Moreover, passing an HttpServletRequest object to its methods, you can also:
+
  
 +
Passing an HttpServletRequest object to its methods, you can:
 
* retrieve the list of Virtual Organizations available on a given portal;
 
* retrieve the list of Virtual Organizations available on a given portal;
 
* retrieve the configured senders of emails sent by the portal;
 
* retrieve the configured senders of emails sent by the portal;
* retrieve the gateway of the portal.
+
* retrieve the gateway of the portal;
 +
* retrieve the current user;
 +
* retrieve the current user's token;
 +
* retrieve the current gCube context in which the application is deployed.
  
 
=== Maven Dependency ===
 
=== Maven Dependency ===
Line 61: Line 63:
 
// get the VOs
 
// get the VOs
 
List<String> listVo = instance.getVOs();
 
List<String> listVo = instance.getVOs();
 +
</source>
 +
 +
* retrieve the current user
 +
<source  lang="java">
 +
// given the HttpServletRequest
 +
GCubeUser user = instance.getCurrentUser(request);
 +
</source>
 +
 +
* retrieve the current user's token
 +
<source  lang="java">
 +
// given the HttpServletRequest
 +
String currentSecurityToken = instance.getCurrentUserToken(request);
 +
</source>
 +
 +
* retrieve the current gCube context in which the application is deployed
 +
<source lang="java">
 +
// given the HttpServletRequest
 +
String currentContext = instance.getCurrentScope(request);
 
</source>
 
</source>
  

Latest revision as of 14:45, 5 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. Starting from gCube 4.2, it also allows to retrieve the current user and gCube context (plus some other information), if combined with the Client Context library.

Passing an HttpServletRequest object to its methods, 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 of the portal;
  • retrieve the current user;
  • retrieve the current user's token;
  • retrieve the current gCube context in which the application is deployed.

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

A new instance of the manager can be retrieved by invoking

PortalContext instance = PortalContext.getConfiguration();

Now it allows you to retrieve:

  • The 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);
  • 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();
  • retrieve the current user
// given the HttpServletRequest
GCubeUser user = instance.getCurrentUser(request);
  • retrieve the current user's token
// given the HttpServletRequest
String currentSecurityToken = instance.getCurrentUserToken(request);
  • retrieve the current gCube context in which the application is deployed
// given the HttpServletRequest
String currentContext = instance.getCurrentScope(request);

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();