mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merge from head.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3314 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -47,6 +47,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
@@ -488,6 +489,66 @@ public final class Node implements Serializable
|
||||
return allowed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the node inherits permissions from the parent node, false otherwise
|
||||
*/
|
||||
public boolean inheritsPermissions()
|
||||
{
|
||||
return this.services.getPermissionService().getInheritParentPermissions(this.nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this node should inherit permissions from the parent node.
|
||||
*
|
||||
* @param inherit True to inherit parent permissions, false otherwise.
|
||||
*/
|
||||
public void setInheritsPermissions(boolean inherit)
|
||||
{
|
||||
this.services.getPermissionService().setInheritParentPermissions(this.nodeRef, inherit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a permission for ALL users to the node.
|
||||
*
|
||||
* @param permission Permission to apply @see org.alfresco.service.cmr.security.PermissionService
|
||||
*/
|
||||
public void setPermission(String permission)
|
||||
{
|
||||
this.services.getPermissionService().setPermission(this.nodeRef, PermissionService.ALL_AUTHORITIES, permission, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a permission for the specified authority (e.g. username or group) to the node.
|
||||
*
|
||||
* @param permission Permission to apply @see org.alfresco.service.cmr.security.PermissionService
|
||||
* @param authority Authority (generally a username or group name) to apply the permission for
|
||||
*/
|
||||
public void setPermission(String permission, String authority)
|
||||
{
|
||||
this.services.getPermissionService().setPermission(this.nodeRef, authority, permission, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a permission for ALL user from the node.
|
||||
*
|
||||
* @param permission Permission to remove @see org.alfresco.service.cmr.security.PermissionService
|
||||
*/
|
||||
public void removePermission(String permission)
|
||||
{
|
||||
this.services.getPermissionService().deletePermission(this.nodeRef, PermissionService.ALL_AUTHORITIES, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a permission for the specified authority (e.g. username or group) from the node.
|
||||
*
|
||||
* @param permission Permission to remove @see org.alfresco.service.cmr.security.PermissionService
|
||||
* @param authority Authority (generally a username or group name) to apply the permission for
|
||||
*/
|
||||
public void removePermission(String permission, String authority)
|
||||
{
|
||||
this.services.getPermissionService().deletePermission(this.nodeRef, authority, permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Display path to this node
|
||||
*/
|
||||
|
@@ -35,6 +35,7 @@ import org.alfresco.service.cmr.repository.ScriptException;
|
||||
import org.alfresco.service.cmr.repository.ScriptService;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.ImporterTopLevel;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
@@ -47,6 +48,8 @@ import org.mozilla.javascript.ScriptableObject;
|
||||
*/
|
||||
public class RhinoScriptService implements ScriptService
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger(RhinoScriptService.class);
|
||||
|
||||
/** The permission-safe node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
@@ -191,7 +194,13 @@ public class RhinoScriptService implements ScriptService
|
||||
*/
|
||||
private Object executeScriptImpl(Reader reader, Map<String, Object> model)
|
||||
throws AlfrescoRuntimeException
|
||||
{
|
||||
{
|
||||
long startTime = 0;
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// check that rhino script engine is available
|
||||
Context cx = Context.enter();
|
||||
try
|
||||
@@ -226,6 +235,12 @@ public class RhinoScriptService implements ScriptService
|
||||
finally
|
||||
{
|
||||
cx.exit();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
long endTime = System.currentTimeMillis();
|
||||
logger.debug("Time to execute script: " + (endTime - startTime) + "ms");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -67,7 +67,8 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
private static final String KEY_RULES_EXECUTED = "RuleServiceImpl.ExecutedRules";
|
||||
|
||||
/** qname of assoc to rules */
|
||||
private QName ASSOC_NAME_RULES = QName.createQName(RuleModel.RULE_MODEL_URI, "rules");
|
||||
private String ASSOC_NAME_RULES_PREFIX = "rules";
|
||||
private RegexQNamePattern ASSOC_NAME_RULES_REGEX = new RegexQNamePattern(RuleModel.RULE_MODEL_URI, "^" + ASSOC_NAME_RULES_PREFIX + ".*");
|
||||
|
||||
/**
|
||||
* The logger
|
||||
@@ -325,7 +326,7 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
|
||||
// Get the rules for this node
|
||||
List<ChildAssociationRef> ruleChildAssocRefs =
|
||||
this.runtimeNodeService.getChildAssocs(ruleFolder, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES);
|
||||
this.runtimeNodeService.getChildAssocs(ruleFolder, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES_REGEX);
|
||||
for (ChildAssociationRef ruleChildAssocRef : ruleChildAssocRefs)
|
||||
{
|
||||
// Create the rule and add to the list
|
||||
@@ -366,7 +367,7 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
{
|
||||
// Get the rules for this node
|
||||
List<ChildAssociationRef> ruleChildAssocRefs =
|
||||
this.runtimeNodeService.getChildAssocs(ruleFolder, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES);
|
||||
this.runtimeNodeService.getChildAssocs(ruleFolder, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES_REGEX);
|
||||
|
||||
ruleCount = ruleChildAssocRefs.size();
|
||||
}
|
||||
@@ -531,7 +532,7 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
private Rule createRule(NodeRef owningNodeRef, NodeRef ruleNodeRef)
|
||||
{
|
||||
// Get the rule properties
|
||||
Map<QName, Serializable> props = this.nodeService.getProperties(ruleNodeRef);
|
||||
Map<QName, Serializable> props = this.runtimeNodeService.getProperties(ruleNodeRef);
|
||||
|
||||
// Create the rule
|
||||
String ruleTypeName = (String)props.get(RuleModel.PROP_RULE_TYPE);
|
||||
@@ -590,7 +591,7 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
ruleNodeRef = this.nodeService.createNode(
|
||||
getSavedRuleFolderRef(nodeRef),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
ASSOC_NAME_RULES,
|
||||
QName.createQName(RuleModel.RULE_MODEL_URI, ASSOC_NAME_RULES_PREFIX + GUID.generate()),
|
||||
RuleModel.TYPE_RULE,
|
||||
props).getChildRef();
|
||||
|
||||
@@ -643,7 +644,7 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
{
|
||||
List<ChildAssociationRef> ruleChildAssocs = this.nodeService.getChildAssocs(
|
||||
folder,
|
||||
RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES);
|
||||
RegexQNamePattern.MATCH_ALL, ASSOC_NAME_RULES_REGEX);
|
||||
for (ChildAssociationRef ruleChildAssoc : ruleChildAssocs)
|
||||
{
|
||||
this.nodeService.removeChild(folder, ruleChildAssoc.getChildRef());
|
||||
@@ -666,30 +667,25 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
this.disabledRules.contains(rule) == false)
|
||||
{
|
||||
PendingRuleData pendingRuleData = new PendingRuleData(actionableNodeRef, actionedUponNodeRef, rule, executeAtEnd);
|
||||
Set<ExecutedRuleData> executedRules =
|
||||
(Set<ExecutedRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_EXECUTED);
|
||||
|
||||
if (executedRules == null || executedRules.contains(new ExecutedRuleData(actionableNodeRef, rule)) == false)
|
||||
{
|
||||
Set<PendingRuleData> pendingRules =
|
||||
(Set<PendingRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_PENDING);
|
||||
if (pendingRules == null)
|
||||
{
|
||||
// bind pending rules to the current transaction
|
||||
pendingRules = new HashSet<PendingRuleData>();
|
||||
AlfrescoTransactionSupport.bindResource(KEY_RULES_PENDING, pendingRules);
|
||||
// bind the rule transaction listener
|
||||
AlfrescoTransactionSupport.bindListener(this.ruleTransactionListener);
|
||||
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Rule '" + rule.getTitle() + "' has been added pending execution to action upon node '" + actionedUponNodeRef.getId() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent hte same rule being executed more than one in the same transaction
|
||||
pendingRules.add(pendingRuleData);
|
||||
}
|
||||
|
||||
Set<PendingRuleData> pendingRules =
|
||||
(Set<PendingRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_PENDING);
|
||||
if (pendingRules == null)
|
||||
{
|
||||
// bind pending rules to the current transaction
|
||||
pendingRules = new HashSet<PendingRuleData>();
|
||||
AlfrescoTransactionSupport.bindResource(KEY_RULES_PENDING, pendingRules);
|
||||
// bind the rule transaction listener
|
||||
AlfrescoTransactionSupport.bindListener(this.ruleTransactionListener);
|
||||
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Rule '" + rule.getTitle() + "' has been added pending execution to action upon node '" + actionedUponNodeRef.getId() + "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent hte same rule being executed more than one in the same transaction
|
||||
pendingRules.add(pendingRuleData);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -699,12 +695,18 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleService#executePendingRules()
|
||||
*/
|
||||
public void executePendingRules()
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Creating the executed rules list");
|
||||
}
|
||||
AlfrescoTransactionSupport.bindResource(KEY_RULES_EXECUTED, new HashSet<ExecutedRuleData>());
|
||||
try
|
||||
{
|
||||
@@ -718,6 +720,10 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
finally
|
||||
{
|
||||
AlfrescoTransactionSupport.unbindResource(KEY_RULES_EXECUTED);
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug("Unbinding resource");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -762,22 +768,121 @@ public class RuleServiceImpl implements RuleService, RuntimeRuleService
|
||||
@SuppressWarnings("unchecked")
|
||||
private void executePendingRule(PendingRuleData pendingRule)
|
||||
{
|
||||
NodeRef actionableNodeRef = pendingRule.getActionableNodeRef();
|
||||
Set<ExecutedRuleData> executedRules =
|
||||
(Set<ExecutedRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_EXECUTED);
|
||||
|
||||
NodeRef actionedUponNodeRef = pendingRule.getActionedUponNodeRef();
|
||||
Rule rule = pendingRule.getRule();
|
||||
|
||||
// Evaluate the condition
|
||||
if (this.actionService.evaluateAction(rule, actionedUponNodeRef) == true)
|
||||
{
|
||||
// Add the rule to the executed rule list
|
||||
// (do this before this is executed to prevent rules being added to the pending list)
|
||||
Set<ExecutedRuleData> executedRules =
|
||||
(Set<ExecutedRuleData>) AlfrescoTransactionSupport.getResource(KEY_RULES_EXECUTED);
|
||||
executedRules.add(new ExecutedRuleData(actionableNodeRef, rule));
|
||||
|
||||
// Execute the rule
|
||||
this.actionService.executeAction(rule, actionedUponNodeRef);
|
||||
}
|
||||
|
||||
if (executedRules == null || canExecuteRule(executedRules, actionedUponNodeRef, rule) == true)
|
||||
{
|
||||
// Evaluate the condition
|
||||
if (this.actionService.evaluateAction(rule, actionedUponNodeRef) == true)
|
||||
{
|
||||
// Add the rule to the executed rule list
|
||||
// (do this before this is executed to prevent rules being added to the pending list)
|
||||
executedRules.add(new ExecutedRuleData(actionedUponNodeRef, rule));
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" ... Adding rule (" + rule.getTitle() + ") and nodeRef (" + actionedUponNodeRef.getId() + ") to executed list");
|
||||
}
|
||||
|
||||
// Execute the rule
|
||||
this.actionService.executeAction(rule, actionedUponNodeRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the rule can be executed
|
||||
*
|
||||
* @param executedRules
|
||||
* @param actionedUponNodeRef
|
||||
* @param rule
|
||||
* @return
|
||||
*/
|
||||
private boolean canExecuteRule(Set<ExecutedRuleData> executedRules, NodeRef actionedUponNodeRef, Rule rule)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Current executed items count = " + executedRules.size());
|
||||
}
|
||||
|
||||
if (executedRules != null)
|
||||
{
|
||||
if (executedRules.contains(new ExecutedRuleData(actionedUponNodeRef, rule)) == true)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Already executed this rule (" + rule.getTitle()+ ") on this nodeRef (" + actionedUponNodeRef.getId() + ")");
|
||||
}
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = checkForCopy(executedRules, actionedUponNodeRef, rule);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Executed this rule (" + rule.getTitle()+ ") on (" + actionedUponNodeRef.getId() + ") executed rule is null");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a copy exists in the executed rules list
|
||||
*
|
||||
* @param executedRules
|
||||
* @param actionedUponNodeRef
|
||||
* @param rule
|
||||
* @return
|
||||
*/
|
||||
private boolean checkForCopy(Set<ExecutedRuleData> executedRules, NodeRef actionedUponNodeRef, Rule rule)
|
||||
{
|
||||
boolean result = true;
|
||||
if (this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_COPIEDFROM) == true)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Has the copied from aspect (" + actionedUponNodeRef.getId() + ")");
|
||||
}
|
||||
NodeRef copiedFrom = (NodeRef)this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_COPY_REFERENCE);
|
||||
|
||||
if (logger.isDebugEnabled() == true && copiedFrom != null) {logger.debug(" >> Got the copedFrom nodeRef (" + copiedFrom.getId() + ")");};
|
||||
|
||||
if (copiedFrom != null && executedRules.contains(new ExecutedRuleData(copiedFrom, rule)) == true)
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Already executed this rule (" + rule.getTitle()+ ") on this the copied from nodeRef (" + copiedFrom.getId() + ")");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Executed this rule (" + rule.getTitle()+ ") on (" + actionedUponNodeRef.getId() + ") copiedFrom is not is list");
|
||||
logger.debug(" > Checking copy");
|
||||
}
|
||||
result = checkForCopy(executedRules, copiedFrom, rule);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (logger.isDebugEnabled() == true)
|
||||
{
|
||||
logger.debug(" >> Executed this rule (" + rule.getTitle()+ ") on (" + actionedUponNodeRef.getId() + ") no copied from aspect");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,16 +22,15 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.index.FilterIndexReader;
|
||||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.TermDocs;
|
||||
import org.apache.lucene.index.TermEnum;
|
||||
import org.apache.lucene.index.TermPositions;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.Hits;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MultiSearcher;
|
||||
import org.apache.lucene.search.Searcher;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
|
||||
@@ -63,19 +62,23 @@ public class FilterIndexReaderByNodeRefs2 extends FilterIndexReader
|
||||
Searcher searcher = new IndexSearcher(reader);
|
||||
for (NodeRef nodeRef : deletions)
|
||||
{
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
query.add(new TermQuery(new Term("ID", nodeRef.toString())), true, false);
|
||||
query.add(new TermQuery(new Term("ISNODE", "T")), false, false);
|
||||
TermQuery query = new TermQuery(new Term("ID", nodeRef.toString()));
|
||||
Hits hits = searcher.search(query);
|
||||
if (hits.length() > 0)
|
||||
{
|
||||
for (int i = 0; i < hits.length(); i++)
|
||||
{
|
||||
deletedDocuments.set(hits.id(i), true);
|
||||
Document doc = hits.doc(i);
|
||||
if (doc.getField("ISCONTAINER") == null)
|
||||
{
|
||||
deletedDocuments.set(hits.id(i), true);
|
||||
// There should only be one thing to delete
|
||||
//break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
|
@@ -47,7 +47,6 @@ import java.util.zip.CRC32;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.search.IndexerException;
|
||||
import org.alfresco.repo.search.impl.lucene.FilterIndexReaderByNodeRefs;
|
||||
import org.alfresco.repo.search.impl.lucene.FilterIndexReaderByNodeRefs2;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -61,12 +60,14 @@ import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.MultiReader;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.Hits;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Searcher;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.InputStream;
|
||||
import org.apache.lucene.store.OutputStream;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
/**
|
||||
@@ -205,6 +206,11 @@ public class IndexInfo
|
||||
|
||||
private static HashMap<File, IndexInfo> indexInfos = new HashMap<File, IndexInfo>();
|
||||
|
||||
static
|
||||
{
|
||||
System.setProperty("disableLuceneLocks", "true");
|
||||
}
|
||||
|
||||
public static synchronized IndexInfo getIndexInfo(File file)
|
||||
{
|
||||
IndexInfo indexInfo = indexInfos.get(file);
|
||||
@@ -249,7 +255,6 @@ public class IndexInfo
|
||||
// a spanking new index
|
||||
version = 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Open the files and channels
|
||||
@@ -364,7 +369,7 @@ public class IndexInfo
|
||||
}
|
||||
for (String id : deletable)
|
||||
{
|
||||
IndexEntry entry = indexEntries.remove(id);
|
||||
indexEntries.remove(id);
|
||||
deleteQueue.add(id);
|
||||
}
|
||||
synchronized (cleaner)
|
||||
@@ -2008,7 +2013,6 @@ public class IndexInfo
|
||||
}
|
||||
}
|
||||
// Check it is not deleting
|
||||
boolean foundDelta;
|
||||
for (IndexEntry entry : indexEntries.values())
|
||||
{
|
||||
if (entry.getType() == IndexType.DELTA)
|
||||
@@ -2095,16 +2099,20 @@ public class IndexInfo
|
||||
{
|
||||
Searcher searcher = new IndexSearcher(reader);
|
||||
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
query.add(new TermQuery(new Term("ID", nodeRef.toString())), true, false);
|
||||
query.add(new TermQuery(new Term("ISNODE", "T")), false, false);
|
||||
TermQuery query = new TermQuery(new Term("ID", nodeRef.toString()));
|
||||
Hits hits = searcher.search(query);
|
||||
if (hits.length() > 0)
|
||||
{
|
||||
for (int i = 0; i < hits.length(); i++)
|
||||
{
|
||||
reader.delete(hits.id(i));
|
||||
invalidIndexes.add(key);
|
||||
Document doc = hits.doc(i);
|
||||
if (doc.getField("ISCONTAINER") == null)
|
||||
{
|
||||
reader.delete(hits.id(i));
|
||||
invalidIndexes.add(key);
|
||||
// There should only be one thing to delete
|
||||
// break;
|
||||
}
|
||||
}
|
||||
}
|
||||
searcher.close();
|
||||
@@ -2332,7 +2340,10 @@ public class IndexInfo
|
||||
{
|
||||
int count = 0;
|
||||
IndexReader[] readers = new IndexReader[toMerge.size() - 1];
|
||||
RAMDirectory ramDirectory = null;
|
||||
IndexWriter writer = null;
|
||||
long docCount = 0;
|
||||
File outputLocation = null;
|
||||
for (IndexEntry entry : toMerge.values())
|
||||
{
|
||||
File location = new File(indexDirectory, entry.getName());
|
||||
@@ -2348,10 +2359,20 @@ public class IndexInfo
|
||||
reader = IndexReader.open(emptyIndex);
|
||||
}
|
||||
readers[count++] = reader;
|
||||
docCount += entry.getDocumentCount();
|
||||
}
|
||||
else if (entry.getStatus() == TransactionStatus.MERGE_TARGET)
|
||||
{
|
||||
writer = new IndexWriter(location, new StandardAnalyzer(), true);
|
||||
outputLocation = location;
|
||||
if (docCount < 10000)
|
||||
{
|
||||
ramDirectory = new RAMDirectory();
|
||||
writer = new IndexWriter(ramDirectory, new StandardAnalyzer(), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer = new IndexWriter(location, new StandardAnalyzer(), true);
|
||||
}
|
||||
writer.setUseCompoundFile(true);
|
||||
writer.minMergeDocs = 1000;
|
||||
writer.mergeFactor = 5;
|
||||
@@ -2360,6 +2381,30 @@ public class IndexInfo
|
||||
}
|
||||
writer.addIndexes(readers);
|
||||
writer.close();
|
||||
|
||||
if (ramDirectory != null)
|
||||
{
|
||||
String[] files = ramDirectory.list();
|
||||
Directory directory = FSDirectory.getDirectory(outputLocation, true);
|
||||
for (int i = 0; i < files.length; i++)
|
||||
{
|
||||
// make place on ram disk
|
||||
OutputStream os = directory.createFile(files[i]);
|
||||
// read current file
|
||||
InputStream is = ramDirectory.openFile(files[i]);
|
||||
// and copy to ram disk
|
||||
int len = (int) is.length();
|
||||
byte[] buf = new byte[len];
|
||||
is.readBytes(buf, 0, len);
|
||||
os.writeBytes(buf, len);
|
||||
// graceful cleanup
|
||||
is.close();
|
||||
os.close();
|
||||
}
|
||||
ramDirectory.close();
|
||||
directory.close();
|
||||
}
|
||||
|
||||
for (IndexReader reader : readers)
|
||||
{
|
||||
reader.close();
|
||||
|
@@ -23,7 +23,6 @@ import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.TemplateException;
|
||||
import org.alfresco.service.cmr.repository.TemplateProcessor;
|
||||
import org.alfresco.util.ISO9075;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import freemarker.cache.MruCacheStorage;
|
||||
@@ -43,7 +42,10 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
private final static String MSG_ERROR_TEMPLATE_FAIL = "error_template_fail";
|
||||
private final static String MSG_ERROR_TEMPLATE_IO = "error_template_io";
|
||||
|
||||
private static Logger logger = Logger.getLogger(FreeMarkerProcessor.class);
|
||||
private static final Logger logger = Logger.getLogger(FreeMarkerProcessor.class);
|
||||
|
||||
/** Pseudo path to String based template */
|
||||
private static final String PATH = "string://fixed";
|
||||
|
||||
/** FreeMarker processor configuration */
|
||||
private Configuration config = null;
|
||||
@@ -75,7 +77,9 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The FreeMarker config instance for this processor
|
||||
* Get the FreeMarker configuration for this instance
|
||||
*
|
||||
* @return FreeMarker configuration
|
||||
*/
|
||||
private Configuration getConfig()
|
||||
{
|
||||
@@ -100,26 +104,30 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
return this.config;
|
||||
}
|
||||
|
||||
/**
|
||||
* FreeMarker configuration for loading the specified template directly from a String
|
||||
*
|
||||
* @param path Pseudo Path to the template
|
||||
* @param template Template content
|
||||
*
|
||||
* @return FreeMarker configuration
|
||||
*/
|
||||
private Configuration getStringConfig(String path, String template)
|
||||
{
|
||||
Configuration config = new Configuration();
|
||||
|
||||
Configuration config = new Configuration();
|
||||
|
||||
// setup template cache
|
||||
config.setCacheStorage(new MruCacheStorage(20, 0));
|
||||
|
||||
// use our custom loader to find templates on the ClassPath
|
||||
StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
|
||||
stringTemplateLoader.putTemplate(path, template);
|
||||
config.setTemplateLoader(stringTemplateLoader);
|
||||
|
||||
// use our custom object wrapper that can deal with QNameMap objects directly
|
||||
config.setObjectWrapper(new QNameAwareObjectWrapper());
|
||||
|
||||
// rethrow any exception so we can deal with them
|
||||
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||
|
||||
return config;
|
||||
// use our custom loader to load a template directly from a String
|
||||
StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
|
||||
stringTemplateLoader.putTemplate(path, template);
|
||||
config.setTemplateLoader(stringTemplateLoader);
|
||||
|
||||
// use our custom object wrapper that can deal with QNameMap objects directly
|
||||
config.setObjectWrapper(new QNameAwareObjectWrapper());
|
||||
|
||||
// rethrow any exception so we can deal with them
|
||||
config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,8 +150,12 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
|
||||
try
|
||||
{
|
||||
long startTime = 0;
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Executing template: " + template + " on model: " + model);
|
||||
{
|
||||
logger.debug("Executing template: " + template);// + " on model: " + model);
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
Template t = getConfig().getTemplate(template);
|
||||
if (t != null)
|
||||
@@ -162,6 +174,12 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
{
|
||||
throw new TemplateException(MSG_ERROR_NO_TEMPLATE, new Object[] {template});
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
long endTime = System.currentTimeMillis();
|
||||
logger.debug("Time to execute template: " + (endTime - startTime) + "ms");
|
||||
}
|
||||
}
|
||||
catch (IOException ioerr)
|
||||
{
|
||||
@@ -169,8 +187,9 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
}
|
||||
}
|
||||
|
||||
private static final String PATH = "string://fixed";
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.TemplateProcessor#processString(java.lang.String, java.lang.Object, java.io.Writer)
|
||||
*/
|
||||
public void processString(String template, Object model, Writer out)
|
||||
{
|
||||
if (template == null || template.length() == 0)
|
||||
@@ -188,8 +207,12 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
|
||||
try
|
||||
{
|
||||
long startTime = 0;
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Executing template: " + template + " on model: " + model);
|
||||
{
|
||||
logger.debug("Executing template: " + template);// + " on model: " + model);
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
Template t = getStringConfig(PATH, template).getTemplate(PATH);
|
||||
if (t != null)
|
||||
@@ -198,6 +221,12 @@ public class FreeMarkerProcessor implements TemplateProcessor
|
||||
{
|
||||
// perform the template processing against supplied data model
|
||||
t.process(model, out);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
long endTime = System.currentTimeMillis();
|
||||
logger.debug("Time to execute template: " + (endTime - startTime) + "ms");
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
|
@@ -127,6 +127,9 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplateString(java.lang.String, java.lang.String, java.lang.Object, java.io.Writer)
|
||||
*/
|
||||
public void processTemplateString(String engine, String template, Object model, Writer out)
|
||||
throws TemplateException
|
||||
{
|
||||
@@ -146,6 +149,9 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.TemplateService#processTemplateString(java.lang.String, java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public String processTemplateString(String engine, String template, Object model)
|
||||
throws TemplateException
|
||||
{
|
||||
@@ -154,7 +160,6 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the TemplateProcessor implementation for the named template engine
|
||||
*
|
||||
@@ -169,7 +174,7 @@ public class TemplateServiceImpl implements TemplateService, ApplicationContextA
|
||||
Map<String, TemplateProcessor> procMap = processors.get();
|
||||
if (procMap == null)
|
||||
{
|
||||
procMap = new HashMap<String, TemplateProcessor>(7, 1.0f);
|
||||
procMap = new HashMap<String, TemplateProcessor>(2, 1.0f);
|
||||
processors.set(procMap);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user