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> <groupId>org.gcube.contentmanagement</groupId>
<artifactId>storage-manager-wrapper</artifactId> <artifactId>storage-manager-wrapper</artifactId>
</dependency> </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 --> <!-- tabular-data-widget-common-event -->
<dependency> <dependency>
@ -185,6 +192,8 @@
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version> <version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- LOGGING --> <!-- LOGGING -->
<dependency> <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.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; 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.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.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
@ -97,7 +98,7 @@ public interface TDGWTService extends RemoteService {
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public UserInfo hello() throws TDGWTServiceException; public UserInfo hello() throws TDGWTServiceException;
/** /**
* Restore UI session * Restore UI session
* *
@ -106,6 +107,16 @@ public interface TDGWTService extends RemoteService {
*/ */
public TRId restoreUISession() throws TDGWTServiceException; public TRId restoreUISession() throws TDGWTServiceException;
/**
* Resolve Uri
*
* @param uriResolverSession
* @return
* @throws TDGWTServiceException
*/
public String getUriFromResolver(UriResolverSession uriResolverSession)
throws TDGWTServiceException;
// TabularResource // TabularResource
/** /**
* Get current TRId * Get current TRId
@ -121,9 +132,9 @@ public interface TDGWTService extends RemoteService {
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public TabResource getInSessionTabResourceInfo() throws TDGWTServiceException; public TabResource getInSessionTabResourceInfo()
throws TDGWTServiceException;
/** /**
* Get informations on the current tabular resource call service * Get informations on the current tabular resource call service
* *
@ -245,15 +256,15 @@ public interface TDGWTService extends RemoteService {
public void closeAllTabularResources() throws TDGWTServiceException; public void closeAllTabularResources() throws TDGWTServiceException;
/** /**
* Close Tabular Resource with TRId equals to closeTRId * Close Tabular Resource with TRId equals to closeTRId and open if not null
* and open if not null that with TRId equals to openTRId * that with TRId equals to openTRId
* *
* @param openTRId * @param openTRId
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId) public void closeTabularResourceAndOpen(TRId openTRId, TRId closeTRId)
throws TDGWTServiceException; throws TDGWTServiceException;
/** /**
* Close Tabular Resource with TRId equals to closeTRId * Close Tabular Resource with TRId equals to closeTRId
* *
@ -262,7 +273,7 @@ public interface TDGWTService extends RemoteService {
*/ */
public void closeTabularResource(TRId closeTRId) public void closeTabularResource(TRId closeTRId)
throws TDGWTServiceException; throws TDGWTServiceException;
/** /**
* Set Current Tabular Resource that passed as parameter if not null * Set Current Tabular Resource that passed as parameter if not null
* *
@ -354,7 +365,8 @@ public interface TDGWTService extends RemoteService {
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public void setShare(ShareTabResource shareInfo) throws TDGWTServiceException; public void setShare(ShareTabResource shareInfo)
throws TDGWTServiceException;
/** /**
* Share template * Share template
@ -363,10 +375,9 @@ public interface TDGWTService extends RemoteService {
* @return * @return
* @throws TDGWTServiceException * @throws TDGWTServiceException
*/ */
public void setShareTemplate(ShareTemplate shareTemplate) throws TDGWTServiceException; public void setShareTemplate(ShareTemplate shareTemplate)
throws TDGWTServiceException;
// Open // 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.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; 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.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.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId;
@ -85,6 +86,8 @@ public interface TDGWTServiceAsync {
void restoreUISession(AsyncCallback<TRId> callback); void restoreUISession(AsyncCallback<TRId> callback);
void getUriFromResolver(UriResolverSession uriResolverSession, AsyncCallback<String> callback);
// TabularResource // TabularResource
void getCurrentTRId(AsyncCallback<TRId> callback); void getCurrentTRId(AsyncCallback<TRId> callback);

View File

@ -78,18 +78,17 @@ public class SessionUtil {
ASLSession session; ASLSession session;
if (username == null) { if (username == null) {
logger.warn("no user found in session, using test one"); logger.warn("no user found in session, using test one");
throw new TDGWTSessionExpiredException("Session Expired!"); throw new TDGWTSessionExpiredException("Session Expired!");
// Remove comment for Test // Remove comment for Test
/* /*
username = Constants.DEFAULT_USER; * username = Constants.DEFAULT_USER; String scope =
String scope = Constants.DEFAULT_SCOPE; * Constants.DEFAULT_SCOPE;
*
httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE, username); * httpSession.setAttribute(ScopeHelper.USERNAME_ATTRIBUTE,
session = SessionManager.getInstance().getASLSession( * username); session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); * httpSession.getId(), username); session.setScope(scope);
session.setScope(scope); */
*/
} else { } else {
session = SessionManager.getInstance().getASLSession( session = SessionManager.getInstance().getASLSession(
httpSession.getId(), username); httpSession.getId(), username);
@ -206,26 +205,31 @@ public class SessionUtil {
public static void addToCurrentTabularResourcesOpen( public static void addToCurrentTabularResourcesOpen(
HttpSession httpSession, TabResource tabResource) { HttpSession httpSession, TabResource tabResource) {
@SuppressWarnings("unchecked") if (tabResource.getTrId() != null
ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession && tabResource.getTrId().getId() != null
.getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN); & !tabResource.getTrId().getId().isEmpty()) {
if (t != null) {
for (TabResource tr : t) { @SuppressWarnings("unchecked")
if (tr.getTrId().getId() ArrayList<TabResource> t = (ArrayList<TabResource>) httpSession
.compareTo(tabResource.getTrId().getId()) == 0) { .getAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
t.remove(tr); if (t != null) {
break; 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.setAttribute(
httpSession SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, t);
.removeAttribute(SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN);
} else {
t = new ArrayList<TabResource>();
t.add(tabResource);
} }
httpSession.setAttribute(
SessionConstants.CURRENT_TABULAR_RESOURCES_OPEN, t);
} }
public static void removeFromCurrentTabularResourcesOpen( 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.Codelist;
import org.gcube.portlets.user.td.gwtservice.shared.tr.type.Dataset; 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.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.gwtservice.shared.user.UserInfo;
import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; 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.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.api.DiscoveryClient;
import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -1777,8 +1779,8 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements
Date dateU = sdfDate.parse(tabResource.getValidUntilTo()); Date dateU = sdfDate.parse(tabResource.getValidUntilTo());
GregorianCalendar validUntilToC = new GregorianCalendar(); GregorianCalendar validUntilToC = new GregorianCalendar();
validUntilToC.setTime(dateU); validUntilToC.setTime(dateU);
ValidUntilMetadata validUntil = new ValidUntilMetadata(); ValidUntilMetadata validUntil = new ValidUntilMetadata(
validUntil.setValue(validUntilToC); validUntilToC);
tr.setMetadata(validUntil); tr.setMetadata(validUntil);
} catch (ParseException e) { } catch (ParseException e) {
logger.info("ValidUntilMetadata is not set, no valid calendar present"); 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()); Date dateU = sdfDate.parse(tabResource.getValidUntilTo());
GregorianCalendar validUntilToC = new GregorianCalendar(); GregorianCalendar validUntilToC = new GregorianCalendar();
validUntilToC.setTime(dateU); validUntilToC.setTime(dateU);
ValidUntilMetadata validUntil = new ValidUntilMetadata(); ValidUntilMetadata validUntil = new ValidUntilMetadata(
validUntil.setValue(validUntilToC); validUntilToC);
tr.setMetadata(validUntil); tr.setMetadata(validUntil);
} catch (ParseException e) { } catch (ParseException e) {
logger.info("ValidUntilMetadata is not set, no valid calendar present"); 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 * @param resource
* @return * @return
*/ */
public ResourceTD createResourceTD(Resource resource) { protected ResourceTD createResourceTD(Resource resource) {
ResourceTD resourceTD = null; ResourceTD resourceTD = null;
Class<? extends Resource> resourceClass = resource.getResourceType(); Class<? extends Resource> resourceClass = resource.getResourceType();
if (resourceClass == InternalURI.class) { if (resourceClass == InternalURI.class) {
InternalURI internalURI = (InternalURI) resource; InternalURI internalURI = (InternalURI) resource;
String uri=null; String uri=null;
if(internalURI.getUri()!=null){
uri=internalURI
.getUri().toString();
}
return new InternalURITD(internalURI.getFileId(),uri); return new InternalURITD(internalURI.getFileId(),uri);
} else { } else {
if (resourceClass == StringResource.class) { if (resourceClass == StringResource.class) {
@ -118,5 +115,8 @@ public class ResourceTDCreator {
return resourceTD; 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 + "]";
}
}