public KwlReturnObject getAuditDetails(HashMap<String, Object> requestParams)
     throws ServiceException {
   List ll = null;
   int dl = 0;
   try {
     StringBuffer usersList = null;
     if (requestParams.containsKey("userslist"))
       usersList = (StringBuffer) requestParams.get("userslist");
     String groups = requestParams.get("groups").toString();
     int start = Integer.parseInt(requestParams.get("start").toString());
     int limit = Integer.parseInt(requestParams.get("limit").toString());
     int interval = Integer.parseInt(requestParams.get("interval").toString());
     String query = "from AuditTrail at where";
     if (StringUtil.isNullOrEmpty(usersList.toString())) {
       query += " at.user.userID in (" + usersList + ")  and";
     }
     query +=
         " DATEDIFF(date(now()),date(at.auditTime)) <= ? and "
             + "at.action.auditGroup.groupName in ("
             + groups
             + ") order by at.auditTime desc";
     ll = HibernateUtil.executeQuery(hibernateTemplate, query, interval);
     dl = ll.size();
     ll =
         HibernateUtil.executeQueryPaging(
             hibernateTemplate, query, new Object[] {interval}, new Integer[] {start, limit});
   } catch (Exception e) {
     throw ServiceException.FAILURE(
         "auditTrailDAOImpl.getRecentActivityDetails : " + e.getMessage(), e);
   }
   return new KwlReturnObject(true, "002", "", ll, dl);
 }
  public KwlReturnObject getRecentActivityDetails(HashMap<String, Object> requestParams)
      throws ServiceException {
    List ll = null;
    int dl = 0;
    String recid = "";
    String companyid = "";
    try {
      if (requestParams.containsKey("recid") && requestParams.get("recid") != null) {
        recid = requestParams.get("recid").toString();
      }
      if (requestParams.containsKey("companyid") && requestParams.get("companyid") != null) {
        companyid = requestParams.get("companyid").toString();
      }
      String query =
          "from AuditTrail where user.company.companyID=? and recid=? order by auditTime desc";
      ll =
          HibernateUtil.executeQueryPaging(
              hibernateTemplate, query, new Object[] {companyid, recid}, new Integer[] {0, 15});
      dl = ll.size();

    } catch (Exception e) {
      throw ServiceException.FAILURE(
          "detailPanelDAOImpl.getRecentActivityDetails : " + e.getMessage(), e);
    }
    return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
  }
  public KwlReturnObject getDocumentList(
      HashMap<String, Object> requestParams, StringBuffer usersList) throws ServiceException {
    String tagSearch = requestParams.containsKey("tag") ? requestParams.get("tag").toString() : "";
    String quickSearch = requestParams.containsKey("ss") ? requestParams.get("ss").toString() : "";
    int start = 0;
    int limit = 20;
    int dl = 0;
    Object[] params = null;
    if (requestParams.containsKey("start")
        && requestParams.containsKey("limit")
        && !StringUtil.isNullOrEmpty(requestParams.get("start").toString())) {
      start = Integer.parseInt(requestParams.get("start").toString());
      limit = Integer.parseInt(requestParams.get("limit").toString());
    }
    List ll = null;
    try {
      String companyid = requestParams.get("companyid").toString();
      String Hql =
          "select c from com.krawler.common.admin.Docmap c where c.docid.company.companyID=? ";
      params = new Object[] {companyid};

      if (!StringUtil.isNullOrEmpty(tagSearch)) {
        tagSearch = tagSearch.replaceAll("'", "");
        Hql += " and c.docid.tags like '%" + tagSearch + "%' ";
      }
      if (!StringUtil.isNullOrEmpty(quickSearch)) {
        Hql += " and c.docid.docname like '" + quickSearch + "%' ";
      }

      String selectInQuery =
          Hql
              + " and c.docid.userid.userID in ("
              + usersList
              + ") order by c.docid.uploadedon desc ";
      ll = HibernateUtil.executeQuery(hibernateTemplate, selectInQuery, params);
      dl = ll.size();

      ll =
          HibernateUtil.executeQueryPaging(
              hibernateTemplate, selectInQuery, params, new Integer[] {start, limit});
    } catch (ServiceException ex) {
      throw ServiceException.FAILURE("documentDAOImpl.getDocumentList", ex);
    }
    return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
  }
 public KwlReturnObject getCompanyTypes() throws ServiceException {
   List ll = new ArrayList();
   try {
     String query = "from CompanyType";
     ll = HibernateUtil.executeQuery(hibernateTemplate, query);
   } catch (Exception e) {
     throw ServiceException.FAILURE("AccCommonTablesDAOImpl.getCompanyTypes", e);
   }
   return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, ll.size());
 }
 public KwlReturnObject getDocumentsForTable(HashMap<String, Object> queryParams, boolean allflag)
     throws ServiceException {
   KwlReturnObject kmsg = null;
   try {
     kmsg = HibernateUtil.getTableData(hibernateTemplate, queryParams, allflag);
   } catch (Exception e) {
     throw ServiceException.FAILURE("documentDAOImpl.getDocumentsForTable : " + e.getMessage(), e);
   }
   return kmsg;
 }
 public KwlReturnObject getAuditGroupData() throws ServiceException {
   List ll = null;
   int dl = 0;
   try {
     String query =
         "from AuditGroup where groupName not in ('User', 'Company', 'Log in', 'Log out')";
     ll = HibernateUtil.executeQuery(hibernateTemplate, query);
     dl = ll.size();
   } catch (Exception e) {
     throw ServiceException.FAILURE(e.getMessage(), e);
   }
   return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
 }
  public KwlReturnObject documentSearch(HashMap<String, Object> requestParams)
      throws ServiceException {
    List ll = null;
    int dl = 0;
    String MyQuery1 = "";
    String MyQuery = "";
    String querytxt = "";
    String companyid = "";
    try {
      if (requestParams.containsKey("companyid") && requestParams.get("companyid") != null) {
        companyid = requestParams.get("companyid").toString();
      }
      if (requestParams.containsKey("keyword") && requestParams.get("keyword") != null) {
        querytxt = requestParams.get("keyword").toString();
      }

      Pattern p = Pattern.compile("^(?i)tag:[[\\s]*([\\w\\s]+[(/|\\{1})]?)*[\\s]*[\\w]+[\\s]*]*$");
      Matcher m = p.matcher(querytxt);
      boolean b = m.matches();
      ArrayList filter_params = new ArrayList();

      if (!b) {
        MyQuery = querytxt;
        MyQuery1 = querytxt;
        if (querytxt.length() > 2) {
          MyQuery = querytxt + "%";
          MyQuery1 = "% " + MyQuery;
        }
        String Hql =
            "select c from com.krawler.common.admin.Docs c  where c.company.companyID=? and c.deleteflag=0";
        Hql =
            Hql
                + "and ( c.docname like ? or c.docsize like ? or c.doctype like ? or c.userid.firstName like ? or c.userid.lastName like ? ) ";
        filter_params.add(companyid);
        filter_params.add(MyQuery);
        filter_params.add(MyQuery);
        filter_params.add(MyQuery);
        filter_params.add(MyQuery);
        filter_params.add(MyQuery);

        ll = HibernateUtil.executeQuery(hibernateTemplate, Hql, filter_params.toArray());
        dl = ll.size();
      }
    } catch (ServiceException e) {
      throw ServiceException.FAILURE("documentDAOImpl.documentSearch", e);
    } catch (Exception e) {
      throw ServiceException.FAILURE("documentDAOImpl.documentSearch", e);
    }
    return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
  }
  public KwlReturnObject downloadDocument(String id) throws ServiceException {

    List ll = null;
    int dl = 0;
    try {
      ll =
          HibernateUtil.executeQuery(
              hibernateTemplate,
              "FROM " + "com.krawler.common.admin.Docmap AS crmdocs1 where crmdocs1.docid.docid =?",
              new Object[] {id});
      dl = ll.size();
    } catch (Exception e) {
      throw ServiceException.FAILURE(e.getMessage(), e);
    }
    return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
  }
 public KwlReturnObject getDocuments(HashMap<String, Object> requestParams)
     throws ServiceException {
   List ll = null;
   int dl = 0;
   String recid = "";
   try {
     if (requestParams.containsKey("recid") && requestParams.get("recid") != null) {
       recid = requestParams.get("recid").toString();
     }
     String Hql = "select dm.docid FROM com.krawler.common.admin.Docmap dm where dm.recid=? ";
     ll = HibernateUtil.executeQuery(hibernateTemplate, Hql, new Object[] {recid});
     dl = ll.size();
   } catch (Exception e) {
     throw ServiceException.FAILURE("documentDAOImpl.getDocuments : " + e.getMessage(), e);
   }
   return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
 }
  public KwlReturnObject getAuditData(HashMap<String, Object> requestParams)
      throws ServiceException {
    int start = 0;
    int limit = 30;
    String groupid = "";
    String searchtext = "";
    String companyid = "";
    List ll = null;
    int dl = 0;
    try {
      if (requestParams.containsKey("start")
          && requestParams.containsKey("limit")
          && !StringUtil.isNullOrEmpty(requestParams.get("start").toString())) {
        start = Integer.parseInt(requestParams.get("start").toString());
        limit = Integer.parseInt(requestParams.get("limit").toString());
      }
      if (requestParams.containsKey("groupid") && requestParams.get("groupid") != null) {
        groupid = requestParams.get("groupid").toString();
      }
      if (requestParams.containsKey("search") && requestParams.get("search") != null) {
        searchtext = requestParams.get("search").toString();
      }
      if (requestParams.containsKey("companyid") && requestParams.get("companyid") != null) {
        companyid = requestParams.get("companyid").toString();
      }

      String auditID = "";
      if (searchtext.compareTo("") != 0) {
        String query2 = searchtext + "*";
        SearchBean bean = new SearchBean();
        String indexPath = storageHandlerImplObj.GetAuditTrailIndexPath();
        String[] searchWithIndex = {"details", "ipaddr", "username"};
        Hits hitResult = bean.skynetsearchMulti(query2, searchWithIndex, indexPath);
        if (hitResult != null) {
          Iterator itrH = hitResult.iterator();
          while (itrH.hasNext()) {
            Hit hit1 = (Hit) itrH.next();
            org.apache.lucene.document.Document doc = hit1.getDocument();
            auditID += "'" + doc.get("transactionid") + "',";
          }
          if (auditID.length() > 0) {
            auditID = auditID.substring(0, auditID.length() - 1);
          }
        }
      }

      if (groupid.compareTo("") != 0 && searchtext.compareTo("") != 0) {
        /* query for both gid and search  */
        if (auditID.length() > 0) {
          String query =
              "from AuditTrail where user.company.companyID=? and ID in ("
                  + auditID
                  + ") and action.auditGroup.ID = ? order by auditTime desc";
          ll =
              HibernateUtil.executeQuery(
                  hibernateTemplate, query, new Object[] {companyid, groupid});
          dl = ll.size();
          ll =
              HibernateUtil.executeQueryPaging(
                  hibernateTemplate,
                  query,
                  new Object[] {companyid, groupid},
                  new Integer[] {start, limit});
        } else {
          dl = 0;
          ll = new ArrayList();
        }
      } else if (groupid.compareTo("") != 0 && searchtext.compareTo("") == 0) {
        /* query only for gid  */
        String query =
            "from AuditTrail where user.company.companyID=? and action.auditGroup.ID = ? order by auditTime desc";
        ll =
            HibernateUtil.executeQuery(hibernateTemplate, query, new Object[] {companyid, groupid});
        dl = ll.size();
        ll =
            HibernateUtil.executeQueryPaging(
                hibernateTemplate,
                query,
                new Object[] {companyid, groupid},
                new Integer[] {start, limit});
      } else if (groupid.compareTo("") == 0 && searchtext.compareTo("") != 0) {
        /* query only for search  */
        if (auditID.length() > 0) {
          String query =
              "from AuditTrail where user.company.companyID=? and ID in ("
                  + auditID
                  + ")  order by auditTime desc";
          ll = HibernateUtil.executeQuery(hibernateTemplate, query, new Object[] {companyid});
          dl = ll.size();
          ll =
              HibernateUtil.executeQueryPaging(
                  hibernateTemplate, query, new Object[] {companyid}, new Integer[] {start, limit});
        } else {
          dl = 0;
          ll = new ArrayList();
        }
      } else {
        /* query for all  */
        String query = "from AuditTrail where user.company.companyID=?  order by auditTime desc";
        ll = HibernateUtil.executeQuery(hibernateTemplate, query, new Object[] {companyid});
        dl = ll != null ? ll.size() : 0;
        ll =
            HibernateUtil.executeQueryPaging(
                hibernateTemplate, query, new Object[] {companyid}, new Integer[] {start, limit});
      }
    } catch (IOException ex) {
      throw ServiceException.FAILURE(ex.getMessage(), ex);
    } catch (ServiceException ex) {
      throw ServiceException.FAILURE(ex.getMessage(), ex);
    } catch (Exception ex) {
      throw ServiceException.FAILURE(ex.getMessage(), ex);
    }
    return new KwlReturnObject(true, KwlReturnMsg.S01, "", ll, dl);
  }