public String getFormattedExpiryDate() {
   if (detailedUser.getExpirationDate() != null) {
     String dateFormat = messages.get("global.pattern.date");
     SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);
     return dateFormatter.format(detailedUser.getExpirationDate());
   } else {
     return "";
   }
 }
 public boolean isShowComment() {
   if (detailedUser.isGuest()) {
     if (detailedUser.getOwnerLogin().equals(userLoggedIn.getLogin())) {
       if ((detailedUser.getComment() != null) && (!detailedUser.getComment().equals(""))) {
         return true;
       }
     }
   }
   return false;
 }
 /* ***********************************************************
  *                   Event handlers&processing
  ************************************************************ */
 public Zone getShowUser(String mail) throws BusinessException {
   //        detailedUser =
   // userFacade.findUserFromAuthorizedDomainOnly(userLoggedIn.getDomainIdentifier(), mail);
   detailedUser = userFacade.loadUserDetails(mail, userLoggedIn.getDomainIdentifier());
   //        detailedUser = userFacade.searchUser(mail, "", "", userLoggedIn);
   return userDetailsTemplateZone;
 }
 @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 Long getUserAvailableSize(UserVo userVo) throws BusinessException {
    Account account = accountService.findByLsUuid(userVo.getLsUuid());

    return Math.min(
        documentEntryService.getAvailableSize(account),
        documentEntryService.getUserMaxFileSize(account));
  }
 @Override
 public List<String> autoCompleteMail(UserVo currentUserVo, String pattern)
     throws BusinessException {
   List<User> users = userService.autoCompleteUser(currentUserVo.getLogin(), pattern);
   logger.debug("nb result for completion : " + users.size());
   // TODO : FMA : Use database configuration for auto complete limit
   return getMailList(users, AUTO_COMPLETE_LIMIT);
 }
 @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 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);
 }
 public boolean getDisplayWidget() {
   if (!userVoExists) {
     return false;
   }
   if (isGuest) {
     return true;
   }
   if (globalQuota) {
     return userVo.isAdministrator();
   }
   return true;
 }
 @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 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 List<UserVo> autoCompleteUserSortedByFavorites(UserVo currentUserVo, String pattern)
      throws BusinessException {
    List<User> users = userService.autoCompleteUser(currentUserVo.getLogin(), pattern);
    logger.debug("nb result for completion : " + users.size());

    // TODO : FIXME : FMA : add favorite sort.
    // userSet.addAll(recipientFavouriteFacade.findRecipientFavorite(input,
    // userVo));
    // return recipientFavouriteFacade.recipientsOrderedByWeightDesc(new
    // ArrayList<UserVo>(userSet), userVo);

    // TODO : FMA : Use database configuration for auto complete limit
    return getUserVoList(users, AUTO_COMPLETE_LIMIT, true);
  }
  @SetupRender
  void setupRender() throws BusinessException {
    if (getDisplayWidget() && userVo != null && userVo.getDomainIdentifier() != null) {
      //			DomainVo domain = domainFacade.retrieveDomain(userVo.getDomainIdentifier());
      globalQuota = documentFacade.isGlobalQuotaActive(userVo);
      canUpload = userVo.isUpload();
      isGuest = userVo.isGuest();

      // the formater for the displayed date : we hide the timeline date, and add our date in the
      // description
      localisedDateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);

      if (canUpload) {

        if (!globalQuota) {
          long userAvailableQuota = documentFacade.getUserAvailableQuota(userVo);
          long userTotalQuota = documentFacade.getUserTotalQuota(userVo);
          long userUsedQuota = userTotalQuota - userAvailableQuota;

          if (userUsedQuota < 0) userUsedQuota = 0;
          if (userTotalQuota < 1) {
            usedQuotaPercent = 0;
          } else {
            usedQuotaPercent = (int) (100 * userUsedQuota / userTotalQuota);
            if (usedQuotaPercent > 100) usedQuotaPercent = 100;
          }

          FileUtils.Unit preferedUnity = FileUtils.getAppropriateUnitSize(userTotalQuota);
          usedQuota = FileUtils.getFriendlySize(userUsedQuota, messages, preferedUnity);
          totalQuota = FileUtils.getFriendlySize(userTotalQuota, messages, preferedUnity);
        } else {
          Long usedQuotaB = domainFacade.getUsedSpace(userVo.getDomainIdentifier());

          Long globalQuotaB = documentFacade.getGlobalQuota(userVo);
          FileUtils.Unit preferedUnity = FileUtils.getAppropriateUnitSize(globalQuotaB);
          usedQuota = FileUtils.getFriendlySize(usedQuotaB, messages, preferedUnity);
          totalQuota = FileUtils.getFriendlySize(globalQuotaB, messages, preferedUnity);
          if (usedQuotaB < 1) {
            usedQuotaPercent = 0;
          } else {
            usedQuotaPercent = (int) (100 * usedQuotaB / globalQuotaB);
            if (usedQuotaPercent > 100) usedQuotaPercent = 100;
          }
        }
      }

      if (isGuest) {
        if (userVo.getExpirationDate() != null)
          expirationDate = localisedDateFormat.format(userVo.getExpirationDate());
        else {
          logger.error("userVo.getExpirationDate() is null !");
          expirationDate = "Null";
        }
      }
    }
  }
  @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 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 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 getUserTotalQuota(UserVo userVo) throws BusinessException {
   Account account = accountService.findByLsUuid(userVo.getLsUuid());
   return documentEntryService.getTotalSize(account);
 }
 public String getUserComment() {
   return detailedUser.getComment();
 }
 @Override
 public InputStream retrieveFileStream(DocumentVo doc, UserVo actorVo) throws BusinessException {
   return retrieveFileStream(doc, actorVo.getLsUuid());
 }
 public boolean getDisplayGlobalQuota() {
   return globalQuota && userVo.isAdministrator();
 }
 @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);
 }