1 19 20 package za.org.coefficient.statistics.services; 21 22 import java.util.Date ; 23 import java.util.Map ; 24 25 import net.sf.hibernate.HibernateException; 26 import net.sf.hibernate.util.HibernateUtil; 27 import za.org.coefficient.core.Project; 28 import za.org.coefficient.interfaces.StatisticsMessageSender; 29 import za.org.coefficient.statistics.data.ModuleStatistics; 30 import za.org.coefficient.statistics.data.ProjectStatistics; 31 32 44 public class StatisticsService { 45 46 public void doStatistics(String name, Long projectId, String action) throws HibernateException { 47 48 long prjId = projectId.longValue(); 49 Project prj = 50 (Project) HibernateUtil.load(Project.class, new Long (prjId)); 51 ProjectStatistics ps = prj.getStatistics(); 52 53 if(ps != null) { 54 ps.archiveStats(); 56 57 if ((name == null || name.trim().equals("")) 59 && StatisticsMessageSender.VIEW.equals(action)) { 60 ps.getCurrentData().setViewCount(ps.getCurrentData().getViewCount() + 1); 61 } if ((name == null || name.trim().equals("")) 62 && StatisticsMessageSender.DOWNLOAD.equals(action)) { 63 ps.getCurrentData().setDownloadCount(ps.getCurrentData().getDownloadCount() + 1); 64 } else if (name != null && !name.trim().equals("")) { 65 Map modStats = ps.getModuleStatistics(); 66 ModuleStatistics ms = (ModuleStatistics) modStats.get(name); 67 68 if (ms == null) { 70 ms = new ModuleStatistics(); 71 ms.setStatsDate(new Date (System.currentTimeMillis())); 72 ms.setName(name); 73 ps.addModuleStatistics(ms); 74 } 75 if (StatisticsMessageSender.UPDATE.equals(action)) { 76 ms.getCurrentData().setUpdateCount(ms.getCurrentData().getUpdateCount() + 1); 77 } else if (StatisticsMessageSender.CREATE.equals(action)) { 78 ms.getCurrentData().setCreateCount(ms.getCurrentData().getCreateCount() + 1); 79 } else if (StatisticsMessageSender.COMPLETE.equals(action)) { 80 ms.getCurrentData().setCompleteCount(ms.getCurrentData().getCompleteCount() + 1); 81 } 82 } 83 84 ps.calculateRank(); 86 HibernateUtil.saveOrUpdate(ps); 87 } else { 88 System.err.println("<< project statistics were null"); 89 } 90 91 } 92 93 } 94 | Popular Tags |