1 19 20 package za.org.coefficient.modules.project; 21 22 import org.apache.commons.lang.StringUtils; 23 24 import za.org.coefficient.core.Constants; 25 import za.org.coefficient.core.Project; 26 import za.org.coefficient.interfaces.CoefficientContext; 27 import za.org.coefficient.modules.BaseModule; 28 import za.org.coefficient.util.common.HibernatePager; 29 import za.org.coefficient.util.ejb.VelocityScreenUtil; 30 import za.org.coefficient.util.ejb.SecurityUtil; 31 32 import java.util.HashMap ; 33 34 39 public abstract class BaseProjectBrowse extends BaseModule { 40 42 private static final String PROJECT_PAGER = "__project_pager_"; 43 private static final String UNAPPROVED_PROJECT_PAGER = 44 "__unapproved__project_pager_"; 45 46 48 public CoefficientContext baseViewProjects(CoefficientContext ctx, boolean active) 49 throws Exception { 50 HashMap map = new HashMap (); 51 HibernatePager hp = null; 52 if ((ctx.getParameter("projectName") != null) 53 && !ctx.getParameter("projectName") 54 .trim() 55 .equals("")) { 56 if (active) { 57 hp = (HibernatePager) ctx.getSessionAttribute(PROJECT_PAGER); 58 } else { 59 hp = (HibernatePager) ctx.getSessionAttribute(UNAPPROVED_PROJECT_PAGER); 60 } 61 if (hp == null) { 62 if (active) { 63 hp = new HibernatePager(Project.class, "statistics.currentData.rank", 64 Constants.MAX_ELEMENTS_PER_PAGE, false); 65 } else { 66 hp = new HibernatePager(Project.class, "name", 67 Constants.MAX_ELEMENTS_PER_PAGE); 68 } 69 } 70 HashMap andSearchParams = new HashMap (); 71 andSearchParams.put("active", new Boolean (active)); 72 HashMap orSearchParams = new HashMap (); 73 orSearchParams.put("name", ctx.getParameter("projectName")); 74 orSearchParams.put("description", ctx.getParameter("projectName")); 75 hp.setFromWhereAndInitialize(andSearchParams, orSearchParams, null); 76 } else if (ctx.getParameter("next") != null) { 77 if (active) { 78 hp = (HibernatePager) ctx.getSessionAttribute(PROJECT_PAGER); 79 } else { 80 hp = (HibernatePager) ctx.getSessionAttribute(UNAPPROVED_PROJECT_PAGER); 81 } 82 if (hp == null) { 83 ctx.setError("Invalid operation"); 84 } else { 85 hp.next(); 86 } 87 } else if (ctx.getParameter("previous") != null) { 88 if (active) { 89 hp = (HibernatePager) ctx.getSessionAttribute(PROJECT_PAGER); 90 } else { 91 hp = (HibernatePager) ctx.getSessionAttribute(UNAPPROVED_PROJECT_PAGER); 92 } 93 94 if (hp == null) { 95 ctx.setError("Invalid operation"); 96 } else { 97 hp.previous(); 98 } 99 } else if (ctx.getParameter("page") != null) { 100 if (active) { 101 hp = (HibernatePager) ctx.getSessionAttribute(PROJECT_PAGER); 102 } else { 103 hp = (HibernatePager) ctx.getSessionAttribute(UNAPPROVED_PROJECT_PAGER); 104 } 105 if (hp == null) { 106 ctx.setError("pager does not exist"); 107 } else { 108 hp.goToPage(ctx.getParameterAsInteger("page").intValue()); 109 } 110 } else { 111 HashMap searchParams = new HashMap (); 112 searchParams.put("active", new Boolean (active)); 113 if (active) { 114 hp = new HibernatePager(Project.class, "statistics.currentData.rank", 115 Constants.MAX_ELEMENTS_PER_PAGE, searchParams, false); 116 } else { 117 hp = new HibernatePager(Project.class, "name", 118 Constants.MAX_ELEMENTS_PER_PAGE, searchParams); 119 } 120 } 121 122 if (!ctx.isError()) { 123 map.put("pager", hp); 124 125 map.put("module", this); 127 if (active) { 128 map.put("active", new Boolean (active)); 129 ctx.setSessionAttribute(PROJECT_PAGER, hp); 130 } else { 131 ctx.setSessionAttribute(UNAPPROVED_PROJECT_PAGER, hp); 132 } 133 134 if (ctx.getCurrentUser() != null) { 135 map.put("loggedIn", new Boolean (true)); 136 } 137 map.put("project_name", ProjectConstants.PROJECT_NAME); 138 map.put("project_name_cap", StringUtils.capitalise(ProjectConstants.PROJECT_NAME)); 139 map.put("user", ctx.getCurrentUser()); 140 if(ctx.getCurrentUser() != null && 141 ctx.getCurrentUser().getSystemRole().getRoleValue() 142 <= SecurityUtil.SITE_MODERATOR_ROLE_VAL) { 143 map.put("userIsAdmin", new Boolean (true)); 144 } 145 StringBuffer sb = 146 VelocityScreenUtil.getProcessedScreen("browse-view.vm", map); 147 148 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 150 } 151 return ctx; 152 } 153 } 154 | Popular Tags |