AR-380 - Export/Import of Forums/Discussions failed.

AR-395 - Provide abstract bean definition for DictionaryBootstrap
Fix build issue; JCR Import failed due to recent extension config changes
Fix issue in ISO9075 encoder; failed to encode colon properly meaning that Discussion Posts (with have colon seperated dates in their name) were not importing/exporting.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2299 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2006-02-05 16:25:30 +00:00
parent 2c72626944
commit 70e55cebd5
17 changed files with 529 additions and 93 deletions

View File

@@ -310,6 +310,28 @@ import org.alfresco.service.namespace.QName;
exporter.endAssocs(nodeRef);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#startReference(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void startReference(NodeRef nodeRef, QName childName)
{
for (Exporter exporter : exporters)
{
exporter.startReference(nodeRef, childName);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#endReference(org.alfresco.service.cmr.repository.NodeRef)
*/
public void endReference(NodeRef nodeRef)
{
for (Exporter exporter : exporters)
{
exporter.endReference(nodeRef);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#warning(java.lang.String)

View File

@@ -23,25 +23,27 @@ import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.Path;
import org.alfresco.service.cmr.repository.datatype.TypeConversionException;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.view.ExportPackageHandler;
import org.alfresco.service.cmr.view.Exporter;
import org.alfresco.service.cmr.view.ExporterContext;
@@ -53,12 +55,12 @@ import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.descriptor.DescriptorService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.ParameterCheck;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
/**
* Default implementation of the Exporter Service.
*
@@ -229,23 +231,32 @@ public class ExporterComponent
*/
private class DefaultCrawler implements ExporterCrawler
{
// Flush threshold
private int flushThreshold = 500;
private int flushCount = 0;
private ExporterContext context;
private Map<NodeRef, NodeRef> nodesWithSecondaryLinks = new HashMap<NodeRef, NodeRef>();
private Map<NodeRef, NodeRef> nodesWithAssociations = new HashMap<NodeRef, NodeRef>();
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.ExporterCrawler#export(org.alfresco.service.cmr.view.Exporter)
*/
public void export(ExporterCrawlerParameters parameters, Exporter exporter)
{
ExporterContext context = new ExporterContextImpl(parameters);
// Initialise Crawler
nodesWithSecondaryLinks.clear();
nodesWithAssociations.clear();
context = new ExporterContextImpl(parameters);
exporter.start(context);
//
// Export Nodes
//
// determine if root repository node
NodeRef nodeRef = context.getExportOf();
boolean rootNode = nodeService.getRootNode(nodeRef.getStoreRef()).equals(nodeRef);
if (parameters.isCrawlSelf() && !rootNode)
{
// export root node of specified export location
walkStartNamespaces(parameters, exporter);
walkNode(nodeRef, parameters, exporter);
walkEndNamespaces(parameters, exporter);
@@ -261,6 +272,28 @@ public class ExporterComponent
walkEndNamespaces(parameters, exporter);
}
}
//
// Export Secondary Links between Nodes
//
for (NodeRef nodeWithAssociations : nodesWithSecondaryLinks.keySet())
{
walkStartNamespaces(parameters, exporter);
walkNodeSecondaryLinks(nodeWithAssociations, parameters, exporter);
walkEndNamespaces(parameters, exporter);
}
//
// Export Associations between Nodes
//
for (NodeRef nodeWithAssociations : nodesWithAssociations.keySet())
{
walkStartNamespaces(parameters, exporter);
walkNodeAssociations(nodeWithAssociations, parameters, exporter);
walkEndNamespaces(parameters, exporter);
}
exporter.end();
}
@@ -310,14 +343,6 @@ public class ExporterComponent
return;
}
// Do we need to flush?
flushCount++;
if (flushCount > flushThreshold)
{
AlfrescoTransactionSupport.flush();
flushCount = 0;
}
exporter.startNode(nodeRef);
// Export node aspects
@@ -451,6 +476,11 @@ public class ExporterComponent
{
continue;
}
if (childAssoc.isPrimary() == false)
{
nodesWithSecondaryLinks.put(nodeRef, nodeRef);
continue;
}
if (i == 0 || childAssocs.get(i - 1).getTypeQName().equals(childAssocType) == false)
{
exporter.startAssoc(nodeRef, childAssocType);
@@ -467,12 +497,114 @@ public class ExporterComponent
exporter.endAssocs(nodeRef);
}
// TODO: Export node associations
// Export node associations
if (parameters.isCrawlAssociations())
{
List<AssociationRef> associations = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
if (associations.size() > 0)
{
nodesWithAssociations.put(nodeRef, nodeRef);
}
}
// Signal end of node
exporter.endNode(nodeRef);
}
/**
* Export Secondary Links
*
* @param nodeRef
* @param parameters
* @param exporter
*/
private void walkNodeSecondaryLinks(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter)
{
exporter.startReference(nodeRef, null);
exporter.startAssocs(nodeRef);
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(nodeRef);
for (int i = 0; i < childAssocs.size(); i++)
{
ChildAssociationRef childAssoc = childAssocs.get(i);
// determine if child association should be exported
QName childAssocType = childAssoc.getTypeQName();
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssocType.getNamespaceURI()))
{
continue;
}
if (childAssoc.isPrimary())
{
continue;
}
if (!isWithinExport(childAssoc.getChildRef(), parameters))
{
continue;
}
// export the association
if (i == 0 || childAssocs.get(i - 1).getTypeQName().equals(childAssocType) == false)
{
exporter.startAssoc(nodeRef, childAssocType);
}
QName childName = childAssoc.getQName();
if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), childName.getNamespaceURI()))
{
exporter.startReference(childAssoc.getChildRef(), childName);
exporter.endReference(childAssoc.getChildRef());
}
if (i == childAssocs.size() - 1 || childAssocs.get(i + 1).getTypeQName().equals(childAssocType) == false)
{
exporter.endAssoc(nodeRef, childAssocType);
}
}
exporter.endAssocs(nodeRef);
exporter.endReference(nodeRef);
}
/**
* Export Node Associations
*
* @param nodeRef
* @param parameters
* @param exporter
*/
private void walkNodeAssociations(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter)
{
exporter.startReference(nodeRef, null);
exporter.startAssocs(nodeRef);
List<AssociationRef> assocs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
for (int i = 0; i < assocs.size(); i++)
{
AssociationRef assoc = assocs.get(i);
// determine if association should be exported
QName assocType = assoc.getTypeQName();
if (isExcludedURI(parameters.getExcludeNamespaceURIs(), assocType.getNamespaceURI()))
{
continue;
}
if (!isWithinExport(assoc.getTargetRef(), parameters))
{
continue;
}
// export the association
if (i == 0 || assocs.get(i - 1).getTypeQName().equals(assocType) == false)
{
exporter.startAssoc(nodeRef, assocType);
}
exporter.startReference(assoc.getTargetRef(), null);
exporter.endReference(assoc.getTargetRef());
if (i == assocs.size() - 1 || assocs.get(i + 1).getTypeQName().equals(assocType) == false)
{
exporter.endAssoc(nodeRef, assocType);
}
}
exporter.endAssocs(nodeRef);
exporter.endReference(nodeRef);
}
/**
* Is the specified URI an excluded URI?
*
@@ -491,6 +623,40 @@ public class ExporterComponent
return false;
}
/**
* Determine if specified Node Reference is within the set of nodes to be exported
*
* @param nodeRef node reference to check
* @return true => node reference is within export set
*/
private boolean isWithinExport(NodeRef nodeRef, ExporterCrawlerParameters parameters)
{
boolean isWithin = false;
// Current strategy is to determine if node is a child of the root exported node
NodeRef exportRoot = context.getExportOf();
if (nodeRef.equals(exportRoot) && parameters.isCrawlSelf() == true)
{
// node to export is the root export node (and root is to be exported)
isWithin = true;
}
else
{
// locate export root in primary parent path of node
Path nodePath = nodeService.getPath(nodeRef);
for (int i = nodePath.size() -1; i >= 0; i--)
{
Path.ChildAssocElement pathElement = (Path.ChildAssocElement)nodePath.get(i);
if (pathElement.getRef().getChildRef().equals(exportRoot))
{
isWithin = true;
break;
}
}
}
return isWithin;
}
}
@@ -500,6 +666,7 @@ public class ExporterComponent
private class ExporterContextImpl implements ExporterContext
{
private NodeRef exportOf;
private NodeRef parent;
private String exportedBy;
private Date exportedDate;
private String exporterVersion;
@@ -521,6 +688,9 @@ public class ExporterComponent
// get export of
exportOf = getNodeRef(parameters.getExportFrom());
// get export parent
parent = getParent(exportOf, parameters.isCrawlSelf());
// get exporter version
exporterVersion = descriptorService.getServerDescriptor().getVersion();
}
@@ -557,6 +727,15 @@ public class ExporterComponent
return exportOf;
}
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.view.ExporterContext#getExportParent()
*/
public NodeRef getExportParent()
{
return parent;
}
/**
* Get the Node Ref from the specified Location
*
@@ -567,7 +746,7 @@ public class ExporterComponent
{
ParameterCheck.mandatory("Location", location);
// Establish node to import within
// Establish node to export from
NodeRef nodeRef = (location == null) ? null : location.getNodeRef();
if (nodeRef == null)
{
@@ -596,7 +775,39 @@ public class ExporterComponent
return nodeRef;
}
/**
* Gets the parent node of the items to be exported
*
* @param exportOf
* @param exportSelf
* @return
*/
private NodeRef getParent(NodeRef exportOf, boolean exportSelf)
{
NodeRef parent = null;
if (exportSelf)
{
NodeRef rootNode = nodeService.getRootNode(exportOf.getStoreRef());
if (rootNode.equals(exportOf))
{
parent = exportOf;
}
else
{
ChildAssociationRef parentRef = nodeService.getPrimaryParent(exportOf);
parent = parentRef.getParentRef();
}
}
else
{
parent = exportOf;
}
return parent;
}
}
}

View File

@@ -231,6 +231,16 @@ public class ExporterComponentTest extends BaseSpringTest
// System.out.println("TestProgress: endACL: " + nodeRef);
}
public void startReference(NodeRef nodeRef, QName childName)
{
// System.out.println("TestProgress: startReference: " + nodeRef);
}
public void endReference(NodeRef nodeRef)
{
// System.out.println("TestProgress: endReference: " + nodeRef);
}
}
}

View File

@@ -243,7 +243,24 @@ import org.alfresco.util.ParameterCheck;
{
exporter.endAssocs(nodeRef);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#startReference(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void startReference(NodeRef nodeRef, QName childName)
{
exporter.startReference(nodeRef, childName);
}
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#endReference(org.alfresco.service.cmr.repository.NodeRef)
*/
public void endReference(NodeRef nodeRef)
{
exporter.endReference(nodeRef);
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#warning(java.lang.String)
*/

View File

@@ -69,6 +69,8 @@ import org.xml.sax.helpers.AttributesImpl;
private static final String AUTHORITY_LOCALNAME = "authority";
private static final String PERMISSION_LOCALNAME = "permission";
private static final String INHERITPERMISSIONS_LOCALNAME = "inherit";
private static final String REFERENCE_LOCALNAME = "reference";
private static final String PATHREF_LOCALNAME = "pathref";
private static QName VIEW_QNAME;
private static QName VALUES_QNAME;
private static QName VALUE_QNAME;
@@ -89,6 +91,8 @@ import org.xml.sax.helpers.AttributesImpl;
private static QName AUTHORITY_QNAME;
private static QName PERMISSION_QNAME;
private static QName INHERITPERMISSIONS_QNAME;
private static QName REFERENCE_QNAME;
private static QName PATHREF_QNAME;
private static final AttributesImpl EMPTY_ATTRIBUTES = new AttributesImpl();
// Service dependencies
@@ -99,7 +103,7 @@ import org.xml.sax.helpers.AttributesImpl;
// View context
private ContentHandler contentHandler;
private Path exportNodePath;
private ExporterContext context;
/**
@@ -138,6 +142,8 @@ import org.xml.sax.helpers.AttributesImpl;
AUTHORITY_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, AUTHORITY_LOCALNAME, namespaceService);
PERMISSION_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, PERMISSION_LOCALNAME, namespaceService);
INHERITPERMISSIONS_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, INHERITPERMISSIONS_LOCALNAME, namespaceService);
REFERENCE_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, REFERENCE_LOCALNAME, namespaceService);
PATHREF_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, PATHREF_LOCALNAME, namespaceService);
}
@@ -148,7 +154,7 @@ import org.xml.sax.helpers.AttributesImpl;
{
try
{
exportNodePath = nodeService.getPath(context.getExportOf());
this.context = context;
contentHandler.startDocument();
contentHandler.startPrefixMapping(NamespaceService.REPOSITORY_VIEW_PREFIX, NamespaceService.REPOSITORY_VIEW_1_0_URI);
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, VIEW_LOCALNAME, VIEW_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
@@ -176,7 +182,7 @@ import org.xml.sax.helpers.AttributesImpl;
// export of
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, EXPORTOF_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
String path = exportNodePath.toPrefixString(namespaceService);
String path = nodeService.getPath(context.getExportOf()).toPrefixString(namespaceService);
contentHandler.characters(path.toCharArray(), 0, path.length());
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, EXPORTOF_QNAME.toPrefixString());
@@ -474,7 +480,7 @@ import org.xml.sax.helpers.AttributesImpl;
// convert node references to paths
if (value instanceof NodeRef)
{
Path nodeRefPath = createRelativePath(nodeRef, (NodeRef)value);
Path nodeRefPath = createRelativePath(context.getExportOf(), nodeRef, (NodeRef)value);
value = (nodeRefPath == null) ? null : nodeRefPath.toPrefixString(namespaceService);
}
@@ -553,7 +559,7 @@ import org.xml.sax.helpers.AttributesImpl;
// convert node references to paths
if (value instanceof NodeRef)
{
value = createRelativePath(nodeRef, (NodeRef)value).toPrefixString(namespaceService);
value = createRelativePath(context.getExportOf(), nodeRef, (NodeRef)value).toPrefixString(namespaceService);
}
// output value
@@ -643,6 +649,44 @@ import org.xml.sax.helpers.AttributesImpl;
throw new ExporterException("Failed to process end associations", e);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#startReference(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName)
*/
public void startReference(NodeRef nodeRef, QName childName)
{
try
{
Path path = createRelativePath(context.getExportParent(), context.getExportParent(), nodeRef);
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, PATHREF_LOCALNAME, PATHREF_QNAME.toPrefixString(), null, path.toPrefixString(namespaceService));
if (childName != null)
{
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, CHILDNAME_LOCALNAME, CHILDNAME_QNAME.toPrefixString(), null, childName.toPrefixString(namespaceService));
}
contentHandler.startElement(REFERENCE_QNAME.getNamespaceURI(), REFERENCE_LOCALNAME, toPrefixString(REFERENCE_QNAME), attrs);
}
catch (SAXException e)
{
throw new ExporterException("Failed to process start reference", e);
}
}
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#endReference(org.alfresco.service.cmr.repository.NodeRef)
*/
public void endReference(NodeRef nodeRef)
{
try
{
contentHandler.endElement(REFERENCE_QNAME.getNamespaceURI(), REFERENCE_LOCALNAME, toPrefixString(REFERENCE_QNAME));
}
catch (SAXException e)
{
throw new ExporterException("Failed to process end reference", e);
}
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.Exporter#warning(java.lang.String)
@@ -685,7 +729,7 @@ import org.xml.sax.helpers.AttributesImpl;
* @param toRef to reference
* @return path
*/
private Path createRelativePath(NodeRef fromRef, NodeRef toRef)
private Path createRelativePath(NodeRef rootRef, NodeRef fromRef, NodeRef toRef)
{
// Check that item exists first
if (!nodeService.exists(toRef))
@@ -694,6 +738,7 @@ import org.xml.sax.helpers.AttributesImpl;
return null;
}
Path rootPath = nodeService.getPath(rootRef);
Path fromPath = nodeService.getPath(fromRef);
Path toPath = nodeService.getPath(toRef);
Path relativePath = null;
@@ -720,19 +765,19 @@ import org.xml.sax.helpers.AttributesImpl;
{
// Determine if from node is relative to export tree
int i = 0;
while (i < exportNodePath.size() && i < fromPath.size() && exportNodePath.get(i).equals(fromPath.get(i)))
while (i < rootPath.size() && i < fromPath.size() && rootPath.get(i).equals(fromPath.get(i)))
{
i++;
}
if (i == exportNodePath.size())
if (i == rootPath.size())
{
// Determine if to node is relative to export tree
i = 0;
while (i < exportNodePath.size() && i < toPath.size() && exportNodePath.get(i).equals(toPath.get(i)))
while (i < rootPath.size() && i < toPath.size() && rootPath.get(i).equals(toPath.get(i)))
{
i++;
}
if (i == exportNodePath.size())
if (i == rootPath.size())
{
// build relative path between from and to
relativePath = new Path();
@@ -756,11 +801,11 @@ import org.xml.sax.helpers.AttributesImpl;
}
catch(Throwable e)
{
String msg = "Failed to determine relative path: export path=" + exportNodePath + "; from path=" + fromPath + "; to path=" + toPath;
String msg = "Failed to determine relative path: root path=" + rootPath + "; from path=" + fromPath + "; to path=" + toPath;
throw new ExporterException(msg, e);
}
return relativePath;
}
}