1 19 20 package za.org.coefficient.modules.information; 21 22 import org.apache.commons.lang.StringUtils; 23 24 import net.sf.hibernate.Hibernate; 25 import net.sf.hibernate.Session; 26 import net.sf.hibernate.type.Type; 27 28 import za.org.coefficient.authentication.CoefficientUser; 29 import za.org.coefficient.core.Project; 30 import za.org.coefficient.interfaces.CoefficientContext; 31 import za.org.coefficient.modules.BaseModule; 32 import za.org.coefficient.modules.project.ProjectConstants; 33 import net.sf.hibernate.util.HibernateUtil; 34 import za.org.coefficient.util.ejb.SecurityUtil; 35 import za.org.coefficient.util.ejb.VelocityScreenUtil; 36 37 import java.util.HashMap ; 38 39 53 public class Welcome extends BaseModule { 54 56 public String getMainMethod() { 57 return "view"; 58 } 59 60 public String getModuleDescription() { 61 return "Module that is viewed when first entering the site"; 62 } 63 64 public String getModuleDisplayName() { 65 return "Welcome"; 66 } 67 68 public CoefficientContext view(CoefficientContext ctx) throws Exception { 69 HashMap map = new HashMap (); 70 String welcomeContent = ctx.getPage() 71 .getThemeWelcomeContent(); 72 if ((welcomeContent == null) || welcomeContent.trim() 73 .equals("")) { 74 map.put("themeContent", 75 VelocityScreenUtil.getProcessedScreen("defaultWelcome.vm", map).toString()); 76 } else { 77 map.put("themeContent", welcomeContent); 78 } 79 Session sess = HibernateUtil.getSession(); 80 map.put("totalProjects", 81 ((Integer ) sess.iterate("select count(projects) from " 82 + Project.class.getName() 83 + " as projects where projects.active = ?", 84 new Boolean (true), Hibernate.BOOLEAN).next())); 85 map.put("totalUsers", 86 ((Integer ) sess.iterate("select count(pe_users) from " 87 + CoefficientUser.class.getName() 88 + " as pe_users where pe_users.active = ? and pe_users.systemRole.roleValue = ?", 89 new Object [] { 90 new Boolean (true), 91 new Long (SecurityUtil.SITE_MEMBER_ROLE_VAL) 92 }, new Type[] { Hibernate.BOOLEAN, Hibernate.LONG }).next())); 93 HibernateUtil.finalizeSession(); 96 97 map.put("project_name", ProjectConstants.PROJECT_NAME); 98 map.put("project_name_cap", 99 StringUtils.capitalise(ProjectConstants.PROJECT_NAME)); 100 StringBuffer sb = 101 VelocityScreenUtil.getProcessedScreen("view.vm", map); 102 103 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 105 return ctx; 106 } 107 } 108 | Popular Tags |