From 48d316dba41fc499eb8e412891e4b7be81c37244 Mon Sep 17 00:00:00 2001
From: pkupczyk <pkupczyk>
Date: Mon, 6 Aug 2012 12:47:16 +0000
Subject: [PATCH] SP-202 / BIS-122 : Webuis available from openBIS UI -
 displaying iframe

SVN: 26306
---
 .../client/application/ui/AbstractViewer.java | 20 ++++-
 .../ui/webapp/WebAppComponent.java            | 34 +++++++
 .../WebAppSortingAndCodeComparator.java       |  2 +-
 .../application/ui/webapp/WebAppUrl.java      | 89 +++++++++++++++++++
 .../ui/webapp/WebAppUrlParameter.java         | 42 +++++++++
 .../WebAppSortingAndCodeComparatorTest.java   |  2 +-
 6 files changed, 184 insertions(+), 5 deletions(-)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppComponent.java
 rename openbis/source/java/ch/systemsx/cisd/openbis/generic/{shared/basic => client/web/client/application/ui/webapp}/WebAppSortingAndCodeComparator.java (95%)
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java
 create mode 100644 openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlParameter.java
 rename openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/{shared/basic => client/web/client/application/ui/webapp}/WebAppSortingAndCodeComparatorTest.java (97%)

diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java
index 24e0ffa7c83..82f2850c9c1 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/AbstractViewer.java
@@ -31,7 +31,6 @@ import com.extjs.gxt.ui.client.widget.ContentPanel;
 import com.extjs.gxt.ui.client.widget.Html;
 import com.extjs.gxt.ui.client.widget.Layout;
 import com.extjs.gxt.ui.client.widget.LayoutContainer;
-import com.extjs.gxt.ui.client.widget.Text;
 import com.extjs.gxt.ui.client.widget.button.Button;
 import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
 import com.extjs.gxt.ui.client.widget.layout.TableRowLayout;
@@ -39,6 +38,7 @@ import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
 import com.extjs.gxt.ui.client.widget.toolbar.LabelToolItem;
 import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
 import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Widget;
 
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.AbstractAsyncCallback;
@@ -57,6 +57,9 @@ import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.grid.ID
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityDetailsTabClickListener;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenEntityEditorTabClickListener;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.listener.OpenExperimentBrowserTabClickListener;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp.WebAppComponent;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp.WebAppSortingAndCodeComparator;
+import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp.WebAppUrl;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.widget.SectionsPanel;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.GWTUtils;
 import ch.systemsx.cisd.openbis.generic.client.web.client.application.util.IDelegatedAction;
@@ -68,7 +71,6 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolder;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithIdentifier;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithPermId;
 import ch.systemsx.cisd.openbis.generic.shared.basic.IEntityInformationHolderWithProperties;
-import ch.systemsx.cisd.openbis.generic.shared.basic.WebAppSortingAndCodeComparator;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DatabaseModificationKind;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityVisit;
 import ch.systemsx.cisd.openbis.generic.shared.basic.dto.IEntityProperty;
@@ -465,7 +467,14 @@ public abstract class AbstractViewer<D extends IEntityInformationHolder> extends
                                         @Override
                                         public Component getComponent()
                                         {
-                                            return new Text(webApp.getCode());
+                                            WebAppUrl url =
+                                                    new WebAppUrl(Window.Location.getProtocol(),
+                                                            Window.Location.getHost(),
+                                                            webApp.getCode(), getSessionId());
+                                            url.setEntityKind(entity.getEntityKind());
+                                            url.setEntityType(entity.getEntityType());
+                                            url.setEntityPermId(entity.getPermId());
+                                            return new WebAppComponent(url);
                                         }
 
                                         @Override
@@ -607,4 +616,9 @@ public abstract class AbstractViewer<D extends IEntityInformationHolder> extends
         return getViewContext().getModel().getApplicationInfo();
     }
 
+    protected String getSessionId()
+    {
+        return getViewContext().getModel().getSessionContext().getSessionID();
+    }
+
 }
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppComponent.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppComponent.java
new file mode 100644
index 00000000000..fb9c0b93f3c
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppComponent.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp;
+
+import com.extjs.gxt.ui.client.widget.WidgetComponent;
+import com.google.gwt.user.client.ui.Frame;
+
+/**
+ * Component that displays a web application in an IFRAME.
+ * 
+ * @author pkupczyk
+ */
+public class WebAppComponent extends WidgetComponent
+{
+
+    public WebAppComponent(WebAppUrl url)
+    {
+        super(new Frame(url.toString()));
+    }
+}
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/WebAppSortingAndCodeComparator.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppSortingAndCodeComparator.java
similarity index 95%
rename from openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/WebAppSortingAndCodeComparator.java
rename to openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppSortingAndCodeComparator.java
index f789eb89e41..a5fa7bc8ac3 100644
--- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/WebAppSortingAndCodeComparator.java
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppSortingAndCodeComparator.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package ch.systemsx.cisd.openbis.generic.shared.basic;
+package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp;
 
 import java.util.Comparator;
 
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java
new file mode 100644
index 00000000000..6fa4b40dba4
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrl.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp;
+
+import com.google.gwt.http.client.UrlBuilder;
+
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.BasicEntityType;
+import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
+
+/**
+ * A web application URL that will be used for displaying the web application in an IFRAME.
+ * 
+ * @author pkupczyk
+ */
+public class WebAppUrl
+{
+
+    private UrlBuilder builder = new UrlBuilder();
+
+    public WebAppUrl(String openbisProtocol, String openbisHost, String webAppCode, String sessionId)
+    {
+        if (openbisProtocol == null)
+        {
+            throw new IllegalArgumentException("OpenBIS protocol cannot be null");
+        }
+        if (openbisHost == null)
+        {
+            throw new IllegalArgumentException("OpenBIS host cannot be null");
+        }
+        if (webAppCode == null)
+        {
+            throw new IllegalArgumentException("Web application code cannot be null");
+        }
+        if (sessionId == null)
+        {
+            throw new IllegalArgumentException("Session id cannot be null");
+        }
+
+        builder.setProtocol(openbisProtocol);
+        builder.setHost(openbisHost);
+        builder.setPath(webAppCode);
+        builder.setParameter(WebAppUrlParameter.SESSION_ID.getName(), sessionId);
+    }
+
+    public void setEntityKind(EntityKind entityKind)
+    {
+        if (entityKind != null)
+        {
+            builder.setParameter(WebAppUrlParameter.ENTITY_KIND.getName(), entityKind.name());
+        }
+    }
+
+    public void setEntityType(BasicEntityType entityType)
+    {
+        if (entityType != null)
+        {
+            builder.setParameter(WebAppUrlParameter.ENTITY_TYPE.getName(), entityType.getCode());
+        }
+    }
+
+    public void setEntityPermId(String entityPermId)
+    {
+        if (entityPermId != null)
+        {
+            builder.setParameter(WebAppUrlParameter.ENTITY_PERM_ID.getName(), entityPermId);
+        }
+    }
+
+    @Override
+    public String toString()
+    {
+        return builder.buildString();
+    }
+
+}
diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlParameter.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlParameter.java
new file mode 100644
index 00000000000..551fd183d7e
--- /dev/null
+++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppUrlParameter.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 ETH Zuerich, CISD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp;
+
+/**
+ * Parameters that are passed to a web application in an URL query string.
+ * 
+ * @author pkupczyk
+ */
+public enum WebAppUrlParameter
+{
+
+    SESSION_ID("session-id"), ENTITY_KIND("entity-kind"), ENTITY_TYPE("entity-type"),
+    ENTITY_PERM_ID("entity-perm-id");
+
+    private final String name;
+
+    private WebAppUrlParameter(String name)
+    {
+        this.name = name;
+    }
+
+    public String getName()
+    {
+        return this.name;
+    }
+
+}
diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/WebAppSortingAndCodeComparatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppSortingAndCodeComparatorTest.java
similarity index 97%
rename from openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/WebAppSortingAndCodeComparatorTest.java
rename to openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppSortingAndCodeComparatorTest.java
index 24d2f811702..ccd3ffb4f34 100644
--- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/basic/WebAppSortingAndCodeComparatorTest.java
+++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/client/web/client/application/ui/webapp/WebAppSortingAndCodeComparatorTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package ch.systemsx.cisd.openbis.generic.shared.basic;
+package ch.systemsx.cisd.openbis.generic.client.web.client.application.ui.webapp;
 
 import java.util.ArrayList;
 import java.util.Collections;
-- 
GitLab