mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Initial fix for forum post 34098
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7764 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
<property name="nodeService" ref="nodeService"/>
|
||||
<property name="policyComponent" ref="policyComponent"/>
|
||||
<property name="usageService" ref="usageService"/>
|
||||
<property name="authenticationComponent" ref="authenticationComponent"/>
|
||||
<property name="enabled">
|
||||
<value>${system.usages.enabled}</value>
|
||||
</property>
|
||||
|
@@ -32,6 +32,7 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
@@ -61,6 +62,7 @@ public class ContentUsageImpl implements ContentUsageService,
|
||||
private PersonService personService;
|
||||
private PolicyComponent policyComponent;
|
||||
private UsageService usageService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
@@ -86,6 +88,11 @@ public class ContentUsageImpl implements ContentUsageService,
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||
{
|
||||
this.authenticationComponent = authenticationComponent;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled)
|
||||
{
|
||||
this.enabled = enabled;
|
||||
@@ -288,49 +295,55 @@ public class ContentUsageImpl implements ContentUsageService,
|
||||
|
||||
private void incrementUserUsage(String userName, long contentSize, NodeRef contentNodeRef)
|
||||
{
|
||||
// increment usage - add positive delta
|
||||
if (logger.isDebugEnabled()) logger.debug("incrementUserUsage: username="+userName+", contentSize="+contentSize+", contentNodeRef="+contentNodeRef);
|
||||
|
||||
long currentSize = getUserUsage(userName);
|
||||
long quotaSize = getUserQuota(userName);
|
||||
|
||||
long newSize = currentSize + contentSize;
|
||||
|
||||
// check whether user's quota exceeded
|
||||
if ((quotaSize != -1) && (newSize > quotaSize))
|
||||
if (! userName.equals(authenticationComponent.getSystemUserName()))
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("User (" + userName + ") quota exceeded: content=" + contentSize +
|
||||
", usage=" + currentSize +
|
||||
", quota=" + quotaSize);
|
||||
}
|
||||
throw new ContentQuotaException("User quota exceeded");
|
||||
}
|
||||
// increment usage - add positive delta
|
||||
if (logger.isDebugEnabled()) logger.debug("incrementUserUsage: username="+userName+", contentSize="+contentSize+", contentNodeRef="+contentNodeRef);
|
||||
|
||||
NodeRef personNodeRef = personService.getPerson(userName);
|
||||
usageService.insertDelta(personNodeRef, contentSize);
|
||||
long currentSize = getUserUsage(userName);
|
||||
long quotaSize = getUserQuota(userName);
|
||||
|
||||
long newSize = currentSize + contentSize;
|
||||
|
||||
// check whether user's quota exceeded
|
||||
if ((quotaSize != -1) && (newSize > quotaSize))
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("User (" + userName + ") quota exceeded: content=" + contentSize +
|
||||
", usage=" + currentSize +
|
||||
", quota=" + quotaSize);
|
||||
}
|
||||
throw new ContentQuotaException("User quota exceeded");
|
||||
}
|
||||
|
||||
NodeRef personNodeRef = personService.getPerson(userName);
|
||||
usageService.insertDelta(personNodeRef, contentSize);
|
||||
}
|
||||
}
|
||||
|
||||
private void decrementUserUsage(String userName, long contentSize, NodeRef contentNodeRef)
|
||||
{
|
||||
// decrement usage - add negative delta
|
||||
if (logger.isDebugEnabled()) logger.debug("decrementUserUsage: username="+userName+", contentSize="+contentSize+", contentNodeRef="+contentNodeRef);
|
||||
|
||||
long currentSize = getUserUsage(userName);
|
||||
|
||||
long newSize = currentSize + contentSize;
|
||||
|
||||
if (newSize < 0)
|
||||
if (! userName.equals(authenticationComponent.getSystemUserName()))
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("User (" + userName + ") has negative usage (" + newSize + ") - reset to 0");
|
||||
}
|
||||
}
|
||||
// decrement usage - add negative delta
|
||||
if (logger.isDebugEnabled()) logger.debug("decrementUserUsage: username="+userName+", contentSize="+contentSize+", contentNodeRef="+contentNodeRef);
|
||||
|
||||
NodeRef personNodeRef = personService.getPerson(userName);
|
||||
usageService.insertDelta(personNodeRef, (-contentSize));
|
||||
long currentSize = getUserUsage(userName);
|
||||
|
||||
long newSize = currentSize + contentSize;
|
||||
|
||||
if (newSize < 0)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("User (" + userName + ") has negative usage (" + newSize + ") - reset to 0");
|
||||
}
|
||||
}
|
||||
|
||||
NodeRef personNodeRef = personService.getPerson(userName);
|
||||
usageService.insertDelta(personNodeRef, (-contentSize));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user