Changeset 8717 for trunk/greenstone3-extensions
- Timestamp:
- 2004-12-02T09:50:37+13:00 (19 years ago)
- Location:
- trunk/greenstone3-extensions/gsdl-as
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/AlertingService.java
r8644 r8717 9 9 package org.greenstone.gsdlas; 10 10 11 import java.io.IOException;12 11 import java.lang.reflect.Method; 13 12 import java.net.MalformedURLException; … … 15 14 import java.util.*; 16 15 17 import javax.servlet.ServletException; 18 import javax.servlet.http.HttpServletRequest; 19 import javax.servlet.http.HttpServletResponse; 16 import javax.servlet.http.*; 20 17 21 18 import org.apache.velocity.Template; 22 19 import org.apache.velocity.context.Context; 23 import org.apache.velocity.exception.ParseErrorException;24 import org.apache.velocity.exception.ResourceNotFoundException;25 20 import org.apache.velocity.servlet.VelocityServlet; 26 import org.greenstone.gsdlas. profiles.*;21 import org.greenstone.gsdlas.users.UserManager; 27 22 28 23 /** … … 36 31 public static final Set actions = new TreeSet(); 37 32 static { 38 actions.add("subscribe"); 33 actions.add("createSubscription"); 34 actions.add("deleteSubscription"); 35 actions.add("editSubscription"); 39 36 actions.add("showFeed"); 40 actions.add("listSubscriptions"); // TODO remove (just for debugging) 41 } 37 actions.add("listSubscriptions"); 38 actions.add("login"); 39 actions.add("register"); 40 } 41 42 42 43 43 protected Template handleRequest(HttpServletRequest req, … … 47 47 48 48 if (action == null || !actions.contains(action)) { 49 context.put("title", "Unknown action"); 50 context.put("message", "I don't know how to " + action); 51 context.put("details", "The only actions I know are " + actions); 52 try { 53 return getTemplate("error.vm"); 54 } catch (ResourceNotFoundException e1) { 55 // TODO Auto-generated catch block 56 e1.printStackTrace(); 57 } catch (ParseErrorException e1) { 58 // TODO Auto-generated catch block 59 e1.printStackTrace(); 60 } catch (Exception e1) { 61 // TODO Auto-generated catch block 62 e1.printStackTrace(); 63 } 64 return null; 49 String title = "Unknown action"; 50 String message = "I don't know how to " + action; 51 String details = "The only actions I know are " + actions; 52 return showError(context, message, details); 65 53 } 66 54 67 55 68 56 Map args = req.getParameterMap(); 57 // TODO stop this, we need multi-valued stuff 69 58 args = normalise(args); 70 59 … … 75 64 templateString = (String) method.invoke(this, new Object[] {args, context}); 76 65 } catch (Exception e) { 77 templateString = "error.vm"; 78 context.put("title", "Error"); 79 context.put("message", "A general error has occured, I couldn't do what you told me to do."); 80 context.put("details", e.getMessage() + " (" + e.getClass().getName() + "), action is " + action); 66 String message = "An error has occured, I couldn't do what you told me to do."; 67 String details = e.getMessage() + " (" + e.getClass().getName() + "), action is " + action; 68 return showError(context, message, details); 81 69 } 82 70 … … 88 76 e.printStackTrace(); 89 77 try { 90 error(req, res, e); 91 } catch (ServletException e2) { 92 // TODO Auto-generated catch block 93 e2.printStackTrace(); 94 } catch (IOException e2) { 78 error((HttpServletRequest)context.get(REQUEST), 79 (HttpServletResponse)context.get(RESPONSE), 80 e); 81 } catch (Exception e2) { 95 82 // TODO Auto-generated catch block 96 83 e2.printStackTrace(); … … 104 91 * @param context 105 92 * @return the Velocity template to use 93 * @throws Exception 106 94 */ 107 public String subscribe(Map arguments, Context context) { 108 context.put("title", "Adding Subscription"); 109 if (arguments.size() == 0) { 110 context.put("message", "Empty subscription, not added"); 111 context.put("details", "A subscription has to define at least one predicate."); 112 return "error.vm"; 113 } 114 try { 115 // TODO pass user information to profile store 116 Subscription sub = new Subscription(arguments); 117 // TODO this should probably be somewhere else 118 for (Iterator iter = sub.getPredicates().iterator(); iter.hasNext();) { 119 Predicate predicate = (Predicate) iter.next(); 120 if (predicate != null) { 121 predicate.addSubscription(sub); 122 } 123 } 124 ProfileStore.getInstance().addSubscription(sub); 125 } catch (ParseException e) { 126 context.put("message", "Eror in subscription creation, not added"); 127 context.put("details", e.getMessage()); 128 return "error.vm"; 129 } 130 context.put("message", "Subscription added successfully"); 131 return "general.vm"; 95 public String createSubscription(Map arguments, Context context) throws Exception { 96 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 97 if (!UserManager.getInstance().isLoggedIn(session)) { 98 session.setAttribute("next_action", "createSubscription"); 99 return "login.vm"; 100 } 101 // TODO handle wizard-style stuff 102 // if "finish" 103 ProfileStore.getInstance().createSubscription(arguments); 104 return listSubscriptions(arguments, context); 105 // else show next page 106 } 107 108 public String deleteSubscription(Map arguments, Context context) { 109 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 110 if (!UserManager.getInstance().isLoggedIn(session)) { 111 session.setAttribute("next_action", "deleteSubscription"); 112 return "login.vm"; 113 } 114 String subscriptionID = (String) arguments.get("subscriptionID"); 115 ProfileStore.getInstance().deleteSubscription(subscriptionID); 116 return listSubscriptions(arguments, context); 117 } 118 119 public String editSubscription(Map arguments, Context context) { 120 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 121 if (!UserManager.getInstance().isLoggedIn(session)) { 122 session.setAttribute("next_action", "editSubscription"); 123 return "login.vm"; 124 } 125 // TODO handle wizard-style stuff 126 // if "finish" 127 ProfileStore.getInstance().changeSubscription(arguments, session); 128 return listSubscriptions(arguments, context); 129 // else show next page 132 130 } 133 131 … … 136 134 return "feed.vm"; 137 135 } 138 136 139 137 public String listSubscriptions(Map arguments, Context context) { 140 138 context.put("title", "List of Subscriptions"); 141 139 context.put("list", ProfileStore.getInstance().getAllSubscriptions()); 142 140 return "list.vm"; 141 } 142 143 public String login(Map arguments, Context context) throws Exception { 144 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 145 UserManager.getInstance().loginUser(arguments, session); 146 if (session.getAttribute("next_action") != null) { 147 String nextAction = (String) session.getAttribute("next_action"); 148 Method method = AlertingService.class.getDeclaredMethod(nextAction, new Class[] {Map.class, Context.class}); 149 return (String) method.invoke(this, new Object[] {arguments, context}); 150 } 151 return listSubscriptions(arguments, context); 152 } 153 154 public String register(Map arguments, Context context) throws Exception { 155 HttpSession session = ((HttpServletRequest)context.get(REQUEST)).getSession(true); 156 UserManager.getInstance().createUser(arguments, session); 157 return login(arguments, context); 143 158 } 144 159 … … 172 187 return result; 173 188 } 189 190 /** 191 * @param context 192 * @param message 193 * @param details 194 * @return 195 */ 196 private Template showError(Context context, String message, String details) { 197 context.put("title", "Error"); 198 context.put("message", message); 199 context.put("details", details); 200 try { 201 return getTemplate("error.vm"); 202 } catch (Exception e) { 203 try { 204 super.error((HttpServletRequest)context.get("req"), 205 (HttpServletResponse)context.get("res"), 206 e); 207 } catch (Exception e2) { 208 e2.printStackTrace(); 209 } 210 } 211 return null; 212 } 174 213 } -
trunk/greenstone3-extensions/gsdl-as/src/org/greenstone/gsdlas/ProfileStore.java
r8630 r8717 11 11 import java.util.*; 12 12 13 import javax.servlet.http.HttpSession; 14 13 15 import org.greenstone.gsdlas.profiles.*; 14 16 import org.greenstone.gsdlas.profiles.IdEqualsPredicate; … … 48 50 * the subscription to add to the profile store. 49 51 */ 50 p ublicvoid addSubscription(Subscription subscription) {52 private void addSubscription(Subscription subscription) { 51 53 Predicate documentIdPredicate = subscription.getPredicate("documentID"); 52 54 Predicate collectionIdPredicate = subscription.getPredicate("collectionID"); … … 267 269 return Collections.unmodifiableSet(allSubscriptions); 268 270 } 271 272 273 /** 274 * @param arguments 275 * @throws ParseException 276 */ 277 public void createSubscription(Map arguments) throws ParseException { 278 // TODO pass user information to profile store 279 Subscription sub = new Subscription(arguments); 280 // TODO this should probably be somewhere else 281 for (Iterator iter = sub.getPredicates().iterator(); iter.hasNext();) { 282 Predicate predicate = (Predicate) iter.next(); 283 if (predicate != null) { 284 predicate.addSubscription(sub); 285 } 286 } 287 addSubscription(sub); 288 } 289 290 291 /** 292 * @param subscriptionID 293 */ 294 public void deleteSubscription(String subscriptionID) { 295 // TODO Auto-generated method stub 296 297 } 298 299 /** 300 * @param arguments 301 * @param session 302 */ 303 public void changeSubscription(Map arguments, HttpSession session) { 304 String subscriptionID = (String) arguments.get("subscriptionID"); 305 // TODO Auto-generated method stub 306 307 } 269 308 270 309 } -
trunk/greenstone3-extensions/gsdl-as/test-src/org/greenstone/gsdlas/ProfileStoreTest.java
r8630 r8717 83 83 } 84 84 85 private void addSubscription(Map valueMap) throws ParseException { 86 Subscription sub = new Subscription(valueMap); 87 // TODO this should probably be somewhere else 88 for (Iterator iter = sub.getPredicates().iterator(); iter.hasNext();) { 89 Predicate predicate = (Predicate) iter.next(); 90 if (predicate != null) { 91 predicate.addSubscription(sub); 92 } 93 } 94 ProfileStore.getInstance().addSubscription(sub); 85 private void addSubscription(Map valueMap) throws ParseException { 86 ProfileStore.getInstance().createSubscription(valueMap); 95 87 } 96 88
Note:
See TracChangeset
for help on using the changeset viewer.