public ModelAndView downloadDocuments(HttpServletRequest request, HttpServletResponse response)
      throws ServletException {
    JSONObject jobj = new JSONObject();
    JSONObject myjobj = new JSONObject();
    KwlReturnObject kmsg = null;
    String details = "";
    String auditAction = "";
    try {
      String url = request.getParameter("url");
      url = StringUtil.checkForNull(url);
      String applicant = request.getParameter("applicant");
      applicant = StringUtil.checkForNull(applicant);
      Hashtable ht;
      if (applicant.equalsIgnoreCase("applicant")) {
        kmsg = hrmsExtApplDocsDAOObj.downloadDocument(url);
        ht = getExtDocumentDownloadHash(kmsg.getEntityList());
      } else {
        kmsg = documentDAOObj.downloadDocument(url);
        ht = getDocumentDownloadHash(kmsg.getEntityList());
      }

      String src = storageHandlerImplObj.GetDocStorePath();
      //            String src = "/home/trainee/";
      if (request.getParameter("mailattch") != null) {
        src = src + ht.get("svnname");
      } else {
        src = src + ht.get("userid").toString() + "/" + ht.get("svnname");
      }

      File fp = new File(src);
      byte[] buff = new byte[(int) fp.length()];
      FileInputStream fis = new FileInputStream(fp);
      int read = fis.read(buff);
      javax.activation.FileTypeMap mmap = new javax.activation.MimetypesFileTypeMap();
      response.setContentType(mmap.getContentType(src));
      response.setContentLength((int) fp.length());
      response.setHeader(
          "Content-Disposition",
          request.getParameter("dtype") + "; filename=\"" + ht.get("Name") + "\";");
      response.getOutputStream().write(buff);
      response.getOutputStream().flush();
      response.getOutputStream().close();
      String map = ht.get("relatedto").toString();
      String refid = ht.get("recid").toString();

      myjobj.put("success", true);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
  }
  public HashMap getDocInfo(KwlReturnObject kmsg, storageHandlerImpl storageHandlerObj)
      throws ServiceException {
    HashMap ht = null;
    Hashtable htable;
    if (kmsg.getEntityList().size() != 0) {
      htable = getExtDocumentDownloadHash(kmsg.getEntityList());
      ht = new HashMap();
      String src = storageHandlerObj.GetDocStorePath();
      src = src + htable.get("svnname");
      try {
        File fp = new File(src);

        ht.put("attachment", src);
        ht.put("filename", htable.get("Name"));
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
    return ht;
  }
  public ModelAndView getDocs(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jobj = new JSONObject();
    JSONObject jobj1 = new JSONObject();
    KwlReturnObject kmsg = null;
    KwlReturnObject result = null;
    try {

      HashMap<String, Object> requestParams = new HashMap<String, Object>();
      ArrayList filter_names = new ArrayList(), filter_values = new ArrayList();
      JSONArray jarr = new JSONArray();
      String userid = "";
      int start, limit;

      userid = request.getParameter("userid");
      String currentuser = AuthHandler.getUserid(request);
      String ss = request.getParameter("ss");
      if (request.getParameter("start") == null) {
        start = 0;
        limit = 15;
      } else {
        start = Integer.parseInt(request.getParameter("start"));
        limit = Integer.parseInt(request.getParameter("limit"));
      }

      if (request.getParameter("applicant").equalsIgnoreCase("applicant")) {

        filter_names.add("recid");
        filter_values.add(userid);

        filter_names.add("docid.deleted");
        filter_values.add(false);

        filter_names.add("docid.referenceid");
        filter_values.add(userid);

        requestParams.put("filter_names", filter_names);
        requestParams.put("filter_values", filter_values);
        requestParams.put("ss", ss);
        requestParams.put("searchcol", new String[] {"docid.docname", "docid.docdesc"});
        requestParams.put("start", start);
        requestParams.put("limit", limit);
        requestParams.put("allflag", false);
        result = hrmsExtApplDocsDAOObj.getDocs(requestParams);

        Iterator ite = result.getEntityList().iterator();
        while (ite.hasNext()) {
          HrmsDocmap docs = (HrmsDocmap) ite.next();
          JSONObject tmpObj = new JSONObject();
          tmpObj.put("docid", docs.getDocid().getDocid());
          tmpObj.put("docname", docs.getDocid().getDocname());
          tmpObj.put("docdesc", docs.getDocid().getDocdesc());
          tmpObj.put("uploadedby", docs.getDocid().getUploadedby());
          Float dsize = Math.max(0, Float.parseFloat(docs.getDocid().getDocsize()) / 1024);
          tmpObj.put("docsize", String.valueOf(dsize));
          tmpObj.put(
              "uploaddate",
              AuthHandler.getDateFormatter(request).format(docs.getDocid().getUploadedon()));
          jarr.put(tmpObj);
        }

      } else {
        filter_names.add("recid");
        filter_values.add(userid);

        filter_names.add("docid.deleteflag");
        filter_values.add(0);

        requestParams.put("filter_names", filter_names);
        requestParams.put("filter_values", filter_values);
        requestParams.put("ss", ss);
        requestParams.put("searchcol", new String[] {"docid.docname", "docid.docdesc"});
        requestParams.put("start", start);
        requestParams.put("limit", limit);
        requestParams.put("allflag", false);

        result = documentDAOObj.getDocs(requestParams);

        Iterator ite = result.getEntityList().iterator();
        while (ite.hasNext()) {
          Docmap docs = (Docmap) ite.next();
          JSONObject tmpObj = new JSONObject();
          tmpObj.put("docid", docs.getDocid().getDocid());
          tmpObj.put("docname", docs.getDocid().getDocname());
          tmpObj.put("docdesc", docs.getDocid().getDocdesc());
          tmpObj.put(
              "uploadedby",
              docs.getDocid().getUserid().getFirstName()
                  + " "
                  + docs.getDocid().getUserid().getLastName());
          Float dsize = Math.max(0, Float.parseFloat(docs.getDocid().getDocsize()) / 1024);
          tmpObj.put("docsize", String.valueOf(dsize));
          tmpObj.put(
              "uploaddate",
              AuthHandler.getDateFormatter(request).format(docs.getDocid().getUploadedon()));
          jarr.put(tmpObj);
        }
      }
      jobj.put("data", jarr);
      jobj.put("count", result.getRecordTotalCount());
      jobj1.put("data", jobj.toString());
      jobj1.put("valid", true);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return new ModelAndView("jsonView", "model", jobj1.toString());
  }
  public ModelAndView addDocuments(HttpServletRequest request, HttpServletResponse response)
      throws ServletException {
    JSONObject jobj = new JSONObject();
    JSONObject myjobj = new JSONObject();
    List fileItems = null;
    KwlReturnObject kmsg = null;
    String auditAction = "";
    boolean applicant = false;
    String id = java.util.UUID.randomUUID().toString();
    PrintWriter out = null;
    // Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
      response.setContentType("text/html;charset=UTF-8");
      out = response.getWriter();
      String userid = sessionHandlerImplObj.getUserid(request);
      String map = request.getParameter("mapid");
      HashMap<String, String> arrParam = new HashMap<String, String>();
      boolean fileUpload = false;
      String docdesc;
      ArrayList<FileItem> fi = new ArrayList<FileItem>();
      if (request.getParameter("fileAdd") != null) {
        DiskFileUpload fu = new DiskFileUpload();
        fileItems = fu.parseRequest(request);
        documentDAOObj.parseRequest(fileItems, arrParam, fi, fileUpload);
        arrParam.put("IsIE", request.getParameter("IsIE"));
        if (arrParam.get("applicantid").equalsIgnoreCase("applicant")) {
          applicant = true;
          userid = arrParam.get("refid");
        }
        if (StringUtil.isNullOrEmpty((String) arrParam.get("docdesc")) == false) {
          docdesc = (String) arrParam.get("docdesc");
        }
      }
      for (int cnt = 0; cnt < fi.size(); cnt++) {
        String docID;
        if (applicant) {
          kmsg =
              hrmsExtApplDocsDAOObj.uploadFile(
                  fi.get(cnt),
                  userid,
                  arrParam,
                  profileHandlerDAOObj.getUserFullName(sessionHandlerImplObj.getUserid(request)));
          HrmsDocs doc = (HrmsDocs) kmsg.getEntityList().get(0);
          docID = doc.getDocid();
        } else {
          kmsg = documentDAOObj.uploadFile(fi.get(cnt), userid, arrParam);
          Docs doc = (Docs) kmsg.getEntityList().get(0);
          docID = doc.getDocid();
        }

        String companyID = sessionHandlerImplObj.getCompanyid(request);
        String userID = sessionHandlerImplObj.getUserid(request);
        String refid = arrParam.get("refid");
        jobj.put("userid", userID);
        jobj.put("docid", docID);
        jobj.put("companyid", companyID);
        jobj.put("id", id);
        jobj.put("map", map);
        jobj.put("refid", refid);
        if (arrParam.get("applicantid").equalsIgnoreCase("applicant")) {
          hrmsExtApplDocsDAOObj.saveDocumentMapping(jobj);
        } else {
          documentDAOObj.saveDocumentMapping(jobj);
        }
      }
      myjobj.put("ID", id);
      txnManager.commit(status);
    } catch (Exception e) {
      System.out.println(e.getMessage());
      txnManager.rollback(status);
    } finally {
      out.close();
    }
    return new ModelAndView("jsonView", "model", myjobj.toString());
  }