コード例 #1
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.");
     }
   }
 }
コード例 #2
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);
   }
 }