| 1 package za.org.coefficient.modules.sample; 2 3 import java.util.HashMap ; 4 5 import za.org.coefficient.authentication.CoefficientUser; 6 import za.org.coefficient.authentication.Role; 7 import za.org.coefficient.core.Project; 8 import za.org.coefficient.interfaces.CoefficientContext; 9 import za.org.coefficient.modules.BaseProjectModule; 10 import za.org.coefficient.util.ejb.SecurityUtil; 11 import za.org.coefficient.util.ejb.VelocityScreenUtil; 12 13 32 public class Sample extends BaseProjectModule { 33 34 public String getModuleDisplayName () { 35 return "Sample"; 36 } 37 38 public String getModuleDescription () { 39 return "Sample Module"; 40 } 41 42 public String getMainMethod () { 43 return "doInitialWork"; 45 } 46 47 String roles[] = { 49 SecurityUtil.SITE_ADMIN_ROLE_DESC, 50 SecurityUtil.PROJECT_CHAMPION_ROLE_DESC, 51 SecurityUtil.PROJECT_MEMBER_ROLE_DESC 52 }; 53 54 public String canExecuteForRole (CoefficientContext ctx, 55 String methodName, Role usersHighestRole){ 56 String role = usersHighestRole.getDescription(); 57 58 if ( methodName.equals("doInitialWork") || 59 methodName.equals("displayUsersData") || 60 methodName.equals("getSummaryForProject") || 61 methodName.equals("showSummaryForProject")) { 62 for(int i = 0; i < roles.length; i++) { 63 if (role.equals(roles[i])) { 64 return null; 65 } 66 } 67 return "not authorised"; 68 } 69 70 return "not authorised"; 71 } 72 73 public CoefficientContext deleteAllForProject (CoefficientContext ctx) { 74 return ctx; 75 } 76 77 public String displayUsersData(CoefficientUser user) { 78 return "Users data for the Sample Module: Joe Bloggs, xxx-yyyy"; 85 } 86 87 public String getSummaryForProject(CoefficientContext ctx) { 88 return "There are a total of 1 elements in the Sample module"; 96 } 97 98 public CoefficientContext showSummaryForProject(CoefficientContext ctx) { 99 String html = "<table width='100%'><tr><td>" + getSummaryForProject(ctx) 107 + "</td></tr></table>"; 108 ctx.setModuleContent(html, getModuleDisplayName()); 109 return ctx; 110 } 111 112 public CoefficientContext doInitialWork (CoefficientContext ctx) { 113 Project project = ctx.getProject(); 114 HashMap map = new HashMap (); 115 map.put("name", "Joe Bloggs"); 116 map.put("telephone", "xxx-yyyy"); 117 StringBuffer sb = new StringBuffer ("Problem here"); 118 sb = VelocityScreenUtil.getProcessedScreen("index.vm", map); 119 120 ctx.setModuleContent(sb.toString(), getModuleDisplayName()); 122 return ctx; 123 } 124 125 } 126 127 | Popular Tags |