2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view;
|
|
|
|
|
2016-11-02 23:19:49 +01:00
|
|
|
import java.util.HashMap;
|
2016-09-27 18:38:33 +02:00
|
|
|
import java.util.List;
|
2016-11-02 23:19:49 +01:00
|
|
|
import java.util.Map;
|
2016-06-29 16:50:18 +02:00
|
|
|
|
2021-04-09 15:39:48 +02:00
|
|
|
import org.gcube.datacatalogue.utillibrary.shared.RolesCkanGroupOrOrg;
|
2016-06-13 09:48:29 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GCubeCkanDataCatalog;
|
2018-02-04 12:05:22 +01:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.event.ShowRevertOperationWidgetEvent;
|
2016-06-13 09:48:29 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources;
|
2016-11-21 10:12:24 +01:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole;
|
2016-06-23 12:49:45 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
2021-06-15 18:37:17 +02:00
|
|
|
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductResponse;
|
2021-10-05 11:33:37 +02:00
|
|
|
import org.gcube.portlets.widgets.ckan2zenodopublisher.client.CkanToZenodoPublisherServiceAsync;
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-01 15:36:20 +02:00
|
|
|
import com.google.gwt.core.client.GWT;
|
2016-06-13 09:48:29 +02:00
|
|
|
import com.google.gwt.event.logical.shared.ResizeEvent;
|
|
|
|
import com.google.gwt.event.logical.shared.ResizeHandler;
|
|
|
|
import com.google.gwt.event.shared.HandlerManager;
|
2016-11-02 23:19:49 +01:00
|
|
|
import com.google.gwt.http.client.URL;
|
2016-11-29 17:20:50 +01:00
|
|
|
import com.google.gwt.json.client.JSONObject;
|
|
|
|
import com.google.gwt.json.client.JSONParser;
|
2017-04-07 16:16:32 +02:00
|
|
|
import com.google.gwt.json.client.JSONString;
|
2016-11-29 17:20:50 +01:00
|
|
|
import com.google.gwt.json.client.JSONValue;
|
2017-02-03 22:45:04 +01:00
|
|
|
import com.google.gwt.user.client.Cookies;
|
2016-06-13 09:48:29 +02:00
|
|
|
import com.google.gwt.user.client.Window;
|
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
import com.google.gwt.user.client.ui.Frame;
|
|
|
|
import com.google.gwt.user.client.ui.Image;
|
|
|
|
import com.google.gwt.user.client.ui.RootPanel;
|
|
|
|
import com.google.gwt.user.client.ui.ScrollPanel;
|
2016-06-29 16:50:18 +02:00
|
|
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class GCubeCkanDataCatalogPanel.
|
|
|
|
*
|
2016-07-15 18:19:05 +02:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 9, 2016
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public class GCubeCkanDataCatalogPanel extends BaseViewTemplate {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
|
|
|
private CkanMetadataManagementPanel managementPanel;
|
|
|
|
private ScrollPanel centerScrollable = new ScrollPanel();
|
2016-06-23 12:49:45 +02:00
|
|
|
private CkanFramePanel ckanFramePanel;
|
2016-06-29 16:50:18 +02:00
|
|
|
private CkanOrganizationsPanel ckanOrganizationsPanel;
|
2016-11-21 10:12:24 +01:00
|
|
|
private CkanGroupsPanel ckanGroupsPanel;
|
2016-06-13 09:48:29 +02:00
|
|
|
private Image loading = new Image(CkanPortletResources.ICONS.loading());
|
|
|
|
private RootPanel rootPanel;
|
|
|
|
private HandlerManager eventBus;
|
2016-06-23 18:30:01 +02:00
|
|
|
private CkanConnectorAccessPoint ckanAccessPoint;
|
2021-06-15 18:37:17 +02:00
|
|
|
private ManageProductResponse manageProductResponse = null;
|
2018-02-20 15:51:25 +01:00
|
|
|
private String viewPerVREPath = null;
|
2016-11-29 17:20:50 +01:00
|
|
|
private static String latestSelectedProductIdentifier;
|
2016-07-15 18:19:05 +02:00
|
|
|
public static final int IFRAME_FIX_HEIGHT = 1800;
|
2017-04-07 18:43:26 +02:00
|
|
|
private JSONObject obj;
|
2016-06-29 18:35:01 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
* Instantiates a new g cube ckan data catalog panel.
|
|
|
|
*
|
2021-06-15 18:37:17 +02:00
|
|
|
* @param rootPanel the root panel
|
|
|
|
* @param eventManager the event manager
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2021-06-15 18:37:17 +02:00
|
|
|
public GCubeCkanDataCatalogPanel(RootPanel rootPanel, HandlerManager eventManager) {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
this.rootPanel = rootPanel;
|
|
|
|
this.eventBus = eventManager;
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
// postMessage(obj.toString(), ckanFramePanel.getFrame());
|
2017-04-07 18:43:26 +02:00
|
|
|
// send message about gateway url
|
|
|
|
obj = new JSONObject();
|
|
|
|
String landingPageVREs = Window.Location.getProtocol() + "//" + Window.Location.getHostName() + "/explore";
|
|
|
|
JSONString value = new JSONString(landingPageVREs);
|
|
|
|
obj.put("explore_vres_landing_page", value);
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2016-06-23 12:49:45 +02:00
|
|
|
ckanFramePanel = new CkanFramePanel(eventBus);
|
2016-06-13 09:48:29 +02:00
|
|
|
managementPanel = new CkanMetadataManagementPanel(eventBus);
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanOrganizationsPanel = new CkanOrganizationsPanel(this);
|
2016-11-21 10:12:24 +01:00
|
|
|
ckanGroupsPanel = new CkanGroupsPanel(this);
|
2016-06-13 09:48:29 +02:00
|
|
|
initPanel();
|
2016-06-29 18:35:01 +02:00
|
|
|
setTopPanelVisible(true);
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2016-11-02 23:19:49 +01:00
|
|
|
// decode parameters (they could have been encoded)
|
2018-02-04 12:05:22 +01:00
|
|
|
final Map<String, String> paramsMap = new HashMap<String, String>(2);
|
2016-11-02 23:19:49 +01:00
|
|
|
String queryParameters = Window.Location.getQueryString();
|
2021-06-15 18:37:17 +02:00
|
|
|
if (queryParameters != null && !queryParameters.isEmpty()) {
|
2016-11-02 23:19:49 +01:00
|
|
|
String decoded = URL.decodeQueryString(queryParameters); // equals should be encoded too (%3D)
|
|
|
|
String[] params = decoded.substring(decoded.indexOf("?") + 1).split("&");
|
|
|
|
for (int i = 0; i < params.length; i++) {
|
|
|
|
String[] queryAndValue = params[i].split("=");
|
|
|
|
paramsMap.put(queryAndValue[0], queryAndValue[1]);
|
|
|
|
}
|
|
|
|
GWT.log("Extracted parameters are " + paramsMap);
|
|
|
|
}
|
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
String pathParameter = paramsMap.get(GCubeCkanDataCatalog.GET_PATH_PARAMETER); // Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER);
|
2016-11-02 23:19:49 +01:00
|
|
|
String queryParameter = paramsMap.get(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);// Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);
|
2016-09-14 16:42:46 +02:00
|
|
|
|
2020-07-03 17:15:11 +02:00
|
|
|
String browserLocationURL = getBrowserLocationURL();
|
2021-06-15 18:37:17 +02:00
|
|
|
|
|
|
|
GCubeCkanDataCatalog.service.getCKanConnector(browserLocationURL, pathParameter, queryParameter,
|
2016-07-20 19:14:46 +02:00
|
|
|
new AsyncCallback<CkanConnectorAccessPoint>() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-07-20 19:14:46 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(CkanConnectorAccessPoint ckan) {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
if (ckan.isOutsideLoginOnPortal()) {
|
2017-02-04 08:50:30 +01:00
|
|
|
|
|
|
|
// the portlet is outside the portal and no user is logged
|
|
|
|
// in show only home and statistics
|
|
|
|
managementPanel.doNotShowUserRelatedInfo();
|
|
|
|
|
2017-02-10 10:04:03 +01:00
|
|
|
// set the cookie as session cookie (removed on browser close)
|
|
|
|
Cookies.setCookie("ckan_hide_header", "true", null, ".d4science.org", "/", false);
|
2017-02-04 08:50:30 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the iframe url
|
2016-07-20 19:14:46 +02:00
|
|
|
ckanAccessPoint = ckan;
|
|
|
|
instanceCkanFrame(ckan.buildURI());
|
|
|
|
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
|
2021-06-15 18:37:17 +02:00
|
|
|
|
2020-07-03 17:15:11 +02:00
|
|
|
String browserLocationURL = getBrowserLocationURL();
|
2019-12-05 14:26:23 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
// check if view per organisation is enabled
|
|
|
|
// and performing some actions in this case (e.g. removed the management
|
|
|
|
// buttons, etc.)
|
|
|
|
GCubeCkanDataCatalog.service.isViewPerVREEnabled(browserLocationURL,
|
|
|
|
new AsyncCallback<String>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
GWT.log("isViewPerVREEnabled?: " + result);
|
|
|
|
if (result != null && !result.isEmpty()) {
|
|
|
|
// hide all management buttons
|
|
|
|
managementPanel.removeGenericManagementButtons();
|
|
|
|
// set real relative path
|
|
|
|
ckanAccessPoint.addPathInfo(result);
|
|
|
|
// save this information
|
|
|
|
viewPerVREPath = result;
|
|
|
|
}
|
|
|
|
}
|
2019-12-05 14:26:23 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-07-22 09:55:35 +02:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
// ?
|
2019-12-05 14:26:23 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
}
|
|
|
|
});
|
2019-12-05 14:26:23 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
if (!ckan.isOutsideLoginOnPortal()) {
|
2017-02-04 08:50:30 +01:00
|
|
|
|
|
|
|
// MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE
|
|
|
|
GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback<RolesCkanGroupOrOrg>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
showEditInsertButtons(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(RolesCkanGroupOrOrg result) {
|
|
|
|
switch (result) {
|
|
|
|
case ADMIN:
|
|
|
|
showEditInsertButtons(true);
|
|
|
|
break;
|
|
|
|
case EDITOR:
|
|
|
|
showEditInsertButtons(true);
|
|
|
|
break;
|
|
|
|
case MEMBER:
|
|
|
|
showEditInsertButtons(false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
showEditInsertButtons(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2017-02-04 08:50:30 +01:00
|
|
|
// retrieve organizations
|
2021-06-15 18:37:17 +02:00
|
|
|
GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(
|
|
|
|
new AsyncCallback<List<BeanUserInOrgGroupRole>>() {
|
2017-02-04 08:50:30 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(List<BeanUserInOrgGroupRole> result) {
|
|
|
|
ckanOrganizationsPanel.setOrganizations(result);
|
|
|
|
}
|
2016-07-22 09:55:35 +02:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
// an error message will be displayed
|
|
|
|
ckanOrganizationsPanel.setOrganizations(null);
|
|
|
|
}
|
|
|
|
});
|
2016-07-22 09:55:35 +02:00
|
|
|
|
2017-02-04 08:50:30 +01:00
|
|
|
// retrieve groups
|
2021-06-15 18:37:17 +02:00
|
|
|
GCubeCkanDataCatalog.service.getCkanGroupsNamesAndUrlsForUser(
|
|
|
|
new AsyncCallback<List<BeanUserInOrgGroupRole>>() {
|
2017-02-03 22:45:04 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
@Override
|
|
|
|
public void onSuccess(List<BeanUserInOrgGroupRole> result) {
|
|
|
|
ckanGroupsPanel.setGroups(result);
|
|
|
|
}
|
2017-01-26 18:47:46 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
ckanGroupsPanel.setGroups(null);
|
|
|
|
}
|
|
|
|
});
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2018-02-04 12:05:22 +01:00
|
|
|
// check if the url encodes a revert operation to be performed
|
2021-06-15 18:37:17 +02:00
|
|
|
if (paramsMap.containsKey(GCubeCkanDataCatalog.REVERT_QUERY_PARAM)
|
|
|
|
&& paramsMap.get(GCubeCkanDataCatalog.REVERT_QUERY_PARAM).equals("true")) {
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2018-02-04 12:05:22 +01:00
|
|
|
eventBus.fireEvent(new ShowRevertOperationWidgetEvent(Window.Location.getHref()));
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2018-02-04 12:05:22 +01:00
|
|
|
}
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2017-02-04 08:50:30 +01:00
|
|
|
/**
|
|
|
|
* Just check if it is enabled.. then we need to listen for dom events coming
|
|
|
|
*/
|
2021-06-15 18:37:17 +02:00
|
|
|
GCubeCkanDataCatalog.service
|
|
|
|
.isManageProductEnabled(new AsyncCallback<ManageProductResponse>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(ManageProductResponse result) {
|
|
|
|
manageProductResponse = result;
|
|
|
|
if (manageProductResponse != null) {
|
|
|
|
|
|
|
|
if(manageProductResponse.isGRSFManageEnabled()) {
|
|
|
|
managementPanel.showManageCMSProductsButton(
|
|
|
|
manageProductResponse.isManageEnabled());
|
|
|
|
}else if(manageProductResponse.isManageEnabled()) {
|
|
|
|
managementPanel.showManageCMSProductsButton(manageProductResponse.isManageEnabled());
|
|
|
|
managementPanel.enableManageCMSProductsButton(manageProductResponse.isManageEnabled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
managementPanel.showManageGRSFProductButton(false);
|
|
|
|
}
|
|
|
|
});
|
2017-02-04 08:50:30 +01:00
|
|
|
|
|
|
|
}
|
2016-07-22 09:55:35 +02:00
|
|
|
|
2016-07-20 19:14:46 +02:00
|
|
|
}
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-20 19:14:46 +02:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2016-06-29 18:35:01 +02:00
|
|
|
|
2016-07-20 19:14:46 +02:00
|
|
|
GCubeCkanDataCatalogPanel.this.rootPanel.remove(loading);
|
|
|
|
Window.alert("Sorry, An error occurred during contacting Gcube Ckan Data Catalogue!");
|
|
|
|
}
|
|
|
|
});
|
2016-07-22 09:56:20 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
Window.addResizeHandler(new ResizeHandler() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResize(ResizeEvent event) {
|
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
GWT.log("onWindowResized width: " + event.getWidth() + " height: " + event.getHeight());
|
2016-06-13 09:48:29 +02:00
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
});
|
2016-07-22 09:56:20 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
rootPanel.add(loading);
|
|
|
|
rootPanel.add(this);
|
|
|
|
updateSize();
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2017-04-07 16:16:32 +02:00
|
|
|
// listen for DOM messages
|
2016-07-18 11:34:34 +02:00
|
|
|
listenForPostMessage();
|
2017-04-07 18:43:26 +02:00
|
|
|
|
2021-10-05 11:33:37 +02:00
|
|
|
|
|
|
|
CkanToZenodoPublisherServiceAsync.Util.getInstance().checkZenodoEnvironment(new AsyncCallback<Boolean>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
managementPanel.visibilityPublishOnZenodoButton(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(Boolean result) {
|
|
|
|
GWT.log("checkZenodoEnvironment result: "+result);
|
|
|
|
managementPanel.visibilityPublishOnZenodoButton(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
2021-06-15 18:37:17 +02:00
|
|
|
|
2020-07-03 17:15:11 +02:00
|
|
|
/**
|
|
|
|
* Gets the browser location URL.
|
|
|
|
*
|
|
|
|
* @return the browser location URL
|
|
|
|
*/
|
|
|
|
public String getBrowserLocationURL() {
|
2021-06-15 18:37:17 +02:00
|
|
|
|
2020-07-03 17:15:11 +02:00
|
|
|
String browserLocationURL = null;
|
2021-06-15 18:37:17 +02:00
|
|
|
|
2020-07-03 17:15:11 +02:00
|
|
|
try {
|
|
|
|
browserLocationURL = Window.Location.getHref();
|
2021-06-15 18:37:17 +02:00
|
|
|
} catch (Exception e) {
|
2020-07-03 17:15:11 +02:00
|
|
|
// silent
|
|
|
|
}
|
2021-06-15 18:37:17 +02:00
|
|
|
|
|
|
|
GWT.log("Returning browserLocationURL: " + browserLocationURL);
|
2020-07-03 17:15:11 +02:00
|
|
|
return browserLocationURL;
|
|
|
|
}
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
public static String getLatestSelectedProductIdentifier() {
|
2016-11-29 17:20:50 +01:00
|
|
|
return latestSelectedProductIdentifier;
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
* Gets the top panel height.
|
|
|
|
*
|
|
|
|
* @return the top panel height
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public int getTopPanelHeight() {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
if (managementPanel.isVisible())
|
2016-06-13 09:48:29 +02:00
|
|
|
return managementPanel.getCurrentHeight();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the top panel visible.
|
|
|
|
*
|
2021-06-15 18:37:17 +02:00
|
|
|
* @param bool the new top panel visible
|
2016-06-13 09:48:29 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public void setTopPanelVisible(boolean bool) {
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
managementPanel.setVisible(bool);
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2016-06-22 16:23:51 +02:00
|
|
|
/**
|
2016-06-23 12:49:45 +02:00
|
|
|
* show or hide edit/insert buttons according to the role.
|
|
|
|
*
|
2021-06-15 18:37:17 +02:00
|
|
|
* @param show the show
|
2016-06-22 16:23:51 +02:00
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public void showEditInsertButtons(boolean show) {
|
|
|
|
|
2016-06-22 16:23:51 +02:00
|
|
|
managementPanel.showInsertAndEditProductButtons(show);
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
/**
|
|
|
|
* Instance ckan frame.
|
|
|
|
*
|
2021-06-15 18:37:17 +02:00
|
|
|
* @param ckanUrlConnector the ckan url connector
|
2016-06-13 09:48:29 +02:00
|
|
|
* @return the frame
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public Frame instanceCkanFrame(String ckanUrlConnector) {
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanFramePanel.setVisible(true);
|
|
|
|
ckanOrganizationsPanel.setVisible(false);
|
2016-11-21 10:12:24 +01:00
|
|
|
ckanGroupsPanel.setVisible(false);
|
2017-04-07 18:43:26 +02:00
|
|
|
return ckanFramePanel.instanceFrame(ckanUrlConnector, obj.toString(), ckanAccessPoint.getBaseUrl());
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits the panel.
|
|
|
|
*/
|
|
|
|
private void initPanel() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
setTopPanelVisible(false);
|
|
|
|
addToTop(managementPanel);
|
2016-06-29 16:50:18 +02:00
|
|
|
VerticalPanel containerIntoScrollPanel = new VerticalPanel();
|
|
|
|
containerIntoScrollPanel.setWidth("100%");
|
|
|
|
containerIntoScrollPanel.add(ckanFramePanel);
|
|
|
|
containerIntoScrollPanel.add(ckanOrganizationsPanel);
|
2016-11-21 10:12:24 +01:00
|
|
|
containerIntoScrollPanel.add(ckanGroupsPanel);
|
2016-06-29 16:50:18 +02:00
|
|
|
centerScrollable.add(containerIntoScrollPanel);
|
|
|
|
ckanOrganizationsPanel.setVisible(false);
|
2016-06-22 16:23:51 +02:00
|
|
|
addToMiddle(centerScrollable);
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update window size.
|
|
|
|
*/
|
2016-07-15 18:19:05 +02:00
|
|
|
public void updateSize() {
|
2021-06-15 18:37:17 +02:00
|
|
|
/*
|
|
|
|
* RootPanel workspace = rootPanel; int topBorder = workspace.getAbsoluteTop();
|
|
|
|
* GWT.log("top: "+topBorder); int footer = 30; // 85 footer is bottombar +
|
|
|
|
* sponsor int rootHeight = Window.getClientHeight() - topBorder - 5 - footer;
|
|
|
|
* int height = rootHeight - getTopPanelHeight(); if (ckanFramePanel.getFrame()
|
|
|
|
* != null) { int newH =managementPanel != null &&
|
|
|
|
* managementPanel.getCurrentHeight() > 0 ? managementPanel.getOffsetHeight() +
|
|
|
|
* height : height; ckanFramePanel.getFrame().setHeight(2000+"px"); }
|
|
|
|
*/
|
2016-06-13 09:48:29 +02:00
|
|
|
|
2016-07-15 18:19:05 +02:00
|
|
|
RootPanel workspace = this.rootPanel;
|
2016-06-22 16:23:51 +02:00
|
|
|
int topBorder = workspace.getAbsoluteTop();
|
2016-07-15 18:19:05 +02:00
|
|
|
int footer = 55;
|
|
|
|
int rootHeight = Window.getClientHeight() - topBorder - 5 - footer;
|
2016-06-22 16:23:51 +02:00
|
|
|
int height = rootHeight - getTopPanelHeight();
|
2016-07-15 18:19:05 +02:00
|
|
|
if (this.ckanFramePanel.getFrame() != null) {
|
2021-06-15 18:37:17 +02:00
|
|
|
int newH = this.managementPanel != null && this.managementPanel.getCurrentHeight() > 0
|
|
|
|
? this.managementPanel.getOffsetHeight() + height
|
|
|
|
: height;
|
2016-07-18 11:42:22 +02:00
|
|
|
this.ckanFramePanel.getFrame().setHeight(newH + "px");
|
2016-06-23 18:30:01 +02:00
|
|
|
}
|
2021-06-15 18:37:17 +02:00
|
|
|
// workspace.setHeight(height+"px");
|
2016-06-22 16:23:51 +02:00
|
|
|
}
|
2016-06-22 18:40:38 +02:00
|
|
|
|
2017-02-15 18:49:48 +01:00
|
|
|
/**
|
|
|
|
* Print a message
|
2021-06-15 18:37:17 +02:00
|
|
|
*
|
2017-02-15 18:49:48 +01:00
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
protected native void printString(String string) /*-{
|
|
|
|
console.log(string);
|
|
|
|
}-*/;
|
2016-07-18 11:34:34 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen for post message.
|
|
|
|
*/
|
|
|
|
private final native void listenForPostMessage() /*-{
|
2021-06-15 18:37:17 +02:00
|
|
|
var that = this;
|
|
|
|
$wnd
|
|
|
|
.addEventListener(
|
|
|
|
"message",
|
|
|
|
function(msg) {
|
|
|
|
console.log("read message...");
|
|
|
|
that.@org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.view.GCubeCkanDataCatalogPanel::onPostMessage(Ljava/lang/String;Ljava/lang/String;)(msg.data, msg.origin);
|
|
|
|
});
|
2016-07-18 11:34:34 +02:00
|
|
|
}-*/;
|
2017-04-07 18:43:26 +02:00
|
|
|
|
2016-07-18 11:34:34 +02:00
|
|
|
/**
|
|
|
|
* On post message.
|
|
|
|
*
|
2021-06-15 18:37:17 +02:00
|
|
|
* @param data the data
|
2016-07-18 11:34:34 +02:00
|
|
|
* @param origin the origin
|
|
|
|
*/
|
|
|
|
private void onPostMessage(String data, String origin) {
|
2021-06-15 18:37:17 +02:00
|
|
|
printString("Read data: " + data + ", from origin: " + origin);
|
|
|
|
printString("Ckan base url: " + ckanAccessPoint.getBaseUrl());
|
2016-07-18 11:34:34 +02:00
|
|
|
|
2016-11-29 17:20:50 +01:00
|
|
|
// parsing data.. it is a json bean of the type
|
2017-04-07 18:43:26 +02:00
|
|
|
printString("Incoming message is " + data + " from " + origin);
|
2016-11-29 17:20:50 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
if (ckanAccessPoint.getBaseUrl().indexOf(origin) >= 0) {
|
2016-07-20 19:14:46 +02:00
|
|
|
// The data has been sent from your site
|
|
|
|
// The data sent with postMessage is stored in event.data
|
2016-11-29 17:20:50 +01:00
|
|
|
String height = null;
|
|
|
|
String productId = null;
|
2016-11-30 16:06:13 +01:00
|
|
|
boolean isProductKeyMissing = false;
|
2016-11-29 17:20:50 +01:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
try {
|
2016-11-29 17:20:50 +01:00
|
|
|
JSONValue parsedJSON = JSONParser.parseStrict(data);
|
|
|
|
JSONObject object = parsedJSON.isObject();
|
2016-11-29 18:42:27 +01:00
|
|
|
GWT.log("Object is " + object);
|
2021-06-15 18:37:17 +02:00
|
|
|
if (object != null) {
|
|
|
|
// Supporting Task #12286: parsing the translate values for 'dataset',
|
|
|
|
// 'organization' and so on
|
|
|
|
if (object.containsKey("translate")) {
|
2018-08-30 15:19:49 +02:00
|
|
|
JSONObject theTranslate = (JSONObject) object.get("translate");
|
2018-08-30 17:35:45 +02:00
|
|
|
GWT.log("theTranslate is " + object);
|
2018-08-30 15:19:49 +02:00
|
|
|
for (String key : theTranslate.keySet()) {
|
2021-06-15 18:37:17 +02:00
|
|
|
// GWT.log("theTranslate key " + key);
|
2018-08-30 17:35:45 +02:00
|
|
|
String value = theTranslate.get(key).isString().stringValue();
|
2021-06-15 18:37:17 +02:00
|
|
|
printString("Customizing navigation link '" + key + "' with translate: " + value);
|
|
|
|
managementPanel.customizeLabelAccordingTranslate(key, value);
|
2018-08-30 15:19:49 +02:00
|
|
|
}
|
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
} else if (object.containsKey("height")) {
|
2018-08-30 15:19:49 +02:00
|
|
|
|
|
|
|
height = object.get("height").isString().stringValue();
|
2021-06-15 18:37:17 +02:00
|
|
|
if (object.containsKey("product"))
|
2018-08-30 15:19:49 +02:00
|
|
|
productId = object.get("product").isString().stringValue();
|
|
|
|
else
|
|
|
|
isProductKeyMissing = true;
|
|
|
|
}
|
2016-11-29 17:20:50 +01:00
|
|
|
}
|
2021-06-15 18:37:17 +02:00
|
|
|
} catch (Exception e) {
|
2016-11-29 18:42:27 +01:00
|
|
|
GWT.log("Exception is " + e);
|
2016-11-29 17:20:50 +01:00
|
|
|
}
|
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
if (height != null)
|
2016-11-29 17:20:50 +01:00
|
|
|
setIFrameHeight(height.toString());
|
|
|
|
|
|
|
|
// show or hide the manage product button
|
2021-06-15 18:37:17 +02:00
|
|
|
if (!isProductKeyMissing) {
|
2016-11-30 16:06:13 +01:00
|
|
|
latestSelectedProductIdentifier = productId.toString();
|
2017-04-03 16:43:36 +02:00
|
|
|
managementPanel.enableShareItemButton(productId != null && !productId.isEmpty());
|
2019-12-09 12:33:01 +01:00
|
|
|
managementPanel.enablePublishOnZenodoButton(productId != null && !productId.isEmpty());
|
2021-06-15 18:37:17 +02:00
|
|
|
managementPanel.enableManageGRSFProductButton(
|
|
|
|
productId != null && !productId.isEmpty() && manageProductResponse.isGRSFManageEnabled());
|
2016-11-30 16:06:13 +01:00
|
|
|
}
|
2016-07-20 19:14:46 +02:00
|
|
|
} else {
|
|
|
|
// The data hasn't been sent from your site!
|
|
|
|
// Be careful! Do not use it.
|
|
|
|
return;
|
|
|
|
}
|
2016-07-18 11:34:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the i frame height.
|
|
|
|
*
|
|
|
|
* @param height the new i frame height
|
|
|
|
*/
|
2021-06-15 18:37:17 +02:00
|
|
|
private void setIFrameHeight(String height) {
|
2016-07-18 11:34:34 +02:00
|
|
|
String parsedHeight = null;
|
2021-06-15 18:37:17 +02:00
|
|
|
if (height == null || height.isEmpty())
|
2016-07-18 11:34:34 +02:00
|
|
|
return;
|
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
if (height.contains("px")) {
|
2016-07-18 11:34:34 +02:00
|
|
|
parsedHeight = height;
|
2021-06-15 18:37:17 +02:00
|
|
|
} else {
|
|
|
|
try {
|
2016-07-18 11:34:34 +02:00
|
|
|
int intH = Integer.parseInt(height);
|
|
|
|
parsedHeight = intH + " px";
|
2021-06-15 18:37:17 +02:00
|
|
|
} catch (Exception e) {
|
2016-07-18 11:34:34 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
if (parsedHeight != null) {
|
|
|
|
GWT.log("Setting new height for ckan iFrame: " + height);
|
2016-07-18 11:34:34 +02:00
|
|
|
this.ckanFramePanel.getFrame().setHeight(height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 18:40:38 +02:00
|
|
|
/**
|
2016-06-23 12:49:45 +02:00
|
|
|
* Gets the base urlckan connector.
|
|
|
|
*
|
2016-06-23 18:30:01 +02:00
|
|
|
* @return the base urlckan connector
|
2016-06-22 18:40:38 +02:00
|
|
|
*/
|
|
|
|
public String getBaseURLCKANConnector() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-07-01 16:51:51 +02:00
|
|
|
return ckanAccessPoint.getBaseUrlWithContext();
|
2016-06-22 18:40:38 +02:00
|
|
|
}
|
2017-04-07 16:16:32 +02:00
|
|
|
|
2017-02-15 18:49:48 +01:00
|
|
|
/**
|
|
|
|
* Return the catalogue url (e.g. http://ckan-d-d4s.d4science.org:443/)
|
2021-06-15 18:37:17 +02:00
|
|
|
*
|
2017-02-15 18:49:48 +01:00
|
|
|
* @return
|
|
|
|
*/
|
2021-06-15 18:37:17 +02:00
|
|
|
public String getCatalogueUrl() {
|
2017-04-07 16:16:32 +02:00
|
|
|
|
2017-02-15 18:49:48 +01:00
|
|
|
printString("Base url for iframe is " + ckanAccessPoint.getCatalogueBaseUrl());
|
|
|
|
return ckanAccessPoint.getCatalogueBaseUrl();
|
|
|
|
}
|
2016-06-23 12:49:45 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the gcube token value to ckan connector.
|
|
|
|
*
|
|
|
|
* @return the gcube token value to ckan connector
|
|
|
|
*/
|
|
|
|
public String getGcubeTokenValueToCKANConnector() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-23 18:30:01 +02:00
|
|
|
return ckanAccessPoint.getGcubeTokenValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the path info.
|
|
|
|
*
|
|
|
|
* @return the path info
|
|
|
|
*/
|
|
|
|
public String getPathInfo() {
|
2016-07-15 18:19:05 +02:00
|
|
|
|
2016-06-23 18:30:01 +02:00
|
|
|
return ckanAccessPoint.getPathInfoParameter();
|
2016-06-23 12:49:45 +02:00
|
|
|
}
|
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
/**
|
2016-07-15 18:19:05 +02:00
|
|
|
* Show the organizations panel.
|
2016-06-29 16:50:18 +02:00
|
|
|
*/
|
|
|
|
public void showOrganizations() {
|
2016-06-29 18:35:01 +02:00
|
|
|
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanOrganizationsPanel.setVisible(true);
|
2016-11-21 10:12:24 +01:00
|
|
|
ckanGroupsPanel.setVisible(false);
|
|
|
|
ckanFramePanel.setVisible(false);
|
|
|
|
}
|
2016-11-29 17:20:50 +01:00
|
|
|
|
2016-11-21 10:12:24 +01:00
|
|
|
/**
|
|
|
|
* Show the groups panel.
|
|
|
|
*/
|
|
|
|
public void showGroups() {
|
|
|
|
|
|
|
|
ckanGroupsPanel.setVisible(true);
|
|
|
|
ckanOrganizationsPanel.setVisible(false);
|
2016-06-29 16:50:18 +02:00
|
|
|
ckanFramePanel.setVisible(false);
|
|
|
|
}
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2017-10-31 12:17:44 +01:00
|
|
|
/**
|
|
|
|
* Show management panel
|
2021-06-15 18:37:17 +02:00
|
|
|
*
|
2017-10-31 12:17:44 +01:00
|
|
|
* @param show
|
|
|
|
*/
|
2021-06-15 18:37:17 +02:00
|
|
|
public void showManagementPanel(boolean show) {
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2021-06-15 18:37:17 +02:00
|
|
|
managementPanel.showManageGRSFProductButton(show);
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2017-10-31 12:17:44 +01:00
|
|
|
}
|
2018-02-20 15:51:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the view per vre is enabled
|
|
|
|
*/
|
|
|
|
public boolean isViewPerVREEnabled() {
|
|
|
|
return viewPerVREPath != null;
|
|
|
|
}
|
2018-08-30 15:19:49 +02:00
|
|
|
|
2016-06-13 09:48:29 +02:00
|
|
|
}
|