mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Fixes for supporting full repository export/import.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2625 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -53,6 +53,7 @@ import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.service.cmr.view.ExporterService;
|
||||
import org.alfresco.service.cmr.view.ImporterException;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.alfresco.service.cmr.view.ReferenceType;
|
||||
import org.alfresco.service.descriptor.DescriptorService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -158,7 +159,7 @@ public class ExporterComponent
|
||||
ParameterCheck.mandatory("View Writer", viewWriter);
|
||||
|
||||
// Construct a basic XML Exporter
|
||||
Exporter xmlExporter = createXMLExporter(viewWriter);
|
||||
Exporter xmlExporter = createXMLExporter(viewWriter, parameters.getReferenceType());
|
||||
|
||||
// Export
|
||||
exportView(xmlExporter, parameters, progress);
|
||||
@@ -174,7 +175,7 @@ public class ExporterComponent
|
||||
// create exporter around export handler
|
||||
exportHandler.startExport();
|
||||
OutputStream dataFile = exportHandler.createDataStream();
|
||||
Exporter xmlExporter = createXMLExporter(dataFile);
|
||||
Exporter xmlExporter = createXMLExporter(dataFile, parameters.getReferenceType());
|
||||
URLExporter urlExporter = new URLExporter(xmlExporter, exportHandler);
|
||||
|
||||
// export
|
||||
@@ -201,9 +202,10 @@ public class ExporterComponent
|
||||
* output stream in xml format.
|
||||
*
|
||||
* @param viewWriter the output stream to write to
|
||||
* @param referenceType the format of references to export
|
||||
* @return the xml exporter
|
||||
*/
|
||||
private Exporter createXMLExporter(OutputStream viewWriter)
|
||||
private Exporter createXMLExporter(OutputStream viewWriter, ReferenceType referenceType)
|
||||
{
|
||||
// Define output format
|
||||
OutputFormat format = OutputFormat.createPrettyPrint();
|
||||
@@ -215,12 +217,18 @@ public class ExporterComponent
|
||||
try
|
||||
{
|
||||
XMLWriter writer = new XMLWriter(viewWriter, format);
|
||||
return new ViewXMLExporter(namespaceService, nodeService, searchService, dictionaryService, permissionService, writer);
|
||||
ViewXMLExporter exporter = new ViewXMLExporter(namespaceService, nodeService, searchService, dictionaryService, permissionService, writer);
|
||||
exporter.setReferenceType(referenceType);
|
||||
return exporter;
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
throw new ExporterException("Failed to create XML Writer for export", e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new ExporterException("Failed to create XML Writer for export", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -254,12 +262,12 @@ public class ExporterComponent
|
||||
|
||||
// determine if root repository node
|
||||
NodeRef nodeRef = context.getExportOf();
|
||||
boolean rootNode = nodeService.getRootNode(nodeRef.getStoreRef()).equals(nodeRef);
|
||||
if (parameters.isCrawlSelf() && !rootNode)
|
||||
if (parameters.isCrawlSelf())
|
||||
{
|
||||
// export root node of specified export location
|
||||
walkStartNamespaces(parameters, exporter);
|
||||
walkNode(nodeRef, parameters, exporter);
|
||||
boolean rootNode = nodeService.getRootNode(nodeRef.getStoreRef()).equals(nodeRef);
|
||||
walkNode(nodeRef, parameters, exporter, rootNode);
|
||||
walkEndNamespaces(parameters, exporter);
|
||||
}
|
||||
else if (parameters.isCrawlChildNodes())
|
||||
@@ -269,7 +277,7 @@ public class ExporterComponent
|
||||
for (ChildAssociationRef childAssoc : childAssocs)
|
||||
{
|
||||
walkStartNamespaces(parameters, exporter);
|
||||
walkNode(childAssoc.getChildRef(), parameters, exporter);
|
||||
walkNode(childAssoc.getChildRef(), parameters, exporter, false);
|
||||
walkEndNamespaces(parameters, exporter);
|
||||
}
|
||||
}
|
||||
@@ -335,7 +343,7 @@ public class ExporterComponent
|
||||
*
|
||||
* @param nodeRef the node to navigate
|
||||
*/
|
||||
private void walkNode(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter)
|
||||
private void walkNode(NodeRef nodeRef, ExporterCrawlerParameters parameters, Exporter exporter, boolean exportAsRef)
|
||||
{
|
||||
// Export node (but only if it's not excluded from export)
|
||||
QName type = nodeService.getType(nodeRef);
|
||||
@@ -343,8 +351,16 @@ public class ExporterComponent
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
exporter.startNode(nodeRef);
|
||||
|
||||
// export node as reference to node, or as the actual node
|
||||
if (exportAsRef)
|
||||
{
|
||||
exporter.startReference(nodeRef, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
exporter.startNode(nodeRef);
|
||||
}
|
||||
|
||||
// Export node aspects
|
||||
exporter.startAspects(nodeRef);
|
||||
@@ -361,7 +377,7 @@ public class ExporterComponent
|
||||
|
||||
// Export node permissions
|
||||
AccessStatus readPermission = permissionService.hasPermission(nodeRef, PermissionService.READ_PERMISSIONS);
|
||||
if (readPermission.equals(AccessStatus.ALLOWED))
|
||||
if (authenticationService.isCurrentUserTheSystemUser() || readPermission.equals(AccessStatus.ALLOWED))
|
||||
{
|
||||
Set<AccessPermission> permissions = permissionService.getAllSetPermissions(nodeRef);
|
||||
boolean inheritPermissions = permissionService.getInheritParentPermissions(nodeRef);
|
||||
@@ -442,7 +458,7 @@ public class ExporterComponent
|
||||
}
|
||||
if (!isExcludedURI(parameters.getExcludeNamespaceURIs(), childAssoc.getQName().getNamespaceURI()))
|
||||
{
|
||||
walkNode(childAssoc.getChildRef(), parameters, exporter);
|
||||
walkNode(childAssoc.getChildRef(), parameters, exporter, false);
|
||||
}
|
||||
if (i == childAssocs.size() - 1 || childAssocs.get(i + 1).getTypeQName().equals(childAssocType) == false)
|
||||
{
|
||||
@@ -463,7 +479,15 @@ public class ExporterComponent
|
||||
}
|
||||
|
||||
// Signal end of node
|
||||
exporter.endNode(nodeRef);
|
||||
// export node as reference to node, or as the actual node
|
||||
if (exportAsRef)
|
||||
{
|
||||
exporter.endReference(nodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
exporter.endNode(nodeRef);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -43,6 +43,7 @@ import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.service.cmr.view.ExporterService;
|
||||
import org.alfresco.service.cmr.view.Location;
|
||||
import org.alfresco.service.cmr.view.ReferenceType;
|
||||
import org.alfresco.service.cmr.view.RepositoryExporterService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
@@ -276,6 +277,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
parameters.setCrawlAssociations(true);
|
||||
parameters.setCrawlNullProperties(true);
|
||||
parameters.setExcludeNamespaceURIs(new String[] {});
|
||||
parameters.setReferenceType(ReferenceType.NODEREF);
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@@ -294,7 +296,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
public FileExportHandle exportStore(ExporterCrawlerParameters exportParameters, String packageName, Exporter progress)
|
||||
{
|
||||
// create a temporary file to hold the acp export
|
||||
File tempFile = TempFileProvider.createTempFile("repoExp", "." + ACPExportPackageHandler.ACP_EXTENSION);
|
||||
File tempFile = TempFileProvider.createTempFile("repoExp" + packageName, "." + ACPExportPackageHandler.ACP_EXTENSION);
|
||||
|
||||
// create acp export handler around the temp file
|
||||
File dataFile = new File(packageName);
|
||||
@@ -383,6 +385,7 @@ public class RepositoryExporterComponent implements RepositoryExporterService
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private class RepositoryFileExporter implements ExportStore<RepositoryExportHandle>
|
||||
{
|
||||
private TempFileExporter tempFileExporter = new TempFileExporter();
|
||||
|
@@ -34,6 +34,7 @@ import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.view.Exporter;
|
||||
import org.alfresco.service.cmr.view.ExporterContext;
|
||||
import org.alfresco.service.cmr.view.ExporterException;
|
||||
import org.alfresco.service.cmr.view.ReferenceType;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.xml.sax.ContentHandler;
|
||||
@@ -72,6 +73,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
private static final String INHERITPERMISSIONS_LOCALNAME = "inherit";
|
||||
private static final String REFERENCE_LOCALNAME = "reference";
|
||||
private static final String PATHREF_LOCALNAME = "pathref";
|
||||
private static final String NODEREF_LOCALNAME = "noderef";
|
||||
private static QName VIEW_QNAME;
|
||||
private static QName VALUES_QNAME;
|
||||
private static QName VALUE_QNAME;
|
||||
@@ -94,6 +96,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
private static QName INHERITPERMISSIONS_QNAME;
|
||||
private static QName REFERENCE_QNAME;
|
||||
private static QName PATHREF_QNAME;
|
||||
private static QName NODEREF_QNAME;
|
||||
private static final AttributesImpl EMPTY_ATTRIBUTES = new AttributesImpl();
|
||||
|
||||
// Service dependencies
|
||||
@@ -107,6 +110,10 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
private ContentHandler contentHandler;
|
||||
private ExporterContext context;
|
||||
|
||||
// Configuration
|
||||
private ReferenceType referenceType;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
@@ -147,6 +154,18 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
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);
|
||||
NODEREF_QNAME = QName.createQName(NamespaceService.REPOSITORY_VIEW_PREFIX, NODEREF_LOCALNAME, namespaceService);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set Reference Type to export with
|
||||
*
|
||||
* @param referenceType reference type to export
|
||||
*/
|
||||
public void setReferenceType(ReferenceType referenceType)
|
||||
{
|
||||
this.referenceType = referenceType;
|
||||
}
|
||||
|
||||
|
||||
@@ -518,7 +537,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
NodeRef valueNodeRef = (NodeRef)value;
|
||||
if (nodeRef.getStoreRef().equals(valueNodeRef.getStoreRef()))
|
||||
{
|
||||
Path nodeRefPath = createRelativePath(context.getExportOf(), nodeRef, valueNodeRef);
|
||||
Path nodeRefPath = createPath(context.getExportOf(), nodeRef, valueNodeRef);
|
||||
value = (nodeRefPath == null) ? null : nodeRefPath.toPrefixString(namespaceService);
|
||||
}
|
||||
}
|
||||
@@ -632,9 +651,24 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
{
|
||||
try
|
||||
{
|
||||
Path path = createRelativePath(context.getExportParent(), context.getExportParent(), nodeRef);
|
||||
// determine format of reference e.g. node or path based
|
||||
ReferenceType referenceFormat = referenceType;
|
||||
if (nodeRef.equals(nodeService.getRootNode(nodeRef.getStoreRef())))
|
||||
{
|
||||
referenceFormat = ReferenceType.PATHREF;
|
||||
}
|
||||
|
||||
// output reference
|
||||
AttributesImpl attrs = new AttributesImpl();
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, PATHREF_LOCALNAME, PATHREF_QNAME.toPrefixString(), null, path.toPrefixString(namespaceService));
|
||||
if (referenceFormat.equals(ReferenceType.PATHREF))
|
||||
{
|
||||
Path path = createPath(context.getExportParent(), context.getExportParent(), nodeRef);
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, PATHREF_LOCALNAME, PATHREF_QNAME.toPrefixString(), null, path.toPrefixString(namespaceService));
|
||||
}
|
||||
else
|
||||
{
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, NODEREF_LOCALNAME, NODEREF_QNAME.toPrefixString(), null, nodeRef.toString());
|
||||
}
|
||||
if (childName != null)
|
||||
{
|
||||
attrs.addAttribute(NamespaceService.REPOSITORY_VIEW_1_0_URI, CHILDNAME_LOCALNAME, CHILDNAME_QNAME.toPrefixString(), null, childName.toPrefixString(namespaceService));
|
||||
@@ -704,7 +738,7 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
* @param toRef to reference
|
||||
* @return path
|
||||
*/
|
||||
private Path createRelativePath(NodeRef rootRef, NodeRef fromRef, NodeRef toRef)
|
||||
private Path createPath(NodeRef rootRef, NodeRef fromRef, NodeRef toRef)
|
||||
{
|
||||
// Check that item exists first
|
||||
if (!nodeService.exists(toRef))
|
||||
@@ -713,6 +747,14 @@ import org.xml.sax.helpers.AttributesImpl;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check whether item is the root node of the store
|
||||
// If so, always return absolute path
|
||||
if (toRef.equals(nodeService.getRootNode(toRef.getStoreRef())))
|
||||
{
|
||||
return nodeService.getPath(toRef);
|
||||
}
|
||||
|
||||
// construct relative path
|
||||
Path rootPath = createIndexedPath(rootRef, nodeService.getPath(rootRef));
|
||||
Path fromPath = createIndexedPath(fromRef, nodeService.getPath(fromRef));
|
||||
Path toPath = createIndexedPath(toRef, nodeService.getPath(toRef));
|
||||
|
Reference in New Issue
Block a user