diff --git a/src/main/java/org/gcube/portal/knime/KNIMEAppConfigurationAction.java b/src/main/java/org/gcube/portal/knime/KNIMEAppConfigurationAction.java new file mode 100644 index 0000000..79c702e --- /dev/null +++ b/src/main/java/org/gcube/portal/knime/KNIMEAppConfigurationAction.java @@ -0,0 +1,39 @@ +package org.gcube.portal.knime; + +import javax.portlet.ActionRequest; +import javax.portlet.ActionResponse; +import javax.portlet.PortletConfig; +import javax.portlet.PortletPreferences; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.portlet.DefaultConfigurationAction; + +public class KNIMEAppConfigurationAction extends DefaultConfigurationAction { + private static Log _log = LogFactoryUtil.getLog(KNIMEAppConfigurationAction.class); + @Override + public void processAction( + PortletConfig portletConfig, ActionRequest actionRequest, + ActionResponse actionResponse) throws Exception { + + super.processAction(portletConfig, actionRequest, actionResponse); + + PortletPreferences prefs = actionRequest.getPreferences(); + String appURL = prefs.getValue("KNIMEAppURL", "true"); + String appURLTokenParam = prefs.getValue("KNIMEAppURLTokenParam", "true"); + + _log.debug("KNIMEAppURL = " + appURL + " in PublicWebappConfigurationAction.processAction()."); + _log.debug("KNIMEAppURLTokenParam = " + appURLTokenParam + " in PublicWebappConfigurationAction.processAction()."); + } + + @Override + public String render(PortletConfig portletConfig, + RenderRequest renderRequest, RenderResponse renderResponse) + throws Exception { + + return "/html/knimeappintegration/config.jsp"; + } + +} \ No newline at end of file diff --git a/src/main/java/org/gcube/portal/knime/KNIMEAppIntegration.java b/src/main/java/org/gcube/portal/knime/KNIMEAppIntegration.java new file mode 100644 index 0000000..8ae127b --- /dev/null +++ b/src/main/java/org/gcube/portal/knime/KNIMEAppIntegration.java @@ -0,0 +1,103 @@ +package org.gcube.portal.knime; + +import static org.gcube.common.authorization.client.Constants.authorizationService; + +import java.io.IOException; + +import javax.portlet.PortletException; +import javax.portlet.PortletRequestDispatcher; +import javax.portlet.RenderRequest; +import javax.portlet.RenderResponse; + +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; + +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.service.UserLocalServiceUtil; +import com.liferay.portal.util.PortalUtil; +import com.liferay.util.bridges.mvc.MVCPortlet; + +/** + * Portlet implementation class KNIMEAppIntegration + */ +public class KNIMEAppIntegration extends MVCPortlet { + + private static Log _log = LogFactoryUtil.getLog(KNIMEAppIntegration.class); + + public void doView(RenderRequest request, RenderResponse response)throws PortletException, IOException { + response.setContentType("text/html"); + + String username = getCurrentUsername(request); + String context = getCurrentContext(request); + String token = getCurrentUserToken(context, username); + + _log.debug("KNIMEAppIntegration doView " + username + " - " + context); + + if (token != null){ + request.setAttribute("securityToken", token); + } + + PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/html/knimeappintegration/view.jsp"); + dispatcher.include(request, response); + } + + + private static String getCurrentUsername(RenderRequest request) { + long userId; + try { + userId = PortalUtil.getUser(request).getUserId(); + return UserLocalServiceUtil.getUser(userId).getScreenName(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + private static String getCurrentContext(RenderRequest request) { + long groupId = -1; + try { + groupId = PortalUtil.getScopeGroupId(request); + return getCurrentContext(groupId); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + private static String getCurrentContext(long groupId) { + try { + PortalContext pContext = PortalContext.getConfiguration(); + return pContext.getCurrentScope(""+groupId); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + /** + *

+ * Returns the gCube authorisation token for the given user + *

+ * @param scope infrastrucure context (scope) + * @param username the GCubeUser username @see {@link GCubeUser} + * @return the Token for the user in the context, or null if a token for this user could not be found + */ + private static String getCurrentUserToken(String context, String username) { + String userToken = null; + + try { + ScopeProvider.instance.set(context); + userToken = authorizationService().resolveTokenByUserAndContext(username, context); + SecurityTokenProvider.instance.set(userToken); + } + catch (Exception e) { + _log.error("Error while trying to generate token for user " + username + "in scope " + context); + e.printStackTrace(); + return null; + } + + return userToken; + } + + +} diff --git a/src/main/webapp/WEB-INF/liferay-display.xml b/src/main/webapp/WEB-INF/liferay-display.xml index 1cb568a..1a0a7d8 100644 --- a/src/main/webapp/WEB-INF/liferay-display.xml +++ b/src/main/webapp/WEB-INF/liferay-display.xml @@ -4,5 +4,6 @@ + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties index b8dbc36..53ab278 100644 --- a/src/main/webapp/WEB-INF/liferay-plugin-package.properties +++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties @@ -1,9 +1,9 @@ name=VREApp-Integration-portlet module-group-id=liferay -module-incremental-version=1 +module-incremental-version=2 tags= short-description= change-log= -page-url=http://www.liferay.com +page-url=http://www.d4science.org author=M.Assante -licenses=EUPL \ No newline at end of file +licenses=EUPL diff --git a/src/main/webapp/WEB-INF/liferay-portlet.xml b/src/main/webapp/WEB-INF/liferay-portlet.xml index 85d85cb..3b86cfd 100644 --- a/src/main/webapp/WEB-INF/liferay-portlet.xml +++ b/src/main/webapp/WEB-INF/liferay-portlet.xml @@ -15,6 +15,19 @@ vre-app-integration-portlet + + knime-app-integration + /icon.png + org.gcube.portal.knime.KNIMEAppConfigurationAction + false + /css/main.css + + /js/main.js + + + knime-app-integration-portlet + + administrator Administrator diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml index 9ad0bfc..de954db 100644 --- a/src/main/webapp/WEB-INF/portlet.xml +++ b/src/main/webapp/WEB-INF/portlet.xml @@ -44,4 +44,48 @@ user + + knime-app-integration + KNIME App Integration + + org.gcube.portal.knime.KNIMEAppIntegration + + + view-template + /html/knimeappintegration/view.jsp + + + config-template + /html/knimeappintegration/config.jsp + + 0 + + text/html + view + config + + + KNIME App Integration + KNIME App Integration + + + + + portletSetupShowBorders + false + + + + administrator + + + guest + + + power-user + + + user + + \ No newline at end of file diff --git a/src/main/webapp/html/knimeappintegration/config.jsp b/src/main/webapp/html/knimeappintegration/config.jsp new file mode 100644 index 0000000..5a10244 --- /dev/null +++ b/src/main/webapp/html/knimeappintegration/config.jsp @@ -0,0 +1,70 @@ +<%@include file="/html/init.jsp"%> + + + +<% + String KNIMEAppURL_cfg = GetterUtil.getString(portletPreferences.getValue("KNIMEAppURL", StringPool.BLANK)); + String KNIMEAppURLTokenParam_cfg = GetterUtil + .getString(portletPreferences.getValue("KNIMEAppURLTokenParam", StringPool.BLANK)); + Integer KNIMEiFrameHeightParam_cfg = GetterUtil + .getInteger(portletPreferences.getValue("KNIMEiFrameHeightParam", "1000")); + boolean KNIMEWindowPreference_cfg = GetterUtil + .getBoolean(portletPreferences.getValue("KNIMEWindowPreference", StringPool.FALSE)); + String applicationNameParam_cfg = GetterUtil + .getString(portletPreferences.getValue("applicationNameParam", "the Application")); + if (applicationNameParam_cfg.equals("")) + applicationNameParam_cfg = "the Application"; +%> + + + + + + + + + + + + + + + +

Display options (default iFrame):

+ + +
+ + + + + + + + + +
\ No newline at end of file diff --git a/src/main/webapp/html/knimeappintegration/view.jsp b/src/main/webapp/html/knimeappintegration/view.jsp new file mode 100644 index 0000000..b767520 --- /dev/null +++ b/src/main/webapp/html/knimeappintegration/view.jsp @@ -0,0 +1,69 @@ +<%@include file="/html/init.jsp"%> + + +<% + String KNIMEAppURL_view = GetterUtil.getString(portletPreferences.getValue("KNIMEAppURL", StringPool.BLANK)); + String KNIMEAppURLTokenParam_view = GetterUtil + .getString(portletPreferences.getValue("KNIMEAppURLTokenParam", StringPool.BLANK)); + Integer iFrameHeight = GetterUtil.getInteger(portletPreferences.getValue("KNIMEiFrameHeightParam", "1000")); + pageContext.setAttribute("iFrameHeight", iFrameHeight); + + boolean KNIMEWindowPreference = GetterUtil.getBoolean(portletPreferences.getValue("KNIMEWindowPreference", StringPool.FALSE)); + pageContext.setAttribute("KNIMEWindowPreference", KNIMEWindowPreference); + + String applicationNameParam_view = GetterUtil.getString(portletPreferences.getValue("applicationNameParam", "the Application")); + pageContext.setAttribute("applicationNameParam_view", applicationNameParam_view); + + Object securityTokenObj = request.getAttribute("securityToken"); + String securityToken = ""; + if (securityToken != null) { + securityToken = securityTokenObj.toString(); + } + + /* handle the case where the page is called with GET parameters needing to be forwarded*/ + String completeURL = PortalUtil.getCurrentCompleteURL(request); + String queryString = ""; + if (completeURL.indexOf("?") > 0) { + queryString = completeURL.substring(completeURL.indexOf("?") + 1); + queryString = queryString.trim(); + } + + /* handle the case where the KNIMEAppURL provided has GET parameters needing to be forwarded*/ + if (KNIMEAppURL_view.indexOf("&") > 0) { + if (queryString != null && !queryString.equals("")) { //not empty + queryString += "&" + KNIMEAppURL_view.substring(KNIMEAppURL_view.indexOf("&") + 1); + } else { + queryString = KNIMEAppURL_view.substring(KNIMEAppURL_view.indexOf("&") + 1); + } + KNIMEAppURL_view = KNIMEAppURL_view.substring(0, KNIMEAppURL_view.indexOf("&")); + queryString = queryString.trim(); + } + + String applicationURL = KNIMEAppURL_view; + if (!KNIMEAppURLTokenParam_view.equals("")) { + applicationURL += "&" + KNIMEAppURLTokenParam_view + "=" + securityToken; + if (queryString != null && !queryString.equals("")) { + applicationURL += "&" + queryString; + } + } else { + if (queryString != null && !queryString.equals("")) { + applicationURL += "&" + queryString; + } + } + System.out.println("applicationURL: "+applicationURL); + pageContext.setAttribute("applicationURL", applicationURL); + pageContext.setAttribute("newWindow", true); +%> + + + + + +

If no new window appears, please click here to open ${applicationNameParam_view}

+ +
+