mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixed test to flush session, avoiding unique constraint violation
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2858 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -30,6 +30,7 @@ import org.alfresco.model.ContentModel;
|
|||||||
import org.alfresco.repo.node.StoreArchiveMap;
|
import org.alfresco.repo.node.StoreArchiveMap;
|
||||||
import org.alfresco.repo.node.archive.RestoreNodeReport.RestoreStatus;
|
import org.alfresco.repo.node.archive.RestoreNodeReport.RestoreStatus;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||||
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
@@ -56,6 +57,7 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
{
|
{
|
||||||
private static final String USER_A = "AAAAA";
|
private static final String USER_A = "AAAAA";
|
||||||
private static final String USER_B = "BBBBB";
|
private static final String USER_B = "BBBBB";
|
||||||
|
private static final QName ASPECT_ATTACHABLE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "attachable");
|
||||||
private static final QName ASSOC_ATTACHMENTS = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "attachments");
|
private static final QName ASSOC_ATTACHMENTS = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "attachments");
|
||||||
private static final QName QNAME_A = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "a");
|
private static final QName QNAME_A = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "a");
|
||||||
private static final QName QNAME_B = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "b");
|
private static final QName QNAME_B = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "b");
|
||||||
@@ -194,6 +196,7 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
QNAME_A,
|
QNAME_A,
|
||||||
ContentModel.TYPE_FOLDER,
|
ContentModel.TYPE_FOLDER,
|
||||||
properties).getChildRef();
|
properties).getChildRef();
|
||||||
|
nodeService.addAspect(a, ASPECT_ATTACHABLE, null);
|
||||||
properties.put(ContentModel.PROP_NODE_UUID, "aa");
|
properties.put(ContentModel.PROP_NODE_UUID, "aa");
|
||||||
childAssocAtoAA = nodeService.createNode(
|
childAssocAtoAA = nodeService.createNode(
|
||||||
a,
|
a,
|
||||||
@@ -202,6 +205,7 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
ContentModel.TYPE_CONTENT,
|
ContentModel.TYPE_CONTENT,
|
||||||
properties);
|
properties);
|
||||||
aa = childAssocAtoAA.getChildRef();
|
aa = childAssocAtoAA.getChildRef();
|
||||||
|
nodeService.addAspect(aa, ASPECT_ATTACHABLE, null);
|
||||||
properties.put(ContentModel.PROP_NODE_UUID, "b");
|
properties.put(ContentModel.PROP_NODE_UUID, "b");
|
||||||
b = nodeService.createNode(
|
b = nodeService.createNode(
|
||||||
workStoreRootNodeRef,
|
workStoreRootNodeRef,
|
||||||
@@ -326,6 +330,9 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
verifyNodeExistence(b_, false);
|
verifyNodeExistence(b_, false);
|
||||||
verifyNodeExistence(bb_, true);
|
verifyNodeExistence(bb_, true);
|
||||||
|
|
||||||
|
// flush
|
||||||
|
AlfrescoTransactionSupport.flush();
|
||||||
|
|
||||||
// check that the required properties are present and correct
|
// check that the required properties are present and correct
|
||||||
Map<QName, Serializable> bb_Properties = nodeService.getProperties(bb_);
|
Map<QName, Serializable> bb_Properties = nodeService.getProperties(bb_);
|
||||||
Path bb_originalPath = (Path) bb_Properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PATH);
|
Path bb_originalPath = (Path) bb_Properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PATH);
|
||||||
@@ -351,6 +358,9 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
verifyNodeExistence(bb_, true);
|
verifyNodeExistence(bb_, true);
|
||||||
verifyChildAssocExistence(childAssocBtoBB_, true);
|
verifyChildAssocExistence(childAssocBtoBB_, true);
|
||||||
|
|
||||||
|
// flush
|
||||||
|
AlfrescoTransactionSupport.flush();
|
||||||
|
|
||||||
// restore the node
|
// restore the node
|
||||||
nodeService.restoreNode(b_, null, null, null);
|
nodeService.restoreNode(b_, null, null, null);
|
||||||
// check
|
// check
|
||||||
@@ -362,6 +372,10 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
// delete both trees in order 'b', 'a'
|
// delete both trees in order 'b', 'a'
|
||||||
nodeService.deleteNode(b);
|
nodeService.deleteNode(b);
|
||||||
nodeService.deleteNode(a);
|
nodeService.deleteNode(a);
|
||||||
|
|
||||||
|
// flush
|
||||||
|
AlfrescoTransactionSupport.flush();
|
||||||
|
|
||||||
// restore in reverse order
|
// restore in reverse order
|
||||||
nodeService.restoreNode(a_, null, null, null);
|
nodeService.restoreNode(a_, null, null, null);
|
||||||
nodeService.restoreNode(b_, null, null, null);
|
nodeService.restoreNode(b_, null, null, null);
|
||||||
@@ -374,6 +388,10 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
// delete both trees in order 'b', 'a'
|
// delete both trees in order 'b', 'a'
|
||||||
nodeService.deleteNode(a);
|
nodeService.deleteNode(a);
|
||||||
nodeService.deleteNode(b);
|
nodeService.deleteNode(b);
|
||||||
|
|
||||||
|
// flush
|
||||||
|
AlfrescoTransactionSupport.flush();
|
||||||
|
|
||||||
// restore in reverse order
|
// restore in reverse order
|
||||||
nodeService.restoreNode(b_, null, null, null);
|
nodeService.restoreNode(b_, null, null, null);
|
||||||
nodeService.restoreNode(a_, null, null, null);
|
nodeService.restoreNode(a_, null, null, null);
|
||||||
@@ -386,6 +404,10 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
// delete a then b
|
// delete a then b
|
||||||
nodeService.deleteNode(a);
|
nodeService.deleteNode(a);
|
||||||
nodeService.deleteNode(b);
|
nodeService.deleteNode(b);
|
||||||
|
|
||||||
|
// flush
|
||||||
|
AlfrescoTransactionSupport.flush();
|
||||||
|
|
||||||
// in restoring 'a' first, there will be some associations that won't be recreated
|
// in restoring 'a' first, there will be some associations that won't be recreated
|
||||||
nodeService.restoreNode(a_, null, null, null);
|
nodeService.restoreNode(a_, null, null, null);
|
||||||
nodeService.restoreNode(b_, null, null, null);
|
nodeService.restoreNode(b_, null, null, null);
|
||||||
@@ -438,6 +460,10 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
nodeService.deleteNode(b);
|
nodeService.deleteNode(b);
|
||||||
long end = System.nanoTime();
|
long end = System.nanoTime();
|
||||||
cumulatedArchiveTimeNs += (end - start);
|
cumulatedArchiveTimeNs += (end - start);
|
||||||
|
|
||||||
|
// flush
|
||||||
|
AlfrescoTransactionSupport.flush();
|
||||||
|
|
||||||
// now restore
|
// now restore
|
||||||
start = System.nanoTime();
|
start = System.nanoTime();
|
||||||
nodeService.restoreNode(b_, null, null, null);
|
nodeService.restoreNode(b_, null, null, null);
|
||||||
@@ -565,4 +591,21 @@ public class ArchiveAndRestoreTest extends TestCase
|
|||||||
// List<RestoreNodeReport> restoredByB = nodeArchiveService.restoreAllArchivedNodes(workStoreRef);
|
// List<RestoreNodeReport> restoredByB = nodeArchiveService.restoreAllArchivedNodes(workStoreRef);
|
||||||
// assertEquals("User B should not have seen A's delete", 1, restoredByB.size());
|
// assertEquals("User B should not have seen A's delete", 1, restoredByB.size());
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Deny the current user the rights to write to the destination location
|
||||||
|
// * and ensure that the use-case is handled properly.
|
||||||
|
// */
|
||||||
|
// public void testPermissionsLackingOnDestination() throws Exception
|
||||||
|
// {
|
||||||
|
// // remove 'b', deny permissions to workspace root and attempt a restore
|
||||||
|
// nodeService.deleteNode(b);
|
||||||
|
// permissionService.setPermission(workStoreRootNodeRef, USER_B, PermissionService.ADD_CHILDREN, false);
|
||||||
|
// commitAndBeginNewTransaction();
|
||||||
|
//
|
||||||
|
// // the restore of b should fail for user B
|
||||||
|
// authenticationService.authenticate(USER_B, USER_B.toCharArray());
|
||||||
|
// RestoreNodeReport report = nodeArchiveService.restoreArchivedNode(b_);
|
||||||
|
// assertEquals("Expected permission denied status", RestoreStatus.FAILURE_PERMISSION, report.getStatus());
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,11 @@ public interface NodeDaoService
|
|||||||
*/
|
*/
|
||||||
public boolean isDirty();
|
public boolean isDirty();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush the data changes to the persistence layer.
|
||||||
|
*/
|
||||||
|
public void flush();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a list of all stores in the repository
|
* Fetch a list of all stores in the repository
|
||||||
*
|
*
|
||||||
|
@@ -117,6 +117,14 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
|
|||||||
return ((Boolean)getHibernateTemplate().execute(callback)).booleanValue();
|
return ((Boolean)getHibernateTemplate().execute(callback)).booleanValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just flushes the session
|
||||||
|
*/
|
||||||
|
public void flush()
|
||||||
|
{
|
||||||
|
getSession().flush();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see #QUERY_GET_ALL_STORES
|
* @see #QUERY_GET_ALL_STORES
|
||||||
*/
|
*/
|
||||||
@@ -337,7 +345,6 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
|
|||||||
assoc.setTypeQName(assocTypeQName);
|
assoc.setTypeQName(assocTypeQName);
|
||||||
assoc.setIsPrimary(isPrimary);
|
assoc.setIsPrimary(isPrimary);
|
||||||
assoc.setQname(qname);
|
assoc.setQname(qname);
|
||||||
// assoc.setIsArchived(false);
|
|
||||||
assoc.buildAssociation(parentNode, childNode);
|
assoc.buildAssociation(parentNode, childNode);
|
||||||
// persist
|
// persist
|
||||||
getHibernateTemplate().save(assoc);
|
getHibernateTemplate().save(assoc);
|
||||||
@@ -450,7 +457,6 @@ public class HibernateNodeDaoServiceImpl extends HibernateDaoSupport implements
|
|||||||
{
|
{
|
||||||
NodeAssoc assoc = new NodeAssocImpl();
|
NodeAssoc assoc = new NodeAssocImpl();
|
||||||
assoc.setTypeQName(assocTypeQName);
|
assoc.setTypeQName(assocTypeQName);
|
||||||
// assoc.setIsArchived(false);
|
|
||||||
assoc.buildAssociation(sourceNode, targetNode);
|
assoc.buildAssociation(sourceNode, targetNode);
|
||||||
// persist
|
// persist
|
||||||
getHibernateTemplate().save(assoc);
|
getHibernateTemplate().save(assoc);
|
||||||
|
@@ -523,6 +523,11 @@ public abstract class AlfrescoTransactionSupport
|
|||||||
{
|
{
|
||||||
listener.flush();
|
listener.flush();
|
||||||
}
|
}
|
||||||
|
// flush changes
|
||||||
|
for (NodeDaoService nodeDaoServices : getNodeDaoServices())
|
||||||
|
{
|
||||||
|
nodeDaoServices.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user