public void insertAuditLog(
      AuditAction action, String details, HttpServletRequest request, String recid, String extraid)
      throws ServiceException {
    try {
      User user =
          (User) hibernateTemplate.load(User.class, sessionHandlerImplObj.getUserid(request));
      String ipaddr = null;
      if (StringUtil.isNullOrEmpty(request.getHeader("x-real-ip"))) {
        ipaddr = request.getRemoteAddr();
      } else {
        ipaddr = request.getHeader("x-real-ip");
      }

      insertAuditLog(action, details, ipaddr, user, recid, extraid);
    } catch (Exception e) {
      throw ServiceException.FAILURE(e.getMessage(), e);
    }
  }
  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());
  }