Fixed SAIL-384: HEAD merge fallout: CMIS TCK

- Implemented NodeService.getAssoc(id)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20939 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-07-05 14:04:36 +00:00
parent ca5fa3a973
commit b59b9604e9
7 changed files with 72 additions and 14 deletions

View File

@@ -650,6 +650,12 @@
targetNode.id = #targetNode.id#
</select>
<select id="select_NodeAssocById" parameterClass="NodeAssoc" resultMap="result_NodeAssoc">
<include refid="alfresco.node.select_NodeAssoc_Results"/>
where
assoc.id = #id#
</select>
<!-- Common results for result_ChildAssoc -->
<sql id="select_ChildAssoc_Results">
select

View File

@@ -2124,12 +2124,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
for (NodeAssocEntity nodeAssocEntity : nodeAssocEntities)
{
Long assocId = nodeAssocEntity.getId();
QName assocTypeQName = qnameDAO.getQName(nodeAssocEntity.getTypeQNameId()).getSecond();
AssociationRef assocRef = new AssociationRef(
nodeAssocEntity.getId(),
nodeAssocEntity.getSourceNode().getNodeRef(),
assocTypeQName,
nodeAssocEntity.getTargetNode().getNodeRef());
AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
results.add(new Pair<Long, AssociationRef>(assocId, assocRef));
}
return results;
@@ -2142,17 +2137,23 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
for (NodeAssocEntity nodeAssocEntity : nodeAssocEntities)
{
Long assocId = nodeAssocEntity.getId();
QName assocTypeQName = qnameDAO.getQName(nodeAssocEntity.getTypeQNameId()).getSecond();
AssociationRef assocRef = new AssociationRef(
nodeAssocEntity.getId(),
nodeAssocEntity.getSourceNode().getNodeRef(),
assocTypeQName,
nodeAssocEntity.getTargetNode().getNodeRef());
AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
results.add(new Pair<Long, AssociationRef>(assocId, assocRef));
}
return results;
}
public Pair<Long, AssociationRef> getNodeAssoc(Long assocId)
{
NodeAssocEntity nodeAssocEntity = selectNodeAssocById(assocId);
if (nodeAssocEntity == null)
{
throw new ConcurrencyFailureException("Assoc ID does not point to a valid association: " + assocId);
}
AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
return new Pair<Long, AssociationRef>(assocId, assocRef);
}
/*
* Child assocs
*/
@@ -3082,6 +3083,7 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
protected abstract int deleteNodeAssocsToAndFrom(Long nodeId, Set<Long> assocTypeQNameIds);
protected abstract List<NodeAssocEntity> selectNodeAssocsBySource(Long sourceNodeId);
protected abstract List<NodeAssocEntity> selectNodeAssocsByTarget(Long targetNodeId);
protected abstract NodeAssocEntity selectNodeAssocById(Long assocId);
protected abstract Long insertChildAssoc(ChildAssocEntity assoc);
protected abstract int deleteChildAssocById(Long assocId);
protected abstract int updateChildAssocIndex(

View File

@@ -26,6 +26,10 @@ package org.alfresco.repo.domain.node;
import java.util.List;
import org.alfresco.repo.domain.qname.QNameDAO;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.namespace.QName;
/**
* Bean for <b>alf_node_assoc</b> table.
*
@@ -62,6 +66,20 @@ public class NodeAssocEntity
return sb.toString();
}
/**
* Helper method to fetch the association reference
*/
public AssociationRef getAssociationRef(QNameDAO qnameDAO)
{
QName assocTypeQName = qnameDAO.getQName(typeQNameId).getSecond();
AssociationRef assocRef = new AssociationRef(
id,
sourceNode.getNodeRef(),
assocTypeQName,
targetNode.getNodeRef());
return assocRef;
}
public Long getId()
{
return id;

View File

@@ -284,6 +284,13 @@ public interface NodeDAO extends NodeBulkLoader
*/
public Collection<Pair<Long, AssociationRef>> getTargetNodeAssocs(Long sourceNodeId);
/**
* @return Returns a specific node association with the given ID
*
* @throws ConcurrencyFailureException if the association ID is invalid
*/
public Pair<Long, AssociationRef> getNodeAssoc(Long assocId);
/*
* Child Assocs
*/

View File

@@ -101,6 +101,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
private static final String DELETE_NODE_ASSOCS_TO_AND_FROM = "alfresco.node.delete_NodeAssocsToAndFrom";
private static final String SELECT_NODE_ASSOCS_BY_SOURCE = "alfresco.node.select_NodeAssocsBySource";
private static final String SELECT_NODE_ASSOCS_BY_TARGET = "alfresco.node.select_NodeAssocsByTarget";
private static final String SELECT_NODE_ASSOC_BY_ID = "alfresco.node.select_NodeAssocById";
private static final String SELECT_NODE_PRIMARY_CHILD_ACLS = "alfresco.node.select_NodePrimaryChildAcls";
private static final String INSERT_CHILD_ASSOC = "alfresco.node.insert_ChildAssoc";
private static final String DELETE_CHILD_ASSOC_BY_ID = "alfresco.node.delete_ChildAssocById";
@@ -657,6 +658,15 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
return (List<NodeAssocEntity>) template.queryForList(SELECT_NODE_ASSOCS_BY_TARGET, assoc);
}
@Override
protected NodeAssocEntity selectNodeAssocById(Long assocId)
{
NodeAssocEntity assoc = new NodeAssocEntity();
assoc.setId(assocId);
return (NodeAssocEntity) template.queryForObject(SELECT_NODE_ASSOC_BY_ID, assoc);
}
@Override
protected Long insertChildAssoc(ChildAssocEntity assoc)
{

View File

@@ -2200,6 +2200,10 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
sourceRef,
anotherTargetRef,
ASSOC_TYPE_QNAME_TEST_NEXT);
Long anotherAssocId = anotherAssocRef.getId();
assertNotNull("Created association does not have an ID", anotherAssocId);
AssociationRef anotherAssocRefCheck = nodeService.getAssoc(anotherAssocId);
assertEquals("Assoc fetched by ID is incorrect.", anotherAssocRef, anotherAssocRefCheck);
// remove assocs
List<AssociationRef> assocs = nodeService.getTargetAssocs(sourceRef, ASSOC_TYPE_QNAME_TEST_NEXT);
@@ -2222,6 +2226,12 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(sourceRef, qname);
assertEquals("Incorrect number of targets", 1, targetAssocs.size());
assertTrue("Target not found", targetAssocs.contains(assocRef));
// Check that IDs are present
for (AssociationRef targetAssoc : targetAssocs)
{
assertNotNull("Association does not have ID", targetAssoc.getId());
}
}
public void testGetSourceAssocs() throws Exception
@@ -2234,6 +2244,12 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
List<AssociationRef> sourceAssocs = nodeService.getSourceAssocs(targetRef, qname);
assertEquals("Incorrect number of source assocs", 1, sourceAssocs.size());
assertTrue("Source not found", sourceAssocs.contains(assocRef));
// Check that IDs are present
for (AssociationRef sourceAssoc : sourceAssocs)
{
assertNotNull("Association does not have ID", sourceAssoc.getId());
}
}
/**

View File

@@ -1786,8 +1786,7 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl
public AssociationRef getAssoc(Long id)
{
throw new UnsupportedOperationException("TODO: Implement the method for the new DAO implementation.");
// return nodeDaoService.getNodeAssocOrNull(id);
return nodeDAO.getNodeAssoc(id).getSecond();
}
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern)