Added Uri Resolver

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@100790 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2014-10-17 16:39:53 +00:00
parent 78182ecb33
commit ee8ba0adb2
7 changed files with 175 additions and 49 deletions

11
pom.xml
View File

@ -176,7 +176,14 @@
<groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId>
</dependency>
<!-- Uri Resolver Manager -->
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- tabular-data-widget-common-event -->
<dependency>
@ -185,6 +192,8 @@
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- LOGGING -->
<dependency>

View File

@ -64,6 +64,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
@ -97,7 +98,7 @@ public interface TDGWTService extends RemoteService {
* @throws TDGWTServiceException
*/
public UserInfo hello() throws TDGWTServiceException;
/**
* Restore UI session
*
@ -106,6 +107,16 @@ public interface TDGWTService extends RemoteService {
*/
public TRId restoreUISession() throws TDGWTServiceException;
/**
* Resolve Uri
*
* @param uriResolverSession
* @return
* @throws TDGWTServiceException
*/
public String getUriFromResolver(UriResolverSession uriResolverSession)
throws TDGWTServiceException;
// TabularResource
/**
* Get current TRId
@ -121,9 +132,9 @@ public interface TDGWTService extends RemoteService {
* @return
* @throws TDGWTServiceException
*/
public TabResource getInSessionTabResourceInfo() throws TDGWTServiceException;
public TabResource getInSessionTabResourceInfo()
throws TDGWTServiceException;
/**
* Get informations on the current tabular resource call service
*
@ -245,15 +256,15 @@ public interface TDGWTService extends RemoteService {
public void closeAllTabularResources() throws TDGWTServiceException;
/**
* Close Tabular Resource with TRId equals to closeTRId
* and open if not null that with TRId equals to openTRId
* Close Tabular Resource with TRId equals to closeTRId and open if not null
* that with TRId equals to openTRId
*
* @param openTRId
* @throws TDGWTServiceException
*/
public void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId)
throws TDGWTServiceException;
/**
* Close Tabular Resource with TRId equals to closeTRId
*
@ -262,7 +273,7 @@ public interface TDGWTService extends RemoteService {
*/
public void closeTabularResource(TRId closeTRId)
throws TDGWTServiceException;
/**
* Set Current Tabular Resource that passed as parameter if not null
*
@ -354,7 +365,8 @@ public interface TDGWTService extends RemoteService {
* @return
* @throws TDGWTServiceException
*/
public void setShare(ShareTabResource shareInfo) throws TDGWTServiceException;
public void setShare(ShareTabResource shareInfo)
throws TDGWTServiceException;
/**
* Share template
@ -363,10 +375,9 @@ public interface TDGWTService extends RemoteService {
* @return
* @throws TDGWTServiceException
*/
public void setShareTemplate(ShareTemplate shareTemplate) throws TDGWTServiceException;
public void setShareTemplate(ShareTemplate shareTemplate)
throws TDGWTServiceException;
// Open
/**

View File

@ -63,6 +63,7 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
@ -85,6 +86,8 @@ public interface TDGWTServiceAsync {
void restoreUISession(AsyncCallback<TRId> callback);
void getUriFromResolver(UriResolverSession uriResolverSession, AsyncCallback<String> callback);
// TabularResource
void getCurrentTRId(AsyncCallback<TRId> callback);

View File

@ -78,18 +78,17 @@ public class SessionUtil {
ASLSession session;
if (username == null) {
logger.warn("no user found in session, using test one");
throw new TDGWTSessionExpiredException("Session Expired!");
throw new TDGWTSessionExpiredException("Session Expired!");
// Remove comment for Test
/*
username = Constants.DEFAULT_USER;
String scope = Constants.DEFAULT_SCOPE;
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username);
session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
session.setScope(scope);
*/
/*
* username = Constants.DEFAULT_USER; String scope =
* Constants.DEFAULT_SCOPE;
*
* httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
* username); session = SessionManager.getInstance().getASLSession(
* httpSession.getId(), username); session.setScope(scope);
*/
} else {
session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username);
@ -206,26 +205,31 @@ public class SessionUtil {
public static void addToCurrentTabularResourcesOpen(
HttpSession httpSession, TabResource tabResource) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null) {
for (TabResource tr : t) {
if (tr.getTrId().getId()
.compareTo(tabResource.getTrId().getId()) == 0) {
t.remove(tr);
break;
if (tabResource.getTrId() != null
&& tabResource.getTrId().getId() != null
& !tabResource.getTrId().getId().isEmpty()) {
@SuppressWarnings("unchecked")
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
if (t != null) {
for (TabResource tr : t) {
if (tr.getTrId().getId()
.compareTo(tabResource.getTrId().getId()) == 0) {
t.remove(tr);
break;
}
}
t.add(tabResource);
httpSession
.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
} else {
t = new ArrayList<TabResource>();
t.add(tabResource);
}
t.add(tabResource);
httpSession
.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
} else {
t = new ArrayList<TabResource>();
t.add(tabResource);
httpSession.setAttribute(
SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, t);
}
httpSession.setAttribute(
SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, t);
}
public static void removeFromCurrentTabularResourcesOpen(

View File

@ -243,9 +243,11 @@ import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Agencies;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset;
import org.gcube.portlets.user.td.gwtservice.shared.tr.union.UnionSession;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger;
@ -1777,8 +1779,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Date dateU = sdfDate.parse(tabResource.getValidUntilTo());
GregorianCalendar validUntilToC = new GregorianCalendar();
validUntilToC.setTime(dateU);
ValidUntilMetadata validUntil = new ValidUntilMetadata();
validUntil.setValue(validUntilToC);
ValidUntilMetadata validUntil = new ValidUntilMetadata(
validUntilToC);
tr.setMetadata(validUntil);
} catch (ParseException e) {
logger.info("ValidUntilMetadata is not set, no valid calendar present");
@ -5099,8 +5101,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Date dateU = sdfDate.parse(tabResource.getValidUntilTo());
GregorianCalendar validUntilToC = new GregorianCalendar();
validUntilToC.setTime(dateU);
ValidUntilMetadata validUntil = new ValidUntilMetadata();
validUntil.setValue(validUntilToC);
ValidUntilMetadata validUntil = new ValidUntilMetadata(
validUntilToC);
tr.setMetadata(validUntil);
} catch (ParseException e) {
logger.info("ValidUntilMetadata is not set, no valid calendar present");
@ -7214,5 +7216,50 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
}
}
/**
*
*/
@Override
public String getUriFromResolver(UriResolverSession uriResolverSession)
throws TDGWTServiceException {
try {
String link = "";
HttpSession session = this.getThreadLocalRequest().getSession();
ASLSession aslSession = SessionUtil.getAslSession(session);
UriResolverManager resolver;
Map<String, String> params = new HashMap<String, String>();
switch(uriResolverSession.getApplicationType()){
case GIS:
resolver= new UriResolverManager(
uriResolverSession.getApplicationType().toString());
params.put("gis-UUID", uriResolverSession.getUuid());
params.put("scope", aslSession.getScope());
link = resolver.getLink(params, true); // true, link is shorted otherwise none
break;
default:
break;
}
return link;
} catch (TDGWTServiceException e) {
throw e;
} catch (SecurityException e) {
e.printStackTrace();
throw new TDGWTServiceException(
"Security exception, you haven't rights!");
} catch (Throwable e) {
e.printStackTrace();
throw new TDGWTServiceException("Error retrieving uri from resolver: "
+ e.getLocalizedMessage());
}
}
}

View File

@ -88,17 +88,14 @@ public class ResourceTDCreator {
* @param resource
* @return
*/
public ResourceTD createResourceTD(Resource resource) {
protected ResourceTD createResourceTD(Resource resource) {
ResourceTD resourceTD = null;
Class<? extends Resource> resourceClass = resource.getResourceType();
if (resourceClass == InternalURI.class) {
InternalURI internalURI = (InternalURI) resource;
String uri=null;
if(internalURI.getUri()!=null){
uri=internalURI
.getUri().toString();
}
return new InternalURITD(internalURI.getFileId(),uri);
} else {
if (resourceClass == StringResource.class) {
@ -118,5 +115,8 @@ public class ResourceTDCreator {
return resourceTD;
}
}

View File

@ -0,0 +1,52 @@
package org.gcube.portlets.user.td.gwtservice.shared.uriresolver;
import java.io.Serializable;
import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType;
/**
*
* @author giancarlo email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
*/
public class UriResolverSession implements Serializable {
private static final long serialVersionUID = -8088974004393312527L;
private String uuid;
private ApplicationType applicationType;
public UriResolverSession() {
super();
}
public UriResolverSession(String uuid, ApplicationType applicationType) {
super();
this.uuid = uuid;
this.applicationType = applicationType;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public ApplicationType getApplicationType() {
return applicationType;
}
public void setApplicationType(ApplicationType applicationType) {
this.applicationType = applicationType;
}
@Override
public String toString() {
return "UriResolverSession [uuid=" + uuid + ", applicationType="
+ applicationType + "]";
}
}