[gatein-commits] gatein SVN: r575 - in portal/trunk/component/portal/src: test/java/org/exoplatform/portal/config and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Thu Nov 12 03:12:42 EST 2009


Author: julien_viet
Date: 2009-11-12 03:12:42 -0500 (Thu, 12 Nov 2009)
New Revision: 575

Modified:
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
   portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelChange.java
   portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
Log:
add a unit test for assessing window move


Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java	2009-11-12 03:51:21 UTC (rev 574)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/Mapper.java	2009-11-12 08:12:42 UTC (rev 575)
@@ -357,43 +357,6 @@
       );
    }
 
-   public List<ModelChange> save(PageData src, Site site, String name)
-   {
-      org.gatein.mop.api.workspace.Page root = site.getRootPage();
-      org.gatein.mop.api.workspace.Page pages = root.getChild("pages");
-      org.gatein.mop.api.workspace.Page dst = pages.getChild(name);
-
-      //
-      LinkedList<ModelChange> changes = new LinkedList<ModelChange>();
-
-      //
-      if (dst == null)
-      {
-         dst = pages.addChild(name);
-         changes.add(new ModelChange.Create(src));
-      }
-      else
-      {
-         changes.add(new ModelChange.Update(src));
-      }
-
-      //
-      Attributes attrs = dst.getAttributes();
-      attrs.setValue(MappedAttributes.TITLE, src.getTitle());
-      attrs.setValue(MappedAttributes.FACTORY_ID, src.getFactoryId());
-      attrs.setValue(MappedAttributes.ACCESS_PERMISSIONS, join("|", src.getAccessPermissions()));
-      attrs.setValue(MappedAttributes.EDIT_PERMISSION, src.getEditPermission());
-      attrs.setValue(MappedAttributes.SHOW_MAX_WINDOW, src.isShowMaxWindow());
-      attrs.setValue(MappedAttributes.CREATOR, src.getCreator());
-      attrs.setValue(MappedAttributes.MODIFIER, src.getModifier());
-
-      //
-      changes.addAll(saveChildren(src, dst.getRootComponent()));
-
-      //
-      return changes;
-   }
-
    private ContainerData load(UIContainer src, List<ComponentData> children)
    {
       Attributes attrs = src.getAttributes();
@@ -485,6 +448,47 @@
       return children;
    }
 
+   public List<ModelChange> save(PageData src, Site site, String name)
+   {
+      org.gatein.mop.api.workspace.Page root = site.getRootPage();
+      org.gatein.mop.api.workspace.Page pages = root.getChild("pages");
+      org.gatein.mop.api.workspace.Page dst = pages.getChild(name);
+
+      //
+      LinkedList<ModelChange> changes = new LinkedList<ModelChange>();
+
+      //
+      if (dst == null)
+      {
+         dst = pages.addChild(name);
+         changes.add(new ModelChange.Create(dst.getObjectId(), src));
+      }
+      else
+      {
+         changes.add(new ModelChange.Update(src));
+      }
+
+      //
+      Attributes attrs = dst.getAttributes();
+      attrs.setValue(MappedAttributes.TITLE, src.getTitle());
+      attrs.setValue(MappedAttributes.FACTORY_ID, src.getFactoryId());
+      attrs.setValue(MappedAttributes.ACCESS_PERMISSIONS, join("|", src.getAccessPermissions()));
+      attrs.setValue(MappedAttributes.EDIT_PERMISSION, src.getEditPermission());
+      attrs.setValue(MappedAttributes.SHOW_MAX_WINDOW, src.isShowMaxWindow());
+      attrs.setValue(MappedAttributes.CREATOR, src.getCreator());
+      attrs.setValue(MappedAttributes.MODIFIER, src.getModifier());
+
+      //
+      UIContainer rootContainer = dst.getRootComponent();
+      LinkedList<ModelChange> childrenChanges = saveChildren(src, rootContainer);
+
+      //
+      changes.addAll(childrenChanges);
+
+      //
+      return changes;
+   }
+
    private void save(ContainerData src, UIContainer dst)
    {
       Attributes dstAttrs = dst.getAttributes();
@@ -502,6 +506,9 @@
       dstAttrs.setValue(MappedAttributes.NAME, src.getName());
    }
 
+   /*
+    * Performs routing of the corresponding save method
+    */
    private void save(ModelData src, WorkspaceObject dst, LinkedList<ModelChange> changes,
       Map<String, String> hierarchyRelationships)
    {
@@ -526,18 +533,18 @@
 
    private LinkedList<ModelChange> saveChildren(final ContainerData src, UIContainer dst)
    {
-
-      //
       LinkedList<ModelChange> changes = new LinkedList<ModelChange>();
 
-      //
+      // The relationship in the hierarchy
+      // basically it's a map of the relationships between parent/child nodes
+      // that is helpful to detect move operations
+      // that we make immutable to avoid any bug
       Map<String, String> hierarchyRelationships = new HashMap<String, String>();
-
-      //
       build(src, hierarchyRelationships);
+      hierarchyRelationships = Collections.unmodifiableMap(hierarchyRelationships);
 
       //
-      saveChildren(src, dst, changes, Collections.unmodifiableMap(hierarchyRelationships));
+      saveChildren(src, dst, changes, hierarchyRelationships);
 
       //
       return changes;
@@ -572,9 +579,11 @@
       //
       for (ModelData srcChild : src.getChildren())
       {
-         String srcId = srcChild.getStorageId();
+         String srcChildId = srcChild.getStorageId();
 
          // Replace dashboard application by container if needed
+         // this should be removed once we make the dashboard as first class
+         // citizen of the portal
          if (srcChild instanceof ApplicationData)
          {
             ApplicationData app = (ApplicationData)srcChild;
@@ -599,13 +608,14 @@
 
          //
          UIComponent dstChild;
-         if (srcId != null)
+         if (srcChildId != null)
          {
-            dstChild = session.findObjectById(ObjectType.COMPONENT, srcId);
+            dstChild = session.findObjectById(ObjectType.COMPONENT, srcChildId);
             if (dstChild == null)
             {
-               throw new AssertionError("Could not find supposed present child with id " + srcId);
+               throw new AssertionError("Could not find supposed present child with id " + srcChildId);
             }
+
             // julien : this can fail due to a bug in chromattic not implementing equals method properly
             // and is replaced with the foreach below
             /*
@@ -614,23 +624,27 @@
                         "that is not present in the target ui container " + session.pathOf(dst));
                     }
             */
-
-            //
             boolean found = false;
             for (UIComponent child : dst)
             {
-               if (child.getObjectId().equals(srcId))
+               if (child.getObjectId().equals(srcChildId))
                {
                   found = true;
                   break;
                }
             }
+
+            //
             if (!found)
             {
-               if (hierarchyRelationships.containsKey(srcId))
+               String srcId = hierarchyRelationships.get(srcChildId);
+               if (srcId != null)
                {
                   // It's a move operation, so we move the node first
                   dst.add(dstChild);
+
+                  //
+                  changes.add(new ModelChange.Move(srcId, dst.getObjectId(), srcChildId));
                }
                else
                {
@@ -666,34 +680,40 @@
             {
                throw new AssertionError("Was not expecting child " + srcChild);
             }
-            changes.add(new ModelChange.Create(srcChild));
+            changes.add(new ModelChange.Create(dst.getObjectId(), srcChild));
          }
 
          //
          save(srcChild, dstChild, changes, hierarchyRelationships);
 
          //
-         String dstId = dstChild.getObjectId();
-         modelObjectMap.put(dstId, srcChild);
-         orders.add(dstId);
+         String dstChildId = dstChild.getObjectId();
+         modelObjectMap.put(dstChildId, srcChild);
+         orders.add(dstChildId);
       }
 
-      // Take care of move operation that could be seen as a remove
+      // Take care of move operation that could be seen as a remove otherwise
       for (UIComponent dstChild : dst)
       {
-         String dstId = dstChild.getObjectId();
-         if (!modelObjectMap.containsKey(dstId) && hierarchyRelationships.containsKey(dstId))
+         String dstChildId = dstChild.getObjectId();
+         if (!modelObjectMap.containsKey(dstChildId))
          {
-            String parentId = hierarchyRelationships.get(dstId);
+            String parentId = hierarchyRelationships.get(dstChildId);
+            if (parentId != null)
+            {
+               // Get the new parent
+               UIContainer parent = session.findObjectById(ObjectType.CONTAINER, parentId);
 
-            // Get the new parent
-            UIContainer parent = session.findObjectById(ObjectType.CONTAINER, parentId);
+               // Perform the move
+               parent.add(dstChild);
 
-            // Perform the move
-            parent.add(dstChild);
+               //
+               changes.add(new ModelChange.Move(dst.getObjectId(), parentId, dstChildId));
 
-            //
-            changes.add(new ModelChange.Destroy(dstId));
+               // julien : we do not need to create an update operation
+               // as later the update operation will be created when the object
+               // will be processed
+            }
          }
       }
 
@@ -701,11 +721,11 @@
       for (Iterator<UIComponent> i = dst.iterator(); i.hasNext();)
       {
          UIComponent dstChild = i.next();
-         String dstId = dstChild.getObjectId();
-         if (!modelObjectMap.containsKey(dstId))
+         String dstChildId = dstChild.getObjectId();
+         if (!modelObjectMap.containsKey(dstChildId))
          {
             i.remove();
-            changes.add(new ModelChange.Destroy(dstId));
+            changes.add(new ModelChange.Destroy(dstChildId));
          }
       }
 
@@ -771,7 +791,7 @@
       );
    }
 
-   public <S, I> void save(ApplicationData<S> src, UIWindow dst)
+   public <S> void save(ApplicationData<S> src, UIWindow dst)
    {
       Attributes attrs = dst.getAttributes();
       attrs.setValue(MappedAttributes.THEME, src.getTheme());

Modified: portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelChange.java
===================================================================
--- portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelChange.java	2009-11-12 03:51:21 UTC (rev 574)
+++ portal/trunk/component/portal/src/main/java/org/exoplatform/portal/pom/data/ModelChange.java	2009-11-12 08:12:42 UTC (rev 575)
@@ -30,10 +30,14 @@
    {
 
       /** . */
+      private final String parentId;
+
+      /** . */
       private final ModelData object;
 
-      public Create(ModelData object)
+      public Create(String parentId, ModelData object)
       {
+         this.parentId = parentId;
          this.object = object;
       }
 
@@ -41,6 +45,12 @@
       {
          return object;
       }
+
+      @Override
+      public String toString()
+      {
+         return "ModelChange.Create[parentId=" + parentId + "id=" + object.getStorageId() + ",name=" + object.getStorageName() + "]";
+      }
    }
 
    public static class Update extends ModelChange
@@ -58,22 +68,75 @@
       {
          return object;
       }
+
+      @Override
+      public String toString()
+      {
+         return "ModelChange.Update[id=" + object.getStorageId() + "]";
+      }
    }
 
    public static class Destroy extends ModelChange
    {
 
       /** . */
-      private final String objectId;
+      private final String id;
 
-      public Destroy(String objectId)
+      public Destroy(String id)
       {
-         this.objectId = objectId;
+         this.id = id;
       }
 
-      public String getObjectId()
+      public String getId()
       {
-         return objectId;
+         return id;
       }
+
+      @Override
+      public String toString()
+      {
+         return "ModelChange.Destroy[id=" + id + "]";
+      }
    }
+
+   public static class Move extends ModelChange
+   {
+
+      /** . */
+      private final String srcId;
+
+      /** . */
+      private final String dstId;
+
+      /** . */
+      private final String id;
+
+      public Move(String srcId, String dstId, String id)
+      {
+         this.srcId = srcId;
+         this.dstId = dstId;
+         this.id = id;
+      }
+
+      public String getSrcId()
+      {
+         return srcId;
+      }
+
+      public String getDstId()
+      {
+         return dstId;
+      }
+
+      public String getId()
+      {
+         return id;
+      }
+
+      @Override
+      public String toString()
+      {
+         return "ModelChange.Move[srcId=" + srcId + ",dstId=" + dstId + ",id" + id + "]";
+      }
+   }
 }

Modified: portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java
===================================================================
--- portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java	2009-11-12 03:51:21 UTC (rev 574)
+++ portal/trunk/component/portal/src/test/java/org/exoplatform/portal/config/TestDataStorage.java	2009-11-12 08:12:42 UTC (rev 575)
@@ -204,6 +204,49 @@
       assertNull(page);
    }
 
+   public void testWindowMove1() throws Exception
+   {
+      Page page = storage_.getPage("portal::test::test4");
+      Application<?> a1 = (Application<?>)page.getChildren().get(0);
+      Container a2 = (Container)page.getChildren().get(1);
+      Application<?> a3 = (Application<?>)a2.getChildren().get(0);
+      Application<?> a4 = (Application<?>)a2.getChildren().remove(1);
+      page.getChildren().add(1, a4);
+      List<ModelChange> changes = storage_.save(page);
+
+      //
+      page = storage_.getPage("portal::test::test4");
+      assertEquals(3, page.getChildren().size());
+      Application<?> c1 = (Application<?>)page.getChildren().get(0);
+      assertEquals(a1.getStorageId(), c1.getStorageId());
+      Application<?> c2 = (Application<?>)page.getChildren().get(1);
+      assertEquals(a4.getStorageId(), c2.getStorageId());
+      Container c3 = (Container)page.getChildren().get(2);
+      assertEquals(a2.getStorageId(), c3.getStorageId());
+      assertEquals(1, c3.getChildren().size());
+      Application<?> c4 = (Application<?>)c3.getChildren().get(0);
+      assertEquals(a3.getStorageId(), c4.getStorageId());
+
+      //
+      assertEquals(6, changes.size());
+      ModelChange.Update ch1 = (ModelChange.Update)changes.get(0);
+      assertEquals(page.getStorageId(), ch1.getObject().getStorageId());
+      ModelChange.Update ch2 = (ModelChange.Update)changes.get(1);
+      assertEquals(a1.getStorageId(), ch2.getObject().getStorageId());
+      ModelChange.Move ch3 = (ModelChange.Move)changes.get(2);
+//      assertEquals(a2.getStorageId(), ch3.getSrcId());
+//      assertEquals(page.getStorageId(), ch3.getDstId());
+      assertEquals(a4.getStorageId(), ch3.getId());
+      ModelChange.Update ch4 = (ModelChange.Update)changes.get(3);
+      assertEquals(a4.getStorageId(), ch4.getObject().getStorageId());
+      ModelChange.Update ch5 = (ModelChange.Update)changes.get(4);
+      assertEquals(a2.getStorageId(), ch5.getObject().getStorageId());
+      ModelChange.Update ch6 = (ModelChange.Update)changes.get(5);
+      assertEquals(a3.getStorageId(), ch6.getObject().getStorageId());
+   }
+
+   // Need to make window move 2 unit test
+
    public void testNavigationCreate() throws Exception
    {
       testPageConfigRemove();



More information about the gatein-commits mailing list