mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-4162: fixed formatting
This commit is contained in:
@@ -25,13 +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 java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
@@ -46,64 +46,65 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransacti
|
|||||||
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.FileFolderService;
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
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;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.Pair;
|
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 MESSAGE_NODE_REF_DOES_NOT_EXIST_TEMPLATE = "Parameter parentNodeRef = {0} does not exist.";
|
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
|
||||||
*/
|
*/
|
||||||
private static Log logger = LogFactory.getLog(DynamicAuthoritiesGet.class);
|
private static Log logger = LogFactory.getLog(DynamicAuthoritiesGet.class);
|
||||||
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 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 */
|
|
||||||
private PatchDAO patchDAO;
|
/** services */
|
||||||
private NodeDAO nodeDAO;
|
private PatchDAO patchDAO;
|
||||||
private QNameDAO qnameDAO;
|
private NodeDAO nodeDAO;
|
||||||
private NodeService nodeService;
|
private QNameDAO qnameDAO;
|
||||||
private PermissionService permissionService;
|
private NodeService nodeService;
|
||||||
private ExtendedSecurityService extendedSecurityService;
|
private PermissionService permissionService;
|
||||||
private TransactionService transactionService;
|
private ExtendedSecurityService extendedSecurityService;
|
||||||
|
private TransactionService transactionService;
|
||||||
/** Content Streamer */
|
/** Content Streamer */
|
||||||
protected ContentStreamer contentStreamer;
|
protected ContentStreamer contentStreamer;
|
||||||
private FileFolderService fileFolderService;
|
private FileFolderService fileFolderService;
|
||||||
@@ -113,41 +114,41 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
{
|
{
|
||||||
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)
|
public void setFileFolderService(FileFolderService fileFolderService)
|
||||||
{
|
{
|
||||||
@@ -158,17 +159,17 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
{
|
{
|
||||||
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);
|
||||||
@@ -184,7 +185,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
{
|
{
|
||||||
processedNodes = processChildrenNodes(parentNodeRef, batchSize.intValue(), recordAspectPair,
|
processedNodes = processChildrenNodes(parentNodeRef, batchSize.intValue(), recordAspectPair,
|
||||||
totalNumberOfRecordsToProcess.intValue(), out, attach);
|
totalNumberOfRecordsToProcess.intValue(), out, attach);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
processedNodes = processNodes(batchSize, maxNodeId, recordAspectPair, totalNumberOfRecordsToProcess,
|
processedNodes = processNodes(batchSize, maxNodeId, recordAspectPair, totalNumberOfRecordsToProcess,
|
||||||
@@ -262,8 +263,10 @@ 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) { throw new WebScriptException(
|
if (mimetype == null)
|
||||||
"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();
|
||||||
@@ -362,19 +365,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,7 +412,7 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
}
|
}
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get parentNodeRef parameter from the request
|
* Get parentNodeRef parameter from the request
|
||||||
*
|
*
|
||||||
@@ -446,57 +449,57 @@ 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,
|
protected List<NodeRef> processChildrenNodes(NodeRef parentNodeRef, final int batchSize,
|
||||||
final Pair<Long, QName> recordAspectPair, final int maxRecordsToProcess, final BufferedWriter out,
|
final Pair<Long, QName> recordAspectPair, final int maxRecordsToProcess, final BufferedWriter out,
|
||||||
final boolean attach)
|
final boolean attach)
|
||||||
@@ -552,31 +555,31 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
return processedNodes;
|
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);
|
||||||
|
|
||||||
// remove dynamic authority permissions
|
// remove dynamic authority permissions
|
||||||
permissionService.clearPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER);
|
permissionService.clearPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER);
|
||||||
permissionService.clearPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER);
|
permissionService.clearPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER);
|
||||||
|
|
||||||
// if record then ...
|
// if record then ...
|
||||||
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD))
|
if (nodeService.hasAspect(nodeRef, ASPECT_RECORD))
|
||||||
{
|
{
|
||||||
Set<String> readersKeySet = null;
|
Set<String> readersKeySet = null;
|
||||||
if (readers != null)
|
if (readers != null)
|
||||||
{
|
{
|
||||||
readersKeySet = readers.keySet();
|
readersKeySet = readers.keySet();
|
||||||
}
|
}
|
||||||
Set<String> writersKeySet = null;
|
Set<String> writersKeySet = null;
|
||||||
@@ -584,8 +587,8 @@ public class DynamicAuthoritiesGet extends AbstractWebScript implements RecordsM
|
|||||||
{
|
{
|
||||||
writersKeySet = writers.keySet();
|
writersKeySet = writers.keySet();
|
||||||
}
|
}
|
||||||
// re-set extended security via API
|
// re-set extended security via API
|
||||||
extendedSecurityService.set(nodeRef, readersKeySet, writersKeySet);
|
extendedSecurityService.set(nodeRef, readersKeySet, writersKeySet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,303 +1,307 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
* Copyright (C) 2005-2014 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* Alfresco is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.alfresco.repo.web.scripts.roles;
|
package org.alfresco.repo.web.scripts.roles;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
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.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.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;
|
||||||
import static org.mockito.Mockito.when;
|
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.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;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedReaderDynamicAuthority;
|
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedReaderDynamicAuthority;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
|
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedWriterDynamicAuthority;
|
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedWriterDynamicAuthority;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.AlfMock;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseWebScriptUnitTest;
|
||||||
import org.alfresco.repo.domain.node.NodeDAO;
|
import org.alfresco.repo.domain.node.NodeDAO;
|
||||||
import org.alfresco.repo.domain.patch.PatchDAO;
|
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;
|
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.FileFolderService;
|
||||||
import org.alfresco.service.cmr.model.FileInfo;
|
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;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.alfresco.service.transaction.TransactionService;
|
import org.alfresco.service.transaction.TransactionService;
|
||||||
import org.alfresco.util.Pair;
|
import org.alfresco.util.Pair;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.mockito.invocation.InvocationOnMock;
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import org.springframework.extensions.webscripts.AbstractWebScript;
|
import org.springframework.extensions.webscripts.AbstractWebScript;
|
||||||
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DynamicAuthoritiesGet Unit Test
|
* DynamicAuthoritiesGet Unit Test
|
||||||
*
|
*
|
||||||
* @author Silviu Dinuta
|
* @author Silviu Dinuta
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest implements RecordsManagementModel
|
public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest implements RecordsManagementModel
|
||||||
{
|
{
|
||||||
/** test data */
|
/** test data */
|
||||||
private static final Long ASPECT_ID = 123l;
|
private static final Long ASPECT_ID = 123l;
|
||||||
private static final QName ASPECT = AlfMock.generateQName();
|
private static final QName ASPECT = AlfMock.generateQName();
|
||||||
|
|
||||||
/** mocks */
|
/** mocks */
|
||||||
@Mock
|
@Mock
|
||||||
private PatchDAO mockedPatchDAO;
|
private PatchDAO mockedPatchDAO;
|
||||||
@Mock
|
@Mock
|
||||||
private NodeDAO mockedNodeDAO;
|
private NodeDAO mockedNodeDAO;
|
||||||
@Mock
|
@Mock
|
||||||
private QNameDAO mockedQnameDAO;
|
private QNameDAO mockedQnameDAO;
|
||||||
@Mock
|
@Mock
|
||||||
private NodeService mockedNodeService;
|
private NodeService mockedNodeService;
|
||||||
@Mock
|
@Mock
|
||||||
private PermissionService mockedPermissionService;
|
private PermissionService mockedPermissionService;
|
||||||
@Mock
|
@Mock
|
||||||
private ExtendedSecurityService mockedExtendedSecurityService;
|
private ExtendedSecurityService mockedExtendedSecurityService;
|
||||||
@Mock
|
@Mock
|
||||||
private TransactionService mockedTransactionService;
|
private TransactionService mockedTransactionService;
|
||||||
@Mock
|
@Mock
|
||||||
private RetryingTransactionHelper mockedRetryingTransactionHelper;
|
private RetryingTransactionHelper mockedRetryingTransactionHelper;
|
||||||
@Mock
|
@Mock
|
||||||
private ContentStreamer contentStreamer;
|
private ContentStreamer contentStreamer;
|
||||||
@Mock
|
@Mock
|
||||||
private FileFolderService mockedFileFolderService;
|
private FileFolderService mockedFileFolderService;
|
||||||
|
|
||||||
/** test component */
|
/** test component */
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private DynamicAuthoritiesGet webScript;
|
private DynamicAuthoritiesGet webScript;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected AbstractWebScript getWebScript()
|
protected AbstractWebScript getWebScript()
|
||||||
{
|
{
|
||||||
return webScript;
|
return webScript;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getWebScriptTemplate()
|
protected String getWebScriptTemplate()
|
||||||
{
|
{
|
||||||
return "alfresco/templates/webscripts/org/alfresco/repository/roles/rm-dynamicauthorities.get.json.ftl";
|
return "alfresco/templates/webscripts/org/alfresco/repository/roles/rm-dynamicauthorities.get.json.ftl";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Before test
|
* Before test
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Before
|
@Before
|
||||||
public void before()
|
public void before()
|
||||||
{
|
{
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
webScript.setNodeService(mockedNodeService);
|
webScript.setNodeService(mockedNodeService);
|
||||||
webScript.setPermissionService(mockedPermissionService);
|
webScript.setPermissionService(mockedPermissionService);
|
||||||
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
|
webScript.setExtendedSecurityService(mockedExtendedSecurityService);
|
||||||
webScript.setFileFolderService(mockedFileFolderService);
|
webScript.setFileFolderService(mockedFileFolderService);
|
||||||
// setup retrying transaction helper
|
// setup retrying transaction helper
|
||||||
Answer<Object> doInTransactionAnswer = new Answer<Object>()
|
Answer<Object> doInTransactionAnswer = new Answer<Object>()
|
||||||
{
|
{
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public Object answer(InvocationOnMock invocation) throws Throwable
|
public Object answer(InvocationOnMock invocation) throws Throwable
|
||||||
{
|
{
|
||||||
RetryingTransactionCallback callback = (RetryingTransactionCallback) invocation.getArguments()[0];
|
RetryingTransactionCallback callback = (RetryingTransactionCallback) invocation.getArguments()[0];
|
||||||
return callback.execute();
|
return callback.execute();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper)
|
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper)
|
||||||
.<Object> doInTransaction(any(RetryingTransactionCallback.class), anyBoolean(), anyBoolean());
|
.<Object> doInTransaction(any(RetryingTransactionCallback.class), anyBoolean(), anyBoolean());
|
||||||
|
|
||||||
when(mockedTransactionService.getRetryingTransactionHelper()).thenReturn(mockedRetryingTransactionHelper);
|
when(mockedTransactionService.getRetryingTransactionHelper()).thenReturn(mockedRetryingTransactionHelper);
|
||||||
|
|
||||||
// max node id
|
// max node id
|
||||||
when(mockedPatchDAO.getMaxAdmNodeID()).thenReturn(500000L);
|
when(mockedPatchDAO.getMaxAdmNodeID()).thenReturn(500000L);
|
||||||
|
|
||||||
// aspect
|
// aspect
|
||||||
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(new Pair<Long, QName>(ASPECT_ID, ASPECT));
|
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(new Pair<Long, QName>(ASPECT_ID, ASPECT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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" })
|
||||||
@Test
|
@Test
|
||||||
public void noNodesWithExtendedSecurity() throws Exception
|
public void noNodesWithExtendedSecurity() throws Exception
|
||||||
{
|
{
|
||||||
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong()))
|
||||||
.thenReturn(Collections.emptyList());
|
.thenReturn(Collections.emptyList());
|
||||||
|
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "3");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "3");
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
assertNotNull(json);
|
assertNotNull(json);
|
||||||
String actualJSONString = json.toString();
|
String actualJSONString = json.toString();
|
||||||
|
|
||||||
// Check the JSON result using Jackson to allow easy equality testing.
|
// Check the JSON result using Jackson to allow easy equality testing.
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
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));
|
||||||
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
||||||
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
eq(ExtendedReaderDynamicAuthority.EXTENDED_READER));
|
||||||
verify(mockedPermissionService, never()).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, never()).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, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
* removed And the dynamic authorities permissions are cleared And extended security is set via the updated API
|
* 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
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void recordsWithExtendedSecurityAspect() throws Exception
|
public void recordsWithExtendedSecurityAspect() 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())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).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);
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(true);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
});
|
||||||
});
|
|
||||||
|
// Set up parameters.
|
||||||
// Set up parameters.
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
assertNotNull(json);
|
||||||
assertNotNull(json);
|
String actualJSONString = json.toString();
|
||||||
String actualJSONString = json.toString();
|
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));
|
|
||||||
|
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));
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
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, times(3)).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
||||||
verify(mockedExtendedSecurityService, times(3)).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* Given that there are non-records with the extended security aspect
|
||||||
* Given that there are non-records with the extended security aspect When the web script is executed Then the
|
* When the web script is executed
|
||||||
* aspect is removed And the dynamic authorities permissions are cleared
|
* Then the aspect is removed And the dynamic authorities permissions are cleared
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void nonRecordsWithExtendedSecurityAspect() throws Exception
|
public void nonRecordsWithExtendedSecurityAspect() 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())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).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);
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
});
|
||||||
});
|
|
||||||
|
// Set up parameters.
|
||||||
// Set up parameters.
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "4");
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
assertNotNull(json);
|
||||||
assertNotNull(json);
|
String actualJSONString = json.toString();
|
||||||
String actualJSONString = json.toString();
|
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));
|
|
||||||
|
|
||||||
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));
|
||||||
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
verify(mockedPermissionService, times(3)).clearPermission(any(NodeRef.class),
|
||||||
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, never()).set(any(NodeRef.class), any(Set.class), any(Set.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void missingBatchSizeParameter() throws Exception
|
public void missingBatchSizeParameter() throws Exception
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
executeJSONWebScript(emptyMap());
|
executeJSONWebScript(emptyMap());
|
||||||
@@ -308,15 +312,15 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals("If parameter batchsize is not provided then 'Bad request' should be returned.",
|
assertEquals("If parameter batchsize is not provided then 'Bad request' should be returned.",
|
||||||
Status.STATUS_BAD_REQUEST, e.getStatus());
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidBatchSizeParameter() throws Exception
|
public void invalidBatchSizeParameter() throws Exception
|
||||||
{
|
{
|
||||||
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.");
|
||||||
}
|
}
|
||||||
@@ -325,15 +329,15 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals("If parameter batchsize is invalid then 'Bad request' should be returned.",
|
assertEquals("If parameter batchsize is invalid then 'Bad request' should be returned.",
|
||||||
Status.STATUS_BAD_REQUEST, e.getStatus());
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void batchSizeShouldBeGraterThanZero() throws Exception
|
public void batchSizeShouldBeGraterThanZero() throws Exception
|
||||||
{
|
{
|
||||||
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.");
|
||||||
}
|
}
|
||||||
@@ -342,79 +346,77 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
assertEquals("If parameter batchsize is not a number greater than 0 then 'Bad request' should be returned.",
|
assertEquals("If parameter batchsize is not a number greater than 0 then 'Bad request' should be returned.",
|
||||||
Status.STATUS_BAD_REQUEST, e.getStatus());
|
Status.STATUS_BAD_REQUEST, e.getStatus());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void extendedSecurityAspectNotCreated() throws Exception
|
public void extendedSecurityAspectNotCreated() throws Exception
|
||||||
{
|
{
|
||||||
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(null);
|
when(mockedQnameDAO.getQName(ASPECT_EXTENDED_SECURITY)).thenReturn(null);
|
||||||
// Set up parameters.
|
// Set up parameters.
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "3");
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "3");
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
assertNotNull(json);
|
assertNotNull(json);
|
||||||
String actualJSONString = json.toString();
|
String actualJSONString = json.toString();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"There where no records to be processed.\"}";
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"There where no records to be processed.\"}";
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
}
|
}
|
||||||
|
|
||||||
@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())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).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);
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
});
|
||||||
});
|
|
||||||
|
// Set up parameters.
|
||||||
// Set up parameters.
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "0");
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "10", "maxProcessedRecords", "0");
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
assertNotNull(json);
|
||||||
assertNotNull(json);
|
String actualJSONString = json.toString();
|
||||||
String actualJSONString = json.toString();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 4 records.\"}";
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed 4 records.\"}";
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@Test
|
public void whenMaxProcessedRecordsIsMissingItDefaultsToBatchSize() throws Exception
|
||||||
public void whenMaxProcessedRecordsIsMissingItDefaultsToBatchSize() throws Exception
|
{
|
||||||
{
|
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())).thenReturn(ids)
|
when(mockedPatchDAO.getNodesByAspectQNameId(eq(ASPECT_ID), anyLong(), anyLong())).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);
|
||||||
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
when(mockedNodeDAO.getNodePair(i)).thenReturn(new Pair<Long, NodeRef>(i, nodeRef));
|
||||||
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
when(mockedNodeService.hasAspect(nodeRef, ASPECT_RECORD)).thenReturn(false);
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_READERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
when(mockedNodeService.getProperty(nodeRef, PROP_WRITERS))
|
||||||
.thenReturn((Serializable) Collections.emptyMap());
|
.thenReturn((Serializable) Collections.emptyMap());
|
||||||
|
});
|
||||||
});
|
|
||||||
|
// Set up parameters.
|
||||||
// Set up parameters.
|
Map<String, String> parameters = ImmutableMap.of("batchsize", "4");
|
||||||
Map<String, String> parameters = ImmutableMap.of("batchsize", "4");
|
JSONObject json = executeJSONWebScript(parameters);
|
||||||
JSONObject json = executeJSONWebScript(parameters);
|
assertNotNull(json);
|
||||||
assertNotNull(json);
|
String actualJSONString = json.toString();
|
||||||
String actualJSONString = json.toString();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed first 4 records.\"}";
|
||||||
String expectedJSONString = "{\"responsestatus\":\"success\",\"message\":\"Processed first 4 records.\"}";
|
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
||||||
assertEquals(mapper.readTree(expectedJSONString), mapper.readTree(actualJSONString));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
@Test
|
@Test
|
||||||
@@ -518,9 +520,10 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given I have records that require migration And I am interested in knowning which records are migrated When I run
|
* Given I have records that require migration
|
||||||
* the migration tool Then I will be returned a CSV file containing the name and node reference of the record
|
* And I am interested in knowning which records are migrated
|
||||||
* migrated
|
* When I run the migration tool
|
||||||
|
* Then I will be returned a CSV file containing the name and node reference of the record migrated
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@@ -558,8 +561,10 @@ public class DynamicAuthoritiesGetUnitTest extends BaseWebScriptUnitTest impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given that I have record that require migration And I'm not interested in knowing which records were migrated
|
* Given that I have record that require migration
|
||||||
* When I run the migration tool And I will not be returned a CSV file of details.
|
* And I'm not interested in knowing which records were migrated
|
||||||
|
* When I run the migration tool
|
||||||
|
* Then I will not be returned a CSV file of details.
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user