Author: julien(a)jboss.com
Date: 2007-12-27 07:09:04 -0500 (Thu, 27 Dec 2007)
New Revision: 9389
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/MockModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
Log:
- reimplemented move operation on the model
- fixed a bug in the move operation in the structural state context
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
11:16:19 UTC (rev 9388)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-27
12:09:04 UTC (rev 9389)
@@ -205,19 +205,88 @@
}
}
}
-// else if (change instanceof StructuralObject.Move)
-// {
-// StructuralObject.Move move = (StructuralObject.Move)change;
-//
-// //
-// update(move.getParent());
-//
-// //
-// update(move.getSource());
-//
-// //
-// update(move.getDestination());
-// }
+ else if (change instanceof StructuralObject.Move)
+ {
+ StructuralObject.Move move = (StructuralObject.Move)change;
+
+ // Get the container object (some may not be loaded)
+ UIContainerObject parent = get(move.getParent());
+ UIContainerObject destination = get(move.getDestination());
+ UIContainerObject source = get(move.getSource());
+
+ // Update parent
+ if (parent != null)
+ {
+ UIObjectContext parentContext = parent.getContext();
+
+ // Update so
+ parentContext.structuralObject = move.getParent();
+
+ // Remove the child if the relationship is loaded on this side
+ if (parentContext.children.relateds != null)
+ {
+ for (Iterator<UIContainerObject> i =
parentContext.children.relateds.iterator();i.hasNext();)
+ {
+ UIContainerObject child = i.next();
+
+ //
+ if (child.getId().equals(move.getSource().getId()))
+ {
+ i.remove();
+ break;
+ }
+ }
+ }
+ }
+
+ //
+ if (destination != null)
+ {
+ UIObjectContext destinationContext = destination.getContext();
+
+ //
+ destinationContext.structuralObject = move.getDestination();
+
+ //
+ if (destinationContext.children.relateds != null)
+ {
+ // Now we really need to add the source as we load collections entirely
+ if (source == null)
+ {
+ source = create(move.getSource());
+
+ //
+ put(source);
+ }
+
+ //
+ destinationContext.children.relateds.add(source);
+ }
+ }
+
+ // Update source
+ if (source != null)
+ {
+ UIObjectContext sourceContext = source.getContext();
+
+ // Update so
+ sourceContext.structuralObject = move.getSource();
+
+ //
+ if (sourceContext.parent.loaded)
+ {
+ if (destination != null)
+ {
+ sourceContext.parent.related = destination;
+ }
+ else
+ {
+ sourceContext.parent.related = null;
+ sourceContext.parent.loaded = false;
+ }
+ }
+ }
+ }
else
{
throw new AssertionError();
@@ -225,9 +294,8 @@
}
/**
- * Get an object from the universe. If the parameter
<code>loadIfAbsent</code> has the value <code>false</code>
- * and the object is not in the universe it will throw an
<code>AssertionError</code> otherwise it will return
- * the object.
+ * Returns an object an object specified by the id that is referenced by this context
or load
+ * it if it is not present.
*
* @param id the id of the object to obtain
* @return the loaded object
@@ -538,12 +606,6 @@
//
return related;
}
-
- void clear()
- {
- related = null;
- loaded = false;
- }
}
class OneToMany
@@ -570,11 +632,6 @@
return list;
}
- void clear()
- {
- relateds = null;
- }
-
private List<UIContainerObject> getChildren(StructuralObject
structuralObject)
{
ArrayList<UIContainerObject> children = new
ArrayList<UIContainerObject>();
@@ -634,7 +691,7 @@
{
if (!owner.isValid())
{
- throw new IllegalStateException("Relationship not valid");
+ throw new IllegalStateException("Relationship cannot be used because
the owner " + owner + " is not valid");
}
if (relateds == null)
{
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-27
11:16:19 UTC (rev 9388)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/MockModelTestCase.java 2007-12-27
12:09:04 UTC (rev 9389)
@@ -359,6 +359,49 @@
assertEquals(Collections.singletonList(mockBar), mockRoot.getChildren());
}
+ public void testMove2() throws MockException
+ {
+ MockObject mockRoot = model.getRoot();
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PAGE);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PAGE);
+
+ //
+ String fooId = mockFoo.getId();
+ String barId = mockBar.getId();
+ String rootId = mockRoot.getId();
+
+ //
+ StructuralObject fooSO = ssc.load(fooId);
+ StructuralObject barSO = ssc.load(barId);
+ StructuralObject rootSO = ssc.load(rootId);
+
+ //
+ StructuralObject.Move move = ssc.move(fooSO, barSO);
+
+ //
+ assertNotNull(move);
+
+ //
+ StructuralObject newFooSO = move.getSource();
+ StructuralObject newBarSO = move.getDestination();
+ StructuralObject newRootSO = move.getParent();
+
+ //
+ assertEquals(rootId, newRootSO.getId());
+ assertEquals(fooId, newFooSO.getId());
+ assertEquals(barId, newBarSO.getId());
+
+ //
+ assertStale(fooSO);
+ assertStale(barSO);
+ assertStale(rootSO);
+
+ //
+ assertNotStale(newRootSO);
+ assertNotStale(newBarSO);
+ assertNotStale(newFooSO);
+ }
+
public void testMoveViolatesConstraint() throws MockException
{
MockObject mockRoot = model.getRoot();
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
11:16:19 UTC (rev 9388)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-27
12:09:04 UTC (rev 9389)
@@ -648,7 +648,7 @@
}
- public void _testMove() throws Exception
+ public void testMove() throws Exception
{
MockObject mockRoot = model.getRoot();
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-27
11:16:19 UTC (rev 9388)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-27
12:09:04 UTC (rev 9389)
@@ -323,7 +323,7 @@
mockSource.move(mockDestination);
//
- return new StructuralObject.Move(mockParent.takeSnapshot(),
mockSource.takeSnapshot(), mockSource.takeSnapshot());
+ return new StructuralObject.Move(mockParent.takeSnapshot(),
mockSource.takeSnapshot(), mockDestination.takeSnapshot());
}
catch (MockException e)
{
Show replies by date