public Collection getEventsByBde(Integer bdeId, boolean occured) throws PersistanceException { return eventDAO.getEventsByBde(bdeId, occured); }
public void recordUserEvent(String message) { eventDAO.storeEvent(new Event(USER, message)); }
public void recordSystemEvent(String systemUUID, String eventCode) { String message = systemUUID + ": " + eventCode; eventDAO.storeEvent(new Event(SYSTEM, message)); }
/** * 查询query对应的扩展事件,扩展新闻,扩展关键词,并返回结果 * * @param query * @return 返回一个由JSONArray表示的相关新闻列表,格式如下: {"q":{q}, "expan":{ * "events":[{"id":"","desc":"","title":""},{"id":"","desc":"","title":""}...], * "news":[{"id":"","desc":"","title":""},{"id":"","desc":"","title":""}...], * "keywords":["",""...]} } */ public JSONObject getExpansion(String query) { init(); JSONObject jsonObj = new JSONObject(); Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; try { conn = dataSource.getConnection(); pstmt = conn.prepareStatement(SQL_SELECT_EXPANSION_BY_KEYWORDS); pstmt.setString(1, query); if (pstmt.execute()) { rs = pstmt.getResultSet(); JSONObject expan = new JSONObject(); while (rs.next()) { // 将查询结果转化为json格式 // 获得所有的events JSONArray eventsArray = new JSONArray(); if (rs.getString("eventsId") != null) { String eventsIdString[] = rs.getString("eventsId").split(","); int[] eventsId = new int[eventsIdString.length]; for (int i = 0; i < eventsIdString.length; i++) { eventsId[i] = Integer.parseInt(eventsIdString[i]); EventDAO eventDao = new EventDAO(); Event event = eventDao.getEventById(eventsId[i]); // 根据event的id进行查询,并且获得相关属性 JSONObject eventObj = new JSONObject(); eventObj.put("id", eventsId[i]); eventObj.put("desc", event.getDesc()); eventObj.put("title", event.getTitle()); eventsArray.add(eventObj); } // for } // 获得所有的news JSONArray newsArray = new JSONArray(); if (rs.getString("newsId") != null) { String newsIdString[] = rs.getString("newsId").split(","); int[] newsId = new int[newsIdString.length]; for (int i = 0; i < newsIdString.length; i++) { newsId[i] = Integer.parseInt(newsIdString[i]); NewsDAO newsDao = new NewsDAO(); News news = newsDao.getNewsById(newsId[i]); JSONObject newsObj = new JSONObject(); newsObj.put("id", newsId[i]); newsObj.put("desc", news.getDescription()); newsObj.put("title", news.getTitle()); newsArray.add(newsObj); } // for } // 获得所有的扩展词 String[] expansionTerms = rs.getString("expansionTerms").split(","); JSONArray expansionArray = new JSONArray(); for (String expansion : expansionTerms) { expansionArray.add(expansion); } // for expan.put("events", eventsArray); expan.put("news", newsArray); expan.put("keywords", expansionArray); } // while jsonObj.put("q", query); jsonObj.put("expan", expan); } // try } catch (SQLException e) { e.printStackTrace(); } finally { try { if (rs != null) rs.close(); if (pstmt != null) pstmt.close(); if (conn != null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } return jsonObj; }