Merged DEV/MOB453 to HEAD

14474: MOB-453 Export multiple root nodes into a single export package (for RM)
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /alfresco/BRANCHES/DEV/MOB453:r14474

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14496 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana 2009-06-02 10:58:42 +00:00
parent 801eac5c2c
commit cbcce91bd8
5 changed files with 276 additions and 89 deletions

View File

@ -270,6 +270,8 @@ public class ExporterComponent
// Export Nodes
//
while (context.canRetrieve())
{
// determine if root repository node
NodeRef nodeRef = context.getExportOf();
if (parameters.isCrawlSelf())
@ -295,7 +297,6 @@ public class ExporterComponent
//
// Export Secondary Links between Nodes
//
for (NodeRef nodeWithAssociations : nodesWithSecondaryLinks.keySet())
{
walkStartNamespaces(parameters, exporter);
@ -306,7 +307,6 @@ public class ExporterComponent
//
// Export Associations between Nodes
//
for (NodeRef nodeWithAssociations : nodesWithAssociations.keySet())
{
walkStartNamespaces(parameters, exporter);
@ -314,6 +314,8 @@ public class ExporterComponent
walkEndNamespaces(parameters, exporter);
}
context.setNextValue();
}
exporter.end();
}
@ -807,7 +809,8 @@ public class ExporterComponent
boolean isWithin = false;
// Current strategy is to determine if node is a child of the root exported node
NodeRef exportRoot = context.getExportOf();
for (NodeRef exportRoot : context.getExportList())
{
if (nodeRef.equals(exportRoot) && parameters.isCrawlSelf() == true)
{
// node to export is the root export node (and root is to be exported)
@ -827,7 +830,7 @@ public class ExporterComponent
}
}
}
}
return isWithin;
}
}
@ -838,12 +841,14 @@ public class ExporterComponent
*/
private class ExporterContextImpl implements ExporterContext
{
private NodeRef exportOf;
private NodeRef parent;
private NodeRef[] exportList;
private NodeRef[] parentList;
private String exportedBy;
private Date exportedDate;
private String exporterVersion;
private int index;
/**
* Construct
*
@ -851,6 +856,8 @@ public class ExporterComponent
*/
public ExporterContextImpl(ExporterCrawlerParameters parameters)
{
index = 0;
// get current user performing export
String currentUserName = authenticationService.getCurrentUserName();
exportedBy = (currentUserName == null) ? "unknown" : currentUserName;
@ -858,16 +865,40 @@ public class ExporterComponent
// get current date
exportedDate = new Date(System.currentTimeMillis());
// get export of
exportOf = getNodeRef(parameters.getExportFrom());
// get export parent
parent = getParent(exportOf, parameters.isCrawlSelf());
// get list of exported nodes
exportList = (parameters.getExportFrom() == null) ? null : parameters.getExportFrom().getNodeRefs();
if (exportList == null)
{
// multi-node export
exportList = new NodeRef[1];
NodeRef exportOf = getNodeRef(parameters.getExportFrom());
exportList[0] = exportOf;
}
parentList = new NodeRef[exportList.length];
for (int i = 0; i < exportList.length; i++)
{
parentList[i] = getParent(exportList[i], parameters.isCrawlSelf());
}
// get exporter version
exporterVersion = descriptorService.getServerDescriptor().getVersion();
}
public boolean canRetrieve()
{
return index < exportList.length;
}
public int setNextValue()
{
return ++index;
}
public void resetContext()
{
index = 0;
}
/* (non-Javadoc)
* @see org.alfresco.service.cmr.view.ExporterContext#getExportedBy()
*/
@ -897,7 +928,11 @@ public class ExporterComponent
*/
public NodeRef getExportOf()
{
return exportOf;
if (canRetrieve())
{
return exportList[index];
}
return null;
}
/*
@ -906,8 +941,31 @@ public class ExporterComponent
*/
public NodeRef getExportParent()
{
return parent;
if (canRetrieve())
{
return parentList[index];
}
return null;
}
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.view.ExporterContext#getExportList()
*/
public NodeRef[] getExportList()
{
return exportList;
}
/*
* (non-Javadoc)
* @see org.alfresco.service.cmr.view.ExporterContext#getExportParentList()
*/
public NodeRef[] getExportParentList()
{
return parentList;
}
/**
* Get the Node Ref from the specified Location

View File

@ -45,6 +45,7 @@ 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.apache.commons.lang.ArrayUtils;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
@ -212,10 +213,19 @@ import org.xml.sax.helpers.AttributesImpl;
// export of
contentHandler.startElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, EXPORTOF_QNAME.toPrefixString(), EMPTY_ATTRIBUTES);
String path = nodeService.getPath(context.getExportOf()).toPrefixString(namespaceService);
contentHandler.characters(path.toCharArray(), 0, path.length());
NodeRef[] exportList = context.getExportList();
int comma = 1;
for(int i=0;i < exportList.length; i++)
{
NodeRef nodeRef = exportList[i];
String path = nodeService.getPath(nodeRef).toPrefixString(namespaceService);
if (i == exportList.length - 1)
{
comma = 0;
}
contentHandler.characters(ArrayUtils.addAll(path.toCharArray(), ",".toCharArray()), 0, path.length() + comma);
}
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, EXPORTOF_LOCALNAME, EXPORTOF_QNAME.toPrefixString());
contentHandler.endElement(NamespaceService.REPOSITORY_VIEW_PREFIX, METADATA_LOCALNAME, METADATA_QNAME.toPrefixString());
}
catch (SAXException e)
@ -545,7 +555,7 @@ import org.xml.sax.helpers.AttributesImpl;
NodeRef valueNodeRef = (NodeRef)value;
if (nodeRef.getStoreRef().equals(valueNodeRef.getStoreRef()))
{
Path nodeRefPath = createPath(context.getExportOf(), nodeRef, valueNodeRef);
Path nodeRefPath = createPath(context.getExportParent(), nodeRef, valueNodeRef);
value = (nodeRefPath == null) ? null : nodeRefPath.toPrefixString(namespaceService);
}
}
@ -574,7 +584,6 @@ import org.xml.sax.helpers.AttributesImpl;
char[] temp = new char[]{strValue.charAt(i)};
contentHandler.characters(temp, 0, 1);
}
}
// output value wrapper if property data type is any
@ -802,12 +811,15 @@ import org.xml.sax.helpers.AttributesImpl;
if (i == rootPath.size())
{
// Determine if to node is relative to export tree
i = 0;
while (i < rootPath.size() && i < toPath.size() && rootPath.get(i).equals(toPath.get(i)))
for (NodeRef nodeRef : context.getExportParentList())
{
i++;
int j = 0;
Path tryPath = createIndexedPath(nodeRef, nodeService.getPath(nodeRef));
while (j < tryPath.size() && j < toPath.size() && tryPath.get(j).equals(toPath.get(j)))
{
j++;
}
if (i == rootPath.size())
if (j == tryPath.size())
{
// build relative path between from and to
relativePath = new Path();
@ -815,14 +827,18 @@ import org.xml.sax.helpers.AttributesImpl;
{
relativePath.append(new Path.ParentElement());
}
if (i < toPath.size())
if (j < toPath.size())
{
relativePath.append(toPath.subPath(i, toPath.size() -1));
relativePath.append(toPath.subPath(j, toPath.size() - 1));
}
break;
}
}
}
}
if (relativePath == null)
{
// default to absolute path

View File

@ -521,7 +521,9 @@ public class ImporterComponent
public void importMetaData(Map<QName, String> properties)
{
// Determine if we're importing a complete repository
String path = properties.get(QName.createQName(NamespaceService.REPOSITORY_VIEW_1_0_URI, "exportOf"));
String complexPath = properties.get(QName.createQName(NamespaceService.REPOSITORY_VIEW_1_0_URI, "exportOf"));
for (String path : complexPath.split(","))
{
if (path != null && path.equals("/"))
{
// Only allow complete repository import into root
@ -532,6 +534,7 @@ public class ImporterComponent
}
}
}
}
/* (non-Javadoc)
* @see org.alfresco.repo.importer.Importer#importNode(org.alfresco.repo.importer.ImportNode)

View File

@ -1,20 +1,102 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.service.cmr.view;
import java.util.Date;
import org.alfresco.service.cmr.repository.NodeRef;
public interface ExporterContext
{
/**
* Gets who initiated the export
*
* @return
*/
public String getExportedBy();
/**
* Gets date at which export occured
*
* @return
*/
public Date getExportedDate();
/**
* Gets version number of exporter
*
* @return
*/
public String getExporterVersion();
/**
* Gets active node for export
*
* @return NodeRef
*/
public NodeRef getExportOf();
/**
* Gets parent of exporting node
*
* @return NodeRef
*/
public NodeRef getExportParent();
/**
* Gets list of nodes for export
*
* @return NodeRef[]
*/
public NodeRef[] getExportList();
/**
* Gets list of parents for exporting nodes
*
* @return NodeRef[]
*/
public NodeRef[] getExportParentList();
/**
* Return true if there is active node for export
*
* @return
*/
public boolean canRetrieve();
/**
* Set next active node from list
*
* @return
*/
public int setNextValue();
/**
* Set first active node
*/
public void resetContext();
}

View File

@ -38,6 +38,7 @@ public class Location
{
private StoreRef storeRef = null;
private NodeRef nodeRef = null;
private NodeRef[] nodeRefs = null;
private String path = null;
private QName childAssocType = null;
@ -54,6 +55,19 @@ public class Location
this.nodeRef = nodeRef;
}
/**
* Construct
*
* @param nodeRefs
*/
public Location(NodeRef[] nodeRefs)
{
ParameterCheck.mandatory("Node Refs", nodeRefs);
this.storeRef = nodeRefs[0].getStoreRef();
this.nodeRefs = nodeRefs;
}
/**
* Construct
*
@ -81,6 +95,20 @@ public class Location
return nodeRef;
}
/**
* @return the node refs
*/
public NodeRef[] getNodeRefs()
{
return nodeRefs;
}
public void setNodeRefs(NodeRef[] nodeRefs)
{
this.nodeRef = null;
this.nodeRefs = nodeRefs;
}
/**
* Sets the location to the specified path
*