private void accessBusinessCheck(UploadRequestUrl requestUrl, String password)
      throws BusinessException {
    UploadRequest request = requestUrl.getUploadRequest();
    if (!isValidPassword(requestUrl, password)) {
      throw new BusinessException(
          BusinessErrorCode.UPLOAD_REQUEST_URL_FORBIDDEN,
          "You do not have the right to get this upload request url : " + requestUrl.getUuid());
    }

    if (!(request.getStatus().equals(UploadRequestStatus.STATUS_ENABLED)
        || request.getStatus().equals(UploadRequestStatus.STATUS_CLOSED))) {
      throw new BusinessException(
          BusinessErrorCode.UPLOAD_REQUEST_READONLY_MODE,
          "The current upload request url is not available : " + requestUrl.getUuid());
    }

    Calendar now = GregorianCalendar.getInstance();
    Calendar compare = GregorianCalendar.getInstance();
    compare.setTime(request.getActivationDate());
    if (now.before(compare)) {
      throw new BusinessException(
          BusinessErrorCode.UPLOAD_REQUEST_NOT_ENABLE_YET,
          "The current upload request url is not enable yet : " + requestUrl.getUuid());
    }
    compare.setTime(request.getExpiryDate());
    if (now.after(compare)) {
      throw new BusinessException(
          BusinessErrorCode.UPLOAD_REQUEST_NOT_ENABLE_YET,
          "The current upload request url is no more available now. : " + requestUrl.getUuid());
    }
  }
 private void deleteBusinessCheck(UploadRequestUrl requestUrl) throws BusinessException {
   UploadRequest request = requestUrl.getUploadRequest();
   if (!request.getStatus().equals(UploadRequestStatus.STATUS_ENABLED)) {
     throw new BusinessException(
         BusinessErrorCode.UPLOAD_REQUEST_READONLY_MODE,
         "The current upload request url is in read only mode : " + requestUrl.getUuid());
   }
 }
 private void createBusinessCheck(UploadRequestUrl requestUrl, DocumentEntry document)
     throws BusinessException {
   UploadRequest request = requestUrl.getUploadRequest();
   if (!request.getStatus().equals(UploadRequestStatus.STATUS_ENABLED)) {
     throw new BusinessException(
         BusinessErrorCode.UPLOAD_REQUEST_READONLY_MODE,
         "The current upload request url is in read only mode : " + requestUrl.getUuid());
   }
   if (request.getMaxFileSize() != null) {
     if (document.getSize() > request.getMaxFileSize()) {
       throw new BusinessException(
           BusinessErrorCode.UPLOAD_REQUEST_FILE_TOO_LARGE,
           "You already have reached the uploaded file limit.");
     }
   }
   if (request.getMaxFileCount() != null) {
     // already reach the limit
     if (request.getUploadRequestEntries().size() >= request.getMaxFileCount()) {
       throw new BusinessException(
           BusinessErrorCode.UPLOAD_REQUEST_TOO_MANY_FILES,
           "You already have reached the uploaded file limit.");
     }
   }
   if (request.getMaxDepositSize() != null) {
     long totalSize = 0;
     for (UploadRequestEntry entry : request.getUploadRequestEntries()) {
       totalSize += entry.getSize();
     }
     totalSize += document.getSize();
     if (totalSize >= request.getMaxDepositSize()) {
       throw new BusinessException(
           BusinessErrorCode.UPLOAD_REQUEST_TOTAL_DEPOSIT_SIZE_TOO_LARGE,
           "You already have reached the limit of your quota.");
     }
   }
 }
 @Override
 public boolean isAdminForThisUploadRequest(Account actor, UploadRequest request) {
   return isAdminforThisDomain(actor, request.getAbstractDomain()) || isOwner(actor, request);
 }
 private boolean isOwner(Account actor, UploadRequest request) {
   return request.getOwner().equals(actor);
 }