[portal-commits] JBoss Portal SVN: r11822 - in branches/JBoss_Portal_Branch_2_7: core/src/main/org/jboss/portal/core/impl/coordination and 2 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Fri Sep 5 19:13:35 EDT 2008


Author: chris.laprun at jboss.com
Date: 2008-09-05 19:13:35 -0400 (Fri, 05 Sep 2008)
New Revision: 11822

Modified:
   branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/coordination/EventWiringManagerBean.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/EventWiringInfo.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/ParameterBindingInfo.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java
   branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java
Log:
- Added getPage method on EventWiringInfo and ParameterBindingInfo
- Added getEventWiring, removeEventWiring(page, name) and renameEventWiring(page, oldName, newName) methods for easier use.
- EventWiringManagerBean uses new method and rename and delete operations should now properly work from the GUI.
- Added more tests.

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java	2008-09-05 20:34:27 UTC (rev 11821)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/CoordinationConfigurator.java	2008-09-05 23:13:35 UTC (rev 11822)
@@ -222,4 +222,10 @@
     * @return window bindings where given window is involved
     */
    Collection<? extends WindowBindingInfo> getWindowBindings(Window window);
+
+   void removeEventWiring(Page page, String wiringName);
+
+   EventWiringInfo getEventWiring(Page page, String name) throws IllegalCoordinationException;
+
+   void renameEventWiring(Page page, String wiringName, String newName) throws IllegalCoordinationException;
 }

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/EventWiringInfo.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/EventWiringInfo.java	2008-09-05 20:34:27 UTC (rev 11821)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/EventWiringInfo.java	2008-09-05 23:13:35 UTC (rev 11822)
@@ -22,6 +22,7 @@
 
 package org.jboss.portal.core.controller.coordination;
 
+import org.jboss.portal.core.model.portal.Page;
 import org.jboss.portal.core.model.portal.Window;
 
 import javax.xml.namespace.QName;
@@ -39,4 +40,6 @@
    Map<Window, QName> getSources();
 
    Map<Window, QName> getDestinations();
+
+   Page getPage();
 }

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/ParameterBindingInfo.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/ParameterBindingInfo.java	2008-09-05 20:34:27 UTC (rev 11821)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/coordination/ParameterBindingInfo.java	2008-09-05 23:13:35 UTC (rev 11822)
@@ -22,6 +22,8 @@
 
 package org.jboss.portal.core.controller.coordination;
 
+import org.jboss.portal.core.model.portal.Page;
+
 /**
  * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot com">Boleslaw Dawidowicz</a>
  * @author <a href="mailto:julien at jboss-portal.org">Julien Viet</a>
@@ -30,4 +32,6 @@
 public interface ParameterBindingInfo
 {
    String getName();
+
+   Page getPage();
 }

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java	2008-09-05 20:34:27 UTC (rev 11821)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/coordination/CoordinationService.java	2008-09-05 23:13:35 UTC (rev 11822)
@@ -57,18 +57,20 @@
  * @version : 0.1 $
  */
 public class CoordinationService extends AbstractJBossService
-   implements CoordinationManager, CoordinationConfigurator
+        implements CoordinationManager, CoordinationConfigurator
 {
-   public static final String SOURCE = "source";
-   public static final String DESTINATION = "destination";
+   private static final String EVENT_ROLE_SOURCE = "source";
+   public static final String SOURCE = EVENT_ROLE_SOURCE;
+   private static final String EVENT_ROLE_DESTINATION = "destination";
+   public static final String DESTINATION = EVENT_ROLE_DESTINATION;
    public static final String BINDING = "binding";
    public static final String PREFIX = "coordination";
    public static final String QNAME_SEPARATOR = ";";
    public static final String PREFIX_EVENT = PREFIX + ".event";
    public static final String PREFIX_PARAMETER = PREFIX + ".parameter";
    public static final String PREFIX_PARAMETER_ALIAS = PREFIX_PARAMETER + ".alias";
-   public static final String PREFIX_EVENT_NAME = PREFIX_EVENT + ".name";
-   public static final String PREFIX_EVENT_WIRING = PREFIX_EVENT + ".wiring";
+   public static final String PREFIX_EVENT_NAME = PREFIX_EVENT + ".name.";
+   public static final String PREFIX_EVENT_WIRING = PREFIX_EVENT + ".wiring.";
    public static final String PREFIX_PARAMETER_NAME = PREFIX_PARAMETER + ".name";
    public static final String PREFIX_PARAMETER_BINDING = PREFIX_PARAMETER + ".binding";
    public static final String PREFIX_PARAMETER_ALIAS_NAME = PREFIX_PARAMETER_ALIAS + ".name";
@@ -78,6 +80,7 @@
 
    protected EventConverter eventConverter = new SimpleEventConverter();
    protected PortalObjectContainer portalObjectContainer;
+   private static final int PREFIX_EVENT_NAME_LENGTH = PREFIX_EVENT_NAME.length();
 
    protected void startService() throws Exception
    {
@@ -101,9 +104,9 @@
 
       // Only explicit wirings
       Map<Window, PortletWindowEvent> windows;
-      if(!implicitMode)
+      if (!implicitMode)
       {
-         windows = getEventWindowsExplicit(page, event, context);   
+         windows = getEventWindowsExplicit(page, event, context);
       }
       // If no explicit wirings for this event fallback to implicit
       else
@@ -158,7 +161,7 @@
          for (Map.Entry<Window, QName> entry : info.getSources().entrySet())
          {
             if (entry.getKey().getName().equals(event.getWindowId()) &&
-               entry.getValue().equals(event.getName()))
+                    entry.getValue().equals(event.getName()))
             {
                for (Window window : info.getDestinations().keySet())
                {
@@ -183,16 +186,16 @@
    {
       Map<Window, PortletWindowEvent> windows = new HashMap<Window, PortletWindowEvent>();
       for (String windowName : context.getWindowNames())
+      {
+         PortletInfo info = context.getPortletInfo(windowName);
+
+         //
+         if (info.getEventing() != null && info.getEventing().getConsumedEvents().containsKey(event.getName()))
          {
-            PortletInfo info = context.getPortletInfo(windowName);
-
-            //
-            if (info.getEventing() != null && info.getEventing().getConsumedEvents().containsKey(event.getName()))
-            {
-               PortletWindowEvent distributedEvent = new PortletWindowEvent(event.getName(), event.getPayload(), windowName);
-               windows.put(context.getWindow(windowName), distributedEvent);
-            }
+            PortletWindowEvent distributedEvent = new PortletWindowEvent(event.getName(), event.getPayload(), windowName);
+            windows.put(context.getWindow(windowName), distributedEvent);
          }
+      }
 
       return windows;
    }
@@ -202,7 +205,7 @@
       ParameterValidation.throwIllegalArgExceptionIfNull(sources, "sources");
       ParameterValidation.throwIllegalArgExceptionIfNull(destinations, "destinations");
       ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(eventName, "event name", null);
-      
+
       if (sources.isEmpty())
       {
          throw new IllegalArgumentException("empty sources map");
@@ -224,7 +227,7 @@
       all.addAll(sw);
       all.addAll(dw);
 
-      
+
       for (Window window : all)
       {
          if (parentPage == null)
@@ -251,8 +254,8 @@
 
       // Set the sources
 
-      String prop_name = PREFIX_EVENT_NAME + "." + eventName;
-      String prop_wiring = PREFIX_EVENT_WIRING + "." + eventName;
+      String prop_name = PREFIX_EVENT_NAME + eventName;
+      String prop_wiring = PREFIX_EVENT_WIRING + eventName;
 
       for (Window window : sw)
       {
@@ -272,7 +275,7 @@
 
    public void removeEventWiring(EventWiringInfo info) throws IllegalCoordinationException
    {
-      ParameterValidation.throwIllegalArgExceptionIfNull(info, "EventWiringInfo");
+      /*ParameterValidation.throwIllegalArgExceptionIfNull(info, "EventWiringInfo");
 
       // Remove all entries
 
@@ -287,6 +290,24 @@
       {
          window.setDeclaredProperty(prop_name, null);
          window.setDeclaredProperty(prop_wiring, null);
+      }*/
+
+      ParameterValidation.throwIllegalArgExceptionIfNull(info, "EventWiringInfo");
+      removeEventWiring(info.getPage(), info.getName());
+   }
+
+   public void removeEventWiring(Page page, String wiringName)
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(wiringName, "Event wiring name");
+      ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
+
+      String prop_name = PREFIX_EVENT_NAME + wiringName;
+      String prop_wiring = PREFIX_EVENT_WIRING + wiringName;
+
+      for (PortalObject window : page.getChildren(PortalObject.WINDOW_MASK))
+      {
+         window.setDeclaredProperty(prop_name, null);
+         window.setDeclaredProperty(prop_wiring, null);
       }
    }
 
@@ -296,6 +317,16 @@
       setEventWiring(eventWiring.getSources(), eventWiring.getDestinations(), newName);
    }
 
+   public void renameEventWiring(Page page, String wiringName, String newName) throws IllegalCoordinationException
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(wiringName, "Event wiring name");
+      ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
+
+      EventWiringInfo info = getEventWiring(page, wiringName);
+      removeEventWiring(page, wiringName);
+      setEventWiring(info.getSources(), info.getDestinations(), newName);
+   }
+
    public void setEventWiringImplicitMode(PageContainer pageContainer, boolean mode) throws IllegalCoordinationException
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(pageContainer, "PageContainer");
@@ -340,6 +371,51 @@
       return events;
    }
 
+   public EventWiringInfo getEventWiring(Page page, String name) throws IllegalCoordinationException
+   {
+      ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
+      ParameterValidation.throwIllegalArgExceptionIfNull(name, "Event wiring name");
+
+      String wiringProp = PREFIX_EVENT_WIRING + name;
+      String nameProp = PREFIX_EVENT_NAME + name;
+
+      Collection<PortalObject> windows = page.getChildren(PortalObject.WINDOW_MASK);
+      Map<Window, QName> sources = new HashMap<Window, QName>(windows.size());
+      Map<Window, QName> destinations = new HashMap<Window, QName>(windows.size());
+      for (PortalObject window : windows)
+      {
+         String eventName = window.getDeclaredProperty(wiringProp);
+
+         if (eventName != null)
+         {
+            String role = window.getDeclaredProperty(nameProp);
+            if (role == null)
+            {
+               throw new IllegalCoordinationException("Couldn't find role associated to event '" + name + "' in window "
+                       + window.getId());
+            }
+
+            QName qname = decodeQName(eventName);
+
+            if (role.equalsIgnoreCase(EVENT_ROLE_SOURCE))
+            {
+               sources.put((Window)window, qname);
+            }
+            else if (role.equalsIgnoreCase(EVENT_ROLE_DESTINATION))
+            {
+               destinations.put((Window)window, qname);
+            }
+         }
+      }
+
+      if (sources.isEmpty() || destinations.isEmpty())
+      {
+         throw new IllegalCoordinationException("Couldn't find sources or destinations for event '" + name + "'");
+      }
+
+      return new EventInfoPOJO(name, page, sources, destinations);
+   }
+
    public Collection<EventWiringInfo> getEventWirings(Page page)
    {
       ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
@@ -349,18 +425,18 @@
       Map<String, EventInfoPOJO> events = new HashMap<String, EventInfoPOJO>();
       for (PortalObject window : page.getChildren(PortalObject.WINDOW_MASK))
       {
-         Set<String> propNames = window.getProperties().keySet();
+         Set<String> propNames = window.getDeclaredProperties().keySet();
 
          for (String propName : propNames)
          {
-            if(propName.startsWith(PREFIX_EVENT_NAME))
+            if (propName.startsWith(PREFIX_EVENT_NAME))
             {
-               String en = propName.substring(PREFIX_EVENT_NAME.length() + 1);
+               String en = propName.substring(PREFIX_EVENT_NAME_LENGTH);
                EventInfoPOJO info;
 
                if (!events.keySet().contains(en))
                {
-                  info = new EventInfoPOJO(en);
+                  info = new EventInfoPOJO(en, page);
                   events.put(en, info);
                }
                else
@@ -368,24 +444,20 @@
                   info = events.get(en);
                }
 
-               String prop_wiring = PREFIX_EVENT_WIRING + "." + en;
+               String prop_wiring = PREFIX_EVENT_WIRING + en;
 
-               String name = window.getProperty(prop_wiring);
-               String role = window.getProperty(propName);
-
-
                //TODO: if information from properties is not consistent should we throw exception?
-
+               String name = window.getDeclaredProperty(prop_wiring);
                if (name != null)
                {
                   QName qname = decodeQName(name);
+                  String role = window.getDeclaredProperty(propName);
 
-
-                  if (qname != null && role != null && role.equalsIgnoreCase("source"))
+                  if (role != null && role.equalsIgnoreCase(EVENT_ROLE_SOURCE))
                   {
                      info.getSources().put((Window)window, qname);
                   }
-                  else if (qname != null && role != null && role.equalsIgnoreCase("destination"))
+                  else if (role != null && role.equalsIgnoreCase(EVENT_ROLE_DESTINATION))
                   {
                      info.getDestinations().put((Window)window, qname);
                   }
@@ -522,7 +594,7 @@
       ParameterValidation.throwIllegalArgExceptionIfNull(page, "Page");
       ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(aliasName, "name", "alias binding");
       ParameterValidation.throwIllegalArgExceptionIfNull(qnames, "aliased QNames");
-      if(qnames.isEmpty())
+      if (qnames.isEmpty())
       {
          throw new IllegalArgumentException("Aliased QNames set is empty!");
       }
@@ -539,7 +611,7 @@
       }
 
       StringBuilder qnameList = new StringBuilder();
-      for (Iterator i = qnames.iterator(); i.hasNext(); )
+      for (Iterator i = qnames.iterator(); i.hasNext();)
       {
          QName qname = (QName)i.next();
          qnameList.append(qname.toString());
@@ -558,9 +630,9 @@
 
       AliasInfoPOJO alias = (AliasInfoPOJO)aliasInfo;
       String propName = PREFIX_PARAMETER_ALIAS_NAME + "." + aliasInfo.getName();
-      if (alias.page.getProperties().keySet().contains(propName))
+      if (alias.getPage().getProperties().keySet().contains(propName))
       {
-         alias.page.setDeclaredProperty(propName,null);
+         alias.getPage().setDeclaredProperty(propName, null);
       }
    }
 
@@ -568,7 +640,7 @@
    {
       removeAliasBinding(aliasBinding);
       AliasInfoPOJO alias = (AliasInfoPOJO)aliasBinding;
-      setAliasBinding(alias.page, newName, alias.getNames());
+      setAliasBinding(alias.getPage(), newName, alias.getNames());
    }
 
    public Collection<AliasBindingInfo> getAliasBindings(Page page)
@@ -590,7 +662,7 @@
                for (String string : qnames)
                {
                   QName qname = QName.valueOf(string);
-                  info.names.add(qname);
+                  info.add(qname);
                }
             }
             aliases.add(info);
@@ -645,13 +717,13 @@
 
          for (String propName : propNames)
          {
-            if(propName.startsWith(PREFIX_PARAMETER_BINDING))
+            if (propName.startsWith(PREFIX_PARAMETER_BINDING))
             {
                String pn = propName.substring(PREFIX_PARAMETER_BINDING.length() + 1);
                WindowInfoPOJO info;
                if (!params.keySet().contains(pn))
                {
-                  info = new WindowInfoPOJO(pn);
+                  info = new WindowInfoPOJO(pn, page);
                   params.put(pn, info);
                }
                else
@@ -666,7 +738,7 @@
                   QName qname = decodeQName(binding);
                   if (qname != null)
                   {
-                     info.windows.put((Window)child, qname);
+                     info.addMapping((Window)child, qname);
                   }
                }
             }
@@ -720,7 +792,6 @@
    }
 
 
-
    private Boolean resolveImplicitMode(PageContainer pageContainer, String prefix)
    {
       String value = pageContainer.getDeclaredProperty(prefix);
@@ -779,21 +850,21 @@
    private class EventInfoPOJO implements EventWiringInfo
    {
       private final String name;
-      private final Map<Window,QName> sources;
-      private final Map<Window,QName> destinations;
+      private final Map<Window, QName> sources;
+      private final Map<Window, QName> destinations;
+      private final Page page;
 
-      private EventInfoPOJO(String name, Map<Window, QName> sources, Map<Window, QName> destinations)
+      private EventInfoPOJO(String name, Page page, Map<Window, QName> sources, Map<Window, QName> destinations)
       {
          this.name = name;
          this.sources = sources;
          this.destinations = destinations;
+         this.page = page;
       }
 
-      private EventInfoPOJO(String name)
+      private EventInfoPOJO(String name, Page page)
       {
-         this.name = name;
-         this.sources = new HashMap<Window,QName>();
-         this.destinations = new HashMap<Window,QName>();
+         this(name, page, new HashMap<Window, QName>(), new HashMap<Window, QName>());
       }
 
       public String getName()
@@ -813,22 +884,26 @@
 
       EventWiringInfo getImmutableWiringInfo()
       {
-         return new EventInfoPOJO(name, Collections.unmodifiableMap(sources), Collections.unmodifiableMap(destinations));
+         return new EventInfoPOJO(name, page, Collections.unmodifiableMap(sources), Collections.unmodifiableMap(destinations));
       }
 
+      public Page getPage()
+      {
+         return page;
+      }
    }
 
    private class WindowInfoPOJO implements WindowBindingInfo
    {
       private final String name;
       private final Map<Window, QName> windows;
-      private final Map<Window, QName> immutableWindows;
+      private final Page page;
 
-      private WindowInfoPOJO(String name)
+      private WindowInfoPOJO(String name, Page page)
       {
          this.name = name;
-         this.windows = new HashMap<Window,QName>();
-         this.immutableWindows = Collections.unmodifiableMap(windows);
+         this.windows = new HashMap<Window, QName>();
+         this.page = page;
       }
 
       public String getName()
@@ -838,8 +913,18 @@
 
       public Map<Window, QName> getWindows()
       {
-         return immutableWindows;
+         return Collections.unmodifiableMap(windows);
       }
+
+      public Page getPage()
+      {
+         return page;
+      }
+
+      private void addMapping(Window window, QName qname)
+      {
+         windows.put(window, qname);
+      }
    }
 
    private class AliasInfoPOJO implements AliasBindingInfo
@@ -847,14 +932,12 @@
       private final String name;
       private final Page page;
       private final Set<QName> names;
-      private final Set<QName> immutableNames;
 
       private AliasInfoPOJO(String name, Page page)
       {
          this.name = name;
          this.page = page;
          this.names = new HashSet<QName>();
-         this.immutableNames = Collections.unmodifiableSet(names);
       }
 
       public String getName()
@@ -864,7 +947,17 @@
 
       public Set<QName> getNames()
       {
-         return immutableNames;
+         return Collections.unmodifiableSet(names);
       }
+
+      public Page getPage()
+      {
+         return page;
+      }
+
+      private void add(QName qname)
+      {
+         names.add(qname);
+      }
    }
 }

Modified: branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java	2008-09-05 20:34:27 UTC (rev 11821)
+++ branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/coordination/CoordinationServiceTestCase.java	2008-09-05 23:13:35 UTC (rev 11822)
@@ -88,18 +88,18 @@
       Page p_1_1 = p_1.createPage("Page_1");
       Page p_1_2 = p_1.createPage("Page_2");
 
-      Page p_1_1_1 = p_1_1.createPage("Page_1");
+      p_1_1.createPage("Page_1");
 
-      Window w_1_1 = p_1_1.createWindow("Window_1", ContentType.PORTLET, "");
-      Window w_1_2 = p_1_1.createWindow("Window_2", ContentType.PORTLET, "");
-      Window w_1_3 = p_1_1.createWindow("Window_3", ContentType.PORTLET, "");
-      Window w_1_4 = p_1_1.createWindow("Window_4", ContentType.PORTLET, "");
+      p_1_1.createWindow("Window_1", ContentType.PORTLET, "");
+      p_1_1.createWindow("Window_2", ContentType.PORTLET, "");
+      p_1_1.createWindow("Window_3", ContentType.PORTLET, "");
+      p_1_1.createWindow("Window_4", ContentType.PORTLET, "");
 
 
-      Window w_2_1 = p_1_2.createWindow("Window_1", ContentType.PORTLET, "");
-      Window w_2_2 = p_1_2.createWindow("Window_2", ContentType.PORTLET, "");
-      Window w_2_3 = p_1_2.createWindow("Window_3", ContentType.PORTLET, "");
-      Window w_2_4 = p_1_2.createWindow("Window_4", ContentType.PORTLET, "");
+      p_1_2.createWindow("Window_1", ContentType.PORTLET, "");
+      p_1_2.createWindow("Window_2", ContentType.PORTLET, "");
+      p_1_2.createWindow("Window_3", ContentType.PORTLET, "");
+      p_1_2.createWindow("Window_4", ContentType.PORTLET, "");
 
 
       TransactionAssert.commitTransaction();
@@ -110,11 +110,10 @@
       TransactionAssert.beginTransaction();
 
       Portal portal_1 = container.getContext("").getPortal("Portal_1");
-      Page page_1  = portal_1.getPage("Page_1");
+      Page page_1 = portal_1.getPage("Page_1");
       Page page_1_1 = page_1.getPage("Page_1");
 
 
-
       assertNull(cos.isEventWiringImplicitModeEnabled(portal_1));
       assertNull(cos.isEventWiringImplicitModeEnabled(page_1));
       assertNull(cos.isEventWiringImplicitModeEnabled(page_1_1));
@@ -200,19 +199,13 @@
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
-      Page page2 = portal1.getPage("Page_2");
+      Page page1 = getPage1();
 
-
       Window w1 = page1.getWindow("Window_1");
       Window w2 = page1.getWindow("Window_2");
       Window w3 = page1.getWindow("Window_3");
       Window w4 = page1.getWindow("Window_4");
 
-      Window w2_1 = page1.getWindow("Window_2");
-
-
       Map<Window, QName> s1 = new HashMap<Window, QName>();
       Map<Window, QName> d1 = new HashMap<Window, QName>();
       s1.put(w1, new QName("juju", "foo"));
@@ -221,10 +214,8 @@
 
       d1.put(w4, new QName("bobo", "bar"));
 
-
       cos.setEventWiring(s1, d1, "event1");
 
-
       Collection<EventWiringInfo> events = cos.getEventWirings(page1);
 
       assertEquals(1, events.size());
@@ -264,7 +255,7 @@
       events = cos.getEventDestinationWirings(w4);
       assertNotNull(events);
       assertTrue(events.isEmpty());
-      
+
       TransactionAssert.commitTransaction();
    }
 
@@ -272,18 +263,13 @@
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
-      Page page2 = portal1.getPage("Page_2");
+      Page page1 = getPage1();
 
       Window w1 = page1.getWindow("Window_1");
       Window w2 = page1.getWindow("Window_2");
-      Window w3 = page1.getWindow("Window_3");
       Window w4 = page1.getWindow("Window_4");
 
-      Window w2_1 = page1.getWindow("Window_2");
 
-
       Map<Window, QName> ws = new HashMap<Window, QName>();
       ws.put(w1, new QName("juju", "foo"));
       ws.put(w2, new QName("juju", "foo1"));
@@ -309,7 +295,7 @@
 
       assertEquals(0, bindings.size());
 
-      
+
       TransactionAssert.commitTransaction();
    }
 
@@ -384,7 +370,6 @@
 
       }
 
-
       assertNotNull(info2);
       assertNotNull(info3);
 
@@ -401,7 +386,6 @@
       assertTrue(info3.getNames().contains(qname9));
 
 
-
       TransactionAssert.commitTransaction();
    }
 
@@ -409,8 +393,7 @@
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
+      Page page1 = getPage1();
 
       Window w1 = page1.getWindow("Window_1");
       Window w2 = page1.getWindow("Window_2");
@@ -434,10 +417,14 @@
 
       events = cos.getEventWirings(page1);
       assertEquals(1, events.size());
-
       info = events.iterator().next();
       assertEquals("new", info.getName());
 
+      cos.renameEventWiring(page1, "new", "newer");
+
+      info = cos.getEventWiring(page1, "newer");
+      assertNotNull(info);
+
       TransactionAssert.commitTransaction();
    }
 
@@ -445,8 +432,7 @@
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
+      Page page1 = getPage1();
 
       Window w1 = page1.getWindow("Window_1");
 
@@ -473,8 +459,7 @@
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
+      Page page1 = getPage1();
 
       Window w1 = page1.getWindow("Window_1");
       Window w2 = page1.getWindow("Window_2");
@@ -495,12 +480,73 @@
       TransactionAssert.commitTransaction();
    }
 
+   public void testGetEventWiring() throws IllegalCoordinationException
+   {
+      TransactionAssert.beginTransaction();
+
+      Page page1 = getPage1();
+
+      Window w1 = page1.getWindow("Window_1");
+      Window w2 = page1.getWindow("Window_2");
+      Window w3 = page1.getWindow("Window_3");
+      Window w4 = page1.getWindow("Window_4");
+
+      Map<Window, QName> s1 = new HashMap<Window, QName>();
+      Map<Window, QName> d1 = new HashMap<Window, QName>();
+      QName source11 = new QName("source", "1");
+      QName source12 = new QName("source", "2");
+      s1.put(w1, source11);
+      s1.put(w2, source12);
+      QName dest11 = new QName("dest", "3");
+      QName dest12 = new QName("dest", "4");
+      d1.put(w3, dest11);
+      d1.put(w4, dest12);
+
+      cos.setEventWiring(s1, d1, "event1");
+
+      s1 = new HashMap<Window, QName>();
+      d1 = new HashMap<Window, QName>();
+      QName source21 = new QName("source2", "1");
+      s1.put(w1, source21);
+      QName dest21 = new QName("dest2", "3");
+      d1.put(w3, dest21);
+
+      cos.setEventWiring(s1, d1, "event2");
+
+      EventWiringInfo info = cos.getEventWiring(page1, "event1");
+      assertNotNull(info);
+      assertEquals("event1", info.getName());
+
+      Map<Window, QName> sources = info.getSources();
+      assertNotNull(sources);
+      assertEquals(2, sources.size());
+      assertEquals(source11, sources.get(w1));
+      assertEquals(source12, sources.get(w2));
+      Map<Window, QName> destinations = info.getDestinations();
+      assertEquals(2, destinations.size());
+      assertEquals(dest11, destinations.get(w3));
+      assertEquals(dest12, destinations.get(w4));
+
+      info = cos.getEventWiring(page1, "event2");
+      assertNotNull(info);
+      assertEquals("event2", info.getName());
+
+      sources = info.getSources();
+      assertNotNull(sources);
+      assertEquals(1, sources.size());
+      assertEquals(source21, sources.get(w1));
+      destinations = info.getDestinations();
+      assertEquals(1, destinations.size());
+      assertEquals(dest21, destinations.get(w3));
+
+      TransactionAssert.commitTransaction();
+   }
+
    public void testRenameWindowBinding() throws Exception
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
+      Page page1 = getPage1();
 
       Window w1 = page1.getWindow("Window_1");
       Window w2 = page1.getWindow("Window_2");
@@ -531,8 +577,7 @@
    {
       TransactionAssert.beginTransaction();
 
-      Portal portal1 = container.getContext("").getPortal("Portal_1");
-      Page page1 = portal1.getPage("Page_1");
+      Page page1 = getPage1();
 
       QName qname1 = new QName("nm1", "local1");
       QName qname2 = new QName("nm2", "local2");
@@ -571,4 +616,10 @@
    {
       this.cos = cos;
    }
+
+   private Page getPage1()
+   {
+      Portal portal1 = container.getContext("").getPortal("Portal_1");
+      return portal1.getPage("Page_1");
+   }
 }

Modified: branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/coordination/EventWiringManagerBean.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/coordination/EventWiringManagerBean.java	2008-09-05 20:34:27 UTC (rev 11821)
+++ branches/JBoss_Portal_Branch_2_7/core-admin/src/main/org/jboss/portal/core/admin/ui/coordination/EventWiringManagerBean.java	2008-09-05 23:13:35 UTC (rev 11822)
@@ -156,7 +156,7 @@
       // create new wiring
       if (currentWiring == null)
       {
-         currentWiring = new EventWiringInfoCreator();
+         currentWiring = new EventWiringInfoCreator(managerBean.getSelectedPage());
       }
 
       // return list of produced events
@@ -334,23 +334,13 @@
 
    public String delete(String name) throws IllegalCoordinationException
    {
-      DisplayEventWiring displayEvent = displayEventWirings.get(name);
-      if (displayEvent != null)
-      {
-         EventWiringInfo event = displayEvent.getEventInfo();
-         managerBean.getCoordinationService().removeEventWiring(event);
-      }
+      managerBean.getCoordinationService().removeEventWiring(managerBean.getSelectedPage(), name);
       return resetSelection();
    }
 
    public String rename(String oldName, String newName) throws IllegalCoordinationException
    {
-      DisplayEventWiring displayEvent = displayEventWirings.get(oldName);
-      if (displayEvent != null)
-      {
-         EventWiringInfo event = displayEvent.getEventInfo();
-         managerBean.getCoordinationService().renameEventWiring(event, newName);
-      }
+      managerBean.getCoordinationService().renameEventWiring(managerBean.getSelectedPage(), oldName, newName);
       return resetSelection();
    }
 
@@ -456,12 +446,23 @@
       }
    }
 
-   private static class EventWiringInfoCreator implements EventWiringInfo
+   private class EventWiringInfoCreator implements EventWiringInfo
    {
       private String name;
       private Map<Window, QName> sources;
       private Map<Window, QName> destinations;
+      private final Page page;
 
+      private EventWiringInfoCreator(Page page)
+      {
+         this.page = page;
+      }
+
+      public Page getPage()
+      {
+         return page;
+      }
+
       public String getName()
       {
          return name;




More information about the portal-commits mailing list