Author: julien(a)jboss.com
Date: 2007-12-27 08:25:10 -0500 (Thu, 27 Dec 2007)
New Revision: 9390
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
more implementation of refresh operation
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27
12:09:04 UTC (rev 9389)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27
13:25:10 UTC (rev 9390)
@@ -31,6 +31,7 @@
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.common.NotYetImplemented;
import java.util.ArrayList;
import java.util.HashMap;
@@ -38,8 +39,6 @@
import java.util.Map;
import java.util.AbstractList;
import java.util.Iterator;
-import java.util.Set;
-import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -419,50 +418,91 @@
// Update the structural state
if (!context.structuralObject.compareTo(refresh.getObject()))
{
- context.structuralObject = refresh.getObject();
- }
+ boolean loaded = context.children.relateds != null;
- //
- boolean loaded = context.children.relateds != null;
+ //
+ if (loaded)
+ {
+ boolean refreshChildren = scope.enterChildren(object, loaded);
- //
- if (loaded)
- {
- boolean refreshChildren = scope.enterChildren(object, loaded);
+ // The new list of children
+ List<UIContainerObject> children = new
ArrayList<UIContainerObject>();
- // Removals
- for (String removedId : refresh.getRemovedChildren())
- {
- }
+ // Take care of the added children
+ for (StructuralObject addedSO : refresh.getAddedChildren())
+ {
+ UIContainerObject added = get(addedSO);
+ //
+ if (added != null)
+ {
+ UIObjectContext addedContext = added.getContext();
- // Compute set of added ids
-// Set<String> addedIds = new HashSet<String>();
-// for (StructuralObject addedSO : refresh.getAddedChildren())
-// {
-// addedIds.add(addedSO.getId());
-// }
+ // Set the parent as stale if needed
+ if (addedContext.parent.loaded)
+ {
+ UIObjectContext addedParentContext =
addedContext.parent.related.getContext();
- List<UIContainerObject> children = new
ArrayList<UIContainerObject>();
+ // Mark the parent as stale
+ addedParentContext.status = UIObject.Status.STALE;
- //
- for (StructuralObject addedSO : refresh.getAddedChildren())
- {
- }
+ //
+ addedParentContext.parent.related =
get(context.structuralObject.getId());
+ }
+ }
+ else
+ {
+ added = create(addedSO);
- //
- for (String validId : refresh.getValidChildren())
- {
- }
+ //
+ put(added);
+ }
+ //
+ children.add(added);
+ }
- //
- for (StructuralObject staleSO :
refresh.getStaleChildren().values())
- {
+ //
+ for (String validId : refresh.getValidChildren())
+ {
+ UIContainerObject valid = get(validId);
+
+ // It must be here...
+ children.add(valid);
+ }
+
+
+ //
+ for (StructuralObject staleSO :
refresh.getStaleChildren().values())
+ {
+ UIContainerObject stale = get(staleSO);
+
+ // Mark as stale
+ stale.getContext().status = UIObject.Status.STALE;
+
+ //
+ children.add(stale);
+ }
+
+ // Removals
+ for (String removedId : refresh.getRemovedChildren())
+ {
+ UIContainerObject removed = get(removedId);
+
+ //
+ if (removed != null)
+ {
+ // We should try to now if it is somehow referenced by
someone that is not us
+ // i.e it has been already be moved somewhere else
+ throw new NotYetImplemented();
+ }
+ }
+
+ // Update state
+ context.structuralObject = refresh.getObject();
+ context.status = UIObject.Status.VALID;
+ context.children.relateds = children;
}
-
- // Update to valid
- context.status = UIObject.Status.VALID;
}
}
catch (NoSuchStateException e)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27
12:09:04 UTC (rev 9389)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27
13:25:10 UTC (rev 9390)
@@ -647,7 +647,38 @@
assertSame(context.getObject(daaId), daa);
}
+ public void testRefreshAfterConcurrentMove() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+
+ MockObject mockFooJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockFooDaa = mockFoo.addChild("daa", MockObject.Type.PAGE);
+
+ MockObject mockBarDaa = mockBar.addChild("daa", MockObject.Type.PAGE);
+
+ // Load fully the context 1
+ UIContext context1 = createContext();
+ loadDescendants(context1);
+
+ // Concurrent move
+ UIContext context2 = createContext();
+
context2.getChild("foo").getChild("juu").move(context2.getChild("bar"));
+
+ //
+ context1.getChild("bar").refresh();
+ }
+
+ private void loadDescendants(UIObject object)
+ {
+ for (UIObject child : object.getChildren())
+ {
+ loadDescendants(child);
+ }
+ }
+
public void testMove() throws Exception
{
MockObject mockRoot = model.getRoot();
Show replies by date