From ac9d7b3012496f411f7ba6c19d31c9496b44327f Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Fri, 3 Sep 2010 14:20:40 -0400 Subject: Add approve functionality. --- src/lq/QuoteUtils.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/lq/QuoteUtils.java') 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 getQuotesPendingApproval() { + PersistenceManager pm = PMF.get().getPersistenceManager(); + try { + Query quoteQuery = pm.newQuery(Quote.class); + quoteQuery.setFilter("approved == null"); + List quotes = (List) quoteQuery.execute(); + pm.retrieveAll(quotes); + return quotes; + } + finally { + pm.close(); + } + } + public static List getQuotesOrderedByIdDesc() { List 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 quotes = (List) 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 quotes = (List) quoteQuery.execute(id); + + for (Quote quote : quotes) { + quote.setApproved(false); + pm.makePersistent(quote); + } + } + finally { + pm.close(); + } + } } -- cgit v1.2.3