Fix to export of associations (AWC-1754)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7762 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2008-01-07 14:51:57 +00:00
parent 6478d72321
commit 75967c3736

View File

@@ -29,6 +29,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -454,11 +455,11 @@ public class ExporterComponent
// Export node children
if (parameters.isCrawlChildNodes())
{
exporter.startAssocs(nodeRef);
// sort associations into assoc type buckets filtering out unneccessary associations
Map<QName, List<ChildAssociationRef>> assocTypes = new HashMap<QName, List<ChildAssociationRef>>();
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef);
for (int i = 0; i < childAssocs.size(); i++)
for (ChildAssociationRef childAssoc : childAssocs)
{
ChildAssociationRef childAssoc = childAssocs.get(i);
QName childAssocType = childAssoc.getTypeQName();
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssocType.getNamespaceURI()))
{
@@ -469,21 +470,40 @@ public class ExporterComponent
nodesWithSecondaryLinks.put(nodeRef, nodeRef);
continue;
}
if (i == 0 || childAssocs.get(i - 1).getTypeQName().equals(childAssocType) == false)
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssoc.getQName().getNamespaceURI()))
{
exporter.startAssoc(nodeRef, childAssocType);
continue;
}
if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssoc.getQName().getNamespaceURI()))
List<ChildAssociationRef> assocRefs = assocTypes.get(childAssocType);
if (assocRefs == null)
{
walkNode(childAssoc.getChildRef(), parameters, exporter, false);
assocRefs = new ArrayList<ChildAssociationRef>();
assocTypes.put(childAssocType, assocRefs);
}
if (i == childAssocs.size() - 1 || childAssocs.get(i + 1).getTypeQName().equals(childAssocType) == false)
assocRefs.add(childAssoc);
}
// output each association type bucket
if (assocTypes.size() > 0)
{
exporter.endAssoc(nodeRef, childAssocType);
exporter.startAssocs(nodeRef);
for (Map.Entry<QName, List<ChildAssociationRef>> assocType : assocTypes.entrySet())
{
List<ChildAssociationRef> assocRefs = assocType.getValue();
if (assocRefs.size() > 0)
{
exporter.startAssoc(nodeRef, assocType.getKey());
for (ChildAssociationRef assocRef : assocRefs)
{
walkNode(assocRef.getChildRef(), parameters, exporter, false);
}
exporter.endAssoc(nodeRef, assocType.getKey());
}
}
exporter.endAssocs(nodeRef);
}
}
// Export node associations
if (parameters.isCrawlAssociations())
@@ -592,13 +612,11 @@ public class ExporterComponent
*/
private void walkNodeSecondaryLinks(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter)
{
exporter.startReference(nodeRef, null);
exporter.startAssocs(nodeRef);
// sort associations into assoc type buckets filtering out unneccessary associations
Map<QName, List<ChildAssociationRef>> assocTypes = new HashMap<QName, List<ChildAssociationRef>>();
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef);
for (int i = 0; i < childAssocs.size(); i++)
for (ChildAssociationRef childAssoc : childAssocs)
{
ChildAssociationRef childAssoc = childAssocs.get(i);
// determine if child association should be exported
QName childAssocType = childAssoc.getTypeQName();
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssocType.getNamespaceURI()))
@@ -614,25 +632,38 @@ public class ExporterComponent
continue;
}
// export the association
if (i == 0 || childAssocs.get(i - 1).getTypeQName().equals(childAssocType) == false)
List<ChildAssociationRef> assocRefs = assocTypes.get(childAssocType);
if (assocRefs == null)
{
exporter.startAssoc(nodeRef, childAssocType);
assocRefs = new ArrayList<ChildAssociationRef>();
assocTypes.put(childAssocType, assocRefs);
}
QName childName = childAssoc.getQName();
if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), childName.getNamespaceURI()))
{
exporter.startReference(childAssoc.getChildRef(), childName);
exporter.endReference(childAssoc.getChildRef());
assocRefs.add(childAssoc);
}
if (i == childAssocs.size() - 1 || childAssocs.get(i + 1).getTypeQName().equals(childAssocType) == false)
// output each association type bucket
if (assocTypes.size() > 0)
{
exporter.endAssoc(nodeRef, childAssocType);
exporter.startReference(nodeRef, null);
exporter.startAssocs(nodeRef);
for (Map.Entry<QName, List<ChildAssociationRef>> assocType : assocTypes.entrySet())
{
List<ChildAssociationRef> assocRefs = assocType.getValue();
if (assocRefs.size() > 0)
{
exporter.startAssoc(nodeRef, assocType.getKey());
for (ChildAssociationRef assocRef : assocRefs)
{
exporter.startReference(assocRef.getChildRef(), assocRef.getQName());
exporter.endReference(assocRef.getChildRef());
}
exporter.endAssoc(nodeRef, assocType.getKey());
}
}
exporter.endAssocs(nodeRef);
exporter.endReference(nodeRef);
}
}
/**
* Export Node Associations
@@ -643,14 +674,11 @@ public class ExporterComponent
*/
private void walkNodeAssociations(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter)
{
exporter.startReference(nodeRef, null);
exporter.startAssocs(nodeRef);
// sort associations into assoc type buckets filtering out unneccessary associations
Map<QName, List<AssociationRef>> assocTypes = new HashMap<QName, List<AssociationRef>>();
List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
for (int i = 0; i < assocs.size(); i++)
for (AssociationRef assoc : assocs)
{
AssociationRef assoc = assocs.get(i);
// determine if association should be exported
QName assocType = assoc.getTypeQName();
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), assocType.getNamespaceURI()))
{
@@ -661,21 +689,38 @@ public class ExporterComponent
continue;
}
// export the association
if (i == 0 || assocs.get(i - 1).getTypeQName().equals(assocType) == false)
List<AssociationRef> assocRefs = assocTypes.get(assocType);
if (assocRefs == null)
{
exporter.startAssoc(nodeRef, assocType);
assocRefs = new ArrayList<AssociationRef>();
assocTypes.put(assocType, assocRefs);
}
exporter.startReference(assoc.getTargetRef(), null);
exporter.endReference(assoc.getTargetRef());
if (i == assocs.size() - 1 || assocs.get(i + 1).getTypeQName().equals(assocType) == false)
assocRefs.add(assoc);
}
// output each association type bucket
if (assocTypes.size() > 0)
{
exporter.endAssoc(nodeRef, assocType);
exporter.startReference(nodeRef, null);
exporter.startAssocs(nodeRef);
for (Map.Entry<QName, List<AssociationRef>> assocType : assocTypes.entrySet())
{
List<AssociationRef> assocRefs = assocType.getValue();
if (assocRefs.size() > 0)
{
exporter.startAssoc(nodeRef, assocType.getKey());
for (AssociationRef assocRef : assocRefs)
{
exporter.startReference(assocRef.getTargetRef(), null);
exporter.endReference(assocRef.getTargetRef());
}
exporter.endAssoc(nodeRef, assocType.getKey());
}
}
exporter.endAssocs(nodeRef);
exporter.endReference(nodeRef);
}
}
/**
* Is the specified URI an excluded URI?