📄 jahiadbauditlogmanagerservice.java
字号:
// To ensure correct sorting, force the string length to 15 positions, // padding it with initial "0"s if needed. timeStr = padTimeString(timeStr); try { statement = dbConn.createStatement(); // check if we want to FIFO old entries maxLogs = Integer.parseInt(JahiaPrivateSettings.readJahiaPropertiesFile().getProperty("jahiaMaxLogs")); query = "SELECT COUNT(*) AS numRows FROM " + TABLE_NAME; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement, query); if(rs.next()) { numRows = rs.getInt("numRows"); } if( (numRows+1) > maxLogs ) { deleteOldestRow(); } // insert current entry query = "INSERT INTO " + TABLE_NAME + " (id_jahia_audit_log, time_jahia_audit_log, username_jahia_audit_log, objecttype_jahia_audit_log, operation_jahia_audit_log, objectid_jahia_audit_log, parentid_jahia_audit_log, parenttype_jahia_audit_log, site_jahia_audit_log, content_jahia_audit_log ) VALUES (" + Integer.toString(entryID) + ",'" + timeStr + "','" + userNameStr + "'," + objectTypeStr + ",'" + operationStr + "'," + objectIDStr + "," + parentObjIDStr + "," + parentTypeStr + ",'" + siteKey + "','" + contentStr + "')"; ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query); } catch (SQLException sqlEx) { toConsole ("SQL Exception occured!" + sqlEx.getMessage()); result = false; } catch (NumberFormatException nfe) { // do nothing, keep default maxLogs } finally { CloseDBConnection (dbConn); CloseStatement (statement); } return result; } /** * get the object ID for an Event to be logged, according to the object type * * @author Mikha雔 Janson * @param je a reference to the JahiaEvent object to log * @param objectType an <code>int</code> representing the type of the of the logged event * @return the objectID, as an <code>int</code> */ private int getObjectID( JahiaEvent je, int objectType) throws JahiaException { try { switch(objectType) { case FIELD_TYPE: return ((JahiaField) je.getObject()).getID(); case CONTAINER_TYPE: return ((JahiaContainer) je.getObject()).getID(); case CONTAINERLIST_TYPE: return ((JahiaContainerList)je.getObject()).getID(); case PAGE_TYPE: return ((JahiaPage) je.getObject()).getID(); case TEMPLATE_TYPE: return ((JahiaPageDefinition) je.getObject()).getID(); default: throw new JahiaException (MSG_INTERNAL_ERROR, "Incompatible Object Type passed to JahiaAuditLogManager", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } } catch (Exception e) { toConsole("EXCEPTION MESSAGE :" + e.getMessage()); throw new JahiaException (MSG_INTERNAL_ERROR, "Exception occurred while retrieving Event Object ID", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } } // end getObjectID /** * get object ID Type for the parent object, by the objectID of a child * * @author Mikha雔 Janson * @param je a reference to the JahiaEvent object to log * @param objectType an <code>int</code> representing the type of the of the logged event * @return the objectID, as a <code>String</code> */ private String[] getParent( JahiaEvent je, int objectType ) throws JahiaException { String[] parent = new String[2]; try { switch(objectType) { case FIELD_TYPE: if( ( (JahiaField)je.getObject() ).getctnid() == 0 ) { parent[0] = Integer.toString( ((JahiaField) je.getObject()).getPageID() ); parent[1] = Integer.toString(PAGE_TYPE); return parent; } else { parent[0] = Integer.toString( ((JahiaField) je.getObject()).getctnid() ); parent[1] = Integer.toString(CONTAINER_TYPE); return parent; } case CONTAINER_TYPE: parent[0] = Integer.toString( ((JahiaContainer) je.getObject()).getListID() ); parent[1] = Integer.toString(CONTAINERLIST_TYPE); return parent; case CONTAINERLIST_TYPE: if( ( (JahiaContainerList)je.getObject() ).getParentEntryID() == 0 ) { parent[0] = Integer.toString( ((JahiaContainerList)je.getObject()).getPageID() ); parent[1] = Integer.toString(PAGE_TYPE); return parent; } else { parent[0] = Integer.toString( ((JahiaContainerList)je.getObject()).getParentEntryID() ); parent[1] = Integer.toString(CONTAINER_TYPE); return parent; } case PAGE_TYPE: parent[0] = Integer.toString( ((JahiaPage) je.getObject()).getParentID() ); parent[1] = Integer.toString(PAGE_TYPE); return parent; case TEMPLATE_TYPE: parent[0] = "-1"; // dummy value parent[1] = Integer.toString(TEMPLATE_TYPE); return parent; default: throw new JahiaException (MSG_INTERNAL_ERROR, "Incompatible Object Type passed to JahiaAuditLogManager", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } } catch (Exception e) { toConsole("EXCEPTION MESSAGE :" + e.getMessage()); throw new JahiaException (MSG_INTERNAL_ERROR, "Exception occurred while retrieving Event Object ID", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } } /** * get IDs of objects contained in an object * * @author Mikha雔 Janson * @param dbconn a database Connection * @param objectType * @ * @return an <code>ArrayList</code> of log entry IDs */ private Vector getChildrenList (Connection dbConn, int objectType, int objectID) { Statement stmt = null; ResultSet rs = null; Vector childrenVect = new Vector(); String table = ""; String objectWord = ""; String query = ""; // get list of children... try { stmt = dbConn.createStatement(); switch (objectType) { // no Children... case LoggingEventListener.FIELD_TYPE: break; // Children can be CONTAINER... case LoggingEventListener.CONTAINERLIST_TYPE: objectWord = "list"; table = "jahia_ctn_entries"; query = makeQuery( table, objectWord, objectID ); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt, query); while( rs.next() ) { Integer[] child = new Integer[2]; child[0] = new Integer(JahiaObjectTool.CONTAINER_TYPE); child[1] = new Integer(rs.getString("id_" + table)); childrenVect.addElement(child); } break; // Children can be FIELD or CONTAINERLIST... case LoggingEventListener.CONTAINER_TYPE: objectWord = "ctn"; table = "jahia_fields_data"; query = makeQuery( table, objectWord, objectID ); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query); // child found in fields... if( rs.next() ) { while( rs.next() ) { Integer[] child = new Integer[2]; child[0] = new Integer(JahiaObjectTool.FIELD_TYPE); child[1] = new Integer(rs.getString("id_" + table)); childrenVect.addElement(child); } // no child found in fields... look in container lists... } else { table = "jahia_ctn_lists"; query = makeQuery( table, objectWord, objectID ); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query); while( rs.next() ) { Integer[] child = new Integer[2]; child[0] = new Integer(JahiaObjectTool.CONTAINERLIST_TYPE); child[1] = new Integer(rs.getString("id_" + table)); childrenVect.addElement(child); } } break; // Children can be PAGE, FIELD or CONTAINERLIST... case LoggingEventListener.PAGE_TYPE: objectWord = "page"; table = "jahia_fields_data"; query = makeQuery( table, objectWord, objectID ); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query); // look in fields... while( rs.next() ) { Integer[] child = new Integer[2]; child[0] = new Integer(JahiaObjectTool.FIELD_TYPE); child[1] = new Integer(rs.getString("id_" + table)); childrenVect.add(child); } // then look in container lists... table = "jahia_ctn_lists"; query = makeQuery( table, objectWord, objectID ); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query); while( rs.next() ) { Integer[] child = new Integer[2]; child[0] = new Integer(LoggingEventListener.CONTAINERLIST_TYPE); child[1] = new Integer(rs.getString("id_" + table)); childrenVect.addElement(child); } // then look in pages... objectWord = "parent"; table = "jahia_pages_data"; query = makeQuery( table, objectWord, objectID ); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(stmt,query); while( rs.next() ) { Integer[] child = new Integer[2]; child[0] = new Integer(JahiaObjectTool.PAGE_TYPE); child[1] = new Integer(rs.getString("id_" + table)); childrenVect.add(child); } break; } } catch (SQLException sqlEx) { toConsole ("SQL Exception occured!" + sqlEx.getMessage()); } finally { CloseStatement (stmt); } return childrenVect; }// end getChildrenList /** * compose a full multi-level list of children * * @author Mikha雔 Janson * @param dbconn a database Connection * @param objectType * @param objectID * @param prevChildrenList * @return an <code>ArrayList</code> of log entry IDs */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -