Difference between revisions of "ClientContextLibrary"

From Gcube Wiki
Jump to: navigation, search
Line 58: Line 58:
  
 
</source>
 
</source>
 +
 +
==Examples for passing the Client Context via Standard HTTP POST or GET ==
  
  

Revision as of 17:36, 24 November 2016

Client Context library for gCube Portlets

Starting from gCube 4.2, the current Context identifier resides client side. If your Portlet does use AJAX calls (i.e. XMLHttpRequest to exchange data with a server behind the scenes) you don't need this component. Everything is already set up for you by the gCube Portal/Gateway in which your application is running.

If you use standard http GET or POST to exchange data with the server instead, and you need to pass to the server the current Infrastructure scope identifier (the Liferay groupId).

Getting the Client Context in Javascript

<script>
var groupId = Liferay.ThemeDisplay.getScopeGroupId();
</script>

Read more about Liferay Javascript Object: [1]

Getting the Client Context in GWT (Widget)

The Client Context has been wrapped as a GWT Widget. Its source code is available in the gCube SVN repository, at this url.

To use the widget, you need to declare the following maven dependency in your project's pom.xml

<dependency>
        <groupId>org.gcube.portal</groupId>
	<artifactId>client-context-library</artifactId>
	<version>[1.0.0-SNAPSHOT,)</version>
	<scope>compile</scope>
</dependency>

as well as the following line in the gwt.xml file of your gwt-portlet:

<!--Inherit the GCubeClientContext widget code -->
<inherits name='org.gcube.portal.clientcontext.GCubeClientContext' />

then you just use the GCubeClientContext.getCurrentContextId() method:

public static native String getCurrentContextId();

Either if you pass this identifier explicitly as parameter, or embed it in the header of your call, in the server you can use the following method to get the infrastructure scope (note: scopeGroupId parameter is the value returned from the GCubeClientContext.getCurrentContextId() method described previously:

import org.gcube.common.portal;
...
PortalContext pContext = PortalContext.getConfiguration();
 
/**
 * 
 * @param scopeGroupId the liferay groupid number (as String) of the VRE/VO
 * @return the scope (context)
 */
String currentScope = pContext.getCurrentScope(String scopeGroupId);

Examples for passing the Client Context via Standard HTTP POST or GET

Related links and references

[1] Liferay Javascript Object usage: https://web.liferay.com/web/pankaj.kathiriya/blog/-/blogs/usage-of-liferay-js-object

[2] gCube Portal Manager API: https://wiki.gcube-system.org/gcube/Portal_Context

[3] gCube UsersManagement Library https://wiki.gcube-system.org/gcube/UserManagement_Core#UserManager_APIs