1 19 package org.openharmonise.rm.logging; 20 21 import java.util.Date ; 22 import java.util.Map ; 23 24 import org.openharmonise.rm.sessions.Session; 25 26 27 35 public abstract class AbstractEventLogger implements EventLogger { 36 37 40 public AbstractEventLogger() { 41 super(); 42 } 43 44 45 48 public void logEvent(LogEvent event) throws LogException { 49 int nUserId = -1; 50 String sSessId = null; 51 int nObjectId = -1; 52 String sObjectType = null; 53 String sAction = null; 54 Date timestamp = null; 55 String sIP = null; 56 String sUserAgent = null; 57 String sReferer = null; 58 String sHeaderInfo = null; 59 60 timestamp = event.getTimestamp(); 61 62 if(event.getUser() != null) { 63 nUserId = event.getUser().getId(); 64 } 65 66 Session sess = event.getSession(); 67 if(sess != null) { 68 sSessId = sess.getSessionId(); 69 } 70 71 if(event.getObject() != null) { 72 sObjectType = event.getObject().getClass().getName(); 73 nObjectId = event.getObjectId(); 74 } 75 76 sAction = event.getLabel(); 77 78 Map headers = null; 79 80 if(event.getState() != null) { 81 headers = event.getState().getHeaders(); 82 83 sIP = event.getState().getRemoteAddress(); 84 } 85 86 if(headers == null) { 87 String sAdditional = event.getAdditionalInfo(); 88 89 saveData(nUserId,sSessId,nObjectId,sObjectType,sAction,timestamp,sIP,sAdditional); 90 91 } else { 92 saveData(nUserId,sSessId,nObjectId,sObjectType,sAction,timestamp,sIP,headers); 93 } 94 95 96 } 97 98 111 abstract protected void saveData( 112 int nUserId, 113 String sSessionId, 114 int nObjectId, 115 String sObjectType, 116 String sAction, 117 Date timestamp, 118 String sIP, 119 Map headers) 120 throws LogException; 121 122 135 abstract protected void saveData( 136 int nUserId, 137 String sSessionId, 138 int nObjectId, 139 String sObjectType, 140 String sAction, 141 Date timestamp, 142 String sIP, 143 String sAdditional) 144 throws LogException; 145 146 } 147 | Popular Tags |