Fix ALF-2332: getRelationships fails for associations whose source or target types are not mapped to the CMIS domain model

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19747 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2010-04-06 17:01:24 +00:00
parent 8aeb83d1c9
commit f901c63daa

View File

@@ -655,9 +655,13 @@ public class CMISServicesImpl implements CMISServices, ApplicationContextAware,
{ {
// by the spec. if typeId=null then it is necessary return ALL associated Relationship objects! // by the spec. if typeId=null then it is necessary return ALL associated Relationship objects!
// establish relationship type to filter on // establish relationship type to filter on
if ((relDef != null) && !relDef.getBaseType().getTypeId().equals(CMISDictionaryModel.RELATIONSHIP_TYPE_ID)) if (relDef == null)
{ {
throw new CMISInvalidArgumentException("Type Id " + relDef.getTypeId() + " is not a relationship type"); relDef = cmisDictionaryService.findType(CMISDictionaryModel.RELATIONSHIP_TYPE_ID);
}
if (!relDef.getBaseType().getTypeId().equals(CMISDictionaryModel.RELATIONSHIP_TYPE_ID))
{
throw new AlfrescoRuntimeException("Type Id " + relDef.getTypeId() + " is not a relationship type");
} }
// retrieve associations // retrieve associations
@@ -671,29 +675,22 @@ public class CMISServicesImpl implements CMISServices, ApplicationContextAware,
assocs.addAll(nodeService.getSourceAssocs(node, RegexQNamePattern.MATCH_ALL)); assocs.addAll(nodeService.getSourceAssocs(node, RegexQNamePattern.MATCH_ALL));
} }
List<AssociationRef> filteredAssocs = new ArrayList<AssociationRef>(assocs.size());
if (null != relDef)
{
// filter association by type // filter association by type
// NOTE: even if typeId = null, we still filter out relationships that do not map to CMIS domain model e.g.
// relationships whose source or target are not folders or documents
Collection<CMISTypeDefinition> subRelDefs = (includeSubTypes ? relDef.getSubTypes(true) : null); Collection<CMISTypeDefinition> subRelDefs = (includeSubTypes ? relDef.getSubTypes(true) : null);
List<AssociationRef> filteredAssocs = new ArrayList<AssociationRef>(assocs.size());
for (AssociationRef assoc : assocs) for (AssociationRef assoc : assocs)
{ {
CMISTypeDefinition assocTypeDef = cmisDictionaryService.findTypeForClass(assoc.getTypeQName(), CMISScope.RELATIONSHIP); CMISTypeDefinition assocTypeDef = cmisDictionaryService.findTypeForClass(assoc.getTypeQName(), CMISScope.RELATIONSHIP);
if (assocTypeDef == null) if (assocTypeDef != null)
{ {
throw new CMISInvalidArgumentException("Association Type QName " + assoc.getTypeQName() + " does not map to a CMIS Relationship Type");
}
if (assocTypeDef.equals(relDef) || (subRelDefs != null && subRelDefs.contains(assocTypeDef))) if (assocTypeDef.equals(relDef) || (subRelDefs != null && subRelDefs.contains(assocTypeDef)))
{ {
filteredAssocs.add(assoc); filteredAssocs.add(assoc);
} }
} }
} }
else
{
filteredAssocs = assocs;
}
AssociationRef[] assocArray = new AssociationRef[filteredAssocs.size()]; AssociationRef[] assocArray = new AssociationRef[filteredAssocs.size()];
filteredAssocs.toArray(assocArray); filteredAssocs.toArray(assocArray);