trying to set CONTEXT_ID_PARAMETER
This commit is contained in:
parent
2fae3ee31a
commit
7d4e363c9f
|
@ -16,17 +16,11 @@ import com.google.gwt.i18n.client.DateTimeFormat;
|
|||
*/
|
||||
public class GeoportalDataViewerConstants {
|
||||
|
||||
// //WAITING_SERVER_ACTION_SERVLET
|
||||
// public static final String WAITING_PARAMETER = "waiting";
|
||||
// public static final String ACTION_TITLE_PARAMETER = "action";
|
||||
// public static final String MESSAGE_PARAMETER = "message";
|
||||
// public static final String WAITING_SERVER_ACTION_SERVLET = GWT.getModuleBaseURL()
|
||||
// + "geoportaldataviewerwaitingservice";
|
||||
|
||||
//WAITING_SERVER_ACTION_SERVLET
|
||||
//Geoportal_Exporter_ACTION_SERVLET
|
||||
public static final String UCD_ID_PARAMETER = "ucdID";
|
||||
public static final String PROIECT_ID_PARAMETER = "projectID";
|
||||
public static final String CONTEXT_ID_PARAMETER = "contextID";
|
||||
public static final String CONTEXT_ID_PARAMETER = "contex_id";
|
||||
public static final String USER_ID_PARAMETER = "user_id";
|
||||
public static final String GEOPORTAL_EXPORT_ACTION_SERVLET = GWT.getModuleBaseURL()
|
||||
+ "geoportalexporterservice";
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.events.AddLayerToMapEv
|
|||
import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEvent;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.events.TimelineProjectRelationsEvent.EVENT_TYPE;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.gis.MapUtils;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.resources.GeoportalImages;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.ModalWindow;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.dialogs.DialogShareableLink;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.ExtentMapUtil;
|
||||
|
@ -24,6 +25,7 @@ import org.gcube.portlets.user.geoportaldataviewer.client.ui.map.MapView;
|
|||
import org.gcube.portlets.user.geoportaldataviewer.client.util.NewBrowserWindow;
|
||||
|
||||
import com.github.gwtbootstrap.client.ui.Button;
|
||||
import com.github.gwtbootstrap.client.ui.Modal;
|
||||
import com.github.gwtbootstrap.client.ui.constants.ButtonType;
|
||||
import com.github.gwtbootstrap.client.ui.constants.IconType;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
|
@ -31,14 +33,22 @@ import com.google.gwt.dom.client.UListElement;
|
|||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.http.client.Request;
|
||||
import com.google.gwt.http.client.RequestBuilder;
|
||||
import com.google.gwt.http.client.RequestBuilder.Method;
|
||||
import com.google.gwt.http.client.RequestCallback;
|
||||
import com.google.gwt.http.client.RequestException;
|
||||
import com.google.gwt.http.client.Response;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.user.client.Random;
|
||||
import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.FlowPanel;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
|
||||
import ol.Coordinate;
|
||||
|
@ -223,18 +233,63 @@ public class ProjectViewer extends Composite {
|
|||
// TODO: handle exception
|
||||
}
|
||||
|
||||
// Reading contextId and userId from GCubeClientContext
|
||||
String currentContextId = GCubeClientContext.getCurrentContextId();
|
||||
String currentUserId = GCubeClientContext.getCurrentUserId();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(GeoportalDataViewerConstants.GEOPORTAL_EXPORT_ACTION_SERVLET + "?");
|
||||
builder.append(GeoportalDataViewerConstants.UCD_ID_PARAMETER + "="
|
||||
+ projectView.getTheProjectDV().getProfileID() + "&");
|
||||
+ projectView.getTheProjectDV().getProfileID());
|
||||
builder.append("&");
|
||||
builder.append(GeoportalDataViewerConstants.PROIECT_ID_PARAMETER + "="
|
||||
+ projectView.getTheProjectDV().getId() + "&");
|
||||
+ projectView.getTheProjectDV().getId());
|
||||
builder.append("&");
|
||||
builder.append(GeoportalDataViewerConstants.CONTEXT_ID_PARAMETER + "=" + currentContextId);
|
||||
builder.append("&");
|
||||
builder.append(GeoportalDataViewerConstants.USER_ID_PARAMETER + "=" + currentUserId);
|
||||
|
||||
String geoportalExportActionServlet = builder.toString();
|
||||
NewBrowserWindow.open(geoportalExportActionServlet, "_blank", null);
|
||||
|
||||
// Method httpMethod = RequestBuilder.GET;
|
||||
// RequestBuilder requestBuilder = new RequestBuilder(httpMethod, geoportalExportActionServlet);
|
||||
|
||||
NewBrowserWindow.open(geoportalExportActionServlet, "_blank", "");
|
||||
|
||||
// try {
|
||||
// requestBuilder.sendRequest("", new RequestCallback() {
|
||||
//
|
||||
// @Override
|
||||
// public void onResponseReceived(Request request, Response response) {
|
||||
// newBrowserWindow.setUrl(geoportalExportActionServlet);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Request request, Throwable exception) {
|
||||
// newBrowserWindow.close();
|
||||
// Modal errorModal = new Modal(true, true);
|
||||
// errorModal.setCloseVisible(true);
|
||||
// errorModal.setTitle("Oops...");
|
||||
// Image geoportalError = new Image(GeoportalImages.ICONS.warningError());
|
||||
// FlowPanel errorPanelMsg = new FlowPanel();
|
||||
// errorPanelMsg.getElement().addClassName("general_warning");
|
||||
// errorPanelMsg.add(geoportalError);
|
||||
// errorPanelMsg.add(new HTML("D4S GeoPortal"));
|
||||
// HTML erroMessage = new HTML(
|
||||
// "Oops something went wrong, error occurred when exporting the project. Error is: "
|
||||
// + exception.getMessage());
|
||||
// errorPanelMsg.add(erroMessage);
|
||||
// errorModal.add(errorPanelMsg);
|
||||
// errorModal.show();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// } catch (RequestException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer.client.ui.util;
|
||||
|
||||
import com.google.gwt.core.client.JavaScriptObject;
|
||||
|
||||
/**
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa{@literal @}isti.cnr.it
|
||||
* Sep 4, 2013
|
||||
*
|
||||
*/
|
||||
public final class NewBrowserWindow extends JavaScriptObject {
|
||||
// All types that extend JavaScriptObject must have a protected,
|
||||
// no-args constructor.
|
||||
protected NewBrowserWindow() {
|
||||
}
|
||||
|
||||
public static native NewBrowserWindow open(String url, String target,
|
||||
String options) /*-{
|
||||
return $wnd.open(url, target, options);
|
||||
}-*/;
|
||||
|
||||
public native void close() /*-{
|
||||
this.close();
|
||||
}-*/;
|
||||
|
||||
public native void setUrl(String url) /*-{
|
||||
if (this.location) {
|
||||
this.location = url;
|
||||
}
|
||||
}-*/;
|
||||
}
|
||||
|
|
@ -21,7 +21,6 @@ import org.gcube.common.scope.api.ScopeProvider;
|
|||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy;
|
||||
import org.gcube.portlets.user.uriresolvermanager.geoportal.GeoportalExporterAPI;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -62,22 +61,28 @@ public class GeoportalExporterActionServlet extends HttpServlet {
|
|||
String projectID = req.getParameter(GeoportalDataViewerConstants.PROIECT_ID_PARAMETER);
|
||||
String ucdID = req.getParameter(GeoportalDataViewerConstants.UCD_ID_PARAMETER);
|
||||
String contextID = req.getParameter(GeoportalDataViewerConstants.CONTEXT_ID_PARAMETER);
|
||||
logger.info("doGet called with [projectID: " + projectID + ", ucdID: " + ucdID + ", contextID: " + contextID + "]");
|
||||
|
||||
if(contextID==null || contextID.isEmpty())
|
||||
String userID = req.getParameter(GeoportalDataViewerConstants.USER_ID_PARAMETER);
|
||||
logger.info("doGet called with [projectID: " + projectID + ", ucdID: " + ucdID + ", contextID: " + contextID
|
||||
+ ", userID: " + userID + "]");
|
||||
|
||||
if (contextID == null || contextID.isEmpty())
|
||||
sendError(resp, "Bad Request. No context found!");
|
||||
|
||||
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
String scope = pContext.getCurrentScope(contextID);
|
||||
logger.info("The scope is {}", scope);
|
||||
|
||||
|
||||
try {
|
||||
//Setting header required to {@PortalContext}
|
||||
MutableHttpServletRequest mutableRequest = new MutableHttpServletRequest(req);
|
||||
mutableRequest.putHeader(PortalContext.VRE_ID_ATTR_NAME, contextID);
|
||||
// mutableRequest.putHeader(PortalContext.USER_ID_ATTR_NAME, contextID);
|
||||
ScopeProvider.instance.set(scope);
|
||||
GeoportalServiceIdentityProxy identity = new GeoportalServiceIdentityProxy(req);
|
||||
GeoportalServiceIdentityProxy identity = new GeoportalServiceIdentityProxy(mutableRequest);
|
||||
String theToken = identity.getToken();
|
||||
String theIdentity = identity.getIdentity();
|
||||
logger.info("The identity is {}", theIdentity);
|
||||
|
||||
|
||||
GeoportalExporterAPI geoportalExporterAPI = new GeoportalExporterAPI();
|
||||
URL urlRequest = geoportalExporterAPI.exportProject("pdf", ucdID, projectID, false);
|
||||
String urlToRedirect = urlRequest.toString();
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package org.gcube.portlets.user.geoportaldataviewer.server;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
|
||||
final class MutableHttpServletRequest extends HttpServletRequestWrapper {
|
||||
// holds custom header and value mapping
|
||||
private final Map<String, String> customHeaders;
|
||||
|
||||
public MutableHttpServletRequest(HttpServletRequest request){
|
||||
super(request);
|
||||
this.customHeaders = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public void putHeader(String name, String value){
|
||||
this.customHeaders.put(name, value);
|
||||
}
|
||||
|
||||
public String getHeader(String name) {
|
||||
// check the custom headers first
|
||||
String headerValue = customHeaders.get(name);
|
||||
|
||||
if (headerValue != null){
|
||||
return headerValue;
|
||||
}
|
||||
// else return from into the original wrapped object
|
||||
return ((HttpServletRequest) getRequest()).getHeader(name);
|
||||
}
|
||||
|
||||
public Enumeration<String> getHeaderNames() {
|
||||
// create a set of the custom header names
|
||||
Set<String> set = new HashSet<String>(customHeaders.keySet());
|
||||
|
||||
// now add the headers from the wrapped request object
|
||||
@SuppressWarnings("unchecked")
|
||||
Enumeration<String> e = ((HttpServletRequest) getRequest()).getHeaderNames();
|
||||
while (e.hasMoreElements()) {
|
||||
// add the names of the request headers into the list
|
||||
String n = e.nextElement();
|
||||
set.add(n);
|
||||
}
|
||||
|
||||
// create an enumeration from the set and return
|
||||
return Collections.enumeration(set);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue