mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged V2.9 to HEAD
9409: Fix ETWONINE-12 9459: Fix for ETWONINE-17 (error message appears instead of notification message when mananging deleted items 9468: User usages - add test, ensure multiple beforeDeletes are only handled once 9473: User usages - add tests + fixes (ETWONINE-43, ETWONINE-44, recalc missing usages) 9491: Remove noop://noop empty store (added during merge) 9662: User usages - minor fix (if "owner" qname not present) 9843: Merged V2.2 to V2.9 9486: Merged HEAD to V2.2 9482: New commands for AVM Console (AVMInterpreter). Version parameter is not longer mandatory for simple commands. 9727: Merged V2.1 to V2.2 9211: Workaround for extraneous ".ppt" extension when saving PowerPoint files over WebDAV git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@10591 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -31,6 +31,9 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.domain.Node;
|
||||
import org.alfresco.repo.domain.PropertyValue;
|
||||
import org.alfresco.repo.domain.QNameDAO;
|
||||
import org.alfresco.repo.domain.QNameEntity;
|
||||
import org.alfresco.repo.node.db.NodeDaoService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
@@ -62,6 +65,7 @@ public class UserUsageTrackingComponent
|
||||
private static boolean busy = false;
|
||||
|
||||
private NodeDaoService nodeDaoService;
|
||||
private QNameDAO qnameDAO;
|
||||
private TransactionServiceImpl transactionService;
|
||||
private ContentUsageImpl contentUsageImpl;
|
||||
|
||||
@@ -78,6 +82,11 @@ public class UserUsageTrackingComponent
|
||||
this.nodeDaoService = nodeDaoService;
|
||||
}
|
||||
|
||||
public void setQnameDAO(QNameDAO qnameDAO)
|
||||
{
|
||||
this.qnameDAO = qnameDAO;
|
||||
}
|
||||
|
||||
public void setTransactionService(TransactionServiceImpl transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
@@ -275,44 +284,73 @@ public class UserUsageTrackingComponent
|
||||
{
|
||||
public Long execute() throws Throwable
|
||||
{
|
||||
QNameEntity ownerQnameEntity = qnameDAO.getQNameEntity(ContentModel.PROP_OWNER);
|
||||
QNameEntity contentQnameEntity = qnameDAO.getQNameEntity(ContentModel.PROP_CONTENT);
|
||||
|
||||
List<String> stores = contentUsageImpl.getStores();
|
||||
long totalUsage = 0;
|
||||
|
||||
for (String store : stores)
|
||||
if (contentQnameEntity != null)
|
||||
{
|
||||
StoreRef storeRef = new StoreRef(store);
|
||||
|
||||
// get nodes for which user is owner
|
||||
Collection<Node> ownerNodes = nodeDaoService.getNodesWithPropertyStringValueForStore(storeRef, ContentModel.PROP_OWNER, userName);
|
||||
|
||||
for (Node ownerNode : ownerNodes)
|
||||
for (String store : stores)
|
||||
{
|
||||
if (ownerNode.getTypeQName().equals(ContentModel.TYPE_CONTENT))
|
||||
StoreRef storeRef = new StoreRef(store);
|
||||
|
||||
// get nodes for which user is owner
|
||||
Collection<Node> ownerNodes = nodeDaoService.getNodesWithPropertyStringValueForStore(storeRef, ContentModel.PROP_OWNER, userName);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
ContentData contentData = ContentData.createContentProperty(ownerNode.getProperties().get(ContentModel.PROP_CONTENT).getStringValue());
|
||||
totalUsage = totalUsage + contentData.getSize();
|
||||
logger.debug("Recalc usage ("+ userName+") store="+storeRef+", ownerNodeCount="+ownerNodes.size());
|
||||
}
|
||||
|
||||
for (Node ownerNode : ownerNodes)
|
||||
{
|
||||
if (ownerNode.getTypeQName().equals(ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
PropertyValue content = ownerNode.getProperties().get(contentQnameEntity.getId());
|
||||
if (content != null)
|
||||
{
|
||||
ContentData contentData = ContentData.createContentProperty(content.getStringValue());
|
||||
totalUsage = totalUsage + contentData.getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get nodes for which user is creator, and then filter out those that have an owner
|
||||
Collection<Node> creatorNodes = nodeDaoService.getNodesWithPropertyStringValueForStore(storeRef, ContentModel.PROP_CREATOR, userName);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Recalc usage ("+ userName+") store="+storeRef+", creatorNodeCount="+creatorNodes.size());
|
||||
}
|
||||
|
||||
for (Node creatorNode : creatorNodes)
|
||||
{
|
||||
// note: it is possible for "owner" qname to be null (eg. ownership never taken)
|
||||
if (creatorNode.getTypeQName().toString().equals(ContentModel.TYPE_CONTENT.toString()) &&
|
||||
((ownerQnameEntity != null) && creatorNode.getProperties().get(ownerQnameEntity.getId()) == null))
|
||||
{
|
||||
PropertyValue content = creatorNode.getProperties().get(contentQnameEntity.getId());
|
||||
if (content != null)
|
||||
{
|
||||
ContentData contentData = ContentData.createContentProperty(content.getStringValue());
|
||||
totalUsage = totalUsage + contentData.getSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get nodes for which user is creator, and then filter out those that have an owner
|
||||
Collection<Node> creatorNodes = nodeDaoService.getNodesWithPropertyStringValueForStore(storeRef, ContentModel.PROP_CREATOR, userName);
|
||||
|
||||
for (Node creatorNode : creatorNodes)
|
||||
{
|
||||
if (creatorNode.getTypeQName().equals(ContentModel.TYPE_CONTENT) &&
|
||||
creatorNode.getProperties().get(ContentModel.PROP_OWNER) == null)
|
||||
{
|
||||
ContentData contentData = ContentData.createContentProperty(creatorNode.getProperties().get(ContentModel.PROP_CONTENT).getStringValue());
|
||||
totalUsage = totalUsage + contentData.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
long quotaSize = contentUsageImpl.getUserQuota(userName);
|
||||
logger.debug("Recalc usage ("+ userName+") totalUsage="+totalUsage+", quota="+quotaSize);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.error("Failed to re-calculate usages - cannot find QName: " + ContentModel.PROP_CONTENT.toString());
|
||||
}
|
||||
|
||||
return totalUsage;
|
||||
}
|
||||
|
Reference in New Issue
Block a user