- Timestamp:
- 2004-12-06T11:44:03+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/packages/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
r8724 r8738 14 14 import java.util.*; 15 15 16 import javax.mail.Session;17 16 import javax.servlet.http.*; 18 17 … … 20 19 import org.apache.velocity.context.Context; 21 20 import org.apache.velocity.servlet.VelocityServlet; 21 import org.greenstone.gsdlas.users.UserManagementException; 22 22 import org.greenstone.gsdlas.users.UserManager; 23 23 … … 30 30 public class AlertingService extends VelocityServlet { 31 31 32 public static final Set actions = new TreeSet();32 public static final Set actions; 33 33 static { 34 actions.add("createSubscription"); 35 actions.add("deleteSubscription"); 36 actions.add("editSubscription"); 37 actions.add("showFeed"); 38 actions.add("listSubscriptions"); 39 actions.add("login"); 40 actions.add("register"); 41 actions.add("logout"); 34 Set set = new TreeSet(); 35 set.add("createSubscription"); 36 set.add("deleteSubscription"); 37 set.add("editSubscription"); 38 set.add("showFeed"); 39 set.add("listSubscriptions"); 40 41 set.add("login"); 42 set.add("register"); 43 set.add("logout"); 44 set.add("showLoginForm"); 45 set.add("showRegistrationForm"); 46 actions = Collections.unmodifiableSet(set); 42 47 } 43 48 … … 67 72 } catch (Exception e) { 68 73 String message = "An error has occured, I couldn't do what you told me to do."; 69 String details = e.getMessage() + " (" + e.getClass().getName() + "), action is " + action; 74 String details = e.getMessage() + " (" + e.getClass().getName() + "); " 75 + e.getCause() 76 + " ; action is " + action; 70 77 return showError(context, message, details); 71 78 } … … 99 106 if (!UserManager.getInstance().isLoggedIn(session)) { 100 107 session.setAttribute("next_action", "createSubscription"); 101 return "login.vm";108 return showLoginForm(arguments, context); 102 109 } 103 110 if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) { 111 arguments.putAll(getPageArgsFromSession(session)); 104 112 ProfileStore.getInstance().createSubscription(arguments); 105 113 return listSubscriptions(arguments, context); … … 113 121 if (!UserManager.getInstance().isLoggedIn(session)) { 114 122 session.setAttribute("next_action", "deleteSubscription"); 115 return "login.vm";123 return showLoginForm(arguments, context); 116 124 } 117 125 String subscriptionID = (String) arguments.get("subscriptionID"); … … 124 132 if (!UserManager.getInstance().isLoggedIn(session)) { 125 133 session.setAttribute("next_action", "editSubscription"); 126 return "login.vm";134 return showLoginForm(arguments, context); 127 135 } 128 136 if (arguments.containsKey("next_page") && arguments.get("next_page").equals("finish")) { … … 138 146 return "feed.vm"; 139 147 } 148 149 public String showLoginForm(Map arguments, Context context) { 150 return "login.vm"; 151 } 152 153 public String showRegistrationForm(Map arguments, Context context) { 154 return "register.vm"; 155 } 140 156 141 157 public String listSubscriptions(Map arguments, Context context) { 142 context.put("title", "List of Subscriptions"); 158 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 159 if (!UserManager.getInstance().isLoggedIn(session)) { 160 session.setAttribute("next_action", "listSubscriptions"); 161 return showLoginForm(arguments, context); 162 } 163 String username = (String) session.getAttribute("username"); 164 context.put("title", "List of Subscriptions for " + username); 143 165 context.put("list", ProfileStore.getInstance().getAllSubscriptions()); 144 166 return "list.vm"; … … 147 169 public String login(Map arguments, Context context) throws Exception { 148 170 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 149 UserManager.getInstance().loginUser(arguments, session); 171 try { 172 UserManager.getInstance().loginUser(arguments, session); 173 } catch (UserManagementException e) { 174 context.put("error", Boolean.TRUE); 175 context.put("errormessage", e.getMessage()); 176 return showLoginForm(arguments, context); 177 } 150 178 if (session.getAttribute("next_action") != null) { 151 179 String nextAction = (String) session.getAttribute("next_action"); … … 158 186 public String register(Map arguments, Context context) throws Exception { 159 187 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 160 UserManager.getInstance().createUser(arguments, session); 188 try { 189 UserManager.getInstance().createUser(arguments, session); 190 } catch (UserManagementException e) { 191 context.put("error", Boolean.TRUE); 192 context.put("errormessage", e.getMessage()); 193 return showRegistrationForm(arguments, context); 194 } 161 195 return login(arguments, context); 162 196 } … … 194 228 for (Iterator iter = args.keySet().iterator(); iter.hasNext();) { 195 229 String key = (String) iter.next(); 196 if (!key.equals("action")) { 197 String firstValue = ((String[]) args.get(key))[0]; 230 if (key.equals("type") || key.equals("host") 231 || key.equals("collection") || key.equals("way")) { 232 // multi-valued attributes 233 String[] values = ((String[]) args.get(key)); 234 result.put(key, Arrays.asList(values)); 235 } else { 236 String firstValue = ((String[])args.get(key))[0]; 198 237 result.put(key, firstValue); 199 238 } … … 260 299 // get page-specific stuff 261 300 if (nextPage.equals("host")) { 262 301 GreenstoneCommunicator gsComm = null; 302 String[] hostNames; 303 try { 304 gsComm = new GreenstoneCommunicator(); 305 hostNames = gsComm.getHostNames(); 306 } catch (Exception e) { 307 hostNames = new String[] { "localhost" }; 308 } 309 context.put("hostnames", hostNames); 263 310 } else if (nextPage.equals("collection")) { 264 311 // TODO might be query instead of just name 312 List hostNames = (List) arguments.get("host"); 313 GreenstoneCommunicator gsComm = null; 314 Map collNames = new TreeMap(); 315 for (Iterator iter = hostNames.iterator(); iter.hasNext();) { 316 String host = (String) iter.next(); 317 Set collNamesForHost = new TreeSet(); 318 try { 319 gsComm = new GreenstoneCommunicator(new URL("http://" + host + ":8080/soap/servlet/rpcrouter")); 320 collNamesForHost.addAll(Arrays.asList(gsComm.getCollectionNames())); 321 } catch (Exception e) { 322 // TODO Auto-generated catch block 323 e.printStackTrace(); 324 } 325 collNames.put(host, collNamesForHost); 326 } 327 context.put("collectionnames", collNames); 328 context.put("hostnames", hostNames); 265 329 } 266 330 … … 324 388 } 325 389 390 private Map getPageArgsFromSession(HttpSession session) { 391 Map result = new TreeMap(); 392 Map pageArgs = (Map) session.getAttribute("page_args"); 393 if (pageArgs != null) { 394 for (Iterator iter = pageArgs.values().iterator(); iter.hasNext();) { 395 Map args = (Map) iter.next(); 396 result.putAll(args); 397 } 398 } 399 return result; 400 } 401 326 402 /** 327 403 * @param page
Note:
See TracChangeset
for help on using the changeset viewer.