mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,245 +1,245 @@
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.email.server.AliasableAspect;
|
||||
import org.alfresco.email.server.EmailServerModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.batch.BatchProcessWorkProvider;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Patch to duplicate the AliasableAspect into the attributes service.
|
||||
*
|
||||
* Inbound email.
|
||||
*
|
||||
* @author mrogers
|
||||
*
|
||||
*/
|
||||
public class AliasableAspectPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.emailAliasableAspect.result";
|
||||
|
||||
private AttributeService attributeService;
|
||||
private NodeDAO nodeDAO;
|
||||
private PatchDAO patchDAO;
|
||||
private QNameDAO qnameDAO;
|
||||
private BehaviourFilter behaviourFilter;
|
||||
|
||||
private final int batchThreads = 3;
|
||||
private final int batchSize = 40;
|
||||
private final long count = batchThreads * batchSize;
|
||||
|
||||
private static Log logger = LogFactory.getLog(AliasableAspectPatch.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
BatchProcessWorkProvider<NodeRef> workProvider = new BatchProcessWorkProvider<NodeRef>()
|
||||
{
|
||||
final List<NodeRef> result = new ArrayList<NodeRef>();
|
||||
|
||||
Long aspectQNameId = 0L;
|
||||
long maxNodeId = getPatchDAO().getMaxAdmNodeID();
|
||||
|
||||
long minSearchNodeId = 1;
|
||||
long maxSearchNodeId = count;
|
||||
|
||||
Pair<Long, QName> val = getQnameDAO().getQName(EmailServerModel.ASPECT_ALIASABLE );
|
||||
|
||||
public int getTotalEstimatedWorkSize()
|
||||
{
|
||||
return result.size();
|
||||
}
|
||||
|
||||
public Collection<NodeRef> getNextWork()
|
||||
{
|
||||
if(val != null)
|
||||
{
|
||||
Long aspectQNameId = val.getFirst();
|
||||
|
||||
result.clear();
|
||||
|
||||
while (result.isEmpty() && minSearchNodeId < maxNodeId)
|
||||
{
|
||||
List<Long> nodeids = getPatchDAO().getNodesByAspectQNameId(aspectQNameId, minSearchNodeId, maxSearchNodeId);
|
||||
|
||||
for(Long nodeid : nodeids)
|
||||
{
|
||||
NodeRef.Status status = getNodeDAO().getNodeIdStatus(nodeid);
|
||||
if(!status.isDeleted())
|
||||
{
|
||||
result.add(status.getNodeRef());
|
||||
}
|
||||
}
|
||||
minSearchNodeId = minSearchNodeId + count;
|
||||
maxSearchNodeId = maxSearchNodeId + count;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
// Configure the helper to run in read-only mode
|
||||
// MNT-10764
|
||||
txnHelper.setForceWritable(true);
|
||||
|
||||
BatchProcessor<NodeRef> batchProcessor = new BatchProcessor<NodeRef>(
|
||||
"AliasableAspectPatch",
|
||||
txnHelper,
|
||||
workProvider,
|
||||
batchThreads,
|
||||
batchSize,
|
||||
applicationEventPublisher,
|
||||
logger,
|
||||
1000);
|
||||
|
||||
BatchProcessWorker<NodeRef> worker = new BatchProcessWorker<NodeRef>()
|
||||
{
|
||||
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
|
||||
public String getIdentifier(NodeRef entry)
|
||||
{
|
||||
return entry.toString();
|
||||
}
|
||||
|
||||
public void process(NodeRef entry) throws Throwable
|
||||
{
|
||||
String alias = (String)nodeService.getProperty(entry, EmailServerModel.PROP_ALIAS);
|
||||
if(alias != null)
|
||||
{
|
||||
NodeRef existing = (NodeRef) getAttributeService().getAttribute(AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_1,
|
||||
AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_2,
|
||||
AliasableAspect.normaliseAlias(alias));
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
if(!existing.equals(entry))
|
||||
{
|
||||
// alias is used by more than one node - warning of some sort?
|
||||
if(logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Email alias is not unique, alias:" + alias + " nodeRef:" + entry);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
behaviourFilter.disableBehaviour(EmailServerModel.ASPECT_ALIASABLE);
|
||||
nodeService.removeAspect(entry, EmailServerModel.ASPECT_ALIASABLE);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
behaviourFilter.enableBehaviour(EmailServerModel.ASPECT_ALIASABLE);
|
||||
}
|
||||
}
|
||||
|
||||
// else do nothing - attribute already exists.
|
||||
}
|
||||
else
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("creating email alias attribute for " + alias);
|
||||
}
|
||||
getAttributeService().createAttribute(entry, AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_1, AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_2, AliasableAspect.normaliseAlias(alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Now set the batch processor to work
|
||||
|
||||
batchProcessor.process(worker, true);
|
||||
|
||||
return I18NUtil.getMessage(MSG_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
|
||||
public AttributeService getAttributeService()
|
||||
{
|
||||
return attributeService;
|
||||
}
|
||||
|
||||
|
||||
public void setNodeDAO(NodeDAO nodeDAO)
|
||||
{
|
||||
this.nodeDAO = nodeDAO;
|
||||
}
|
||||
|
||||
|
||||
public NodeDAO getNodeDAO()
|
||||
{
|
||||
return nodeDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
|
||||
public PatchDAO getPatchDAO()
|
||||
{
|
||||
return patchDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setQnameDAO(QNameDAO qnameDAO)
|
||||
{
|
||||
this.qnameDAO = qnameDAO;
|
||||
}
|
||||
|
||||
|
||||
public QNameDAO getQnameDAO()
|
||||
{
|
||||
return qnameDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||
{
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
|
||||
public BehaviourFilter getBehaviourFilter()
|
||||
{
|
||||
return behaviourFilter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.email.server.AliasableAspect;
|
||||
import org.alfresco.email.server.EmailServerModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.batch.BatchProcessWorkProvider;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorker;
|
||||
import org.alfresco.repo.domain.node.NodeDAO;
|
||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Patch to duplicate the AliasableAspect into the attributes service.
|
||||
*
|
||||
* Inbound email.
|
||||
*
|
||||
* @author mrogers
|
||||
*
|
||||
*/
|
||||
public class AliasableAspectPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SUCCESS = "patch.emailAliasableAspect.result";
|
||||
|
||||
private AttributeService attributeService;
|
||||
private NodeDAO nodeDAO;
|
||||
private PatchDAO patchDAO;
|
||||
private QNameDAO qnameDAO;
|
||||
private BehaviourFilter behaviourFilter;
|
||||
|
||||
private final int batchThreads = 3;
|
||||
private final int batchSize = 40;
|
||||
private final long count = batchThreads * batchSize;
|
||||
|
||||
private static Log logger = LogFactory.getLog(AliasableAspectPatch.class);
|
||||
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
BatchProcessWorkProvider<NodeRef> workProvider = new BatchProcessWorkProvider<NodeRef>()
|
||||
{
|
||||
final List<NodeRef> result = new ArrayList<NodeRef>();
|
||||
|
||||
Long aspectQNameId = 0L;
|
||||
long maxNodeId = getPatchDAO().getMaxAdmNodeID();
|
||||
|
||||
long minSearchNodeId = 1;
|
||||
long maxSearchNodeId = count;
|
||||
|
||||
Pair<Long, QName> val = getQnameDAO().getQName(EmailServerModel.ASPECT_ALIASABLE );
|
||||
|
||||
public int getTotalEstimatedWorkSize()
|
||||
{
|
||||
return result.size();
|
||||
}
|
||||
|
||||
public Collection<NodeRef> getNextWork()
|
||||
{
|
||||
if(val != null)
|
||||
{
|
||||
Long aspectQNameId = val.getFirst();
|
||||
|
||||
result.clear();
|
||||
|
||||
while (result.isEmpty() && minSearchNodeId < maxNodeId)
|
||||
{
|
||||
List<Long> nodeids = getPatchDAO().getNodesByAspectQNameId(aspectQNameId, minSearchNodeId, maxSearchNodeId);
|
||||
|
||||
for(Long nodeid : nodeids)
|
||||
{
|
||||
NodeRef.Status status = getNodeDAO().getNodeIdStatus(nodeid);
|
||||
if(!status.isDeleted())
|
||||
{
|
||||
result.add(status.getNodeRef());
|
||||
}
|
||||
}
|
||||
minSearchNodeId = minSearchNodeId + count;
|
||||
maxSearchNodeId = maxSearchNodeId + count;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
// Configure the helper to run in read-only mode
|
||||
// MNT-10764
|
||||
txnHelper.setForceWritable(true);
|
||||
|
||||
BatchProcessor<NodeRef> batchProcessor = new BatchProcessor<NodeRef>(
|
||||
"AliasableAspectPatch",
|
||||
txnHelper,
|
||||
workProvider,
|
||||
batchThreads,
|
||||
batchSize,
|
||||
applicationEventPublisher,
|
||||
logger,
|
||||
1000);
|
||||
|
||||
BatchProcessWorker<NodeRef> worker = new BatchProcessWorker<NodeRef>()
|
||||
{
|
||||
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
|
||||
public String getIdentifier(NodeRef entry)
|
||||
{
|
||||
return entry.toString();
|
||||
}
|
||||
|
||||
public void process(NodeRef entry) throws Throwable
|
||||
{
|
||||
String alias = (String)nodeService.getProperty(entry, EmailServerModel.PROP_ALIAS);
|
||||
if(alias != null)
|
||||
{
|
||||
NodeRef existing = (NodeRef) getAttributeService().getAttribute(AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_1,
|
||||
AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_2,
|
||||
AliasableAspect.normaliseAlias(alias));
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
if(!existing.equals(entry))
|
||||
{
|
||||
// alias is used by more than one node - warning of some sort?
|
||||
if(logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Email alias is not unique, alias:" + alias + " nodeRef:" + entry);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
behaviourFilter.disableBehaviour(EmailServerModel.ASPECT_ALIASABLE);
|
||||
nodeService.removeAspect(entry, EmailServerModel.ASPECT_ALIASABLE);
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
behaviourFilter.enableBehaviour(EmailServerModel.ASPECT_ALIASABLE);
|
||||
}
|
||||
}
|
||||
|
||||
// else do nothing - attribute already exists.
|
||||
}
|
||||
else
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("creating email alias attribute for " + alias);
|
||||
}
|
||||
getAttributeService().createAttribute(entry, AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_1, AliasableAspect.ALIASABLE_ATTRIBUTE_KEY_2, AliasableAspect.normaliseAlias(alias));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Now set the batch processor to work
|
||||
|
||||
batchProcessor.process(worker, true);
|
||||
|
||||
return I18NUtil.getMessage(MSG_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
|
||||
public AttributeService getAttributeService()
|
||||
{
|
||||
return attributeService;
|
||||
}
|
||||
|
||||
|
||||
public void setNodeDAO(NodeDAO nodeDAO)
|
||||
{
|
||||
this.nodeDAO = nodeDAO;
|
||||
}
|
||||
|
||||
|
||||
public NodeDAO getNodeDAO()
|
||||
{
|
||||
return nodeDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setPatchDAO(PatchDAO patchDAO)
|
||||
{
|
||||
this.patchDAO = patchDAO;
|
||||
}
|
||||
|
||||
|
||||
public PatchDAO getPatchDAO()
|
||||
{
|
||||
return patchDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setQnameDAO(QNameDAO qnameDAO)
|
||||
{
|
||||
this.qnameDAO = qnameDAO;
|
||||
}
|
||||
|
||||
|
||||
public QNameDAO getQnameDAO()
|
||||
{
|
||||
return qnameDAO;
|
||||
}
|
||||
|
||||
|
||||
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
|
||||
{
|
||||
this.behaviourFilter = behaviourFilter;
|
||||
}
|
||||
|
||||
|
||||
public BehaviourFilter getBehaviourFilter()
|
||||
{
|
||||
return behaviourFilter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,130 +1,130 @@
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.workflow.BPMEngineRegistry;
|
||||
import org.alfresco.repo.workflow.WorkflowDeployer;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Generic patch that re-deploys a workflow definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class GenericWorkflowPatch extends AbstractPatch implements ApplicationContextAware
|
||||
{
|
||||
private static final String MSG_DEPLOYED = "patch.genericWorkflow.result.deployed";
|
||||
private static final String MSG_UNDEPLOYED = "patch.genericWorkflow.result.undeployed";
|
||||
private static final String ERR_PROPERTY_REQUIRED = "patch.genericWorkflow.property_required";
|
||||
private static final String MSG_ERROR_ENGINE_DEACTIVATED = "patch.genericWorkflow.error_engine_deactivated";
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private List<Properties> workflowDefinitions;
|
||||
private List<String> undeployWorkflowNames;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException
|
||||
{
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Workflow Definitions
|
||||
*
|
||||
* @param workflowDefinitions List<Properties>
|
||||
*/
|
||||
public void setWorkflowDefinitions(List<Properties> workflowDefinitions)
|
||||
{
|
||||
this.workflowDefinitions = workflowDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Workflow Names to be undeployed
|
||||
*
|
||||
* @param undeployWorkflowNames list with names
|
||||
*/
|
||||
public void setUndeployWorkflowNames(List<String> undeployWorkflowNames)
|
||||
{
|
||||
this.undeployWorkflowNames = undeployWorkflowNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
if ( (workflowDefinitions == null) && (undeployWorkflowNames == null) )
|
||||
{
|
||||
throw new PatchException(ERR_PROPERTY_REQUIRED, "workflowDefinitions", "undeployWorkflowNames", this);
|
||||
}
|
||||
super.checkProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
WorkflowDeployer deployer = (WorkflowDeployer)applicationContext.getBean("workflowPatchDeployer");
|
||||
WorkflowAdminService workflowAdminService = (WorkflowAdminService)applicationContext.getBean("workflowAdminService");
|
||||
|
||||
if(workflowDefinitions != null)
|
||||
{
|
||||
for (Properties props : workflowDefinitions)
|
||||
{
|
||||
props.put(WorkflowDeployer.REDEPLOY, "true");
|
||||
}
|
||||
deployer.setWorkflowDefinitions(workflowDefinitions);
|
||||
deployer.init();
|
||||
}
|
||||
|
||||
int undeployed = 0;
|
||||
StringBuilder errorMessages = new StringBuilder();
|
||||
if(undeployWorkflowNames != null)
|
||||
{
|
||||
List<String> undeployableWorkflows = new ArrayList<String>(undeployWorkflowNames);
|
||||
for(String workflowName : undeployWorkflowNames)
|
||||
{
|
||||
String engineId = BPMEngineRegistry.getEngineId(workflowName);
|
||||
if (workflowAdminService.isEngineEnabled(engineId))
|
||||
{
|
||||
undeployableWorkflows.add(workflowName);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessages.append(I18NUtil.getMessage(MSG_ERROR_ENGINE_DEACTIVATED, workflowName, engineId));
|
||||
}
|
||||
}
|
||||
undeployed = deployer.undeploy(undeployableWorkflows);
|
||||
}
|
||||
|
||||
// done
|
||||
StringBuilder msg = new StringBuilder();
|
||||
if(workflowDefinitions != null)
|
||||
{
|
||||
msg.append(I18NUtil.getMessage(MSG_DEPLOYED, workflowDefinitions.size()));
|
||||
}
|
||||
if(undeployWorkflowNames != null)
|
||||
{
|
||||
if(msg.length() > 0)
|
||||
{
|
||||
msg.append(' ');
|
||||
}
|
||||
msg.append(I18NUtil.getMessage(MSG_UNDEPLOYED, undeployed));
|
||||
}
|
||||
if(errorMessages.length() > 0)
|
||||
{
|
||||
msg.append(errorMessages);
|
||||
}
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.workflow.BPMEngineRegistry;
|
||||
import org.alfresco.repo.workflow.WorkflowDeployer;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.workflow.WorkflowAdminService;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Generic patch that re-deploys a workflow definition
|
||||
*
|
||||
* @author David Caruana
|
||||
*/
|
||||
public class GenericWorkflowPatch extends AbstractPatch implements ApplicationContextAware
|
||||
{
|
||||
private static final String MSG_DEPLOYED = "patch.genericWorkflow.result.deployed";
|
||||
private static final String MSG_UNDEPLOYED = "patch.genericWorkflow.result.undeployed";
|
||||
private static final String ERR_PROPERTY_REQUIRED = "patch.genericWorkflow.property_required";
|
||||
private static final String MSG_ERROR_ENGINE_DEACTIVATED = "patch.genericWorkflow.error_engine_deactivated";
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private List<Properties> workflowDefinitions;
|
||||
private List<String> undeployWorkflowNames;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
throws BeansException
|
||||
{
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Workflow Definitions
|
||||
*
|
||||
* @param workflowDefinitions List<Properties>
|
||||
*/
|
||||
public void setWorkflowDefinitions(List<Properties> workflowDefinitions)
|
||||
{
|
||||
this.workflowDefinitions = workflowDefinitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Workflow Names to be undeployed
|
||||
*
|
||||
* @param undeployWorkflowNames list with names
|
||||
*/
|
||||
public void setUndeployWorkflowNames(List<String> undeployWorkflowNames)
|
||||
{
|
||||
this.undeployWorkflowNames = undeployWorkflowNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkProperties()
|
||||
{
|
||||
if ( (workflowDefinitions == null) && (undeployWorkflowNames == null) )
|
||||
{
|
||||
throw new PatchException(ERR_PROPERTY_REQUIRED, "workflowDefinitions", "undeployWorkflowNames", this);
|
||||
}
|
||||
super.checkProperties();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
WorkflowDeployer deployer = (WorkflowDeployer)applicationContext.getBean("workflowPatchDeployer");
|
||||
WorkflowAdminService workflowAdminService = (WorkflowAdminService)applicationContext.getBean("workflowAdminService");
|
||||
|
||||
if(workflowDefinitions != null)
|
||||
{
|
||||
for (Properties props : workflowDefinitions)
|
||||
{
|
||||
props.put(WorkflowDeployer.REDEPLOY, "true");
|
||||
}
|
||||
deployer.setWorkflowDefinitions(workflowDefinitions);
|
||||
deployer.init();
|
||||
}
|
||||
|
||||
int undeployed = 0;
|
||||
StringBuilder errorMessages = new StringBuilder();
|
||||
if(undeployWorkflowNames != null)
|
||||
{
|
||||
List<String> undeployableWorkflows = new ArrayList<String>(undeployWorkflowNames);
|
||||
for(String workflowName : undeployWorkflowNames)
|
||||
{
|
||||
String engineId = BPMEngineRegistry.getEngineId(workflowName);
|
||||
if (workflowAdminService.isEngineEnabled(engineId))
|
||||
{
|
||||
undeployableWorkflows.add(workflowName);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorMessages.append(I18NUtil.getMessage(MSG_ERROR_ENGINE_DEACTIVATED, workflowName, engineId));
|
||||
}
|
||||
}
|
||||
undeployed = deployer.undeploy(undeployableWorkflows);
|
||||
}
|
||||
|
||||
// done
|
||||
StringBuilder msg = new StringBuilder();
|
||||
if(workflowDefinitions != null)
|
||||
{
|
||||
msg.append(I18NUtil.getMessage(MSG_DEPLOYED, workflowDefinitions.size()));
|
||||
}
|
||||
if(undeployWorkflowNames != null)
|
||||
{
|
||||
if(msg.length() > 0)
|
||||
{
|
||||
msg.append(' ');
|
||||
}
|
||||
msg.append(I18NUtil.getMessage(MSG_UNDEPLOYED, undeployed));
|
||||
}
|
||||
if(errorMessages.length() > 0)
|
||||
{
|
||||
msg.append(errorMessages);
|
||||
}
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,65 +1,65 @@
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.model.filefolder.HiddenAspect;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
public class SWSDPPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SITE_PATCHED = "patch.swsdpPatch.success";
|
||||
private static final String MSG_SKIPPED = "patch.swsdpPatch.skipped";
|
||||
private static final String MSG_MISSING_SURFCONFIG = "patch.swsdpPatch.missingSurfConfig";
|
||||
|
||||
private SiteService siteService;
|
||||
private HiddenAspect hiddenAspect;
|
||||
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setHiddenAspect(HiddenAspect hiddenAspect)
|
||||
{
|
||||
this.hiddenAspect = hiddenAspect;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
SiteInfo siteInfo = siteService.getSite("swsdp");
|
||||
if(siteInfo != null)
|
||||
{
|
||||
NodeRef nodeRef = siteInfo.getNodeRef();
|
||||
NodeRef surfConfigNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, "surf-config");
|
||||
if(surfConfigNodeRef == null)
|
||||
{
|
||||
return I18NUtil.getMessage(MSG_MISSING_SURFCONFIG);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(ChildAssociationRef childRef : nodeService.getChildAssocs(surfConfigNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL))
|
||||
{
|
||||
hiddenAspect.showNode(childRef.getChildRef(), true);
|
||||
}
|
||||
}
|
||||
|
||||
return I18NUtil.getMessage(MSG_SITE_PATCHED);
|
||||
}
|
||||
else
|
||||
{
|
||||
return I18NUtil.getMessage(MSG_SKIPPED);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.model.filefolder.HiddenAspect;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
public class SWSDPPatch extends AbstractPatch
|
||||
{
|
||||
private static final String MSG_SITE_PATCHED = "patch.swsdpPatch.success";
|
||||
private static final String MSG_SKIPPED = "patch.swsdpPatch.skipped";
|
||||
private static final String MSG_MISSING_SURFCONFIG = "patch.swsdpPatch.missingSurfConfig";
|
||||
|
||||
private SiteService siteService;
|
||||
private HiddenAspect hiddenAspect;
|
||||
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setHiddenAspect(HiddenAspect hiddenAspect)
|
||||
{
|
||||
this.hiddenAspect = hiddenAspect;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
SiteInfo siteInfo = siteService.getSite("swsdp");
|
||||
if(siteInfo != null)
|
||||
{
|
||||
NodeRef nodeRef = siteInfo.getNodeRef();
|
||||
NodeRef surfConfigNodeRef = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, "surf-config");
|
||||
if(surfConfigNodeRef == null)
|
||||
{
|
||||
return I18NUtil.getMessage(MSG_MISSING_SURFCONFIG);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(ChildAssociationRef childRef : nodeService.getChildAssocs(surfConfigNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL))
|
||||
{
|
||||
hiddenAspect.showNode(childRef.getChildRef(), true);
|
||||
}
|
||||
}
|
||||
|
||||
return I18NUtil.getMessage(MSG_SITE_PATCHED);
|
||||
}
|
||||
else
|
||||
{
|
||||
return I18NUtil.getMessage(MSG_SKIPPED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,235 +1,235 @@
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* The SharedFolderPatch is a Generic Bootstrap Patch with the extra ability to
|
||||
* rename an existing folder that is in the way (in a different namespace).
|
||||
* <p>
|
||||
* The first use-case is when there is a child called cm:shared and we want to patch a folder with app:shared
|
||||
*
|
||||
* @author mrogers
|
||||
*/
|
||||
public class SharedFolderPatch extends GenericBootstrapPatch
|
||||
{
|
||||
private JobLockService jobLockService;
|
||||
|
||||
private long LOCK_TIME_TO_LIVE=10000;
|
||||
private long LOCK_REFRESH_TIME=5000;
|
||||
|
||||
private String renamePath;
|
||||
|
||||
private Log logger = LogFactory.getLog(SharedFolderPatch.class);
|
||||
|
||||
private static final String MSG_RENAMED = "patch.sharedFolder.result.renamed";
|
||||
|
||||
/**
|
||||
* Run the Shared Folder Patch asynchronously after bootstrap.
|
||||
*/
|
||||
public void executeAsync()
|
||||
{
|
||||
// Lock the push
|
||||
QName lockQName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "patch.sharedFolder");
|
||||
String lockToken = jobLockService.getLock(lockQName, LOCK_TIME_TO_LIVE, 0, 1);
|
||||
SharedFolderPatchCallback callback = new SharedFolderPatchCallback();
|
||||
jobLockService.refreshLock(lockToken, lockQName, LOCK_REFRESH_TIME, callback);
|
||||
|
||||
try
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("SharedFolderPatch: job lock held");
|
||||
}
|
||||
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
applyAsync();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("PUSH: job finished");
|
||||
}
|
||||
|
||||
// Release the locks on the job and stop refreshing
|
||||
callback.isActive = false;
|
||||
jobLockService.releaseLock(lockToken, lockQName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
StoreRef storeRef = importerBootstrap.getStoreRef();
|
||||
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
if (getRenamePath() != null)
|
||||
{
|
||||
List<NodeRef> results = searchService.selectNodes(
|
||||
rootNodeRef,
|
||||
getRenamePath(),
|
||||
null,
|
||||
namespaceService,
|
||||
false);
|
||||
|
||||
if (results.size() > 1)
|
||||
{
|
||||
throw new PatchException(ERR_MULTIPLE_FOUND, renamePath);
|
||||
}
|
||||
else if (results.size() == 1)
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("There is an existing node in the way path:" + getRenamePath());
|
||||
}
|
||||
// A node already exists that we must rename.
|
||||
NodeRef existingNodeRef = results.get(0);
|
||||
|
||||
// get the path of the parent node e.g. company_home
|
||||
LinkedList<String> folderElements = new LinkedList<String>(Arrays.asList(getRenamePath().split("/")));
|
||||
folderElements.removeLast();
|
||||
|
||||
StringBuffer parentPath = new StringBuffer();
|
||||
|
||||
for(String folder : folderElements)
|
||||
{
|
||||
parentPath.append("/");
|
||||
parentPath.append(folder);
|
||||
}
|
||||
|
||||
List<NodeRef> parentResults = searchService.selectNodes(
|
||||
rootNodeRef,
|
||||
parentPath.toString(),
|
||||
null,
|
||||
namespaceService,
|
||||
false);
|
||||
|
||||
if(parentResults.size()==1)
|
||||
{
|
||||
|
||||
NodeRef parentNodeRef = parentResults.get(0);
|
||||
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Found the parent node - doing a move parentNodeRef:" + parentNodeRef);
|
||||
}
|
||||
|
||||
// rename the existing node
|
||||
nodeService.moveNode(existingNodeRef, parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName( NamespaceService.APP_MODEL_1_0_URI, "shared"));
|
||||
return I18NUtil.getMessage(MSG_RENAMED, renamePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Something has gone horribly wrong if we get here - we have multiple parents, or none despite finding the node earlier
|
||||
throw new PatchException(ERR_MULTIPLE_FOUND, parentPath.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Else run the normal GenericBootstrapPatch implementation
|
||||
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Node does not already exist, Running the Generic Bootstrap Patch");
|
||||
}
|
||||
return super.applyInternal();
|
||||
}
|
||||
|
||||
public void setRenamePath(String renamePath)
|
||||
{
|
||||
this.renamePath = renamePath;
|
||||
}
|
||||
|
||||
public String getRenamePath()
|
||||
{
|
||||
return renamePath;
|
||||
}
|
||||
|
||||
public void setJobLockService(JobLockService jobLockService)
|
||||
{
|
||||
this.jobLockService = jobLockService;
|
||||
}
|
||||
|
||||
public JobLockService getJobLockService()
|
||||
{
|
||||
return jobLockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Job to initiate the {@link SharedFolderPatch} if it has been deferred
|
||||
*
|
||||
* @author Mark Rogers
|
||||
* @since 4.2
|
||||
*/
|
||||
public static class SharedFolderPatchJob implements Job
|
||||
{
|
||||
public SharedFolderPatchJob()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the cleaner to do its work
|
||||
*/
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||
{
|
||||
JobDataMap jobData = context.getJobDetail().getJobDataMap();
|
||||
// extract the content cleaner to use
|
||||
Object sharedFolderPatchObj = jobData.get("sharedFolderPatch");
|
||||
if (sharedFolderPatchObj == null || !(sharedFolderPatchObj instanceof SharedFolderPatch))
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"'sharedFolderPatch' data must contain valid 'SharedFolderPatch' reference");
|
||||
}
|
||||
|
||||
// Job Lock Here - should probably move into the patch service at some time.
|
||||
SharedFolderPatch sharedFolderPatch = (SharedFolderPatch) sharedFolderPatchObj;
|
||||
sharedFolderPatch.executeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private class SharedFolderPatchCallback implements JobLockRefreshCallback
|
||||
{
|
||||
public boolean isActive = true;
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockReleased()
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("lock released");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.lock.JobLockService;
|
||||
import org.alfresco.repo.lock.JobLockService.JobLockRefreshCallback;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.admin.PatchException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* The SharedFolderPatch is a Generic Bootstrap Patch with the extra ability to
|
||||
* rename an existing folder that is in the way (in a different namespace).
|
||||
* <p>
|
||||
* The first use-case is when there is a child called cm:shared and we want to patch a folder with app:shared
|
||||
*
|
||||
* @author mrogers
|
||||
*/
|
||||
public class SharedFolderPatch extends GenericBootstrapPatch
|
||||
{
|
||||
private JobLockService jobLockService;
|
||||
|
||||
private long LOCK_TIME_TO_LIVE=10000;
|
||||
private long LOCK_REFRESH_TIME=5000;
|
||||
|
||||
private String renamePath;
|
||||
|
||||
private Log logger = LogFactory.getLog(SharedFolderPatch.class);
|
||||
|
||||
private static final String MSG_RENAMED = "patch.sharedFolder.result.renamed";
|
||||
|
||||
/**
|
||||
* Run the Shared Folder Patch asynchronously after bootstrap.
|
||||
*/
|
||||
public void executeAsync()
|
||||
{
|
||||
// Lock the push
|
||||
QName lockQName = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "patch.sharedFolder");
|
||||
String lockToken = jobLockService.getLock(lockQName, LOCK_TIME_TO_LIVE, 0, 1);
|
||||
SharedFolderPatchCallback callback = new SharedFolderPatchCallback();
|
||||
jobLockService.refreshLock(lockToken, lockQName, LOCK_REFRESH_TIME, callback);
|
||||
|
||||
try
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("SharedFolderPatch: job lock held");
|
||||
}
|
||||
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
applyAsync();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("PUSH: job finished");
|
||||
}
|
||||
|
||||
// Release the locks on the job and stop refreshing
|
||||
callback.isActive = false;
|
||||
jobLockService.releaseLock(lockToken, lockQName);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
StoreRef storeRef = importerBootstrap.getStoreRef();
|
||||
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
|
||||
if (getRenamePath() != null)
|
||||
{
|
||||
List<NodeRef> results = searchService.selectNodes(
|
||||
rootNodeRef,
|
||||
getRenamePath(),
|
||||
null,
|
||||
namespaceService,
|
||||
false);
|
||||
|
||||
if (results.size() > 1)
|
||||
{
|
||||
throw new PatchException(ERR_MULTIPLE_FOUND, renamePath);
|
||||
}
|
||||
else if (results.size() == 1)
|
||||
{
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("There is an existing node in the way path:" + getRenamePath());
|
||||
}
|
||||
// A node already exists that we must rename.
|
||||
NodeRef existingNodeRef = results.get(0);
|
||||
|
||||
// get the path of the parent node e.g. company_home
|
||||
LinkedList<String> folderElements = new LinkedList<String>(Arrays.asList(getRenamePath().split("/")));
|
||||
folderElements.removeLast();
|
||||
|
||||
StringBuffer parentPath = new StringBuffer();
|
||||
|
||||
for(String folder : folderElements)
|
||||
{
|
||||
parentPath.append("/");
|
||||
parentPath.append(folder);
|
||||
}
|
||||
|
||||
List<NodeRef> parentResults = searchService.selectNodes(
|
||||
rootNodeRef,
|
||||
parentPath.toString(),
|
||||
null,
|
||||
namespaceService,
|
||||
false);
|
||||
|
||||
if(parentResults.size()==1)
|
||||
{
|
||||
|
||||
NodeRef parentNodeRef = parentResults.get(0);
|
||||
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Found the parent node - doing a move parentNodeRef:" + parentNodeRef);
|
||||
}
|
||||
|
||||
// rename the existing node
|
||||
nodeService.moveNode(existingNodeRef, parentNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName( NamespaceService.APP_MODEL_1_0_URI, "shared"));
|
||||
return I18NUtil.getMessage(MSG_RENAMED, renamePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Something has gone horribly wrong if we get here - we have multiple parents, or none despite finding the node earlier
|
||||
throw new PatchException(ERR_MULTIPLE_FOUND, parentPath.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Else run the normal GenericBootstrapPatch implementation
|
||||
|
||||
if(logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Node does not already exist, Running the Generic Bootstrap Patch");
|
||||
}
|
||||
return super.applyInternal();
|
||||
}
|
||||
|
||||
public void setRenamePath(String renamePath)
|
||||
{
|
||||
this.renamePath = renamePath;
|
||||
}
|
||||
|
||||
public String getRenamePath()
|
||||
{
|
||||
return renamePath;
|
||||
}
|
||||
|
||||
public void setJobLockService(JobLockService jobLockService)
|
||||
{
|
||||
this.jobLockService = jobLockService;
|
||||
}
|
||||
|
||||
public JobLockService getJobLockService()
|
||||
{
|
||||
return jobLockService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Job to initiate the {@link SharedFolderPatch} if it has been deferred
|
||||
*
|
||||
* @author Mark Rogers
|
||||
* @since 4.2
|
||||
*/
|
||||
public static class SharedFolderPatchJob implements Job
|
||||
{
|
||||
public SharedFolderPatchJob()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the cleaner to do its work
|
||||
*/
|
||||
public void execute(JobExecutionContext context) throws JobExecutionException
|
||||
{
|
||||
JobDataMap jobData = context.getJobDetail().getJobDataMap();
|
||||
// extract the content cleaner to use
|
||||
Object sharedFolderPatchObj = jobData.get("sharedFolderPatch");
|
||||
if (sharedFolderPatchObj == null || !(sharedFolderPatchObj instanceof SharedFolderPatch))
|
||||
{
|
||||
throw new AlfrescoRuntimeException(
|
||||
"'sharedFolderPatch' data must contain valid 'SharedFolderPatch' reference");
|
||||
}
|
||||
|
||||
// Job Lock Here - should probably move into the patch service at some time.
|
||||
SharedFolderPatch sharedFolderPatch = (SharedFolderPatch) sharedFolderPatchObj;
|
||||
sharedFolderPatch.executeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
private class SharedFolderPatchCallback implements JobLockRefreshCallback
|
||||
{
|
||||
public boolean isActive = true;
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockReleased()
|
||||
{
|
||||
if (logger.isTraceEnabled())
|
||||
{
|
||||
logger.trace("lock released");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user