Updated uri resolver

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/tabular-data-resources-widget@114487 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2015-04-28 15:08:52 +00:00
parent 231f41bd7b
commit b724f0f1b1
2 changed files with 81 additions and 32 deletions

View File

@ -232,17 +232,18 @@ public class ResourcesPanel extends FramedPanel {
ResourceTD resource = value.getResourceTD(); ResourceTD resource = value.getResourceTD();
String resourceData = ""; String resourceData = "";
if (resource instanceof InternalURITD) { if (resource instanceof InternalURITD) {
/*InternalURITD internalURITD = (InternalURITD) resource; /*
if (internalURITD.getStringValue() != null * InternalURITD internalURITD = (InternalURITD)
&& !internalURITD.getStringValue().isEmpty()) { * resource; if (internalURITD.getStringValue() !=
resourceData = "<tr>" * null &&
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>" * !internalURITD.getStringValue().isEmpty()) {
+ "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>" * resourceData = "<tr>" +
+ SafeHtmlUtils * "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'><b>File Id: </b></td>"
.htmlEscape(internalURITD * +
.getStringValue()) + "</td>" * "<td style='font-size: 12px; padding: 2px 1px 1px 1px;'>"
+ "</tr>"; * + SafeHtmlUtils .htmlEscape(internalURITD
}*/ * .getStringValue()) + "</td>" + "</tr>"; }
*/
} else { } else {
if (resource instanceof StringResourceTD) { if (resource instanceof StringResourceTD) {
@ -710,8 +711,8 @@ public class ResourcesPanel extends FramedPanel {
UriResolverSession uriResolverSession = new UriResolverSession( UriResolverSession uriResolverSession = new UriResolverSession(
internalURITD.getUrl(), ApplicationType.GIS); internalURITD.getUrl(), ApplicationType.GIS);
TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession, TDGWTServiceAsync.INSTANCE.getUriFromResolver(
new AsyncCallback<String>() { uriResolverSession, new AsyncCallback<String>() {
public void onFailure(Throwable caught) { public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) { if (caught instanceof TDGWTSessionExpiredException) {
@ -720,22 +721,20 @@ public class ResourcesPanel extends FramedPanel {
} else { } else {
Log.error("Error with uri resolver: " Log.error("Error with uri resolver: "
+ caught.getLocalizedMessage()); + caught.getLocalizedMessage());
UtilsGXT3.alert("Error", UtilsGXT3
"Error retrieving uri from resolver"); .alert("Error",
"Error retrieving uri from resolver");
} }
} }
public void onSuccess(String link) { public void onSuccess(String link) {
Log.debug("Retrieved link: " + link); Log.debug("Retrieved link: " + link);
Window.open(link, resourceTDDescriptor.getName(), Window.open(link,
""); resourceTDDescriptor.getName(), "");
} }
}); });
} else { } else {
if (resource instanceof TableResourceTD) { if (resource instanceof TableResourceTD) {
@ -753,11 +752,12 @@ public class ResourcesPanel extends FramedPanel {
protected void requestOpenGenericFile( protected void requestOpenGenericFile(
final ResourceTDDescriptor resourceTDDescriptor) { final ResourceTDDescriptor resourceTDDescriptor) {
ResourceTD resource = resourceTDDescriptor.getResourceTD(); ResourceTD resource = resourceTDDescriptor.getResourceTD();
if (resource instanceof StringResourceTD) { if (resource instanceof InternalURITD) {
StringResourceTD genericFileResourceTD = (StringResourceTD) resource; InternalURITD genericFileResourceTD = (InternalURITD) resource;
UriResolverSession uriResolverSession = new UriResolverSession( UriResolverSession uriResolverSession = new UriResolverSession(
genericFileResourceTD.getStringValue(), genericFileResourceTD.getUrl(), ApplicationType.SMP_ID,
ApplicationType.SMP, resourceTDDescriptor.getName()); resourceTDDescriptor.getName(),
genericFileResourceTD.getMimeType());
TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession, TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession,
new AsyncCallback<String>() { new AsyncCallback<String>() {

View File

@ -1,8 +1,11 @@
package org.gcube.portlets.user.td.resourceswidget.client.charts; package org.gcube.portlets.user.td.resourceswidget.client.charts;
import org.gcube.portlets.user.td.gwtservice.client.rpc.TDGWTServiceAsync;
import org.gcube.portlets.user.td.gwtservice.shared.exception.TDGWTSessionExpiredException;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.InternalURITD;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTD;
import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor; import org.gcube.portlets.user.td.gwtservice.shared.tr.resources.ResourceTDDescriptor;
import org.gcube.portlets.user.td.gwtservice.shared.uriresolver.UriResolverSession;
import org.gcube.portlets.user.td.resourceswidget.client.graphics.Vector2D; import org.gcube.portlets.user.td.resourceswidget.client.graphics.Vector2D;
import org.gcube.portlets.user.td.resourceswidget.client.properties.ZoomLevelPropertiesCombo; import org.gcube.portlets.user.td.resourceswidget.client.properties.ZoomLevelPropertiesCombo;
import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle; import org.gcube.portlets.user.td.resourceswidget.client.resources.ResourceBundle;
@ -10,7 +13,10 @@ import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelElement;
import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelStore; import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelStore;
import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelType; import org.gcube.portlets.user.td.resourceswidget.client.store.ZoomLevelType;
import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3; import org.gcube.portlets.user.td.resourceswidget.client.utils.UtilsGXT3;
import org.gcube.portlets.user.td.widgetcommonevent.client.event.SessionExpiredEvent;
import org.gcube.portlets.user.td.widgetcommonevent.client.type.SessionExpiredType;
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.uriresolver.ApplicationType;
import com.allen_sauer.gwt.log.client.Log; import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -28,6 +34,7 @@ import com.google.gwt.safehtml.shared.UriUtils;
import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window; import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.HasValue;
import com.google.web.bindery.event.shared.EventBus; import com.google.web.bindery.event.shared.EventBus;
import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction; import com.sencha.gxt.cell.core.client.form.ComboBoxCell.TriggerAction;
@ -69,8 +76,9 @@ public class ChartViewerPanel extends FramedPanel {
private static final String COMBO_ZOOM_LEVEL_WIDTH = "100px"; private static final String COMBO_ZOOM_LEVEL_WIDTH = "100px";
private static final int IMAGE_WIDTH = 1024; private static final int IMAGE_WIDTH = 1024;
private static final int IMAGE_HEIGHT = 768; private static final int IMAGE_HEIGHT = 768;
//private static final String RETRIEVE_CHART_FILE_SERVLET = "RetrieveChartFileServlet"; // private static final String RETRIEVE_CHART_FILE_SERVLET =
private static final String RETRIEVE_FILE_AND_DISCOVER_MIME_TYPE_SERVLET="RetrieveFileAndDiscoverMimeTypeServlet"; // "RetrieveChartFileServlet";
private static final String RETRIEVE_FILE_AND_DISCOVER_MIME_TYPE_SERVLET = "RetrieveFileAndDiscoverMimeTypeServlet";
private static final String ATTRIBUTE_STORAGE_URI = "storageURI"; private static final String ATTRIBUTE_STORAGE_URI = "storageURI";
private static final String WIDTH = "800px"; private static final String WIDTH = "800px";
@ -93,9 +101,13 @@ public class ChartViewerPanel extends FramedPanel {
private Vector2D displacement; private Vector2D displacement;
private ChartViewerDialog parent; private ChartViewerDialog parent;
private EventBus eventBus;
private ResourceTDDescriptor resourceTDDescriptor; private ResourceTDDescriptor resourceTDDescriptor;
private boolean test; private boolean test;
private InternalURITD internalURITD;
private String chartLink;
private ImageResource chartImageResource; private ImageResource chartImageResource;
private ImageResource testImageResource; private ImageResource testImageResource;
@ -133,19 +145,19 @@ public class ChartViewerPanel extends FramedPanel {
EventBus eventBus, boolean test) { EventBus eventBus, boolean test) {
super(); super();
ResourceBundle.INSTANCE.resourceCSS().ensureInjected(); ResourceBundle.INSTANCE.resourceCSS().ensureInjected();
this.eventBus = eventBus;
this.parent = parent; this.parent = parent;
this.resourceTDDescriptor = resourceTDDescriptor; this.resourceTDDescriptor = resourceTDDescriptor;
this.test = test; this.test = test;
forceLayoutOnResize = true; forceLayoutOnResize = true;
mask();
if (test) { if (test) {
testImageResource = ResourceBundle.INSTANCE.testImage(); testImageResource = ResourceBundle.INSTANCE.testImage();
create(); create();
} else { } else {
retrieveChart(); retrieveChart();
create();
} }
} }
public static String encodeUrlDelimiters(String s) { public static String encodeUrlDelimiters(String s) {
@ -167,7 +179,6 @@ public class ChartViewerPanel extends FramedPanel {
} }
protected void retrieveChart() { protected void retrieveChart() {
InternalURITD internalURITD;
ResourceTD resource = resourceTDDescriptor.getResourceTD(); ResourceTD resource = resourceTDDescriptor.getResourceTD();
if (resource instanceof InternalURITD) { if (resource instanceof InternalURITD) {
internalURITD = (InternalURITD) resource; internalURITD = (InternalURITD) resource;
@ -179,7 +190,42 @@ public class ChartViewerPanel extends FramedPanel {
return; return;
} }
Log.debug("InteranlURI: " + internalURITD); Log.debug("InteranlURI: " + internalURITD);
final String storageURI = encodeUrlDelimiters(internalURITD.getUrl()); retrieveUrlFromResolver();
}
protected void retrieveUrlFromResolver() {
UriResolverSession uriResolverSession = new UriResolverSession(
internalURITD.getUrl(), ApplicationType.SMP_ID,
resourceTDDescriptor.getName(), internalURITD.getMimeType());
TDGWTServiceAsync.INSTANCE.getUriFromResolver(uriResolverSession,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
if (caught instanceof TDGWTSessionExpiredException) {
eventBus.fireEvent(new SessionExpiredEvent(
SessionExpiredType.EXPIREDONSERVER));
} else {
Log.error("Error with uri resolver: "
+ caught.getLocalizedMessage());
UtilsGXT3.alert("Error",
"Error retrieving uri from resolver: "
+ caught.getLocalizedMessage());
}
}
public void onSuccess(String link) {
Log.debug("Retrieved link: " + link);
chartLink = link;
createChartImageResource();
}
});
}
protected void createChartImageResource() {
final String path = GWT.getModuleBaseURL() final String path = GWT.getModuleBaseURL()
+ RETRIEVE_FILE_AND_DISCOVER_MIME_TYPE_SERVLET; + RETRIEVE_FILE_AND_DISCOVER_MIME_TYPE_SERVLET;
@ -205,7 +251,7 @@ public class ChartViewerPanel extends FramedPanel {
public SafeUri getSafeUri() { public SafeUri getSafeUri() {
SafeUri uri = UriUtils.fromString(path + "?" SafeUri uri = UriUtils.fromString(path + "?"
+ ATTRIBUTE_STORAGE_URI + "=" + storageURI); + ATTRIBUTE_STORAGE_URI + "=" + chartLink);
Log.debug("Image uri:" + uri.asString()); Log.debug("Image uri:" + uri.asString());
return uri; return uri;
@ -233,11 +279,14 @@ public class ChartViewerPanel extends FramedPanel {
}; };
create();
} }
protected void create() { protected void create() {
init(); init();
createPanel(); createPanel();
unmask();
drawInit(); drawInit();
} }