Search in sources :

Example 1 with QuotaResource

use of io.milton.resource.QuotaResource in project lobcder by skoulouzis.

the class DefaultQuotaDataAccessor method getQuotaUsed.

public Long getQuotaUsed(Resource res) {
    if (res instanceof QuotaResource) {
        QuotaResource quotaRes = (QuotaResource) res;
        Long l = quotaRes.getQuotaUsed();
        return l;
    } else {
        return null;
    }
}
Also used : QuotaResource(io.milton.resource.QuotaResource)

Example 2 with QuotaResource

use of io.milton.resource.QuotaResource in project lobcder by skoulouzis.

the class DefaultQuotaDataAccessor method getQuotaAvailable.

public Long getQuotaAvailable(Resource res) {
    if (res instanceof QuotaResource) {
        QuotaResource quotaRes = (QuotaResource) res;
        Long l = quotaRes.getQuotaAvailable();
        return l;
    } else {
        return null;
    }
}
Also used : QuotaResource(io.milton.resource.QuotaResource)

Example 3 with QuotaResource

use of io.milton.resource.QuotaResource in project lobcder by skoulouzis.

the class DefaultStorageChecker method checkStorageOnAdd.

public StorageErrorReason checkStorageOnAdd(Request request, CollectionResource nearestParent, Path parentPath, String host) {
    if (nearestParent instanceof QuotaResource) {
        QuotaResource qr = (QuotaResource) nearestParent;
        Long llAvail = qr.getQuotaAvailable();
        if (llAvail == null) {
            log.debug("no quota data available");
            return null;
        }
        if (llAvail <= 0) {
            log.debug("no quota available, reject");
            return StorageErrorReason.SER_QUOTA_EXCEEDED;
        } else {
            // new content must be less then that available
            Long newContentLength = request.getContentLengthHeader();
            if (newContentLength == null) {
                log.debug("new content length is not available, cant check quota, allow");
                return null;
            }
            if (newContentLength < llAvail) {
                return null;
            } else {
                log.debug("new content length is greater then available storage, reject");
                return StorageErrorReason.SER_QUOTA_EXCEEDED;
            }
        }
    } else {
        return null;
    }
}
Also used : QuotaResource(io.milton.resource.QuotaResource)

Example 4 with QuotaResource

use of io.milton.resource.QuotaResource in project lobcder by skoulouzis.

the class DefaultStorageChecker method checkStorageOnReplace.

public StorageErrorReason checkStorageOnReplace(Request request, CollectionResource parent, Resource replaced, String host) {
    if (parent instanceof QuotaResource) {
        QuotaResource qr = (QuotaResource) parent;
        Long llAvail = qr.getQuotaAvailable();
        if (llAvail == null) {
            log.debug("no quota data available");
            return null;
        }
        if (llAvail <= 0) {
            // new content length must be less then existing
            Long newContentLength = request.getContentLengthHeader();
            if (newContentLength == null) {
                log.debug("new content length is not available, cant check quota, reject");
                return StorageErrorReason.SER_QUOTA_EXCEEDED;
            }
            if (replaced instanceof GetableResource) {
                GetableResource gr = (GetableResource) replaced;
                Long existingLength = gr.getContentLength();
                if (existingLength == null) {
                    log.debug("existing content length cant be determined, cant check quota, reject");
                    return StorageErrorReason.SER_QUOTA_EXCEEDED;
                } else {
                    long diff = existingLength - newContentLength;
                    if (diff > 0) {
                        return null;
                    } else {
                        log.debug("new content is larger then existing content, but no quota is available, reject");
                        return StorageErrorReason.SER_QUOTA_EXCEEDED;
                    }
                }
            } else {
                log.debug("existing content length cant be determined, cant check quota, reject");
                return StorageErrorReason.SER_QUOTA_EXCEEDED;
            }
        } else {
            // difference of new content to existing must be less then available, but if in doubt allow
            Long newContentLength = request.getContentLengthHeader();
            if (newContentLength == null) {
                log.debug("new content length is not available, cant check quota, allow");
                return null;
            }
            if (replaced instanceof GetableResource) {
                GetableResource gr = (GetableResource) replaced;
                Long existingLength = gr.getContentLength();
                if (existingLength == null) {
                    log.debug("existing content length cant be determined, cant check quota, allow");
                    return null;
                } else {
                    // this is the amount extra needed
                    long diff = newContentLength - existingLength;
                    if (diff <= llAvail) {
                        return null;
                    } else {
                        log.debug("new content is larger then existing content, but no quota is available, reject");
                        return StorageErrorReason.SER_QUOTA_EXCEEDED;
                    }
                }
            } else {
                log.debug("existing content length cant be determined, cant check quota, allow");
                return null;
            }
        }
    // if difference between new content and existing is less then available, then ok
    } else {
        return null;
    }
}
Also used : GetableResource(io.milton.resource.GetableResource) QuotaResource(io.milton.resource.QuotaResource)

Aggregations

QuotaResource (io.milton.resource.QuotaResource)4 GetableResource (io.milton.resource.GetableResource)1