コード例 #1
0
 public static JSONObject getJsonForAction(
     Connection conn,
     PreparedStatement pstmt,
     ResultSet rs,
     HttpServletRequest request,
     String callerFlag)
     throws ServiceException {
   java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   JSONObject jobj = new JSONObject();
   ResultSet rs2 = null;
   try {
     int aid = rs.getInt("actionid");
     String author = AuthHandler.getAuthor(conn, rs.getString("actionby"));
     String params = rs.getString("params");
     String userparam[] = params.split(",");
     String query2 = "select textkey from actions where actionid = ?";
     pstmt = conn.prepareStatement(query2);
     pstmt.setInt(1, aid);
     rs2 = pstmt.executeQuery();
     Object[] strParam = new Object[userparam.length];
     for (int i = 0; i < userparam.length; i++) {
       strParam[i] = userparam[i];
     }
     rs2.next();
     String action = rs2.getString("textkey");
     String useraction = MessageSourceProxy.getMessage(action, strParam, request);
     String sdtStr =
         Timezone.toCompanyTimezone(
             conn, rs.getTimestamp("timestamp").toString(), AuthHandler.getCompanyid(request));
     jobj.put("logid", rs.getInt("logid"));
     jobj.put("actionby", author);
     jobj.put("description", useraction);
     if (callerFlag.equals("all") || callerFlag.equals("projname")) {
       String projectname = "";
       String projid = rs.getString("projectid");
       if (!StringUtil.isNullOrEmpty(projid)) {
         projectname = projdb.getProjectName(conn, projid);
       }
       jobj.put("projname", projectname);
     }
     jobj.put("timestamp", sdtStr);
   } catch (ServiceException ex) {
     Logger.getLogger(AuditTrail.class.getName()).log(Level.SEVERE, null, ex);
   } catch (JSONException ex) {
     throw ServiceException.FAILURE("AuditTrail.getJsonForAction", ex);
   } catch (Exception ex) {
     throw ServiceException.FAILURE("AuditTrail.getJsonForAction", ex);
   } finally {
     return jobj;
   }
 }
コード例 #2
0
 public static String getActionLog(Connection conn, HttpServletRequest request)
     throws ServiceException {
   ResultSet rs = null;
   String returnStr = "";
   PreparedStatement pstmt = null;
   String searchString = request.getParameter("ss");
   String limit = request.getParameter("limit");
   String offset = request.getParameter("start");
   JSONObject resobj = new JSONObject();
   JSONObject tempobj = new JSONObject();
   JSONArray jarr = new JSONArray();
   String likeClause = "";
   try {
     String companyid = AuthHandler.getCompanyid(request);
     String loginid = AuthHandler.getUserid(request);
     String[] searchStrObj = new String[] {"params", "actiontext"};
     String myLikeString = StringUtil.getMySearchString(searchString, "and", searchStrObj);
     String flag = "";
     int count1 = 0;
     String type = request.getParameter("type");
     String dateSting = getDateString(conn, request, loginid);
     if (StringUtil.isNullOrEmpty(type)) {
       flag = "no";
       returnStr = getAllLog(conn, request, companyid, limit, offset, searchString, dateSting);
     } else {
       switch (Integer.parseInt(type)) {
         case 0:
           flag = "projname";
           returnStr =
               getLog(conn, request, companyid, limit, offset, searchString, dateSting, flag);
           flag = "no";
           break;
         case 1:
           String admintype = request.getParameter("admintype");
           if (admintype.equals("0")) {
             likeClause = "and al.actionid like '31%' ";
           } else if (admintype.equals("1")) {
             likeClause = "and al.actionid like '32%' ";
           } else {
             likeClause = "and al.actionid like '33%' or al.actionid like '40%' ";
           }
           flag = "admin";
           break;
         case 2:
           flag = "doc";
           likeClause = "and al.actionid like '21%' ";
           break;
         case 3:
           flag = "all";
           likeClause = "and projectid != '' ";
           break;
         case 4:
           flag = "admin";
           likeClause =
               "and (al.actionid like '31%' or al.actionid like '32?' or al.actionid like '33?' or al.actionid like '40%')";
           break;
         case 5:
           flag = "all";
           likeClause = "and (al.actionid like '41%')";
           break;
       }
     }
     if (!flag.equals("no")) {
       count1 =
           getCountQuery(
               conn,
               pstmt,
               companyid,
               likeClause,
               myLikeString,
               searchStrObj,
               searchString,
               dateSting);
       String query =
           "select logid, al.actionid, actionby, params, timestamp, projectid from actionlog al inner join actions a on al.actionid = a.actionid where companyid = ? "
               + likeClause
               + myLikeString
               + dateSting
               + " order by timestamp DESC limit ? offset ?";
       pstmt = conn.prepareStatement(query);
       pstmt.setString(1, companyid);
       int cnt = StringUtil.insertParamSearchString(2, pstmt, searchString, searchStrObj.length);
       pstmt.setInt(cnt++, Integer.parseInt(limit));
       pstmt.setInt(cnt++, Integer.parseInt(offset));
       rs = pstmt.executeQuery();
       while (rs.next()) {
         tempobj = getJsonForAction(conn, pstmt, rs, request, flag);
         jarr.put(tempobj);
       }
       resobj.put("data", jarr);
       resobj.append("count", count1);
       returnStr = resobj.toString();
     }
   } catch (ServiceException ex) {
     Logger.getLogger(AuditTrail.class.getName()).log(Level.SEVERE, null, ex);
   } catch (Exception ex) {
     throw ServiceException.FAILURE("AuditTrail.getActionLog :" + ex.getMessage(), ex);
   } finally {
     return returnStr;
   }
 }