@Override
  public Long getUserAvailableSize(UserVo userVo) throws BusinessException {
    Account account = accountService.findByLsUuid(userVo.getLsUuid());

    return Math.min(
        documentEntryService.getAvailableSize(account),
        documentEntryService.getUserMaxFileSize(account));
  }
 @Override
 public DocumentVo decryptDocument(DocumentVo docVo, UserVo userVo, String password)
     throws BusinessException {
   Account actor = accountService.findByLsUuid(userVo.getLsUuid());
   DocumentEntry documentEntry =
       enciphermentService.decryptDocument(actor, docVo.getIdentifier(), actor, password);
   return documentEntryTransformer.disassemble(documentEntry);
 }
 @Override
 public void removeDocument(UserVo actorVo, DocumentVo document) throws BusinessException {
   Account actor = accountService.findByLsUuid(actorVo.getLsUuid());
   if (actor != null) {
     entryService.deleteAllShareEntriesWithDocumentEntry(actor, document.getIdentifier());
   } else {
     throw new BusinessException(BusinessErrorCode.USER_NOT_FOUND, "The user couldn't be found");
   }
 }
 @Override
 public void renameFile(String userlogin, String docEntryUuid, String newName) {
   Account actor = accountService.findByLsUuid(userlogin);
   try {
     documentEntryService.renameDocumentEntry(actor, docEntryUuid, newName);
   } catch (BusinessException e) {
     logger.error("Can't rename document : " + docEntryUuid + " : " + e.getMessage());
   }
 }
 @Override
 public DocumentVo insertFile(InputStream in, String fileName, UserVo owner)
     throws BusinessException {
   logger.debug("insert files for document entries");
   Account actor = accountService.findByLsUuid(owner.getLsUuid());
   fileName = fileName.replace("\\", "_");
   fileName = fileName.replace(":", "_");
   DocumentEntry createDocumentEntry =
       documentEntryService.createDocumentEntry(actor, in, fileName);
   return documentEntryTransformer.disassemble(createDocumentEntry);
 }
 @Override
 public List<SignatureVo> getAllSignatures(UserVo userVo, DocumentVo documentVo) {
   Account actor = accountService.findByLsUuid(userVo.getLsUuid());
   try {
     DocumentEntry document = documentEntryService.findById(actor, documentVo.getIdentifier());
     return signatureTransformer.disassembleList(
         new ArrayList<Signature>(document.getDocument().getSignatures()));
   } catch (BusinessException e) {
     logger.error("Can't find document : " + documentVo.getIdentifier() + ": " + e.getMessage());
   }
   return null;
 }
 @Override
 public MimeTypeStatus getMimeTypeStatus(String login, String uuid) {
   Account actor = accountService.findByLsUuid(login);
   if (actor != null) {
     DocumentEntry entry;
     try {
       entry = documentEntryService.findById(actor, uuid);
       return documentEntryService.getDocumentMimeTypeStatus(entry);
     } catch (BusinessException e) {
       logger.error("can't get document : " + e.getMessage());
     }
   }
   return null;
 }
  @Override
  public boolean documentHasThumbnail(String actorUuid, String docEntryUuid) {
    if (actorUuid == null) {
      logger.error("Can't find user with null parameter.");
      return false;
    }

    Account actor = accountService.findByLsUuid(actorUuid);
    if (actor == null) {
      logger.error("Can't find logged user.");
      return false;
    }
    return documentEntryService.documentHasThumbnail(actor, docEntryUuid);
  }
 @Override
 public void updateFileProperties(
     String userlogin, String docEntryUuid, String newName, String comment) {
   Account actor = accountService.findByLsUuid(userlogin);
   if (comment == null) {
     comment = "";
   }
   try {
     documentEntryService.updateFileProperties(actor, docEntryUuid, newName, comment);
   } catch (BusinessException e) {
     logger.error(
         "Can't update file properties document : " + docEntryUuid + " : " + e.getMessage());
   }
 }
 @Override
 public DocumentVo getDocument(String login, String uuid) {
   Account actor = accountService.findByLsUuid(login);
   if (actor != null) {
     DocumentEntry entry;
     try {
       entry = documentEntryService.findById(actor, uuid);
       return documentEntryTransformer.disassemble(entry);
     } catch (BusinessException e) {
       logger.error("can't get document : " + e.getMessage());
     }
   }
   return null;
 }
 @Override
 public void insertSignatureFile(
     InputStream file,
     long size,
     String fileName,
     UserVo ownerVo,
     DocumentVo documentVo,
     X509Certificate signerCertificate)
     throws BusinessException {
   Account actor = accountService.findByLsUuid(ownerVo.getLsUuid());
   DocumentEntry documentEntry = documentEntryService.findById(actor, documentVo.getIdentifier());
   signatureService.createSignature(
       actor, documentEntry.getDocument(), file, size, fileName, signerCertificate);
 }
 @Override
 public boolean isSignedDocument(String userLsUuid, DocumentVo documentVo) {
   // Fix me : just write a finder
   boolean res = false;
   Account actor = accountService.findByLsUuid(userLsUuid);
   try {
     DocumentEntry document = documentEntryService.findById(actor, documentVo.getIdentifier());
     Set<Signature> signatures = document.getDocument().getSignatures();
     if (signatures != null && signatures.size() > 0) res = true;
   } catch (BusinessException e) {
     logger.error("Can't find document : " + documentVo.getIdentifier() + ": " + e.getMessage());
   }
   return res;
 }
  @Override
  public boolean isSignedDocumentByCurrentUser(UserVo currentSigner, DocumentVo documentVo)
      throws BusinessException {

    Account actor = accountService.findByLsUuid(currentSigner.getLsUuid());
    DocumentEntry doc = documentEntryService.findById(actor, documentVo.getIdentifier());
    Set<Signature> signatures = doc.getDocument().getSignatures();

    boolean res = false;

    for (Signature signature : signatures) {
      if (signature.getSigner().equals(actor)) {
        res = true;
        break;
      }
    }

    return res;
  }
  @Override
  public SignatureVo getSignature(UserVo currentSigner, DocumentVo documentVo) {
    Account actor = accountService.findByLsUuid(currentSigner.getLsUuid());
    try {
      DocumentEntry document = documentEntryService.findById(actor, documentVo.getIdentifier());
      SignatureVo res = null;
      for (Signature signature : document.getDocument().getSignatures()) {
        if (signature.getSigner().equals(actor)) {
          res = signatureTransformer.disassemble(signature);
          break;
        }
      }
      return res;

    } catch (BusinessException e) {
      logger.error("Can't find document : " + documentVo.getIdentifier() + ": " + e.getMessage());
    }
    return null;
  }
  @Override
  public InputStream getDocumentThumbnail(String actorUuid, String docEntryUuid) {
    if (actorUuid == null) {
      logger.error("Can't find user with null parameter.");
      return null;
    }

    Account actor = accountService.findByLsUuid(actorUuid);
    if (actor == null) {
      logger.error("Can't find logged user.");
      return null;
    }

    try {
      return documentEntryService.getDocumentThumbnailStream(actor, docEntryUuid);
    } catch (BusinessException e) {
      logger.error("Can't get document thumbnail : " + docEntryUuid + " : " + e.getMessage());
    }
    return null;
  }
  @Override
  public DocumentVo updateDocumentContent(
      String currentFileUUID,
      InputStream file,
      long size,
      String fileName,
      UserVo ownerVo,
      String friendlySize)
      throws BusinessException {
    Account actor = accountService.findByLsUuid(ownerVo.getLsUuid());

    DocumentEntry originalEntry = documentEntryService.findById(actor, currentFileUUID);
    String originalFileName = originalEntry.getName();

    DocumentEntry documentEntry =
        documentEntryService.updateDocumentEntry(actor, currentFileUUID, file, size, fileName);
    if (documentEntry.isShared()) {
      // send email, file has been replaced ....
      entryService.sendSharedUpdateDocNotification(documentEntry, friendlySize, originalFileName);
    }

    return documentEntryTransformer.disassemble(documentEntry);
  }
 @Override
 public Long getGlobalQuota(UserVo userVo) throws BusinessException {
   Account actor = accountService.findByLsUuid(userVo.getLsUuid());
   return documentEntryService.getGlobalQuota(actor);
 }
 @Override
 public boolean isUserQuotaActive(UserVo userVo) throws BusinessException {
   Account actor = accountService.findByLsUuid(userVo.getLsUuid());
   return documentEntryService.isUserQuotaActive(actor);
 }
 @Override
 public boolean isEnciphermentActive(UserVo userVo) {
   Account actor = accountService.findByLsUuid(userVo.getLsUuid());
   return documentEntryService.isEnciphermentActive(actor);
 }
 @Override
 public Long getUserTotalQuota(UserVo userVo) throws BusinessException {
   Account account = accountService.findByLsUuid(userVo.getLsUuid());
   return documentEntryService.getTotalSize(account);
 }
 @Override
 public InputStream retrieveFileStream(DocumentVo doc, String lsUid) throws BusinessException {
   Account actor = accountService.findByLsUuid(lsUid);
   return documentEntryService.getDocumentStream(actor, doc.getIdentifier());
 }