[portal-commits] JBoss Portal SVN: r5918 - in trunk: core/src/main/org/jboss/portal/core/impl/model core/src/main/org/jboss/portal/core/impl/model/instance core/src/main/org/jboss/portal/core/impl/model/portal core/src/main/org/jboss/portal/core/model/instance federation/src/main/org/jboss/portal/federation/impl portlet/src/main/org/jboss/portal/portlet

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Wed Dec 20 18:45:17 EST 2006


Author: julien at jboss.com
Date: 2006-12-20 18:45:01 -0500 (Wed, 20 Dec 2006)
New Revision: 5918

Modified:
   trunk/core/src/main/org/jboss/portal/core/impl/model/CustomizationManagerService.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceImpl.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
   trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
   trunk/core/src/main/org/jboss/portal/core/model/instance/Instance.java
   trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceCustomization.java
   trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceDefinition.java
   trunk/federation/src/main/org/jboss/portal/federation/impl/FederatedPortletInvokerService.java
   trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java
   trunk/portlet/src/main/org/jboss/portal/portlet/PortletInvoker.java
Log:
dashboard window destruction leads to potential related instance customization destruction

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/CustomizationManagerService.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/CustomizationManagerService.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/CustomizationManagerService.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -130,7 +130,7 @@
             if (isDashboard(window, user))
             {
                // That's how we manufacture dash board keys
-               String dashboardId = userId + "." + window.getId();
+               String dashboardId = window.getId().toString();
 
                //
                instance = instance.getCustomization(dashboardId);

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceImpl.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/instance/InstanceImpl.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -36,9 +36,14 @@
 import org.jboss.portal.portlet.state.AccessMode;
 import org.jboss.portal.portlet.state.PropertyChange;
 import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.portlet.state.DestroyCloneFailure;
 
 import java.util.Arrays;
 import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -48,6 +53,9 @@
 {
 
    /** . */
+   private static final Logger log = Logger.getLogger(InstanceImpl.class);
+
+   /** . */
    protected Long key;
 
    /** . */
@@ -273,21 +281,68 @@
 
    public InstanceCustomization getCustomization(String customizationId)
    {
+      if (customizationId == null)
+      {
+         throw new IllegalArgumentException();
+      }
+
       // Check if we have an instance for this particular customized id
-      Session session = containerContext.getCurrentSession();
-      Query query = session.createQuery("from InstanceCustomizationImpl where def.key=:defKey and customizationId=:customizationId");
-      query.setParameter("defKey", key);
-      query.setParameter("customizationId", customizationId);
-      query.setCacheable(true);
-      InstanceCustomizationImpl customization = (InstanceCustomizationImpl)query.uniqueResult();
+      InstanceCustomizationImpl customization = loadCustomization(customizationId);
+
+      //
       if (customization == null)
       {
          InstanceDefinitionImpl def = getDef();
          customization = new InstanceCustomizationImpl(def, customizationId, containerContext, getPortletContext());
       }
+
+      //
       return customization;
    }
 
+   public void destroyCustomization(String customizationId)
+   {
+      InstanceCustomizationImpl customization = loadCustomization(customizationId);
+
+      //
+      if (customization != null)
+      {
+         try
+         {
+            PortletContext customizationPortletContext = customization.getPortletContext();
+            List toDestroy = Collections.singletonList(customizationPortletContext);
+            PortletInvoker portletInvoker = containerContext.getPortletInvoker();
+
+            //
+            List failures = portletInvoker.destroyClones(toDestroy);
+            if (failures.size() > 0)
+            {
+               for (Iterator i = failures.iterator();i.hasNext();)
+               {
+                  DestroyCloneFailure failure = (DestroyCloneFailure)i.next();
+                  log.error("Was not able to destroy " + failure.getPortletId() + " for customization " +
+                             customizationId + ", reason is : " + failure.getMessage());
+               }
+            }
+         }
+         catch (PortletInvokerException e)
+         {
+            log.error("Could not destroy customization " + customizationId, e);
+         }
+      }
+   }
+
+   private InstanceCustomizationImpl loadCustomization(String customizationId)
+   {
+      // Check if we have an instance for this particular customized id
+      Session session = containerContext.getCurrentSession();
+      Query query = session.createQuery("from InstanceCustomizationImpl where def.key=:defKey and customizationId=:customizationId");
+      query.setParameter("defKey", key);
+      query.setParameter("customizationId", customizationId);
+      query.setCacheable(true);
+      return (InstanceCustomizationImpl)query.uniqueResult();
+   }
+
    // ContextObject implementation *************************************************************************************
 
    public void setContext(Object context)

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/instance/PersistentInstanceContainer.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -324,32 +324,32 @@
       Session session = ctx.getCurrentSession();
 
       // Lookup instance
-      InstanceDefinitionImpl instance = lookup(session, id);
-      if (instance == null)
+      InstanceDefinitionImpl definition = lookup(session, id);
+      if (definition == null)
       {
          throw new NoSuchInstanceException(id);
       }
-      Set userInstances = instance.getCustomizations();
+      Set customizations = definition.getCustomizations();
 
       // Collect portlet info to destroy for logging purpose
       StringBuffer destroyLog = new StringBuffer("About to destroy portlets for instance=").
-         append(instance.getInstanceId()).
+         append(definition.getInstanceId()).
          append(" [");
 
       //
-      List toDestroy = new ArrayList(userInstances.size());
-      for (Iterator i = userInstances.iterator(); i.hasNext();)
+      List toDestroy = new ArrayList(customizations.size());
+      for (Iterator i = customizations.iterator(); i.hasNext();)
       {
-         InstanceCustomizationImpl userInstance = (InstanceCustomizationImpl)i.next();
+         InstanceCustomizationImpl customization = (InstanceCustomizationImpl)i.next();
 
          // Get the user portlet context
-         PortletContext userPortletContext = userInstance.getPortletContext();
+         PortletContext customizationPortletContext = customization.getPortletContext();
 
          // Add the portlet context
-         toDestroy.add(userPortletContext);
+         toDestroy.add(customizationPortletContext);
 
          //
-         destroyLog.append(userPortletContext);
+         destroyLog.append(customizationPortletContext);
          if (i.hasNext())
          {
             destroyLog.append(',');
@@ -357,10 +357,10 @@
       }
 
       //
-      if (instance.isModifiable())
+      if (definition.isModifiable())
       {
          // Destroy the state only if it is not a producer offered portlet
-         PortletContext sharedPortletContext = instance.getPortletContext();
+         PortletContext sharedPortletContext = definition.getPortletContext();
          toDestroy.add(sharedPortletContext);
          destroyLog.append(sharedPortletContext);
       }
@@ -374,7 +374,7 @@
       if (failures.size() > 0)
       {
          StringBuffer failureLog = new StringBuffer("Some portlet were not properly destroyed for instance=").
-            append(instance.getInstanceId()).
+            append(definition.getInstanceId()).
             append(" [");
          for (Iterator i = failures.iterator(); i.hasNext();)
          {
@@ -390,7 +390,7 @@
       }
 
       // Destroy the user instances
-      for (Iterator i = userInstances.iterator(); i.hasNext();)
+      for (Iterator i = customizations.iterator(); i.hasNext();)
       {
          InstanceCustomizationImpl userInstance = (InstanceCustomizationImpl)i.next();
          i.remove();
@@ -399,8 +399,8 @@
       }
 
       // Delete instance
-      removeBindings(session, instance);
-      session.delete(instance);
+      removeBindings(session, definition);
+      session.delete(definition);
 
       //
       session.flush();

Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -76,25 +76,19 @@
    protected void destroy()
    {
       // Destroy the associated customization
-      DashboardContext dbctx = getDashboardContext();
-      if (dbctx != null)
+      //
+      AbstractPortalObjectContainer container = (AbstractPortalObjectContainer)getObjectNode().getContext().getContainer();
+      InstanceContainer instanceContainer = container.getInstanceContainer();
+      Instance instance = instanceContainer.getDefinition(instanceRef);
+
+      //
+      if (instance != null)
       {
-         String dashboardId = dbctx.getId();
+         // That's how we manufacture dash board keys
+         String customizationId = getId().toString();
 
-         //
-         AbstractPortalObjectContainer container = (AbstractPortalObjectContainer)getObjectNode().getContext().getContainer();
-         InstanceContainer instanceContainer = container.getInstanceContainer();
-         Instance instance = instanceContainer.getDefinition(instanceRef);
-
-         //
-         if (instance != null)
-         {
-            // That's how we manufacture dash board keys
-            String customizationId = dashboardId + "." + getId();
-
-            //
-            Instance customizedInstance = instance.getCustomization(customizationId);
-         }
+         // Destroy related instance customization
+         instance.destroyCustomization(customizationId);
       }
    }
 }

Modified: trunk/core/src/main/org/jboss/portal/core/model/instance/Instance.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/instance/Instance.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/model/instance/Instance.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -94,4 +94,11 @@
     * @return an instance customization
     */
    InstanceCustomization getCustomization(String customizationId);
+
+   /**
+    * Destroy the customization
+    *
+    * @param customizationId the id of the customization to destroy
+    */
+   void destroyCustomization(String customizationId);
 }

Modified: trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceCustomization.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceCustomization.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceCustomization.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -29,7 +29,11 @@
 public interface InstanceCustomization extends Instance
 {
 
-   /** Return the identifier in the scope of its definition. */
+   /**
+    * Return the identifier in the scope of its definition which is the customization id.
+    *
+    * @return the id
+    */
    String getId();
 
    /**

Modified: trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceDefinition.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceDefinition.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/core/src/main/org/jboss/portal/core/model/instance/InstanceDefinition.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -28,7 +28,11 @@
  */
 public interface InstanceDefinition extends Instance
 {
-   /** Return the identifier in the scope of its container. */
+   /**
+    * Return the identifier in the scope of its container.
+    *
+    * @return the instance id
+    */
    String getId();
 
    /**

Modified: trunk/federation/src/main/org/jboss/portal/federation/impl/FederatedPortletInvokerService.java
===================================================================
--- trunk/federation/src/main/org/jboss/portal/federation/impl/FederatedPortletInvokerService.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/federation/src/main/org/jboss/portal/federation/impl/FederatedPortletInvokerService.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -156,19 +156,19 @@
       return reference(cloneContext);
    }
 
-   public List destroyClones(List portletIds) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+   public List destroyClones(List portletContexts) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
    {
-      if (portletIds == null)
+      if (portletContexts == null)
       {
          throw new IllegalArgumentException("Null portlet id list not accepted");
       }
-      if (portletIds.size() == 0)
+      if (portletContexts.size() == 0)
       {
          return Collections.EMPTY_LIST;
       }
 
       //
-      List dereferencedList = new ArrayList(portletIds);
+      List dereferencedList = new ArrayList(portletContexts);
       for (int i = 0; i < dereferencedList.size(); i++)
       {
          PortletContext compoundPortletContext = (PortletContext)dereferencedList.get(i);
@@ -177,7 +177,7 @@
       }
 
       //
-      List failures = portletInvoker.destroyClones(portletIds);
+      List failures = portletInvoker.destroyClones(dereferencedList);
       for (int i = 0; i < failures.size(); i++)
       {
          DestroyCloneFailure failure = (DestroyCloneFailure)failures.get(i);

Modified: trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java
===================================================================
--- trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -169,22 +169,22 @@
       return federated.createClone(compoundPortletContext);
    }
 
-   public List destroyClones(List portletIds) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
+   public List destroyClones(List portletContexts) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
    {
-      if (portletIds == null)
+      if (portletContexts == null)
       {
          throw new IllegalArgumentException("No null list accepted");
       }
-      if (portletIds.size() == 0)
+      if (portletContexts.size() == 0)
       {
          return Collections.EMPTY_LIST;
       }
 
       // Get the invoker and check that we address only one invoker (for now)
       FederatedPortletInvoker invoker = null;
-      for (int i = 0; i < portletIds.size(); i++)
+      for (int i = 0; i < portletContexts.size(); i++)
       {
-         String compoundPortletId = (String)portletIds.get(i);
+         PortletContext compoundPortletId = (PortletContext)portletContexts.get(i);
          FederatedPortletInvoker federated = getFederatedPortletInvokerFor(compoundPortletId);
          if (invoker == null)
          {
@@ -197,7 +197,7 @@
       }
 
       //
-      return invoker.destroyClones(portletIds);
+      return invoker.destroyClones(portletContexts);
    }
 
    public PropertyMap getProperties(PortletContext compoundPortletContext, Set keys) throws PortletInvokerException
@@ -235,18 +235,8 @@
       }
 
       //
-      return getFederatedPortletInvokerFor(compoundPortletContext.getId());
-   }
+      String compoundPortletId = compoundPortletContext.getId();
 
-   /**
-    * Retrieves the portlet invoker associated with the specified compound portlet id or null if it is not found.
-    *
-    * @param compoundPortletId the portlet id for which the invoker is to be retrieved
-    * @return the portlet invoker associated with the specified compound portlet id
-    * @throws IllegalArgumentException if the compound portlet id is not well formed or null
-    */
-   private FederatedPortletInvoker getFederatedPortletInvokerFor(String compoundPortletId) throws IllegalArgumentException, NoSuchPortletException
-   {
       //
       int pos = compoundPortletId.indexOf(SEPARATOR);
       if (pos == -1)
@@ -261,6 +251,8 @@
       {
          throw new NoSuchPortletException(compoundPortletId);
       }
+
+      //
       return federated;
    }
 }

Modified: trunk/portlet/src/main/org/jboss/portal/portlet/PortletInvoker.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/PortletInvoker.java	2006-12-20 22:09:59 UTC (rev 5917)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/PortletInvoker.java	2006-12-20 23:45:01 UTC (rev 5918)
@@ -56,7 +56,7 @@
     * Invoke an operation on a specific portlet.
     *
     * @param invocation the portlet invocation
-    * @return the invocatin response
+    * @return the invocation response
     * @throws IllegalArgumentException if the invocation is null
     */
    PortletInvocationResponse invoke(PortletInvocation invocation) throws IllegalArgumentException, PortletInvokerException;
@@ -76,7 +76,7 @@
     * @param portletContexts a list of portlet contexts to destroy
     * @return a list of {@link org.jboss.portal.portlet.state.DestroyCloneFailure}, one per clone that couldn't be
     *         destroyed
-    * @throws IllegalArgumentException      if the portletId is null
+    * @throws IllegalArgumentException      if the portletContext is null
     * @throws UnsupportedOperationException if the invoker does not support this operation
     */
    List destroyClones(List portletContexts) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException;
@@ -87,7 +87,7 @@
     * @param portletContext the portlet context
     * @param keys           the set of keys to retrieve
     * @return the properties
-    * @throws IllegalArgumentException      if the portletId or the keys arguments are null
+    * @throws IllegalArgumentException      if the portletContext or the keys arguments are null
     * @throws UnsupportedOperationException if the invoker does not support this operation
     */
    PropertyMap getProperties(PortletContext portletContext, Set keys) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException;
@@ -97,7 +97,7 @@
     *
     * @param portletContext the portlet context
     * @return the properties
-    * @throws IllegalArgumentException      if the portletId is null
+    * @throws IllegalArgumentException      if the portletContext is null
     * @throws UnsupportedOperationException if the invoker does not support this operation
     */
    PropertyMap getProperties(PortletContext portletContext) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException;
@@ -107,7 +107,7 @@
     *
     * @param portletContext the portlet context
     * @param changes        the changes
-    * @throws IllegalArgumentException      if the portletId or the properties is null
+    * @throws IllegalArgumentException      if the portletContext or the properties is null
     * @throws UnsupportedOperationException if the invoker does not support this operation
     */
    PortletContext setProperties(PortletContext portletContext, PropertyChange[] changes) throws IllegalArgumentException, PortletInvokerException, UnsupportedOperationException;




More information about the portal-commits mailing list