Fixed AssociationRef.equals method that was causing association matching to fail

Fixed node tests that were hiding a NullPointerException when node associations weren't found
Fixed NodeAssoc AssociationRef caching for cases where the source or target nodes move stores
Removed storage of Path property for archived nodes


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2886 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley 2006-05-12 22:04:49 +00:00
parent 881f966ee8
commit d8878a46ed
8 changed files with 38 additions and 47 deletions

View File

@ -131,11 +131,6 @@
<type>d:childassocref</type> <type>d:childassocref</type>
<mandatory>true</mandatory> <mandatory>true</mandatory>
</property> </property>
<property name="sys:archivedOriginalPath">
<type>d:any</type>
<mandatory>true</mandatory>
<index enabled="false" />
</property>
<property name="sys:archivedBy"> <property name="sys:archivedBy">
<type>d:text</type> <type>d:text</type>
<mandatory>true</mandatory> <mandatory>true</mandatory>

View File

@ -42,7 +42,6 @@ public interface ContentModel
// archived nodes aspect constants // archived nodes aspect constants
static final QName ASPECT_ARCHIVED = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archived"); static final QName ASPECT_ARCHIVED = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archived");
static final QName PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedOriginalParentAssoc"); static final QName PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedOriginalParentAssoc");
static final QName PROP_ARCHIVED_ORIGINAL_PATH = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedOriginalPath");
static final QName PROP_ARCHIVED_BY = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedBy"); static final QName PROP_ARCHIVED_BY = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedBy");
static final QName PROP_ARCHIVED_DATE = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedDate"); static final QName PROP_ARCHIVED_DATE = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archivedDate");
static final QName ASPECT_ARCHIVED_ASSOCS = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archived-assocs"); static final QName ASPECT_ARCHIVED_ASSOCS = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "archived-assocs");

View File

@ -114,7 +114,7 @@ public class ChildAssocImpl implements ChildAssoc
this.qName, this.qName,
child.getNodeRef(), child.getNodeRef(),
this.isPrimary, this.isPrimary,
-1); index);
} }
return childAssocRef; return childAssocRef;
} }

View File

@ -74,15 +74,26 @@ public class NodeAssocImpl implements NodeAssoc
public AssociationRef getNodeAssocRef() public AssociationRef getNodeAssocRef()
{ {
boolean trashReference = false;
// first check if it is available // first check if it is available
refReadLock.lock(); refReadLock.lock();
try try
{ {
if (nodeAssocRef != null) if (nodeAssocRef != null)
{ {
// double check that the parent and child node references match those of our reference
if (nodeAssocRef.getSourceRef() != source.getNodeRef() ||
nodeAssocRef.getTargetRef() != target.getNodeRef())
{
trashReference = true;
}
else
{
// we are sure that the reference is correct
return nodeAssocRef; return nodeAssocRef;
} }
} }
}
finally finally
{ {
refReadLock.unlock(); refReadLock.unlock();
@ -92,7 +103,7 @@ public class NodeAssocImpl implements NodeAssoc
try try
{ {
// double check // double check
if (nodeAssocRef == null ) if (nodeAssocRef == null || trashReference)
{ {
nodeAssocRef = new AssociationRef( nodeAssocRef = new AssociationRef(
getSource().getNodeRef(), getSource().getNodeRef(),

View File

@ -1206,24 +1206,6 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
return assocRef; return assocRef;
} }
public void testAssociationToIncorrectNodeType() throws Exception
{
AssociationRef assocRef = createAssociation();
NodeRef sourceRef = assocRef.getSourceRef();
NodeRef targetRef = assocRef.getTargetRef();
QName qname = assocRef.getTypeQName();
try
{
// attempt the association in reverse
nodeService.createAssociation(sourceRef, targetRef, qname);
fail("Incorrect node type not detected");
}
catch (RuntimeException e)
{
// expected
}
}
public void testDuplicateAssociationDetection() throws Exception public void testDuplicateAssociationDetection() throws Exception
{ {
AssociationRef assocRef = createAssociation(); AssociationRef assocRef = createAssociation();

View File

@ -36,7 +36,6 @@ import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
@ -55,8 +54,8 @@ import org.springframework.context.ApplicationContext;
*/ */
public class ArchiveAndRestoreTest extends TestCase 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 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");
@ -124,10 +123,18 @@ public class ArchiveAndRestoreTest extends TestCase
StoreArchiveMap archiveMap = (StoreArchiveMap) ctx.getBean("storeArchiveMap"); StoreArchiveMap archiveMap = (StoreArchiveMap) ctx.getBean("storeArchiveMap");
archiveMap.getArchiveMap().put(workStoreRef, archiveStoreRef); archiveMap.getArchiveMap().put(workStoreRef, archiveStoreRef);
// grant everyone rights to the work store TestWithUserUtils.createUser(USER_A, USER_A, workStoreRootNodeRef, nodeService, authenticationService);
TestWithUserUtils.createUser(USER_B, USER_B, workStoreRootNodeRef, nodeService, authenticationService);
// grant A and B rights to the work store
permissionService.setPermission( permissionService.setPermission(
workStoreRootNodeRef, workStoreRootNodeRef,
PermissionService.ALL_AUTHORITIES, USER_A,
PermissionService.ALL_PERMISSIONS,
true);
permissionService.setPermission(
workStoreRootNodeRef,
USER_B,
PermissionService.ALL_PERMISSIONS, PermissionService.ALL_PERMISSIONS,
true); true);
@ -137,9 +144,6 @@ public class ArchiveAndRestoreTest extends TestCase
PermissionService.ALL_AUTHORITIES, PermissionService.ALL_AUTHORITIES,
PermissionService.ALL_PERMISSIONS, PermissionService.ALL_PERMISSIONS,
true); true);
TestWithUserUtils.createUser(USER_A, USER_A, workStoreRootNodeRef, nodeService, authenticationService);
TestWithUserUtils.createUser(USER_B, USER_B, workStoreRootNodeRef, nodeService, authenticationService);
} }
finally finally
{ {
@ -335,8 +339,8 @@ public class ArchiveAndRestoreTest extends TestCase
// 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); ChildAssociationRef bb_originalParent = (ChildAssociationRef) bb_Properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
assertNotNull("Original path not stored", bb_originalPath); assertNotNull("Original parent not stored", bb_originalParent);
// restore the node // restore the node
nodeService.restoreNode(bb_, null, null, null); nodeService.restoreNode(bb_, null, null, null);

View File

@ -1071,14 +1071,20 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName)
throws InvalidNodeRefException throws InvalidNodeRefException
{ {
// Invoke policy behaviours
invokeBeforeUpdateNode(sourceRef);
Node sourceNode = getNodeNotNull(sourceRef); Node sourceNode = getNodeNotNull(sourceRef);
Node targetNode = getNodeNotNull(targetRef); Node targetNode = getNodeNotNull(targetRef);
// get the association // get the association
NodeAssoc assoc = nodeDaoService.getNodeAssoc(sourceNode, targetNode, assocTypeQName); NodeAssoc assoc = nodeDaoService.getNodeAssoc(sourceNode, targetNode, assocTypeQName);
if (assoc == null)
{
// nothing to remove
return;
}
AssociationRef assocRef = assoc.getNodeAssocRef(); AssociationRef assocRef = assoc.getNodeAssocRef();
// Invoke policy behaviours
invokeBeforeUpdateNode(sourceRef);
// delete it // delete it
nodeDaoService.deleteNodeAssoc(assoc); nodeDaoService.deleteNodeAssoc(assoc);
@ -1302,7 +1308,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
{ {
Node node = getNodeNotNull(nodeRef); Node node = getNodeNotNull(nodeRef);
ChildAssoc primaryParentAssoc = nodeDaoService.getPrimaryParentAssoc(node); ChildAssoc primaryParentAssoc = nodeDaoService.getPrimaryParentAssoc(node);
Path primaryPath = getPath(nodeRef);
// add the aspect // add the aspect
node.getAspects().add(ContentModel.ASPECT_ARCHIVED); node.getAspects().add(ContentModel.ASPECT_ARCHIVED);
@ -1319,10 +1324,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC), dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC),
primaryParentAssoc.getChildAssocRef()); primaryParentAssoc.getChildAssocRef());
properties.put(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC, archivedPrimaryParentNodeRefProperty); properties.put(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC, archivedPrimaryParentNodeRefProperty);
PropertyValue archivedPrimaryPathProperty = makePropertyValue(
dictionaryService.getProperty(ContentModel.PROP_ARCHIVED_ORIGINAL_PATH),
primaryPath);
properties.put(ContentModel.PROP_ARCHIVED_ORIGINAL_PATH, archivedPrimaryPathProperty);
// move the node // move the node
NodeRef archiveStoreRootNodeRef = getRootNode(archiveStoreRef); NodeRef archiveStoreRootNodeRef = getRootNode(archiveStoreRef);
@ -1559,7 +1560,6 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
// remove the aspect archived aspect // remove the aspect archived aspect
aspects.remove(ContentModel.ASPECT_ARCHIVED); aspects.remove(ContentModel.ASPECT_ARCHIVED);
properties.remove(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC); properties.remove(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
properties.remove(ContentModel.PROP_ARCHIVED_ORIGINAL_PATH);
properties.remove(ContentModel.PROP_ARCHIVED_BY); properties.remove(ContentModel.PROP_ARCHIVED_BY);
properties.remove(ContentModel.PROP_ARCHIVED_DATE); properties.remove(ContentModel.PROP_ARCHIVED_DATE);

View File

@ -115,7 +115,7 @@ public class AssociationRef implements EntityRef, Serializable
{ {
return true; return true;
} }
if (!(o instanceof ChildAssociationRef)) if (!(o instanceof AssociationRef))
{ {
return false; return false;
} }