diff options
author | Kjetil Orbekk <Kjetil Ørbekk orbekk@pvv.ntnu.no> | 2010-09-03 14:20:40 -0400 |
---|---|---|
committer | Kjetil Orbekk <Kjetil Ørbekk orbekk@pvv.ntnu.no> | 2010-09-03 14:20:40 -0400 |
commit | ac9d7b3012496f411f7ba6c19d31c9496b44327f (patch) | |
tree | 28742e4192fd72cc10c024a730d00e5fbea5b1b7 /src | |
parent | d5ab045ec80a10b341db2ac5a591d84741ea846a (diff) |
Add approve functionality.
Diffstat (limited to 'src')
-rw-r--r-- | src/lq/QuoteUtils.java | 50 | ||||
-rw-r--r-- | src/lq/UserUtil.java | 33 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/lq/QuoteUtils.java b/src/lq/QuoteUtils.java index aaa14b9..ab5cdd1 100644 --- a/src/lq/QuoteUtils.java +++ b/src/lq/QuoteUtils.java @@ -21,6 +21,20 @@ public class QuoteUtils { } } + public static List<Quote> getQuotesPendingApproval() { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("approved == null"); + List<Quote> quotes = (List<Quote>) quoteQuery.execute(); + pm.retrieveAll(quotes); + return quotes; + } + finally { + pm.close(); + } + } + public static List<Quote> getQuotesOrderedByIdDesc() { List<Quote> quotes = getQuotes(); Collections.sort(quotes, @@ -53,4 +67,40 @@ public class QuoteUtils { }); return quotes; } + + public static void approveQuote(Long id) { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("id == idParam"); + quoteQuery.declareParameters("Long idParam"); + List<Quote> quotes = (List<Quote>) quoteQuery.execute(id); + + for (Quote quote : quotes) { + quote.setApproved(true); + pm.makePersistent(quote); + } + } + finally { + pm.close(); + } + } + + public static void rejectQuote(Long id) { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("id == idParam"); + quoteQuery.declareParameters("Long idParam"); + List<Quote> quotes = (List<Quote>) quoteQuery.execute(id); + + for (Quote quote : quotes) { + quote.setApproved(false); + pm.makePersistent(quote); + } + } + finally { + pm.close(); + } + } } diff --git a/src/lq/UserUtil.java b/src/lq/UserUtil.java new file mode 100644 index 0000000..4fd9452 --- /dev/null +++ b/src/lq/UserUtil.java @@ -0,0 +1,33 @@ +package lq; + +import javax.servlet.http.HttpServletRequest; +import com.google.appengine.api.users.User; +import com.google.appengine.api.users.UserService; +import com.google.appengine.api.users.UserServiceFactory; + +public class UserUtil { + public static final String getAuthenticatedEmail() { + UserService userService = UserServiceFactory.getUserService(); + User user = userService.getCurrentUser(); + if (user == null) { + return null; + } + else { + return user.getEmail(); + } + } + + public static final boolean isAuthenticated() { + return getAuthenticatedEmail() != null; + } + + public static final String getLoginUrl(String requestUrl) { + UserService userService = UserServiceFactory.getUserService(); + return userService.createLoginURL(requestUrl); + } + + public static final String getLogoutUrl(String requestUrl) { + UserService userService = UserServiceFactory.getUserService(); + return userService.createLogoutURL(requestUrl); + } +} |