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:
Jan Vonka
2008-01-07 16:35:27 +00:00
parent 75967c3736
commit c1fa7ba626
2 changed files with 47 additions and 33 deletions

View File

@@ -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>

View File

@@ -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;
@@ -85,6 +87,11 @@ public class ContentUsageImpl implements ContentUsageService,
{
this.policyComponent = policyComponent;
}
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
{
this.authenticationComponent = authenticationComponent;
}
public void setEnabled(boolean 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())
// 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))
{
logger.warn("User (" + userName + ") quota exceeded: content=" + contentSize +
", usage=" + currentSize +
", quota=" + quotaSize);
if (logger.isWarnEnabled())
{
logger.warn("User (" + userName + ") quota exceeded: content=" + contentSize +
", usage=" + currentSize +
", quota=" + quotaSize);
}
throw new ContentQuotaException("User quota exceeded");
}
throw new ContentQuotaException("User quota exceeded");
NodeRef personNodeRef = personService.getPerson(userName);
usageService.insertDelta(personNodeRef, contentSize);
}
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);
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));
}
NodeRef personNodeRef = personService.getPerson(userName);
usageService.insertDelta(personNodeRef, (-contentSize));
}
/**