mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4162: added extra parentNodeRef parameter, checked writers and
readers individually for null and added unit tests for the changes
This commit is contained in:
@@ -597,6 +597,7 @@
|
|||||||
<property name="extendedSecurityService" ref="extendedSecurityService"/>
|
<property name="extendedSecurityService" ref="extendedSecurityService"/>
|
||||||
<property name="transactionService" ref="transactionService"/>
|
<property name="transactionService" ref="transactionService"/>
|
||||||
<property name="contentStreamer" ref="webscript.content.streamer" />
|
<property name="contentStreamer" ref="webscript.content.streamer" />
|
||||||
|
<property name="fileFolderService" ref="FileFolderService"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<!-- REST impl for GET Holds -->
|
<!-- REST impl for GET Holds -->
|
||||||
|
@@ -2,12 +2,13 @@
|
|||||||
<shortname>Removes dynamic authorities</shortname>
|
<shortname>Removes dynamic authorities</shortname>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
Removes dynamic authorities from in place records created in previous verssions.<br/>
|
Removes dynamic authorities from in place records created in previous verssions.<br/>
|
||||||
URL parameter batchsize is mandatory, and represents the number of records that are processed in one transaction.<br/>
|
URL parameter batchsize is mandatory, and represents the maximum number of records that can be processed in one transaction.<br/>
|
||||||
URL parameter maxProcessedRecords is optional, and represents the maximum number of records that will be processed in one request.<br/>
|
URL parameter maxProcessedRecords is optional, and represents the maximum number of records that will be processed in one request.<br/>
|
||||||
URL parameter export is optional, and if the it's value is true, will export the processed records into a csv file.<br/>
|
URL parameter export is optional, and if the it's value is true, will export the processed records into a csv file.<br/>
|
||||||
|
URL parameter parentNodeRef is optional, and represents the nodeRef of the folder that contains the records to be processed.<br/>
|
||||||
]]>
|
]]>
|
||||||
</description>
|
</description>
|
||||||
<url>/api/rm/rm-dynamicauthorities?batchsize={batchsize}&maxProcessedRecords={maxProcessedRecords?}&export={export?}</url>
|
<url>/api/rm/rm-dynamicauthorities?batchsize={batchsize}&maxProcessedRecords={maxProcessedRecords?}&export={export?}&parentNodeRef={parentNodeRef?}</url>
|
||||||
<format default="json">argument</format>
|
<format default="json">argument</format>
|
||||||
<authentication>admin</authentication>
|
<authentication>admin</authentication>
|
||||||
<transaction allow="readonly">required</transaction>
|
<transaction allow="readonly">required</transaction>
|
||||||
|
@@ -25,12 +25,13 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
@@ -43,121 +44,131 @@ import org.alfresco.repo.domain.patch.PatchDAO;
|
|||||||
import org.alfresco.repo.domain.qname.QNameDAO;
|
import org.alfresco.repo.domain.qname.QNameDAO;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.repo.web.scripts.content.ContentStreamer;
|
import org.alfresco.repo.web.scripts.content.ContentStreamer;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
import org.alfresco.util.TempFileProvider;
|
import org.alfresco.util.TempFileProvider;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
import org.springframework.extensions.webscripts.AbstractWebScript;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
import org.springframework.extensions.webscripts.Format;
|
import org.springframework.extensions.webscripts.Format;
|
||||||
import org.springframework.extensions.webscripts.Status;
|
import org.springframework.extensions.webscripts.Status;
|
||||||
import org.springframework.extensions.webscripts.WebScriptException;
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Webscript used for removing dynamic authorities from the records.
|
* Webscript used for removing dynamic authorities from the records.
|
||||||
*
|
*
|
||||||
* @author Silviu Dinuta
|
* @author Silviu Dinuta
|
||||||
* @since 2.3.0.7
|
* @since 2.3.0.7
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsManagementModel
|
public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsManagementModel
|
||||||
{
|
{
|
||||||
private static final String MESSAGE_PARAMETER_BATCHSIZE_GREATER_THAN_ZERO = "Parameter batchsize should be a number greater than 0.";
|
private static final String MESSAGE_PARAMETER_BATCHSIZE_GREATER_THAN_ZERO = "Parameter batchsize should be a number greater than 0.";
|
||||||
private static final String MESSAGE_PROCESSING_BEGIN = "Processing - BEGIN";
|
private static final String MESSAGE_PROCESSING_BEGIN = "Processing - BEGIN";
|
||||||
private static final String MESSAGE_PROCESSING_END = "Processing - END";
|
private static final String MESSAGE_PROCESSING_END = "Processing - END";
|
||||||
private static final String MESSAGE_PROCESSING_RECORD_END_TEMPLATE = "Processing record {0} - END";
|
private static final String MESSAGE_PROCESSING_RECORD_END_TEMPLATE = "Processing record {0} - END";
|
||||||
private static final String MESSAGE_PROCESSING_RECORD_BEGIN_TEMPLATE = "Processing record {0} - BEGIN";
|
private static final String MESSAGE_PROCESSING_RECORD_BEGIN_TEMPLATE = "Processing record {0} - BEGIN";
|
||||||
private static final String MESSAGE_BATCHSIZE_IS_INVALID = "Parameter batchsize is invalid.";
|
private static final String MESSAGE_BATCHSIZE_IS_INVALID = "Parameter batchsize is invalid.";
|
||||||
private static final String MESSAGE_BATCHSIZE_IS_MANDATORY = "Parameter batchsize is mandatory";
|
private static final String MESSAGE_BATCHSIZE_IS_MANDATORY = "Parameter batchsize is mandatory";
|
||||||
private static final String SUCCESS_STATUS = "success";
|
private static final String MESSAGE_NODE_REF_DOES_NOT_EXIST_TEMPLATE = "Parameter parentNodeRef = {0} does not exist.";
|
||||||
/**
|
private static final String SUCCESS_STATUS = "success";
|
||||||
* The logger
|
/**
|
||||||
*/
|
* The logger
|
||||||
private static Log logger = LogFactory.getLog(DynamicAuthoritiesGet.class);
|
*/
|
||||||
private static final String BATCH_SIZE = "batchsize";
|
private static Log logger = LogFactory.getLog(DynamicAuthoritiesGet.class);
|
||||||
private static final String TOTAL_NUMBER_TO_PROCESS = "maxProcessedRecords";
|
private static final String BATCH_SIZE = "batchsize";
|
||||||
|
private static final String TOTAL_NUMBER_TO_PROCESS = "maxProcessedRecords";
|
||||||
private static final String PARAM_EXPORT = "export";
|
private static final String PARAM_EXPORT = "export";
|
||||||
private static final String MODEL_STATUS = "responsestatus";
|
private static final String PARAM_PARENT_NODE_REF = "parentNodeRef";
|
||||||
private static final String MODEL_MESSAGE = "message";
|
private static final String MODEL_STATUS = "responsestatus";
|
||||||
private static final String MESSAGE_ALL_TEMPLATE = "Processed {0} records.";
|
private static final String MODEL_MESSAGE = "message";
|
||||||
private static final String MESSAGE_PARTIAL_TEMPLATE = "Processed first {0} records.";
|
private static final String MESSAGE_ALL_TEMPLATE = "Processed {0} records.";
|
||||||
private static final String MESSAGE_NO_RECORDS_TO_PROCESS = "There where no records to be processed.";
|
private static final String MESSAGE_PARTIAL_TEMPLATE = "Processed first {0} records.";
|
||||||
|
private static final String MESSAGE_NO_RECORDS_TO_PROCESS = "There where no records to be processed.";
|
||||||
|
|
||||||
/** services */
|
/** services */
|
||||||
private PatchDAO patchDAO;
|
private PatchDAO patchDAO;
|
||||||
private NodeDAO nodeDAO;
|
private NodeDAO nodeDAO;
|
||||||
private QNameDAO qnameDAO;
|
private QNameDAO qnameDAO;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
private ExtendedSecurityService extendedSecurityService;
|
private ExtendedSecurityService extendedSecurityService;
|
||||||
private TransactionService transactionService;
|
private TransactionService transactionService;
|
||||||
/** Content Streamer */
|
/** Content Streamer */
|
||||||
protected ContentStreamer contentStreamer;
|
protected ContentStreamer contentStreamer;
|
||||||
|
private FileFolderService fileFolderService;
|
||||||
|
|
||||||
/** service setters */
|
/** service setters */
|
||||||
public void setPatchDAO(PatchDAO patchDAO)
|
public void setPatchDAO(PatchDAO patchDAO)
|
||||||
{
|
{
|
||||||
this.patchDAO = patchDAO;
|
this.patchDAO = patchDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNodeDAO(NodeDAO nodeDAO)
|
public void setNodeDAO(NodeDAO nodeDAO)
|
||||||
{
|
{
|
||||||
this.nodeDAO = nodeDAO;
|
this.nodeDAO = nodeDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQnameDAO(QNameDAO qnameDAO)
|
public void setQnameDAO(QNameDAO qnameDAO)
|
||||||
{
|
{
|
||||||
this.qnameDAO = qnameDAO;
|
this.qnameDAO = qnameDAO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNodeService(NodeService nodeService)
|
public void setNodeService(NodeService nodeService)
|
||||||
{
|
{
|
||||||
this.nodeService = nodeService;
|
this.nodeService = nodeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermissionService(PermissionService permissionService)
|
public void setPermissionService(PermissionService permissionService)
|
||||||
{
|
{
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExtendedSecurityService(ExtendedSecurityService extendedSecurityService)
|
public void setExtendedSecurityService(ExtendedSecurityService extendedSecurityService)
|
||||||
{
|
{
|
||||||
this.extendedSecurityService = extendedSecurityService;
|
this.extendedSecurityService = extendedSecurityService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransactionService(TransactionService transactionService)
|
public void setTransactionService(TransactionService transactionService)
|
||||||
{
|
{
|
||||||
this.transactionService = transactionService;
|
this.transactionService = transactionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContentStreamer(ContentStreamer contentStreamer)
|
public void setContentStreamer(ContentStreamer contentStreamer)
|
||||||
{
|
{
|
||||||
this.contentStreamer = contentStreamer;
|
this.contentStreamer = contentStreamer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFileFolderService(FileFolderService fileFolderService)
|
||||||
|
{
|
||||||
|
this.fileFolderService = fileFolderService;
|
||||||
|
}
|
||||||
|
|
||||||
protected Map<String, Object> buildModel(WebScriptRequest req, WebScriptResponse res) throws IOException
|
protected Map<String, Object> buildModel(WebScriptRequest req, WebScriptResponse res) throws IOException
|
||||||
{
|
{
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
final Long batchSize = getBatchSizeParameter(req);
|
final Long batchSize = getBatchSizeParameter(req);
|
||||||
// get the max node id and the extended security aspect
|
// get the max node id and the extended security aspect
|
||||||
Long maxNodeId = patchDAO.getMaxAdmNodeID();
|
Long maxNodeId = patchDAO.getMaxAdmNodeID();
|
||||||
final Pair<Long, QName> recordAspectPair = qnameDAO.getQName(ASPECT_EXTENDED_SECURITY);
|
final Pair<Long, QName> recordAspectPair = qnameDAO.getQName(ASPECT_EXTENDED_SECURITY);
|
||||||
if(recordAspectPair == null)
|
if (recordAspectPair == null)
|
||||||
{
|
{
|
||||||
model.put(MODEL_STATUS, SUCCESS_STATUS);
|
model.put(MODEL_STATUS, SUCCESS_STATUS);
|
||||||
model.put(MODEL_MESSAGE, MESSAGE_NO_RECORDS_TO_PROCESS);
|
model.put(MODEL_MESSAGE, MESSAGE_NO_RECORDS_TO_PROCESS);
|
||||||
logger.info(MESSAGE_NO_RECORDS_TO_PROCESS);
|
logger.info(MESSAGE_NO_RECORDS_TO_PROCESS);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long totalNumberOfRecordsToProcess = getMaxToProccessParameter(req, batchSize);
|
Long totalNumberOfRecordsToProcess = getMaxToProccessParameter(req, batchSize);
|
||||||
|
|
||||||
boolean attach = getExportParameter(req);
|
boolean attach = getExportParameter(req);
|
||||||
@@ -168,8 +179,17 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
List<NodeRef> processedNodes = new ArrayList<NodeRef>();
|
List<NodeRef> processedNodes = new ArrayList<NodeRef>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
processedNodes = processNodes(batchSize, maxNodeId, recordAspectPair, totalNumberOfRecordsToProcess, out,
|
NodeRef parentNodeRef = getParentNodeRefParameter(req);
|
||||||
attach);
|
if (parentNodeRef != null)
|
||||||
|
{
|
||||||
|
processedNodes = processChildrenNodes(parentNodeRef, batchSize.intValue(), recordAspectPair,
|
||||||
|
totalNumberOfRecordsToProcess.intValue(), out, attach);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
processedNodes = processNodes(batchSize, maxNodeId, recordAspectPair, totalNumberOfRecordsToProcess,
|
||||||
|
out, attach);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -213,6 +233,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get export parameter from the request
|
* Get export parameter from the request
|
||||||
|
*
|
||||||
* @param req
|
* @param req
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@@ -241,19 +262,14 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
String mimetype = getContainer().getFormatRegistry().getMimeType(req.getAgent(), format);
|
String mimetype = getContainer().getFormatRegistry().getMimeType(req.getAgent(), format);
|
||||||
if (mimetype == null)
|
if (mimetype == null) { throw new WebScriptException(
|
||||||
{
|
"Web Script format '" + format + "' is not registered"); }
|
||||||
throw new WebScriptException("Web Script format '" + format + "' is not registered");
|
|
||||||
}
|
|
||||||
|
|
||||||
// construct model for script / template
|
// construct model for script / template
|
||||||
Status status = new Status();
|
Status status = new Status();
|
||||||
Cache cache = new Cache(getDescription().getRequiredCache());
|
Cache cache = new Cache(getDescription().getRequiredCache());
|
||||||
Map<String, Object> model = buildModel(req, res);
|
Map<String, Object> model = buildModel(req, res);
|
||||||
if (model == null)
|
if (model == null) { return; }
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
model.put("status", status);
|
model.put("status", status);
|
||||||
model.put("cache", cache);
|
model.put("cache", cache);
|
||||||
|
|
||||||
@@ -346,19 +362,19 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
protected Long getMaxToProccessParameter(WebScriptRequest req, final Long batchSize)
|
protected Long getMaxToProccessParameter(WebScriptRequest req, final Long batchSize)
|
||||||
{
|
{
|
||||||
String totalToBeProcessedRecordsStr = req.getParameter(TOTAL_NUMBER_TO_PROCESS);
|
String totalToBeProcessedRecordsStr = req.getParameter(TOTAL_NUMBER_TO_PROCESS);
|
||||||
//default total number of records to be processed to batch size value
|
// default total number of records to be processed to batch size value
|
||||||
Long totalNumberOfRecordsToProcess = batchSize;
|
Long totalNumberOfRecordsToProcess = batchSize;
|
||||||
if (StringUtils.isNotBlank(totalToBeProcessedRecordsStr))
|
if (StringUtils.isNotBlank(totalToBeProcessedRecordsStr))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
totalNumberOfRecordsToProcess = Long.parseLong(totalToBeProcessedRecordsStr);
|
totalNumberOfRecordsToProcess = Long.parseLong(totalToBeProcessedRecordsStr);
|
||||||
}
|
}
|
||||||
catch(NumberFormatException ex)
|
catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
//do nothing here, the value will remain 0L in this case
|
// do nothing here, the value will remain 0L in this case
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalNumberOfRecordsToProcess;
|
return totalNumberOfRecordsToProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +409,30 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get parentNodeRef parameter from the request
|
||||||
|
*
|
||||||
|
* @param req
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected NodeRef getParentNodeRefParameter(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
String parentNodeRefStr = req.getParameter(PARAM_PARENT_NODE_REF);
|
||||||
|
NodeRef parentNodeRef = null;
|
||||||
|
if (StringUtils.isNotBlank(parentNodeRefStr))
|
||||||
|
{
|
||||||
|
parentNodeRef = new NodeRef(parentNodeRefStr);
|
||||||
|
if(!nodeService.exists(parentNodeRef))
|
||||||
|
{
|
||||||
|
String message = MessageFormat.format(MESSAGE_NODE_REF_DOES_NOT_EXIST_TEMPLATE, parentNodeRef.toString());
|
||||||
|
logger.info(message);
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parentNodeRef;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process nodes all nodes or the maximum number of nodes specified by batchsize or totalNumberOfRecordsToProcess
|
* Process nodes all nodes or the maximum number of nodes specified by batchsize or totalNumberOfRecordsToProcess
|
||||||
* parameters
|
* parameters
|
||||||
@@ -407,81 +446,146 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
protected List<NodeRef> processNodes(final Long batchSize, Long maxNodeId, final Pair<Long, QName> recordAspectPair,
|
protected List<NodeRef> processNodes(final Long batchSize, Long maxNodeId, final Pair<Long, QName> recordAspectPair,
|
||||||
Long totalNumberOfRecordsToProcess, final BufferedWriter out, final boolean attach)
|
Long totalNumberOfRecordsToProcess, final BufferedWriter out, final boolean attach)
|
||||||
{
|
{
|
||||||
final Long maxRecordsToProcess = totalNumberOfRecordsToProcess;
|
final Long maxRecordsToProcess = totalNumberOfRecordsToProcess;
|
||||||
final List<NodeRef> processedNodes = new ArrayList<NodeRef>();
|
final List<NodeRef> processedNodes = new ArrayList<NodeRef>();
|
||||||
logger.info(MESSAGE_PROCESSING_BEGIN);
|
logger.info(MESSAGE_PROCESSING_BEGIN);
|
||||||
// by batch size
|
// by batch size
|
||||||
for (Long i = 0L; i < maxNodeId; i+=batchSize)
|
for (Long i = 0L; i < maxNodeId; i += batchSize)
|
||||||
{
|
{
|
||||||
if(maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
final Long currentIndex = i;
|
final Long currentIndex = i;
|
||||||
|
|
||||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
{
|
{
|
||||||
public Void execute() throws Throwable
|
public Void execute() throws Throwable
|
||||||
{
|
{
|
||||||
// get the nodes with the extended security aspect applied
|
// get the nodes with the extended security aspect applied
|
||||||
List<Long> nodeIds = patchDAO.getNodesByAspectQNameId(recordAspectPair.getFirst(), currentIndex,
|
List<Long> nodeIds = patchDAO.getNodesByAspectQNameId(recordAspectPair.getFirst(), currentIndex,
|
||||||
currentIndex + batchSize);
|
currentIndex + batchSize);
|
||||||
|
|
||||||
// process each one
|
// process each one
|
||||||
for (Long nodeId : nodeIds)
|
for (Long nodeId : nodeIds)
|
||||||
{
|
{
|
||||||
if(maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
NodeRef record = nodeDAO.getNodePair(nodeId).getSecond();
|
NodeRef record = nodeDAO.getNodePair(nodeId).getSecond();
|
||||||
String recordName = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
|
String recordName = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
|
||||||
logger.info(MessageFormat.format(MESSAGE_PROCESSING_RECORD_BEGIN_TEMPLATE, recordName));
|
logger.info(MessageFormat.format(MESSAGE_PROCESSING_RECORD_BEGIN_TEMPLATE, recordName));
|
||||||
processNode(record);
|
processNode(record);
|
||||||
logger.info(MessageFormat.format(MESSAGE_PROCESSING_RECORD_END_TEMPLATE, recordName));
|
logger.info(MessageFormat.format(MESSAGE_PROCESSING_RECORD_END_TEMPLATE, recordName));
|
||||||
processedNodes.add(record);
|
processedNodes.add(record);
|
||||||
if (attach)
|
if (attach)
|
||||||
{
|
{
|
||||||
out.write(recordName);
|
out.write(recordName);
|
||||||
out.write(",");
|
out.write(",");
|
||||||
out.write(record.toString());
|
out.write(record.toString());
|
||||||
out.write("\n");
|
out.write("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, false, // read only
|
}, false, // read only
|
||||||
true); // requires new
|
true); // requires new
|
||||||
}
|
}
|
||||||
logger.info(MESSAGE_PROCESSING_END);
|
logger.info(MESSAGE_PROCESSING_END);
|
||||||
return processedNodes;
|
return processedNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected List<NodeRef> processChildrenNodes(NodeRef parentNodeRef, final int batchSize,
|
||||||
* Process each node
|
final Pair<Long, QName> recordAspectPair, final int maxRecordsToProcess, final BufferedWriter out,
|
||||||
*
|
final boolean attach)
|
||||||
* @param nodeRef
|
{
|
||||||
*/
|
final List<NodeRef> processedNodes = new ArrayList<NodeRef>();
|
||||||
@SuppressWarnings({ "unchecked"})
|
final List<FileInfo> children = fileFolderService.search(parentNodeRef, "*", /*filesSearch*/true, /*folderSearch*/true, /*includeSubfolders*/true);
|
||||||
protected void processNode(NodeRef nodeRef)
|
logger.info(MESSAGE_PROCESSING_BEGIN);
|
||||||
{
|
// by batch size
|
||||||
// get the reader/writer data
|
for (int i = 0; i < children.size(); i += batchSize)
|
||||||
Map<String, Integer> readers = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_READERS);
|
{
|
||||||
Map<String, Integer> writers = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_WRITERS);
|
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
||||||
|
{
|
||||||
// remove extended security aspect
|
break;
|
||||||
nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
|
}
|
||||||
|
final int currentIndex = i;
|
||||||
// remove dynamic authority permissions
|
|
||||||
permissionService.clearPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER);
|
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
permissionService.clearPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER);
|
{
|
||||||
|
public Void execute() throws Throwable
|
||||||
// if record then ...
|
{
|
||||||
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD) && readers != null && writers != null)
|
List<FileInfo> nodes = children.subList(currentIndex, Math.min(currentIndex + batchSize, children.size()));
|
||||||
{
|
// process each one
|
||||||
// re-set extended security via API
|
for (FileInfo node : nodes)
|
||||||
extendedSecurityService.set(nodeRef, readers.keySet(), writers.keySet());
|
{
|
||||||
}
|
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
||||||
}
|
{
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
|
NodeRef record = node.getNodeRef();
|
||||||
|
if (nodeService.hasAspect(record, recordAspectPair.getSecond()))
|
||||||
|
{
|
||||||
|
String recordName = (String) nodeService.getProperty(record, ContentModel.PROP_NAME);
|
||||||
|
logger.info(MessageFormat.format(MESSAGE_PROCESSING_RECORD_BEGIN_TEMPLATE, recordName));
|
||||||
|
processNode(record);
|
||||||
|
logger.info(MessageFormat.format(MESSAGE_PROCESSING_RECORD_END_TEMPLATE, recordName));
|
||||||
|
processedNodes.add(record);
|
||||||
|
if (attach)
|
||||||
|
{
|
||||||
|
out.write(recordName);
|
||||||
|
out.write(",");
|
||||||
|
out.write(record.toString());
|
||||||
|
out.write("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, false, // read only
|
||||||
|
true); // requires new
|
||||||
|
}
|
||||||
|
logger.info(MESSAGE_PROCESSING_END);
|
||||||
|
return processedNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process each node
|
||||||
|
*
|
||||||
|
* @param nodeRef
|
||||||
|
*/
|
||||||
|
@SuppressWarnings({ "unchecked" })
|
||||||
|
protected void processNode(NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
// get the reader/writer data
|
||||||
|
Map<String, Integer> readers = (Map<String, Integer>) nodeService.getProperty(nodeRef, PROP_READERS);
|
||||||
|
Map<String, Integer> writers = (Map<String, Integer>) nodeService.getProperty(nodeRef, PROP_WRITERS);
|
||||||
|
|
||||||
|
// remove extended security aspect
|
||||||
|
nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
|
||||||
|
|
||||||
|
// remove dynamic authority permissions
|
||||||
|
permissionService.clearPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER);
|
||||||
|
permissionService.clearPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER);
|
||||||
|
|
||||||
|
// if record then ...
|
||||||
|
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD))
|
||||||
|
{
|
||||||
|
Set<String> readersKeySet = null;
|
||||||
|
if (readers != null)
|
||||||
|
{
|
||||||
|
readersKeySet = readers.keySet();
|
||||||
|
}
|
||||||
|
Set<String> writersKeySet = null;
|
||||||
|
if (writers != null)
|
||||||
|
{
|
||||||
|
writersKeySet = writers.keySet();
|
||||||
|
}
|
||||||
|
// re-set extended security via API
|
||||||
|
extendedSecurityService.set(nodeRef, readersKeySet, writersKeySet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user