Ejemplo n.º 1
0
  @RequestMapping(value = "/setDocument", method = RequestMethod.GET)
  public @ResponseBody Long setDocument(
      @RequestParam(value = "nID_Subject", required = false) long nID_Subject,
      @RequestParam(value = "sID_Subject_Upload") String sID_Subject_Upload,
      @RequestParam(value = "sSubjectName_Upload") String sSubjectName_Upload,
      @RequestParam(value = "sName") String sName,
      // @RequestParam(value = "sFile", required = false) String fileName,
      @RequestParam(value = "nID_DocumentType") Long nID_DocumentType,
      // @RequestParam(value = "nID_DocumentContentType", required = false) Integer
      // nID_DocumentContentType,
      @RequestParam(value = "sDocumentContentType", required = false)
          String documentContentTypeName,
      @RequestParam(value = "soDocumentContent") String sContent,
      @RequestParam(value = "oSignData") String oSignData, // todo required?? (issue587)
      // @RequestParam(value = "oFile", required = false) MultipartFile oFile,
      // @RequestBody byte[] content,
      HttpServletRequest request,
      HttpServletResponse httpResponse)
      throws IOException {

    // MultipartFile oFile = new MockMultipartFile("filename.txt", "fullfilename.txt", "text/plain",
    // sContent.getBytes());
    String sFileName = "filename.txt";
    String sFileContentType = "text/plain";
    byte[] aoContent = sContent.getBytes();

    documentContentTypeName =
        request.getHeader("Content-Type") != null
            ? request.getHeader("filename")
            : documentContentTypeName;
    DocumentContentType documentContentType = null;
    if (documentContentTypeName != null) {
      documentContentType = documentContentTypeDao.getDocumentContentType(documentContentTypeName);
      if (documentContentType == null) {
        documentContentType = new DocumentContentType();
        documentContentType.setName(documentContentTypeName);
        documentContentType.setId(documentContentTypeDao.setDocumentContent(documentContentType));
      }
    } else {
      throw new ActivitiObjectNotFoundException(
          "RequestParam 'nID_DocumentContentType' not found!", DocumentContentType.class);
    }

    Subject subject_Upload = syncSubject_Upload(sID_Subject_Upload);

    return documentDao.setDocument(
        nID_Subject,
        subject_Upload.getId(),
        sID_Subject_Upload,
        sSubjectName_Upload,
        sName,
        nID_DocumentType,
        documentContentType.getId(),
        sFileName,
        sFileContentType,
        aoContent,
        oSignData);
  }
Ejemplo n.º 2
0
  @RequestMapping(value = "/setDocumentFile", method = RequestMethod.POST)
  public @ResponseBody Long setDocumentFile(
      @RequestParam(value = "nID_Subject", required = false) long nID_Subject,
      @RequestParam(value = "sID_Subject_Upload") String sID_Subject_Upload,
      @RequestParam(value = "sSubjectName_Upload") String sSubjectName_Upload,
      @RequestParam(value = "sName") String sName,
      @RequestParam(value = "sFileExtension", required = false) String sFileExtension,
      // @RequestParam(value = "sFile", required = false) String fileName,
      @RequestParam(value = "nID_DocumentType") Long nID_DocumentType,
      @RequestParam(value = "nID_DocumentContentType", required = false)
          Long nID_DocumentContentType,
      @RequestParam(value = "oFile", required = true) MultipartFile oFile,
      @RequestParam(value = "oSignData") String oSignData, // todo required?? (issue587)
      // @RequestBody byte[] content,
      HttpServletRequest request,
      HttpServletResponse httpResponse)
      throws IOException {

    // String sFileName = oFile.getName();
    // String sFileName = oFile.getOriginalFilename();
    // Content-Disposition:attachment; filename=passport.zip
    String sFileName = request.getHeader("filename");
    if (sFileName == null || "".equals(sFileName.trim())) {
      // sFileName = oFile.getOriginalFilename()+".zip";
      String sOriginalFileName = oFile.getOriginalFilename();
      String sOriginalContentType = oFile.getContentType();
      log.info("sFileExtension=" + sFileExtension);
      log.info("sOriginalFileName=" + sOriginalFileName);
      log.info("sOriginalContentType=" + sOriginalContentType);
      // for(String s : request.getHeaderNames()){
      Enumeration<String> a = request.getHeaderNames();
      for (int n = 0; a.hasMoreElements() && n < 100; n++) {
        String s = a.nextElement();
        log.info("n=" + n + ", s=" + s + ", value=" + request.getHeader(s));
      }
      String fileExp = RedisUtil.getFileExp(sOriginalFileName);
      fileExp = fileExp != null ? fileExp : ".zip.zip";
      // fileExp = fileExp.equalsIgnoreCase(sOriginalFileName) ? ".zip" : fileExp;
      fileExp = fileExp.equalsIgnoreCase(sOriginalFileName) ? sFileExtension : fileExp;
      fileExp = fileExp != null ? fileExp.toLowerCase() : ".zip";
      sFileName = sOriginalFileName + (fileExp.startsWith(".") ? "" : ".") + fileExp;
      log.info("sFileName=" + sFileName);
    }
    String sFileContentType = oFile.getContentType();
    byte[] aoContent = oFile.getBytes();

    Subject subject_Upload = syncSubject_Upload(sID_Subject_Upload);
    Long nID_Document =
        documentDao.setDocument(
            nID_Subject,
            subject_Upload.getId(),
            sID_Subject_Upload,
            sSubjectName_Upload,
            sName,
            nID_DocumentType,
            nID_DocumentContentType,
            sFileName,
            sFileContentType,
            aoContent,
            oSignData);
    createHistoryEvent(
        HistoryEventType.SET_DOCUMENT_INTERNAL,
        nID_Subject,
        sSubjectName_Upload,
        nID_Document,
        null);
    return nID_Document;
  }