1 5 package org.exoplatform.services.portal.log.impl; 6 7 import java.util.LinkedList ; 8 import org.exoplatform.commons.utils.PageList; 9 import org.exoplatform.container.monitor.ActionData; 10 import org.exoplatform.services.database.DBObjectPageList; 11 import org.exoplatform.services.database.HibernateService; 12 import org.exoplatform.services.database.ObjectQuery; 13 import org.exoplatform.services.idgenerator.IDGeneratorService; 14 import org.exoplatform.services.portal.log.PortalLogService; 15 import org.exoplatform.services.portal.log.Query; 16 import org.exoplatform.services.portal.log.SessionLogData; 17 import com.thoughtworks.xstream.XStream; 18 import com.thoughtworks.xstream.io.xml.XppDriver; 19 24 public class PortalLogServiceImpl implements PortalLogService { 25 static private XStream xstream_ ; 26 static private String [] MAPPING = 27 { "org/exoplatform/services/portal/log/impl/SessionLogDataDescriptionImpl.hbm.xml", 28 "org/exoplatform/services/portal/log/impl/SessionLogDataImpl.hbm.xml" } ; 29 30 private HibernateService hservice_ ; 31 private IDGeneratorService idService_ ; 32 33 public PortalLogServiceImpl(HibernateService hservice, IDGeneratorService idService) { 34 hservice.addMappingFiles(MAPPING) ; 35 hservice_ = hservice ; 36 idService_ = idService ; 37 } 38 39 public SessionLogData getSessionLogData(String id) throws Exception { 40 return (SessionLogData)hservice_.findOne(SessionLogDataImpl.class, id) ; 41 } 42 43 public void saveSessionLogData(SessionLogData data) throws Exception { 44 SessionLogDataImpl impl = (SessionLogDataImpl) data ; 45 if(impl.getId() == null) impl.setId(idService_.generateStringID(impl)) ; 46 hservice_.create(impl) ; 47 } 48 49 public PageList getSessionLogDatas(Query query) throws Exception { 50 ObjectQuery oq = new ObjectQuery(SessionLogDataDescriptionImpl.class); 51 oq.addLIKE("sessionOwner", query.getSessionOwner()) ; 52 oq.addLIKE("remoteUser", query.getRemoteUser()) ; 53 oq.addLIKE("IPAddress", query.getIPAddress()) ; 54 oq.addLIKE("clientName", query.getClientType()) ; 55 oq.addGT("accessTime", query.getFromDate()) ; 56 oq.addLT("accessTime", query.getToDate()) ; 57 if(query.getError() > 0) { 58 oq.addGT("errorCount", Integer.toString(0)) ; 59 } 60 return new DBObjectPageList(hservice_, oq) ; 61 } 62 63 static public XStream getXStreamInstance() { 64 if (xstream_ == null ) { 65 xstream_ = new XStream(new XppDriver()); 66 xstream_.alias("action-data", ActionData.class); 67 xstream_.alias("session-data", LinkedList .class); 68 } 69 return xstream_ ; 70 } 71 } 72 | Popular Tags |