Author: mir
Date: Tue Feb 23 12:18:30 2010
New Revision: 915298
URL: http://svn.apache.org/viewvc?rev=915298&view=rev
Log:
CLEREZZA-134: IllegalMoveException is now throw when a collection is tried to
move into itself or a subcollection of itself
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java?rev=915298&r1=915297&r2=915298&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/CollectionNode.java
Tue Feb 23 12:18:30 2010
@@ -132,6 +132,15 @@
}
}
+ @Override
+ public HierarchyNode move(CollectionNode newParentCollection, int pos)
throws NodeAlreadyExistsException,
+ IllegalMoveException {
+ if (newParentCollection.isSubcollectionOf(this)) {
+ throw new IllegalMoveException("Collection can not be
moved into itself or a subcollection of itself");
+ }
+ return super.move(newParentCollection, pos);
+ }
+
private void updateMember(UriRef memberUri) {
try {
CollectionNode memberCollection = new
CollectionNode(memberUri,
@@ -169,4 +178,9 @@
deleteProperties(HIERARCHY.members);
}
+ private boolean isSubcollectionOf(CollectionNode collection) {
+ return collection.getNode().getUnicodeString().
+ startsWith(getNode().getUnicodeString());
+ }
+
}
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java?rev=915298&r1=915297&r2=915298&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyManager.java
Tue Feb 23 12:18:30 2010
@@ -200,6 +200,9 @@
targetCollection.getUnicodeString() + "
already exists in " +
"collection.").
type(MediaType.TEXT_PLAIN_TYPE).build();
+ } catch (IllegalMoveException ex) {
+ return
Response.status(Response.Status.CONFLICT).entity(ex.getMessage()).
+ type(MediaType.TEXT_PLAIN_TYPE).build();
}
return Response.created(
URI.create(hierarchyNode.getNode().getUnicodeString())).build();
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java?rev=915298&r1=915297&r2=915298&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/main/java/org/apache/clerezza/platform/content/hierarchy/HierarchyNode.java
Tue Feb 23 12:18:30 2010
@@ -86,10 +86,11 @@
* the new parent collection.
* @throws NodeAlreadyExistsException is thrown if the new parent
collection
* already contains a hierarchy node with the same name.
+ * @throws IllegalMoveException is thrown if the move operation is not
allowed
* @return the HierarchyNode at the new location
*/
public HierarchyNode move(CollectionNode newParentCollection, int pos)
- throws NodeAlreadyExistsException {
+ throws NodeAlreadyExistsException, IllegalMoveException
{
if (newParentCollection.equals(getParent())) {
UriRef nodeUri = getNode();
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java?rev=915298&r1=915297&r2=915298&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.webapp.parent/org.apache.clerezza.platform.content/src/test/java/org/apache/clerezza/platform/content/hierarchy/HierarchyTest.java
Tue Feb 23 12:18:30 2010
@@ -211,6 +211,18 @@
}
@Test
+ public void collectionMoveIntoItselfTest() throws Exception {
+ HierarchyService hierarchyService = getHierarchyService();
+ CollectionNode barNode =
hierarchyService.createCollectionNode(bar);
+ try {
+ barNode.move(barNode, 0);
+ Assert.assertTrue(false);
+ } catch (IllegalMoveException ex) {
+ Assert.assertTrue(true);
+ }
+ }
+
+ @Test
public void rootAutoCreationTest() throws Exception{
HierarchyService hierarchyService = getHierarchyService();
hierarchyService.createCollectionNode(newRootTest);