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>
|
||||||
|
@@ -30,6 +30,7 @@ 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;
|
||||||
|
|
||||||
@@ -43,6 +44,8 @@ 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.model.FileFolderService;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
@@ -77,6 +80,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
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 MESSAGE_NODE_REF_DOES_NOT_EXIST_TEMPLATE = "Parameter parentNodeRef = {0} does not exist.";
|
||||||
private static final String SUCCESS_STATUS = "success";
|
private static final String SUCCESS_STATUS = "success";
|
||||||
/**
|
/**
|
||||||
* The logger
|
* The logger
|
||||||
@@ -85,13 +89,13 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
private static final String BATCH_SIZE = "batchsize";
|
private static final String BATCH_SIZE = "batchsize";
|
||||||
private static final String TOTAL_NUMBER_TO_PROCESS = "maxProcessedRecords";
|
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 PARAM_PARENT_NODE_REF = "parentNodeRef";
|
||||||
private static final String MODEL_STATUS = "responsestatus";
|
private static final String MODEL_STATUS = "responsestatus";
|
||||||
private static final String MODEL_MESSAGE = "message";
|
private static final String MODEL_MESSAGE = "message";
|
||||||
private static final String MESSAGE_ALL_TEMPLATE = "Processed {0} records.";
|
private static final String MESSAGE_ALL_TEMPLATE = "Processed {0} records.";
|
||||||
private static final String MESSAGE_PARTIAL_TEMPLATE = "Processed first {0} records.";
|
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.";
|
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;
|
||||||
@@ -102,6 +106,8 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
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)
|
||||||
{
|
{
|
||||||
@@ -119,29 +125,34 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
@@ -150,7 +161,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
// 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);
|
||||||
@@ -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,7 +362,7 @@ 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))
|
||||||
{
|
{
|
||||||
@@ -354,9 +370,9 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
{
|
{
|
||||||
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;
|
||||||
@@ -394,6 +410,29 @@ 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
|
||||||
@@ -411,9 +450,9 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
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;
|
||||||
}
|
}
|
||||||
@@ -430,7 +469,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
// 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;
|
||||||
}
|
}
|
||||||
@@ -446,29 +485,84 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
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,
|
||||||
|
final Pair<Long, QName> recordAspectPair, final int maxRecordsToProcess, final BufferedWriter out,
|
||||||
|
final boolean attach)
|
||||||
|
{
|
||||||
|
final List<NodeRef> processedNodes = new ArrayList<NodeRef>();
|
||||||
|
final List<FileInfo> children = fileFolderService.search(parentNodeRef, "*", /*filesSearch*/true, /*folderSearch*/true, /*includeSubfolders*/true);
|
||||||
|
logger.info(MESSAGE_PROCESSING_BEGIN);
|
||||||
|
// by batch size
|
||||||
|
for (int i = 0; i < children.size(); i += batchSize)
|
||||||
|
{
|
||||||
|
if (maxRecordsToProcess != 0 && processedNodes.size() >= maxRecordsToProcess)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
final int currentIndex = i;
|
||||||
|
|
||||||
|
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||||
|
{
|
||||||
|
public Void execute() throws Throwable
|
||||||
|
{
|
||||||
|
List<FileInfo> nodes = children.subList(currentIndex, Math.min(currentIndex + batchSize, children.size()));
|
||||||
|
// process each one
|
||||||
|
for (FileInfo node : nodes)
|
||||||
|
{
|
||||||
|
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
|
* Process each node
|
||||||
*
|
*
|
||||||
* @param nodeRef
|
* @param nodeRef
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked"})
|
@SuppressWarnings({ "unchecked" })
|
||||||
protected void processNode(NodeRef nodeRef)
|
protected void processNode(NodeRef nodeRef)
|
||||||
{
|
{
|
||||||
// get the reader/writer data
|
// get the reader/writer data
|
||||||
Map<String, Integer> readers = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_READERS);
|
Map<String, Integer> readers = (Map<String, Integer>) nodeService.getProperty(nodeRef, PROP_READERS);
|
||||||
Map<String, Integer> writers = (Map<String, Integer>)nodeService.getProperty(nodeRef, PROP_WRITERS);
|
Map<String, Integer> writers = (Map<String, Integer>) nodeService.getProperty(nodeRef, PROP_WRITERS);
|
||||||
|
|
||||||
// remove extended security aspect
|
// remove extended security aspect
|
||||||
nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
|
nodeService.removeAspect(nodeRef, ASPECT_EXTENDED_SECURITY);
|
||||||
@@ -478,10 +572,20 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
permissionService.clearPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER);
|
permissionService.clearPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER);
|
||||||
|
|
||||||
// if record then ...
|
// if record then ...
|
||||||
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD) && readers != null && writers != null)
|
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
|
// re-set extended security via API
|
||||||
extendedSecurityService.set(nodeRef, readers.keySet(), writers.keySet());
|
extendedSecurityService.set(nodeRef, readersKeySet, writersKeySet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,12 +23,14 @@ import static java.util.Collections.emptyMap;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyBoolean;
|
import static org.mockito.Matchers.anyBoolean;
|
||||||
import static org.mockito.Matchers.anyLong;
|
import static org.mockito.Matchers.anyLong;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -36,6 +38,7 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -59,6 +62,8 @@ import org.alfresco.repo.domain.qname.QNameDAO;
|
|||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
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.model.FileFolderService;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
@@ -111,6 +116,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
private RetryingTransactionHelper mockedRetryingTransactionHelper;
|
private RetryingTransactionHelper mockedRetryingTransactionHelper;
|
||||||
@Mock
|
@Mock
|
||||||
private ContentStreamer contentStreamer;
|
private ContentStreamer contentStreamer;
|
||||||
|
@Mock
|
||||||
|
private FileFolderService mockedFileFolderService;
|
||||||
|
|
||||||
/** test component */
|
/** test component */
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
@@ -139,6 +146,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
webScript.setNodeService(mockedNodeService);
|
webScript.setNodeService(mockedNodeService);
|
||||||
webScript.setPermissionService(mockedPermissionService);
|
webScript.setPermissionService(mockedPermissionService);
|
||||||
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
|
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
|
||||||
|
webScript.setFileFolderService(mockedFileFolderService);
|
||||||
// setup retrying transaction helper
|
// setup retrying transaction helper
|
||||||
Answer<Object> doInTransactionAnswer = new Answer<Object>()
|
Answer<Object> doInTransactionAnswer = new Answer<Object>()
|
||||||
{
|
{
|
||||||
@@ -165,6 +173,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Given that there are no nodes with the extended security aspect When the action is executed Nothing happens
|
* Given that there are no nodes with the extended security aspect When the action is executed Nothing happens
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "unchecked" })
|
@SuppressWarnings({ "unchecked" })
|
||||||
@@ -185,7 +194,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 0 records.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 0 records.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
|
||||||
|
|
||||||
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
verify(mockedNodeService, never()).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
verify(mockedNodeService, never()).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
verify(mockedNodeService, never()).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
@@ -199,6 +207,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
/**
|
/**
|
||||||
* Given that there are records with the extended security aspect When the action is executed Then the aspect is
|
* Given that there are records with the extended security aspect When the action is executed Then the aspect is
|
||||||
* removed And the dynamic authorities permissions are cleared And extended security is set via the updated API
|
* removed And the dynamic authorities permissions are cleared And extended security is set via the updated API
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -207,8 +216,7 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
||||||
.thenReturn(ids)
|
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
@@ -231,7 +239,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
|
||||||
|
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
@@ -244,8 +251,9 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given that there are non-records with the extended security aspect When the web script is executed Then the aspect is
|
* Given that there are non-records with the extended security aspect When the web script is executed Then the
|
||||||
* removed And the dynamic authorities permissions are cleared
|
* aspect is removed And the dynamic authorities permissions are cleared
|
||||||
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -254,9 +262,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
||||||
.thenReturn(ids)
|
.thenReturn(Collections.emptyList());
|
||||||
.thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
@@ -278,7 +285,6 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
|
||||||
|
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
@@ -309,8 +315,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "dd");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "dd");
|
||||||
executeJSONWebScript(parameters);
|
executeJSONWebScript(parameters);
|
||||||
fail("Expected exception as parameter batchsize is invalid.");
|
fail("Expected exception as parameter batchsize is invalid.");
|
||||||
}
|
}
|
||||||
@@ -326,8 +332,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "0");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "0");
|
||||||
executeJSONWebScript(parameters);
|
executeJSONWebScript(parameters);
|
||||||
fail("Expected exception as parameter batchsize is not a number greater than 0.");
|
fail("Expected exception as parameter batchsize is not a number greater than 0.");
|
||||||
}
|
}
|
||||||
@@ -355,11 +361,10 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
@Test
|
@Test
|
||||||
public void processAllRecordsWhenMaxProcessedRecordsIsZero() throws Exception
|
public void processAllRecordsWhenMaxProcessedRecordsIsZero() throws Exception
|
||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l,4l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l, 4l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
||||||
.thenReturn(ids)
|
.thenReturn(Collections.emptyList());
|
||||||
.thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
@@ -387,9 +392,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
||||||
.thenReturn(ids)
|
.thenReturn(Collections.emptyList());
|
||||||
.thenReturn(Collections.emptyList());
|
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
@@ -412,14 +416,13 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@Test
|
@Test
|
||||||
public void recordsWithExtendedSecurityAspectAndNullWritersAndReaders() throws Exception
|
public void recordsWithExtendedSecurityAspectAndNullWritersAndReaders() throws Exception
|
||||||
{
|
{
|
||||||
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
||||||
.thenReturn(ids)
|
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
ids.stream().forEach((i) -> {
|
ids.stream().forEach((i) -> {
|
||||||
@@ -439,6 +442,8 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
ArgumentCaptor<Set> readerKeysCaptor = ArgumentCaptor.forClass(Set.class);
|
||||||
|
ArgumentCaptor<Set> writersKeysCaptor = ArgumentCaptor.forClass(Set.class);
|
||||||
|
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
@@ -447,14 +452,76 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
||||||
verify(mockedExtendedSecurityService, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
verify(mockedExtendedSecurityService, times(3)).set(any(NodeRef.class), readerKeysCaptor.capture(),
|
||||||
|
writersKeysCaptor.capture());
|
||||||
|
List<Set> allReaderKeySets = readerKeysCaptor.getAllValues();
|
||||||
|
List<Set> allWritersKeySets = writersKeysCaptor.getAllValues();
|
||||||
|
for (Set keySet : allReaderKeySets)
|
||||||
|
{
|
||||||
|
assertNull(keySet);
|
||||||
|
}
|
||||||
|
for (Set keySet : allWritersKeySets)
|
||||||
|
{
|
||||||
|
assertNull(keySet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
|
@Test
|
||||||
|
public void recordsWithExtendedSecurityAspectAndNullWriters() throws Exception
|
||||||
|
{
|
||||||
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
|
||||||
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).thenReturn(ids)
|
||||||
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
|
ids.stream().forEach((i) -> {
|
||||||
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS)).thenReturn(null);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set up parameters.
|
||||||
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
||||||
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
|
assertNotNull(json);
|
||||||
|
String actualJSONString = json.toString();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
ArgumentCaptor<Set> readerKeysCaptor = ArgumentCaptor.forClass(Set.class);
|
||||||
|
ArgumentCaptor<Set> writersKeysCaptor = ArgumentCaptor.forClass(Set.class);
|
||||||
|
|
||||||
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_READERS));
|
||||||
|
verify(mockedNodeService, times(3)).getProperty(any(NodeRef.class), eq(PROP_WRITERS));
|
||||||
|
verify(mockedNodeService, times(3)).removeAspect(any(NodeRef.class), eq(ASPECT_EXTENDED_SECURITY));
|
||||||
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
|
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
||||||
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
|
eq(ExtendedWriterDynamicAuthority.EXTENDED_WRITER));
|
||||||
|
verify(mockedExtendedSecurityService, times(3)).set(any(NodeRef.class), readerKeysCaptor.capture(),
|
||||||
|
writersKeysCaptor.capture());
|
||||||
|
List<Set> allReaderKeySets = readerKeysCaptor.getAllValues();
|
||||||
|
List<Set> allWritersKeySets = writersKeysCaptor.getAllValues();
|
||||||
|
for (Set keySet : allReaderKeySets)
|
||||||
|
{
|
||||||
|
assertNotNull(keySet);
|
||||||
|
}
|
||||||
|
for (Set keySet : allWritersKeySets)
|
||||||
|
{
|
||||||
|
assertNull(keySet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given I have records that require migration
|
* Given I have records that require migration And I am interested in knowning which records are migrated When I run
|
||||||
* And I am interested in knowning which records are migrated
|
* the migration tool Then I will be returned a CSV file containing the name and node reference of the record
|
||||||
* When I run the migration tool
|
* migrated
|
||||||
* Then I will be returned a CSV file containing the name and node reference of the record migrated
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -491,10 +558,9 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given that I have record that require migration
|
* Given that I have record that require migration And I'm not interested in knowing which records were migrated
|
||||||
* And I'm not interested in knowing which records were migrated
|
* When I run the migration tool And I will not be returned a CSV file of details.
|
||||||
* When I run the migration tool
|
*
|
||||||
* And I will not be returned a CSV file of details.
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -527,4 +593,121 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
verify(contentStreamer, never()).streamContent(any(WebScriptRequest.class), any(WebScriptResponse.class),
|
verify(contentStreamer, never()).streamContent(any(WebScriptRequest.class), any(WebScriptResponse.class),
|
||||||
any(File.class), any(Long.class), any(Boolean.class), any(String.class), any(Map.class));
|
any(File.class), any(Long.class), any(Boolean.class), any(String.class), any(Map.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invalidParentNodeRefParameter() throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Set up parameters.
|
||||||
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "parentNodeRef", "invalidNodeRef");
|
||||||
|
executeJSONWebScript(parameters);
|
||||||
|
fail("Expected exception as parameter parentNodeRef is invalid.");
|
||||||
|
}
|
||||||
|
catch (WebScriptException e)
|
||||||
|
{
|
||||||
|
assertEquals("If parameter parentNodeRef is invalid then 'Internal server error' should be returned.",
|
||||||
|
Status.STATUS_INTERNAL_SERVER_ERROR, e.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void inexistentParentNodeRefParameter() throws Exception
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
|
when(mockedNodeService.exists(parentNodeRef)).thenReturn(false);
|
||||||
|
// Set up parameters.
|
||||||
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "parentNodeRef",
|
||||||
|
parentNodeRef.toString());
|
||||||
|
executeJSONWebScript(parameters);
|
||||||
|
fail("Expected exception as parameter parentNodeRef does not exist.");
|
||||||
|
}
|
||||||
|
catch (WebScriptException e)
|
||||||
|
{
|
||||||
|
assertEquals("If parameter parentNodeRef is does not exist then 'Bad Reequest' should be returned.",
|
||||||
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void processedWithParentNodeRef() throws Exception
|
||||||
|
{
|
||||||
|
List<Long> ids = Stream.of(1l, 2l, 3l).collect(Collectors.toList());
|
||||||
|
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
|
List<FileInfo> children = new ArrayList<FileInfo>();
|
||||||
|
ids.stream().forEach((i) -> {
|
||||||
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
||||||
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT)).thenReturn(true);
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
String name = "name" + i;
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, ContentModel.PROP_NAME)).thenReturn((Serializable) name);
|
||||||
|
FileInfo mockedFileInfo = mock(FileInfo.class);
|
||||||
|
when(mockedFileInfo.getNodeRef()).thenReturn(nodeRef);
|
||||||
|
children.add(mockedFileInfo);
|
||||||
|
});
|
||||||
|
when(mockedFileFolderService.search(eq(parentNodeRef), eq("*"), eq(true), eq(true), eq(true)))
|
||||||
|
.thenReturn(children);
|
||||||
|
|
||||||
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "3", "maxProcessedRecords", "4", "export",
|
||||||
|
"false", "parentNodeRef", parentNodeRef.toString());
|
||||||
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
|
assertNotNull(json);
|
||||||
|
String actualJSONString = json.toString();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 3 records.\"}";
|
||||||
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
|
||||||
|
verify(contentStreamer, never()).streamContent(any(WebScriptRequest.class), any(WebScriptResponse.class),
|
||||||
|
any(File.class), any(Long.class), any(Boolean.class), any(String.class), any(Map.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Test
|
||||||
|
public void processedWithParentNodeRefWithFirstTwoBatchesAlreadyProcessed() throws Exception
|
||||||
|
{
|
||||||
|
List<Long> ids = Stream.of(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l).collect(Collectors.toList());
|
||||||
|
NodeRef parentNodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
|
List<FileInfo> children = new ArrayList<FileInfo>();
|
||||||
|
ids.stream().forEach((i) -> {
|
||||||
|
NodeRef nodeRef = AlfMock.generateNodeRef(mockedNodeService);
|
||||||
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
||||||
|
if (i <= 6l)
|
||||||
|
{
|
||||||
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT)).thenReturn(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT)).thenReturn(true);
|
||||||
|
}
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
String name = "name" + i;
|
||||||
|
when(mockedNodeService.getProperty(nodeRef, ContentModel.PROP_NAME)).thenReturn((Serializable) name);
|
||||||
|
FileInfo mockedFileInfo = mock(FileInfo.class);
|
||||||
|
when(mockedFileInfo.getNodeRef()).thenReturn(nodeRef);
|
||||||
|
children.add(mockedFileInfo);
|
||||||
|
});
|
||||||
|
when(mockedFileFolderService.search(eq(parentNodeRef), eq("*"), eq(true), eq(true), eq(true)))
|
||||||
|
.thenReturn(children);
|
||||||
|
|
||||||
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "3", "parentNodeRef", parentNodeRef.toString());
|
||||||
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
|
assertNotNull(json);
|
||||||
|
String actualJSONString = json.toString();
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 2 records.\"}";
|
||||||
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
|
|
||||||
|
verify(contentStreamer, never()).streamContent(any(WebScriptRequest.class), any(WebScriptResponse.class),
|
||||||
|
any(File.class), any(Long.class), any(Boolean.class), any(String.class), any(Map.class));
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user