[gatein-commits] gatein SVN: r7168 - in epp/portal/branches/EPP_5_2_Branch: portlet/dashboard/src/main/webapp/groovy/gadget/webui/component and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Aug 17 17:37:09 EDT 2011


Author: theute
Date: 2011-08-17 17:37:09 -0400 (Wed, 17 Aug 2011)
New Revision: 7168

Modified:
   epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
   epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl
   epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java
   epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
Log:
JBEPP-927: TODO gadget not working besides the dashboard
JBEPP-1081: NPE if portlet information cannot be retrieved


Modified: epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java	2011-08-17 20:57:56 UTC (rev 7167)
+++ epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/java/org/exoplatform/gadget/webui/component/UIGadgetPortlet.java	2011-08-17 21:37:09 UTC (rev 7168)
@@ -26,6 +26,7 @@
 import org.exoplatform.container.ExoContainerContext;
 import org.exoplatform.portal.webui.application.GadgetUtil;
 import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.application.WebuiApplication;
 import org.exoplatform.webui.application.WebuiRequestContext;
 import org.exoplatform.webui.application.portlet.PortletRequestContext;
 import org.exoplatform.webui.config.annotation.ComponentConfig;
@@ -38,6 +39,7 @@
 import org.json.JSONObject;
 
 import javax.portlet.PortletPreferences;
+import javax.portlet.PortletRequest;
 
 /**
  * Created by The eXo Platform SARL
@@ -52,11 +54,48 @@
 
    private static final Logger log = LoggerFactory.getLogger(LocalImporter.class);
 
+   /** User pref. */
+   private String userPref;
+   
    public UIGadgetPortlet() throws Exception
    {
       addChild(UIGadgetViewMode.class, null, null);
    }
+   
+   public String getUserPref()
+   {
+      return userPref;
+   }
 
+   @Override
+   public void processAction(WebuiRequestContext context) throws Exception
+   {
+      super.processAction(context);
+
+      //
+      PortletRequest req = context.getRequest();
+
+      //
+      userPref = req.getParameter("userPref");
+      if (userPref != null && !userPref.isEmpty())
+      {
+         PortletPreferences prefs = req.getPreferences();
+         prefs.setValue("userPref", userPref);
+         prefs.store();
+      }
+   }
+
+   @Override
+   public void processRender(WebuiApplication app, WebuiRequestContext context) throws Exception
+   {
+      PortletRequest req = context.getRequest();
+      PortletPreferences prefs = req.getPreferences();
+      userPref = prefs.getValue("userPref", null);
+
+      //
+      super.processRender(app, context);
+   }
+
    public String getUrl()
    {
       PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();

Modified: epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl	2011-08-17 20:57:56 UTC (rev 7167)
+++ epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl	2011-08-17 21:37:09 UTC (rev 7168)
@@ -13,7 +13,7 @@
 	
 	if(url != null) {
   	def metadata = uicomponent.getParent().getMetadata(url);
-  	def userPref = null;
+  	def userPref = uicomponent.getParent().getUserPref();
   	JavascriptManager jsmanager = rcontext.getJavascriptManager();
   	jsmanager.importJavascript("eXo.gadget.UIGadget") ;
   	jsmanager.addCustomizedOnLoadScript("eXo.gadget.UIGadget.createGadget('$url','$id', $metadata, $userPref, 'canvas', '$hostName');") ;

Modified: epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java	2011-08-17 20:57:56 UTC (rev 7167)
+++ epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/ModelAdapter.java	2011-08-17 21:37:09 UTC (rev 7168)
@@ -27,7 +27,6 @@
 import org.exoplatform.portal.config.model.TransientApplicationState;
 import org.exoplatform.portal.pc.ExoPortletState;
 import org.exoplatform.portal.pc.ExoPortletStateType;
-import org.exoplatform.portal.pom.config.Utils;
 import org.exoplatform.portal.pom.spi.gadget.Gadget;
 import org.exoplatform.portal.pom.spi.portlet.Portlet;
 import org.exoplatform.portal.pom.spi.portlet.PortletBuilder;
@@ -40,6 +39,7 @@
 
 import java.io.Serializable;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -204,6 +204,12 @@
          String url = GadgetUtil.reproduceUrl(model.getUrl(), model.isLocal());
          ExoPortletState prefs = new ExoPortletState(WRAPPER_ID);
          prefs.getState().put("url", Arrays.asList(url));
+         DataStorage dataStorage = (DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+         Gadget gadget = dataStorage.load(applicationState, ApplicationType.GADGET);
+         if (gadget != null && gadget.getUserPref() != null)
+         {
+            prefs.getState().put("userPref", Collections.singletonList(gadget.getUserPref()));
+         }
          return StatefulPortletContext.create(LOCAL_STATE_ID, ExoPortletStateType.getInstance(), prefs);
       }
 
@@ -211,7 +217,33 @@
       public ApplicationState<Gadget> update(ExoContainer container, ExoPortletState updateState,
                                              ApplicationState<Gadget> gadgetApplicationState) throws Exception
       {
-         throw new UnsupportedOperationException("Cannot edit gadget preferences");
+         // Compute new preferences
+         String userPref = null;
+         for (Map.Entry<String, List<String>> entry : updateState.getState().entrySet())
+         {
+            if (entry.getKey().equals("userPref") && entry.getValue().size() > 0)
+            {
+               userPref = entry.getValue().get(0);
+            }
+         }
+
+         if (gadgetApplicationState instanceof TransientApplicationState<?>)
+         {
+            throw new UnsupportedOperationException("todo");
+         }
+         else
+         {
+            if (userPref != null)
+            {
+               Gadget gadget = new Gadget();
+               gadget.addUserPref(userPref);
+               DataStorage dataStorage = (DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+               dataStorage.save(gadgetApplicationState, gadget);
+            }
+         }
+
+         //
+         return gadgetApplicationState;
       }
 
       @Override

Modified: epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java	2011-08-17 20:57:56 UTC (rev 7167)
+++ epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/UIPortlet.java	2011-08-17 21:37:09 UTC (rev 7168)
@@ -52,7 +52,6 @@
 import org.gatein.common.net.media.MediaType;
 import org.gatein.common.util.ParameterValidation;
 import org.gatein.pc.api.Mode;
-import org.gatein.pc.api.NoSuchPortletException;
 import org.gatein.pc.api.PortletContext;
 import org.gatein.pc.api.PortletInvoker;
 import org.gatein.pc.api.PortletInvokerException;
@@ -935,10 +934,12 @@
             {
                producedOfferedPortlet = portletInvoker.getPortlet(producerOfferedPortletContext);
             }
-            catch (NoSuchPortletException nspe)
+            catch (Exception exp)
             {
+               // Whenever couldn't invoke the portlet object, set the request portlet to null for the error tobe
+               // properly handled and displayed when the portlet is rendered
                producedOfferedPortlet = null;
-               nspe.printStackTrace();
+               exp.printStackTrace();
             }
 
             this.adapter = adapter;
@@ -1001,7 +1002,8 @@
    public void update(C updateState) throws Exception
    {
       WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
-      ExoContainer container = context.getApplication().getApplicationServiceContainer();      state.setApplicationState(adapter.update(container, updateState, state.getApplicationState()));
+      ExoContainer container = context.getApplication().getApplicationServiceContainer();
+      state.setApplicationState(adapter.update(container, updateState, state.getApplicationState()));
       setState(state);
    }
    



More information about the gatein-commits mailing list