コード例 #1
0
  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());
    }
  }
コード例 #2
0
 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());
   }
 }
コード例 #3
0
 private boolean isValidPassword(UploadRequestUrl data, String password) {
   if (data.isProtectedByPassword()) {
     if (password == null) return false;
     String hashedPassword = HashUtils.hashSha1withBase64(password.getBytes());
     return hashedPassword.equals(data.getPassword());
   }
   return true;
 }
コード例 #4
0
 @Override
 public UploadRequestEntry createUploadRequestEntry(
     String uploadRequestUrlUuid, InputStream fi, String fileName, String password)
     throws BusinessException {
   // Retrieve upload request URL
   UploadRequestUrl requestUrl = find(uploadRequestUrlUuid, password);
   // HOOK : Extract owner for upload request URL
   Account owner = requestUrl.getUploadRequest().getOwner();
   // Store the file into the owner account.
   DocumentEntry document = documentEntryService.createDocumentEntry(owner, fi, fileName);
   createBusinessCheck(requestUrl, document);
   Account actor = accountRepository.getUploadRequestSystemAccount();
   // Create the link between the document and the upload request URL.
   UploadRequestEntry uploadRequestEntry =
       new UploadRequestEntry(document, requestUrl.getUploadRequest());
   UploadRequestEntry requestEntry = uploadRequestEntryBusinessService.create(uploadRequestEntry);
   MailContainerWithRecipient mail =
       mailBuildingService.buildAckUploadRequest(
           (User) requestUrl.getUploadRequest().getOwner(), requestUrl, requestEntry);
   notifierService.sendNotification(mail);
   return requestEntry;
 }
コード例 #5
0
 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.");
     }
   }
 }
コード例 #6
0
 @Override
 public void deleteUploadRequestEntry(
     String uploadRequestUrlUuid, String password, String entryUuid) throws BusinessException {
   UploadRequestUrl requestUrl = find(uploadRequestUrlUuid, password);
   deleteBusinessCheck(requestUrl);
   Set<UploadRequestEntry> entries = requestUrl.getUploadRequest().getUploadRequestEntries();
   UploadRequestEntry found = null;
   for (UploadRequestEntry entry : entries) {
     if (entry.getUuid().equals(entryUuid)) {
       found = entry;
       break;
     }
   }
   if (found != null) {
     String documentEntryUuid = null;
     if (found.getDocumentEntry() != null) {
       documentEntryUuid = found.getDocumentEntry().getUuid();
     }
     found.setDocumentEntry(null);
     found = uploadRequestEntryBusinessService.update(found);
     if (documentEntryUuid != null) {
       // TODO: HOOK : Extract owner for upload request URL
       // Actor should be used instead of owner
       Account owner = requestUrl.getUploadRequest().getOwner();
       // Store the file into the owner account.
       DocumentEntry documentEntry = documentEntryService.findById(owner, documentEntryUuid);
       documentEntryService.deleteDocumentEntry(owner, documentEntry);
     }
     uploadRequestEntryBusinessService.delete(found);
   } else {
     throw new BusinessException(
         BusinessErrorCode.FORBIDDEN,
         "You do not have the right to delete a file into upload request : "
             + uploadRequestUrlUuid);
   }
 }