Big hunk of merge.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3265 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Britt Park
2006-06-28 17:31:18 +00:00
parent b55958b062
commit 7d940d08e1
35 changed files with 491 additions and 241 deletions

View File

@@ -218,9 +218,9 @@ public class ExporterActionExecuter extends ActionExecuterAbstractBase
String packageName = (String)ruleAction.getParameterValue(PARAM_PACKAGE_NAME);
// add the default Alfresco content package extension if an extension hasn't been given
if (packageName.indexOf(".") == -1)
if (!packageName.endsWith("." + ACPExportPackageHandler.ACP_EXTENSION))
{
packageName = packageName + "." + ACPExportPackageHandler.ACP_EXTENSION;
packageName += (packageName.charAt(packageName.length() -1) == '.') ? ACPExportPackageHandler.ACP_EXTENSION : "." + ACPExportPackageHandler.ACP_EXTENSION;
}
// set the name for the new node

View File

@@ -156,7 +156,6 @@
unique="false"
not-null="false" />
<property name="changeTxnId" column="change_txn_id" type="string" length="56" not-null="true" />
<property name="deleted" column="deleted" type="boolean" not-null="true" />
</class>
<class
@@ -285,7 +284,7 @@
where
status.key.protocol = :storeProtocol and
status.key.identifier = :storeIdentifier and
status.deleted = :deleted and
status.node.id is not null and
status.changeTxnId = :changeTxnId
</query>
@@ -297,7 +296,19 @@
where
status.key.protocol = :storeProtocol and
status.key.identifier = :storeIdentifier and
status.deleted = :deleted and
status.node.id is not null and
status.changeTxnId = :changeTxnId
</query>
<query name="node.GetDeletedNodeStatuses">
select
status
from
org.alfresco.repo.domain.hibernate.NodeStatusImpl as status
where
status.key.protocol = :storeProtocol and
status.key.identifier = :storeIdentifier and
status.node.id is null and
status.changeTxnId = :changeTxnId
</query>

View File

@@ -99,13 +99,4 @@ public class NodeStatusImpl implements NodeStatus, Serializable
{
return (node == null);
}
/**
* For Hibernate use
*/
@SuppressWarnings("unused")
private void setDeleted(boolean deleted)
{
// this is a convenience, derived property
}
}

View File

@@ -23,8 +23,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.ContentData;
@@ -32,6 +30,8 @@ import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.view.ExportPackageHandler;
import org.alfresco.service.cmr.view.ExporterException;
import org.alfresco.util.TempFileProvider;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
/**
@@ -54,7 +54,7 @@ public class ACPExportPackageHandler
protected ZipOutputStream zipStream;
protected int iFileCnt = 0;
/**
* Construct
*
@@ -71,7 +71,7 @@ public class ACPExportPackageHandler
String zipFilePath = zipFile.getPath();
if (!zipFilePath.endsWith("." + ACP_EXTENSION))
{
zipFilePath += "." + ACP_EXTENSION;
zipFilePath += (zipFilePath.charAt(zipFilePath.length() -1) == '.') ? ACP_EXTENSION : "." + ACP_EXTENSION;
}
File absZipFile = new File(destDir, zipFilePath);
@@ -118,6 +118,9 @@ public class ACPExportPackageHandler
public void startExport()
{
zipStream = new ZipOutputStream(outputStream);
// NOTE: This encoding allows us to workaround bug...
// http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
zipStream.setEncoding("Cp437");
}
/* (non-Javadoc)
@@ -150,9 +153,9 @@ public class ACPExportPackageHandler
// create zip entry for stream to export
String contentDirPath = contentDir.getPath();
if (contentDirPath.indexOf(".") != -1)
if (contentDirPath.charAt(contentDirPath.length() -1) != '.' && contentDirPath.lastIndexOf('.') != -1)
{
contentDirPath = contentDirPath.substring(0, contentDirPath.indexOf("."));
contentDirPath = contentDirPath.substring(0, contentDirPath.lastIndexOf("."));
}
String extension = "bin";
if (mimetypeService != null)
@@ -197,7 +200,7 @@ public class ACPExportPackageHandler
String dataFilePath = dataFile.getPath();
if (!dataFilePath.endsWith(".xml"))
{
dataFilePath += ".xml";
dataFilePath += (dataFilePath .charAt(dataFilePath .length() -1) == '.') ? "xml" : ".xml";
}
// add data file to zip stream

View File

@@ -532,7 +532,7 @@ import org.xml.sax.helpers.AttributesImpl;
}
// convert node references to paths
if (value instanceof NodeRef)
if (value instanceof NodeRef && referenceType.equals(ReferenceType.PATHREF))
{
NodeRef valueNodeRef = (NodeRef)value;
if (nodeRef.getStoreRef().equals(valueNodeRef.getStoreRef()))

View File

@@ -24,11 +24,11 @@ import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.alfresco.service.cmr.view.ImportPackageHandler;
import org.alfresco.service.cmr.view.ImporterException;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipFile;
/**
@@ -39,7 +39,8 @@ import org.alfresco.service.cmr.view.ImporterException;
public class ACPImportPackageHandler
implements ImportPackageHandler
{
public final static String DEFAULT_ENCODING = "UTF-8";
protected File file;
protected ZipFile zipFile;
protected String dataFileEncoding;
@@ -65,7 +66,9 @@ public class ACPImportPackageHandler
log("Importing from zip file " + file.getAbsolutePath());
try
{
zipFile = new ZipFile(file);
// NOTE: This encoding allows us to workaround bug...
// http://bugs.sun.com/bugdatabase/view_bug.do;:WuuT?bug_id=4820807
zipFile = new ZipFile(file, "Cp437");
}
catch(IOException e)
{
@@ -86,7 +89,7 @@ public class ACPImportPackageHandler
// TODO: First, locate xml meta-data file by name
// Scan the zip entries one by one (the slow approach)
Enumeration entries = zipFile.entries();
Enumeration entries = zipFile.getEntries();
while(entries.hasMoreElements())
{
ZipEntry entry = (ZipEntry)entries.nextElement();
@@ -113,7 +116,7 @@ public class ACPImportPackageHandler
// open the meta-data xml file
InputStream dataStream = zipFile.getInputStream(xmlMetaDataEntry);
Reader inputReader = (dataFileEncoding == null) ? new InputStreamReader(dataStream) : new InputStreamReader(dataStream, dataFileEncoding);
Reader inputReader = (dataFileEncoding == null) ? new InputStreamReader(dataStream, DEFAULT_ENCODING) : new InputStreamReader(dataStream, dataFileEncoding);
return new BufferedReader(inputReader);
}
catch(UnsupportedEncodingException e)

View File

@@ -37,6 +37,8 @@ import org.alfresco.service.cmr.view.ImporterException;
public class FileImportPackageHandler
implements ImportPackageHandler
{
public final static String DEFAULT_ENCODING = "UTF-8";
protected File sourceDir;
protected File dataFile;
protected String dataFileEncoding;
@@ -71,7 +73,7 @@ public class FileImportPackageHandler
try
{
InputStream inputStream = new FileInputStream(dataFile);
Reader inputReader = (dataFileEncoding == null) ? new InputStreamReader(inputStream) : new InputStreamReader(inputStream, dataFileEncoding);
Reader inputReader = (dataFileEncoding == null) ? new InputStreamReader(inputStream, DEFAULT_ENCODING) : new InputStreamReader(inputStream, dataFileEncoding);
return new BufferedReader(inputReader);
}
catch(UnsupportedEncodingException e)

View File

@@ -557,9 +557,9 @@ public class ImporterComponent
{
importContent(nodeRef, property.getKey(), (String)objVal);
}
else if (objVal instanceof List)
else if (objVal instanceof Collection)
{
for (String value : (List<String>)objVal)
for (String value : (Collection<String>)objVal)
{
importContent(nodeRef, property.getKey(), value);
}
@@ -716,12 +716,11 @@ public class ImporterComponent
if (unresolvedRef != null)
{
NodeRef nodeRef = resolveImportedNodeRef(importedRef.context.getNodeRef(), unresolvedRef);
if (nodeRef == null)
// TODO: Provide a better mechanism for invalid references? e.g. report warning
if (nodeRef != null)
{
// TODO: Probably need an alternative mechanism here e.g. report warning
throw new ImporterException("Failed to find item referenced (in property " + importedRef.property + ") as " + importedRef.value);
resolvedRefs.add(nodeRef);
}
resolvedRefs.add(nodeRef);
}
}
refProperty = (Serializable)resolvedRefs;
@@ -729,11 +728,7 @@ public class ImporterComponent
else
{
refProperty = resolveImportedNodeRef(importedRef.context.getNodeRef(), (String)importedRef.value);
if (refProperty == null)
{
// TODO: Probably need an alternative mechanism here e.g. report warning
throw new ImporterException("Failed to find item referenced (in property " + importedRef.property + ") as " + importedRef.value);
}
// TODO: Provide a better mechanism for invalid references? e.g. report warning
}
}
@@ -1024,23 +1019,31 @@ public class ImporterComponent
}
else
{
// resolve relative path
try
{
List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, importedRef, null, namespaceService, false);
if (nodeRefs.size() > 0)
{
nodeRef = nodeRefs.get(0);
}
}
catch(XPathException e)
{
nodeRef = new NodeRef(importedRef);
}
catch(AlfrescoRuntimeException e1)
{
// Note: Invalid reference format - try path search instead
}
// determine if node reference
if (NodeRef.isNodeRef(importedRef))
{
nodeRef = new NodeRef(importedRef);
}
else
{
// resolve relative path
try
{
List<NodeRef> nodeRefs = searchService.selectNodes(sourceNodeRef, importedRef, null, namespaceService, false);
if (nodeRefs.size() > 0)
{
nodeRef = nodeRefs.get(0);
}
}
catch(XPathException e)
{
nodeRef = new NodeRef(importedRef);
}
catch(AlfrescoRuntimeException e1)
{
// Note: Invalid reference format - try path search instead
}
}
}
return nodeRef;
@@ -1235,7 +1238,7 @@ public class ImporterComponent
NodeRef nodeRef = assocRef.getChildRef();
// Note: non-admin authorities take ownership of new nodes
if (!authorityService.hasAdminAuthority())
if (!(authorityService.hasAdminAuthority() || authenticationService.isCurrentUserTheSystemUser()))
{
ownableService.takeOwnership(nodeRef);
}

View File

@@ -17,7 +17,7 @@
<value name="applied-on-date" field="appliedOnDate"/>
<value name="was-executed" field="wasExecuted"/>
<value name="succeeded" field="succeeded"/>
<value name="report" field="report"/>
<value name="report" field="report" usage="optional"/>
</structure>
</collection>
</structure>

View File

@@ -80,4 +80,15 @@ public class MetaDataContext extends ElementContext
return properties;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return "MetaDataContext[properties=" + properties.size() + "]";
}
}

View File

@@ -49,4 +49,15 @@ public class NodeItemContext extends ElementContext
{
return nodeContext;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return "NodeItemContext[nodeContext=" + nodeContext.toString() + "]";
}
}

View File

@@ -197,7 +197,11 @@ public class ViewParser implements Parser
// Handle special view directives
if (defName.equals(VIEW_METADATA))
{
parserContext.elementStack.push(new MetaDataContext(defName, (ElementContext)element));
MetaDataContext metaDataContext = new MetaDataContext(defName, (ElementContext)element);
parserContext.elementStack.push(metaDataContext);
if (logger.isDebugEnabled())
logger.debug(indentLog("Pushed " + metaDataContext, parserContext.elementStack.size() -1));
}
else if (defName.equals(VIEW_ASPECTS) || defName.equals(VIEW_PROPERTIES) || defName.equals(VIEW_ASSOCIATIONS) || defName.equals(VIEW_ACL))
{
@@ -210,7 +214,11 @@ public class ViewParser implements Parser
throw new ImporterException("Element " + defName + " can only be declared within a node");
}
NodeContext node = (NodeContext)element;
parserContext.elementStack.push(new NodeItemContext(defName, node));
NodeItemContext nodeItemContext = new NodeItemContext(defName, node);
parserContext.elementStack.push(nodeItemContext);
if (logger.isDebugEnabled())
logger.debug(indentLog("Pushed " + nodeItemContext, parserContext.elementStack.size() -1));
// process ACL specific attributes
if (defName.equals(VIEW_ACL))

View File

@@ -36,6 +36,7 @@ import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.namespace.QName;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ImporterTopLevel;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;
@@ -197,8 +198,11 @@ public class RhinoScriptService implements ScriptService
{
// The easiest way to embed Rhino is just to create a new scope this way whenever
// you need one. However, initStandardObjects is an expensive method to call and it
// allocates a fair amount of memory.
// allocates a fair amount of memory. ImporterTopLevel provides a scope allowing
// the import of java classes and packages.
Scriptable topLevelScope = new ImporterTopLevel(cx);
Scriptable scope = cx.initStandardObjects();
scope.setParentScope(topLevelScope);
// insert supplied object model into root of the default scope
if (model != null)

View File

@@ -156,7 +156,7 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
// create a first store directly
StoreRef storeRef = nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.nanoTime());
"Test_" + System.currentTimeMillis());
rootNodeRef = nodeService.getRootNode(storeRef);
}
@@ -622,6 +622,36 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
nodeService.hasAspect(nodeRef, ASPECT_QNAME_TEST_TITLED));
}
public void testCascadeDelete() throws Exception
{
// build the node and commit the node graph
Map<QName, ChildAssociationRef> assocRefs = buildNodeGraph(nodeService, rootNodeRef);
NodeRef n3Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n1_p_n3")).getChildRef();
NodeRef n4Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n2_p_n4")).getChildRef();
NodeRef n6Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n3_p_n6")).getChildRef();
NodeRef n7Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n5_p_n7")).getChildRef();
NodeRef n8Ref = assocRefs.get(QName.createQName(BaseNodeServiceTest.NAMESPACE, "n6_p_n8")).getChildRef();
// control checks
assertEquals("n6 not present", 1, countNodesByReference(n6Ref));
assertEquals("n8 not present", 1, countNodesByReference(n8Ref));
assertEquals("n6 primary parent association not present on n3", 1, countChildrenOfNode(n3Ref));
assertEquals("n6 secondary parent association not present on n4", 1, countChildrenOfNode(n4Ref));
assertEquals("n8 secondary parent association not present on n7", 1, countChildrenOfNode(n7Ref));
// delete n6
nodeService.deleteNode(n6Ref);
// commit to check
setComplete();
endTransaction();
assertEquals("n6 not directly deleted", 0, countNodesByReference(n6Ref));
assertEquals("n8 not cascade deleted", 0, countNodesByReference(n8Ref));
assertEquals("n6 primary parent association not removed from n3", 0, countChildrenOfNode(n3Ref));
assertEquals("n6 secondary parent association not removed from n4", 0, countChildrenOfNode(n4Ref));
assertEquals("n8 secondary parent association not removed from n7", 0, countChildrenOfNode(n7Ref));
}
public static class BadOnDeleteNodePolicy implements
NodeServicePolicies.OnDeleteNodePolicy,
NodeServicePolicies.BeforeDeleteNodePolicy
@@ -703,10 +733,12 @@ public abstract class BaseNodeServiceTest extends BaseSpringTest
"select node.childAssocs" +
" from " +
NodeImpl.class.getName() + " node" +
" where node.uuid = ?";
" where node.uuid = ? and node.store.key.protocol = ? and node.store.key.identifier = ?";
Session session = getSession();
List results = session.createQuery(query)
.setString(0, nodeRef.getId())
.setString(1, nodeRef.getStoreRef().getProtocol())
.setString(2, nodeRef.getStoreRef().getIdentifier())
.list();
int count = results.size();
return count;

View File

@@ -80,6 +80,7 @@ public class FullIndexRecoveryComponent extends HibernateDaoSupport implements I
{
public static final String QUERY_GET_NEXT_CHANGE_TXN_IDS = "node.GetNextChangeTxnIds";
public static final String QUERY_GET_CHANGED_NODE_STATUSES = "node.GetChangedNodeStatuses";
public static final String QUERY_GET_DELETED_NODE_STATUSES = "node.GetDeletedNodeStatuses";
public static final String QUERY_GET_CHANGED_NODE_STATUSES_COUNT = "node.GetChangedNodeStatusesCount";
private static final String START_TXN_ID = "000";
@@ -705,8 +706,7 @@ public class FullIndexRecoveryComponent extends HibernateDaoSupport implements I
public Object doInHibernate(Session session)
{
Query query = session.getNamedQuery(QUERY_GET_CHANGED_NODE_STATUSES_COUNT);
query.setBoolean("deleted", false)
.setString("storeProtocol", storeRef.getProtocol())
query.setString("storeProtocol", storeRef.getProtocol())
.setString("storeIdentifier", storeRef.getIdentifier())
.setString("changeTxnId", changeTxnId)
.setReadOnly(true);
@@ -726,8 +726,7 @@ public class FullIndexRecoveryComponent extends HibernateDaoSupport implements I
public Object doInHibernate(Session session)
{
Query query = session.getNamedQuery(QUERY_GET_CHANGED_NODE_STATUSES);
query.setBoolean("deleted", false)
.setString("storeProtocol", storeRef.getProtocol())
query.setString("storeProtocol", storeRef.getProtocol())
.setString("storeIdentifier", storeRef.getIdentifier())
.setString("changeTxnId", changeTxnId)
.setReadOnly(true);
@@ -746,9 +745,8 @@ public class FullIndexRecoveryComponent extends HibernateDaoSupport implements I
{
public Object doInHibernate(Session session)
{
Query query = session.getNamedQuery(QUERY_GET_CHANGED_NODE_STATUSES);
query.setBoolean("deleted", true)
.setString("storeProtocol", storeRef.getProtocol())
Query query = session.getNamedQuery(QUERY_GET_DELETED_NODE_STATUSES);
query.setString("storeProtocol", storeRef.getProtocol())
.setString("storeIdentifier", storeRef.getIdentifier())
.setString("changeTxnId", changeTxnId)
.setReadOnly(true);

View File

@@ -289,7 +289,7 @@ public class SearcherComponentTest extends TestCase
/**
* Tests the <b>like</b> and <b>contains</b> functions (FTS functions) within a currently executing transaction
*/
public void testLikeAndContains() throws Exception
public void xtestLikeAndContains() throws Exception
{
Map<QName, ChildAssociationRef> assocRefs = BaseNodeServiceTest.buildNodeGraph(nodeService, rootNodeRef);

View File

@@ -280,6 +280,23 @@ public class LDAPGroupExportSource implements ExportSource, InitializingBean
ContentModel.TYPE_AUTHORITY_CONTAINER.getLocalName(), ContentModel.TYPE_AUTHORITY_CONTAINER
.toPrefixString(namespaceService), attrs);
if ((authorityDAO != null ) && authorityDAO.authorityExists(group.gid))
{
NodeRef authNodeRef = authorityDAO.getAuthorityNodeRefOrNull(group.gid);
if (authNodeRef != null)
{
String uguid = authorityDAO.getAuthorityNodeRefOrNull(group.gid).getId();
writer.startElement(nodeUUID.getNamespaceURI(), nodeUUID.getLocalName(), nodeUUID
.toPrefixString(namespaceService), new AttributesImpl());
writer.characters(uguid.toCharArray(), 0, uguid.length());
writer.endElement(nodeUUID.getNamespaceURI(), nodeUUID.getLocalName(), nodeUUID
.toPrefixString(namespaceService));
}
}
writer.startElement(ContentModel.PROP_AUTHORITY_NAME.getNamespaceURI(), ContentModel.PROP_AUTHORITY_NAME
.getLocalName(), ContentModel.PROP_AUTHORITY_NAME.toPrefixString(namespaceService),
new AttributesImpl());