From 3a7cafc7df0ec601ef0c4b6b5a5e09e767ac1730 Mon Sep 17 00:00:00 2001 From: Giancarlo Panichi Date: Wed, 29 Apr 2015 09:51:21 +0000 Subject: [PATCH] Updated requests on storage by id git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-gwt-service@114529 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gwtservice/server/TDGWTServiceImpl.java | 74 ++---------- .../uriresolver/UriResolverTDClient.java | 109 ++++++++++++++++++ .../BackgroundOperationMonitorCreator.java | 21 +++- .../monitor/OperationMonitorCreator.java | 21 +++- 4 files changed, 157 insertions(+), 68 deletions(-) create mode 100644 src/main/java/org/gcube/portlets/user/td/gwtservice/server/uriresolver/UriResolverTDClient.java diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java index 9c526fa..683fb59 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/TDGWTServiceImpl.java @@ -161,6 +161,7 @@ import org.gcube.portlets.user.td.gwtservice.server.trservice.QueryService; import org.gcube.portlets.user.td.gwtservice.server.trservice.TDTypeValueMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TabularResourceTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap; +import org.gcube.portlets.user.td.gwtservice.server.uriresolver.UriResolverTDClient; import org.gcube.portlets.user.td.gwtservice.shared.Constants; import org.gcube.portlets.user.td.gwtservice.shared.chart.ChartTopRatingSession; import org.gcube.portlets.user.td.gwtservice.shared.codelisthelper.CodelistMappingSession; @@ -193,9 +194,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.monitor.BackgroundOperationM import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitor; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorCreator; import org.gcube.portlets.user.td.gwtservice.shared.monitor.OperationMonitorSession; +import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.DetachColumnRulesSession; import org.gcube.portlets.user.td.gwtservice.shared.rule.RuleDescriptionData; -import org.gcube.portlets.user.td.gwtservice.shared.rule.ApplyAndDetachColumnRulesSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXExportSession; import org.gcube.portlets.user.td.gwtservice.shared.sdmx.SDMXImportSession; import org.gcube.portlets.user.td.gwtservice.shared.share.Contacts; @@ -295,7 +296,6 @@ import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.PeriodDataT import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.RelationshipData; import org.gcube.portlets.user.td.widgetcommonevent.shared.tr.column.ValueDataFormat; import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; -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; @@ -9024,66 +9024,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements HttpSession session = this.getThreadLocalRequest().getSession(); ASLSession aslSession = SessionUtil.getAslSession(session); logger.debug("Get uri from resolver: " + uriResolverSession); - - UriResolverManager resolver; - Map params = new HashMap(); - - switch (uriResolverSession.getApplicationType()) { - case GIS: - resolver = new UriResolverManager(uriResolverSession - .getApplicationType().toString()); - params.put("gis-UUID", uriResolverSession.getUuid()); - params.put("scope", aslSession.getScope()); - logger.debug("Uri Resolver params: " + params); - link = resolver.getLink(params, true); // true, link is shorted - // otherwise none - break; - case SMP: - resolver = new UriResolverManager(uriResolverSession - .getApplicationType().toString()); - params.put("smp-uri", uriResolverSession.getUuid()); - if (uriResolverSession.getFileName() == null) { - params.put("fileName", ""); - } else { - params.put("fileName", uriResolverSession.getFileName()); - } - if (uriResolverSession.getMimeType() == null) { - params.put("contentType", ""); - } else { - params.put("contentType", uriResolverSession.getMimeType()); - } - logger.debug("Uri Resolver params: " + params); - link = resolver.getLink(params, true); // true, link is shorted - // otherwise none - break; - case SMP_ID: - resolver = new UriResolverManager(uriResolverSession - .getApplicationType().toString()); - params.put("smp-id", uriResolverSession.getUuid()); - if (uriResolverSession.getFileName() == null) { - params.put("fileName", ""); - } else { - params.put("fileName", uriResolverSession.getFileName()); - } - if (uriResolverSession.getMimeType() == null) { - params.put("contentType", ""); - } else { - params.put("contentType", uriResolverSession.getMimeType()); - } - logger.debug("Uri Resolver params: " + params); - link = resolver.getLink(params, true); // true, link is shorted - // otherwise none - break; - - default: - logger.debug("No resolver enable on this application type"); - throw new TDGWTServiceException( - "Error retrieving uri from resolver:" - + " No resolver enable on this application type"); - - } - - logger.debug("Retrieved Link: " + link); + + UriResolverTDClient uriResolverTDClient=new UriResolverTDClient(); + link=uriResolverTDClient.resolve(uriResolverSession, aslSession); + return link; } catch (TDGWTServiceException e) { @@ -9258,8 +9202,10 @@ public class TDGWTServiceImpl extends RemoteServiceServlet implements } } } - - String link = getUriFromResolver(uriResolverSession); + + UriResolverTDClient uriResolverTDClient=new UriResolverTDClient(); + String link=uriResolverTDClient.resolve(uriResolverSession, aslSession); + if (link == null || link.isEmpty()) { throw new TDGWTServiceException( diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/server/uriresolver/UriResolverTDClient.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/uriresolver/UriResolverTDClient.java new file mode 100644 index 0000000..81a1d33 --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/server/uriresolver/UriResolverTDClient.java @@ -0,0 +1,109 @@ +package org.gcube.portlets.user.td.gwtservice.server.uriresolver; + +import java.util.HashMap; +import java.util.Map; + +import org.gcube.application.framework.core.session.ASLSession; +import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; +import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession; +import org.gcube.portlets.user.uriresolvermanager.UriResolverManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Client for retrieve link + * + * + * @author giancarlo email: g.panichi@isti.cnr.it + * + */ +public class UriResolverTDClient { + private static Logger logger = LoggerFactory + .getLogger(UriResolverTDClient.class); + + public UriResolverTDClient() { + + } + + public String resolve(UriResolverSession uriResolverSession, + ASLSession aslSession) throws TDGWTServiceException { + try { + + String link = ""; + + logger.debug("Get uri from resolver: " + uriResolverSession); + + UriResolverManager resolver; + Map params = new HashMap(); + + switch (uriResolverSession.getApplicationType()) { + case GIS: + resolver = new UriResolverManager(uriResolverSession + .getApplicationType().toString()); + params.put("gis-UUID", uriResolverSession.getUuid()); + params.put("scope", aslSession.getScope()); + logger.debug("Uri Resolver params: " + params); + link = resolver.getLink(params, true); // true, link is shorted + // otherwise none + break; + case SMP: + resolver = new UriResolverManager(uriResolverSession + .getApplicationType().toString()); + params.put("smp-uri", uriResolverSession.getUuid()); + if (uriResolverSession.getFileName() == null) { + params.put("fileName", ""); + } else { + params.put("fileName", uriResolverSession.getFileName()); + } + if (uriResolverSession.getMimeType() == null) { + params.put("contentType", ""); + } else { + params.put("contentType", uriResolverSession.getMimeType()); + } + logger.debug("Uri Resolver params: " + params); + link = resolver.getLink(params, true); // true, link is shorted + // otherwise none + break; + case SMP_ID: + resolver = new UriResolverManager(uriResolverSession + .getApplicationType().toString()); + params.put("smp-id", uriResolverSession.getUuid()); + if (uriResolverSession.getFileName() == null) { + params.put("fileName", ""); + } else { + params.put("fileName", uriResolverSession.getFileName()); + } + if (uriResolverSession.getMimeType() == null) { + params.put("contentType", ""); + } else { + params.put("contentType", uriResolverSession.getMimeType()); + } + logger.debug("Uri Resolver params: " + params); + link = resolver.getLink(params, true); // true, link is shorted + // otherwise none + break; + + default: + logger.debug("No resolver enable on this application type"); + throw new TDGWTServiceException( + "Error retrieving uri from resolver:" + + " No resolver enable on this application type"); + + } + + logger.debug("Retrieved Link: " + link); + return link; + + } catch (TDGWTServiceException e) { + throw e; + } catch (Throwable e) { + e.printStackTrace(); + throw new TDGWTServiceException( + "Error retrieving uri from resolver: " + + e.getLocalizedMessage()); + } + + } + +} diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java index 6d6a53b..696f7a5 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/BackgroundOperationMonitorCreator.java @@ -30,6 +30,7 @@ import org.gcube.portlets.user.td.gwtservice.server.trservice.JobClassifierMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TabularResourceTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.WorkerStateMap; +import org.gcube.portlets.user.td.gwtservice.server.uriresolver.UriResolverTDClient; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; @@ -40,7 +41,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.task.TaskS; import org.gcube.portlets.user.td.gwtservice.shared.task.TaskWrapper; import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsJobS; import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata; +import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -420,7 +423,14 @@ public class BackgroundOperationMonitorCreator { + exportSession.getFileDescription() + " ,mimetype: text/csv" + " ,folder: " + exportSession.getItemId() + "]"); - storage.createItemOnWorkspace(exportMetadata.getUri(), user, + + + UriResolverSession uriResolverSession = new UriResolverSession( + exportMetadata.getUri(), ApplicationType.SMP_ID); + UriResolverTDClient uriResolverTDClient=new UriResolverTDClient(); + String link=uriResolverTDClient.resolve(uriResolverSession, aslSession); + + storage.createItemOnWorkspace(link, user, exportSession.getFileName(), exportSession.getFileDescription(), "text/csv", exportSession.getItemId()); @@ -466,7 +476,14 @@ public class BackgroundOperationMonitorCreator { + exportSession.getFileDescription() + " ,mimetype: application/json" + " ,folder: " + exportSession.getItemId() + "]"); - storage.createItemOnWorkspace(exportMetadata.getUri(), user, + + UriResolverSession uriResolverSession = new UriResolverSession( + exportMetadata.getUri(), ApplicationType.SMP_ID); + UriResolverTDClient uriResolverTDClient=new UriResolverTDClient(); + String link=uriResolverTDClient.resolve(uriResolverSession, aslSession); + + + storage.createItemOnWorkspace(link, user, exportSession.getFileName(), exportSession.getFileDescription(), "application/json", exportSession.getItemId()); diff --git a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java index 797cad3..ceff189 100644 --- a/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java +++ b/src/main/java/org/gcube/portlets/user/td/gwtservice/shared/monitor/OperationMonitorCreator.java @@ -29,6 +29,7 @@ import org.gcube.portlets.user.td.gwtservice.server.trservice.JobClassifierMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TabularResourceTypeMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.TaskStateMap; import org.gcube.portlets.user.td.gwtservice.server.trservice.WorkerStateMap; +import org.gcube.portlets.user.td.gwtservice.server.uriresolver.UriResolverTDClient; import org.gcube.portlets.user.td.gwtservice.shared.csv.CSVExportSession; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTServiceException; import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException; @@ -40,7 +41,9 @@ import org.gcube.portlets.user.td.gwtservice.shared.task.TaskWrapper; import org.gcube.portlets.user.td.gwtservice.shared.task.ValidationsJobS; import org.gcube.portlets.user.td.gwtservice.shared.tr.TabResource; import org.gcube.portlets.user.td.gwtservice.shared.tr.table.metadata.TabExportMetadata; +import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession; import org.gcube.portlets.user.td.widgetcommonevent.shared.TRId; +import org.gcube.portlets.user.td.widgetcommonevent.shared.uriresolver.ApplicationType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -475,7 +478,14 @@ public class OperationMonitorCreator { + exportSession.getFileDescription() + " ,mimetype: text/csv" + " ,folder: " + exportSession.getItemId() + "]"); - storage.createItemOnWorkspace(exportMetadata.getUri(), user, + + UriResolverSession uriResolverSession = new UriResolverSession( + exportMetadata.getUri(), ApplicationType.SMP_ID); + UriResolverTDClient uriResolverTDClient=new UriResolverTDClient(); + String link=uriResolverTDClient.resolve(uriResolverSession, aslSession); + + + storage.createItemOnWorkspace(link, user, exportSession.getFileName(), exportSession.getFileDescription(), "text/csv", exportSession.getItemId()); @@ -521,7 +531,14 @@ public class OperationMonitorCreator { + exportSession.getFileDescription() + " ,mimetype: application/json" + " ,folder: " + exportSession.getItemId() + "]"); - storage.createItemOnWorkspace(exportMetadata.getUri(), user, + + UriResolverSession uriResolverSession = new UriResolverSession( + exportMetadata.getUri(), ApplicationType.SMP_ID); + UriResolverTDClient uriResolverTDClient=new UriResolverTDClient(); + String link=uriResolverTDClient.resolve(uriResolverSession, aslSession); + + + storage.createItemOnWorkspace(link, user, exportSession.getFileName(), exportSession.getFileDescription(), "application/json", exportSession.getItemId());