diff --git a/source/java/org/alfresco/repo/usage/ContentUsageImpl.java b/source/java/org/alfresco/repo/usage/ContentUsageImpl.java index 5b3af785f4..8a6b9e2817 100644 --- a/source/java/org/alfresco/repo/usage/ContentUsageImpl.java +++ b/source/java/org/alfresco/repo/usage/ContentUsageImpl.java @@ -450,7 +450,7 @@ public class ContentUsageImpl implements ContentUsageService, ", usage=" + currentSize + ", quota=" + quotaSize); } - throw new ContentQuotaException("User quota exceeded"); + throw new ContentQuotaException("User quota exceeded", newSize, quotaSize, ContentModel.TYPE_CONTENT); } NodeRef personNodeRef = getPerson(userName); diff --git a/source/java/org/alfresco/service/cmr/usage/ContentQuotaException.java b/source/java/org/alfresco/service/cmr/usage/ContentQuotaException.java index 3a4e36b359..9572a88697 100644 --- a/source/java/org/alfresco/service/cmr/usage/ContentQuotaException.java +++ b/source/java/org/alfresco/service/cmr/usage/ContentQuotaException.java @@ -18,22 +18,32 @@ */ package org.alfresco.service.cmr.usage; -import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.service.namespace.QName; /** * */ -public class ContentQuotaException extends AlfrescoRuntimeException +public class ContentQuotaException extends QuotaViolationException { private static final long serialVersionUID = 1346806021547860709L; public ContentQuotaException(String msg) { - super(msg); + this(msg, null, -1L, -1L, null); } public ContentQuotaException(String msg, Throwable cause) { - super(msg, cause); + this(msg, cause, -1L, -1L, null); + } + + public ContentQuotaException(String msg, long usage, long quotaLimit, QName quotaRestrictedType) + { + this(msg, null, usage, quotaLimit, quotaRestrictedType); + } + + public ContentQuotaException(String msg, Throwable cause, long usage, long quotaLimit, QName quotaRestrictedType) + { + super(msg, cause, usage, quotaLimit, quotaRestrictedType); } } diff --git a/source/java/org/alfresco/service/cmr/usage/QuotaViolationException.java b/source/java/org/alfresco/service/cmr/usage/QuotaViolationException.java new file mode 100644 index 0000000000..9b6540e9c0 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/usage/QuotaViolationException.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2005-2013 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.service.cmr.usage; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.service.namespace.QName; + +/** + * This exception will be thrown when a content type-based quota has been violated. + * + * @author Neil Mc Erlean + */ +public class QuotaViolationException extends AlfrescoRuntimeException +{ + private static final long serialVersionUID = 1L; + + /** The content type that has been quota-restricted. */ + private final QName quotaRestrictedType; + + /** The quota limit applied to that type. */ + private final long quotaLimit; + + /** The usage that violated the quota limit. */ + private final long usage; + + public QuotaViolationException(String msgId, long usage, long quotaLimit, QName quotaRestrictedType) + { + this(msgId, null, usage, quotaLimit, quotaRestrictedType); + } + + public QuotaViolationException(String msgId, Throwable cause, long usage, long quotaLimit, QName quotaRestrictedType) + { + super(msgId); + + this.quotaRestrictedType = quotaRestrictedType; + this.quotaLimit = quotaLimit; + this.usage = usage; + } + + /** Gets the type of the node which has been quota restricted. */ + public QName getQuotaRestrictedType() { return quotaRestrictedType; } + + /** Gets the quota limit applied to the restricted type. */ + public long getQuotaLimit() { return quotaLimit; } + + /** Gets the usage that violated the quota limit. */ + public long getUsage() { return usage; } + + /** {@inheritDoc} */ + @Override public String toString() + { + final String restrictedType = quotaRestrictedType == null ? "null" : quotaRestrictedType.getPrefixString(); + + StringBuilder msg = new StringBuilder(); + msg.append(this.getClass().getSimpleName()) + .append(" '").append(getMessage()).append("' ") + .append("(").append(restrictedType).append(": ") + .append(usage).append(" violates limit ").append(quotaLimit).append(")"); + return msg.toString(); + } +}