server side implemented
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/widgets/catalogue-sharing-widget@146441 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c7c4dd2ece
commit
a2ce478a2b
|
@ -44,5 +44,10 @@
|
|||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
|
||||
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/validation-api-1.0.0.GA.jar" sourcepath="/home/costantino/Downloads/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
|
||||
<classpathentry excluding="**" kind="src" output="${webappDirectory}/WEB-INF/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="${webappDirectory}/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<property name="context-root" value="catalogue-sharing-widget"/>
|
||||
<property name="java-output-path" value="/catalogue-sharing-widget/target/catalogue-sharing-widget-1.0.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</wb-module>
|
||||
|
|
27
pom.xml
27
pom.xml
|
@ -60,6 +60,12 @@
|
|||
<artifactId>gwt-user</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope-maps</artifactId>
|
||||
<scope>provided</scope>
|
||||
<!-- put at provided for deploying -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-dev</artifactId>
|
||||
|
@ -75,6 +81,12 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.portlets.user</groupId>
|
||||
<artifactId>gcube-url-shortener</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
|
@ -86,6 +98,21 @@
|
|||
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.common.portal</groupId>
|
||||
<artifactId>portal-manager</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>portal-service</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -8,9 +8,9 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
|||
/**
|
||||
* The client side stub for the RPC service.
|
||||
*/
|
||||
@RemoteServiceRelativePath("share")
|
||||
@RemoteServiceRelativePath("shareservices")
|
||||
public interface ShareServices extends RemoteService {
|
||||
|
||||
ItemUrls greetServer(String uuid) throws Exception;
|
||||
ItemUrls getPackageUrl(String uuid) throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,6 @@ import com.google.gwt.user.client.rpc.AsyncCallback;
|
|||
|
||||
public interface ShareServicesAsync {
|
||||
|
||||
void greetServer(String uuid, AsyncCallback<ItemUrls> callback);
|
||||
void getPackageUrl(String uuid, AsyncCallback<ItemUrls> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,121 @@
|
|||
package org.gcube.portlets_widgets.catalogue_sharing_widget.server;
|
||||
|
||||
public class ShareServicesImpl {
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.common.portal.PortalContext;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePerUrlReader;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue;
|
||||
import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory;
|
||||
import org.gcube.portlets.user.urlshortener.UrlShortener;
|
||||
import org.gcube.portlets_widgets.catalogue_sharing_widget.client.ShareServices;
|
||||
import org.gcube.portlets_widgets.catalogue_sharing_widget.shared.ItemUrls;
|
||||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
import com.liferay.portal.kernel.log.Log;
|
||||
import com.liferay.portal.kernel.log.LogFactoryUtil;
|
||||
|
||||
public class ShareServicesImpl extends RemoteServiceServlet implements ShareServices{
|
||||
|
||||
private static final long serialVersionUID = -2060855544534802987L;
|
||||
private static final Log logger = LogFactoryUtil.getLog(ShareServicesImpl.class);
|
||||
public static final String GCUBE_REQUEST_URL = "gcube-request-url";
|
||||
|
||||
/**
|
||||
* Retrieve an instance of the library for the scope
|
||||
* @param scope if it is null it is evaluated from the session
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public DataCatalogue getCatalogue(String scope) throws Exception{
|
||||
|
||||
String scopeInWhichDiscover = (scope != null && !scope.isEmpty()) ? scope : getCurrentContext(getThreadLocalRequest(), false);
|
||||
logger.debug("Discovering ckan instance into scope " + scopeInWhichDiscover);
|
||||
return DataCatalogueFactory.getFactory().getUtilsPerScope(scopeInWhichDiscover);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemUrls getPackageUrl(String uuid) throws Exception{
|
||||
|
||||
String scopePerCurrentUrl = getScopeFromClientUrl(getThreadLocalRequest());
|
||||
DataCatalogue catalogue = getCatalogue(scopePerCurrentUrl);
|
||||
String longUrl = catalogue.getUnencryptedUrlFromDatasetIdOrName(uuid);
|
||||
String shortUrl = null;
|
||||
|
||||
UrlShortener shortener = new UrlShortener();
|
||||
if(shortener!=null && shortener.isAvailable())
|
||||
shortUrl = shortener.shorten(longUrl);
|
||||
|
||||
return new ItemUrls(shortUrl, longUrl, uuid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the scope in which ckan information needs to be discovered from the url
|
||||
* @param httpServletRequest
|
||||
* @return
|
||||
*/
|
||||
public static String getScopeFromClientUrl(HttpServletRequest httpServletRequest){
|
||||
|
||||
if(httpServletRequest == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
String scopeToReturn = null;
|
||||
try{
|
||||
String clientUrl = getCurrentClientUrl(httpServletRequest).split("\\?")[0];
|
||||
logger.debug("Client url is " + clientUrl);
|
||||
|
||||
// check if this information is in session, otherwise set it and return
|
||||
HttpSession session = httpServletRequest.getSession();
|
||||
|
||||
if((scopeToReturn = (String) session.getAttribute(clientUrl)) != null){
|
||||
logger.debug("Scope to return is " + scopeToReturn);
|
||||
}else{
|
||||
// ask to the ckan library and set it
|
||||
scopeToReturn = ApplicationProfileScopePerUrlReader.getScopePerUrl(clientUrl);
|
||||
logger.debug("Scope to return is " + scopeToReturn);
|
||||
session.setAttribute(clientUrl, scopeToReturn);
|
||||
}
|
||||
}catch(Exception e){
|
||||
scopeToReturn = getCurrentContext(httpServletRequest, false);
|
||||
logger.warn("Failed to determine the scope from the client url, returning the current one: " + scopeToReturn);
|
||||
}
|
||||
return scopeToReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current scope by using the portal manager
|
||||
* @param b
|
||||
* @return a GcubeUser object
|
||||
*/
|
||||
public static String getCurrentContext(HttpServletRequest request, boolean setInThread){
|
||||
|
||||
if(request == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
String context = pContext.getCurrentScope(request);
|
||||
logger.debug("Returning context " + context);
|
||||
|
||||
if(context != null && setInThread)
|
||||
ScopeProvider.instance.set(context);
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed to get the url of the client
|
||||
* @param httpServletRequest the httpServletRequest object
|
||||
* @return the instance of the user
|
||||
* @see the url at client side
|
||||
*/
|
||||
public static String getCurrentClientUrl(HttpServletRequest httpServletRequest) {
|
||||
if(httpServletRequest == null)
|
||||
throw new IllegalArgumentException("HttpServletRequest is null!");
|
||||
|
||||
return httpServletRequest.getHeader(GCUBE_REQUEST_URL);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,16 @@ public class ItemUrls implements Serializable {
|
|||
private String shortUrl;
|
||||
private String url;
|
||||
private String catalogueUUID;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ItemUrls() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* @param shortUrl
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets_widgets.catalogue_sharing_widget.server.GreetingServiceImpl</servlet-class>
|
||||
<servlet-name>shareservices</servlet-name>
|
||||
<servlet-class>org.gcube.portlets_widgets.catalogue_sharing_widget.server.ShareServicesImpl</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<url-pattern>/ShareCatalogue/greet</url-pattern>
|
||||
<servlet-name>shareservices</servlet-name>
|
||||
<url-pattern>/ShareCatalogue/shareservices</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Default page to serve -->
|
||||
|
|
Loading…
Reference in New Issue