/**
   * @param accessCode - строковой код доступа к документу
   * @param organID - номер-�?Д субьекта-органа оператора документа
   * @param docTypeID - номер-�?Д типа документа (опционально)
   * @param password - строка-пароль (опционально)
   */
  @RequestMapping(
      value = "/getDocumentAccessByHandler",
      method = RequestMethod.GET,
      headers = {"Accept=application/json"})
  public @ResponseBody Document getDocumentAccessByHandler(
      @RequestParam(value = "sCode_DocumentAccess") String accessCode,
      @RequestParam(value = "nID_DocumentOperator_SubjectOrgan") Long organID,
      @RequestParam(value = "nID_DocumentType", required = false) Long docTypeID,
      @RequestParam(value = "sPass", required = false) String password,
      HttpServletResponse resp) {

    Document document =
        handlerFactory
            .buildHandlerFor(documentDao.getOperator(organID))
            .setDocumentType(docTypeID)
            .setAccessCode(accessCode)
            .setPassword(password)
            .getDocument();
    try {
      createHistoryEvent(
          HistoryEventType.GET_DOCUMENT_ACCESS_BY_HANDLER,
          document.getSubject().getId(),
          subjectOrganDao.getSubjectOrgan(organID).getName(),
          null,
          document);
    } catch (Exception e) {
      log.warn("can`t create history event!", e);
    }
    return document;
  }
  @RequestMapping(value = "/getDocumentFile", method = RequestMethod.GET)
  public @ResponseBody byte[] getDocumentFile(
      @RequestParam(value = "nID") Long id,
      @RequestParam(value = "nID_Subject") long nID_Subject,
      @RequestParam(value = "sCode_DocumentAccess", required = false) String accessCode,
      @RequestParam(value = "nID_DocumentOperator_SubjectOrgan", required = false) Long organID,
      @RequestParam(value = "nID_DocumentType", required = false) Long docTypeID,
      @RequestParam(value = "sPass", required = false) String password,
      HttpServletRequest request,
      HttpServletResponse httpResponse)
      throws ActivitiRestException {
    Document document = documentDao.getDocument(id);
    if (nID_Subject != document.getSubject().getId()) {

      if (accessCode != null) {
        Document oDocument =
            handlerFactory
                .buildHandlerFor(documentDao.getOperator(organID))
                .setDocumentType(docTypeID)
                .setAccessCode(accessCode)
                .setPassword(password)
                .getDocument();
        if (oDocument == null) {
          throw new ActivitiRestException("401", "You don't have access by accessCode!");
        }
      } else {
        throw new ActivitiRestException("401", "You don't have access!");
      }
    }
    byte[] content = documentDao.getDocumentContent(document.getContentKey());
    // byte[] content = "".getBytes();

    httpResponse.setHeader("Content-disposition", "attachment; filename=" + document.getFile());
    // httpResponse.setHeader("Content-Type", document.getDocumentContentType()
    //		.getName() + ";charset=UTF-8");
    httpResponse.setHeader("Content-Type", document.getContentType() + ";charset=UTF-8");
    httpResponse.setContentLength(content.length);
    return content;
  }