1 package org.sourceforge.vlibrary.user.actions;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.apache.log4j.Logger;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionForward;
12 import org.apache.struts.action.ActionMapping;
13 import org.apache.struts.util.MessageResources;
14 import org.sourceforge.vlibrary.Constants;
15 import org.sourceforge.vlibrary.exceptions.LibraryException;
16 import org.sourceforge.vlibrary.user.domain.Book;
17 import org.sourceforge.vlibrary.user.domain.Reader;
18 import org.sourceforge.vlibrary.user.valuebeans.LibraryTransaction;
19
20 public class StatusBookAction extends LibraryAction {
21
22
23
24
25
26
27
28
29
30
31
32
33 private static Logger logger =
34 Logger.getLogger(StatusBookAction.class.getName());
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @Override
51 public ActionForward executeAction(ActionMapping mapping,
52 ActionForm form,
53 HttpServletRequest request,
54 HttpServletResponse response,
55 MessageResources messages)
56 throws Exception {
57 final ArrayList<LibraryException> errors = new ArrayList<LibraryException>();
58
59
60 long book = 0;
61 try {
62 book = Long.parseLong(request.getParameter(Constants.ID));
63 } catch (final Exception e) {
64 final String errString = messages.getMessage("error.trans.bad.id");
65 logger.error(errString,e);
66 errors.add(new LibraryException(errString,e));
67 return standardForward(mapping,request,errors);
68 }
69
70
71 try {
72
73 Book bk = new Book();
74 bk.setId(book);
75 bk = libraryManager.retrieveBook( book);
76 request.setAttribute(Constants.BOOK,bk);
77
78
79 final List<LibraryTransaction> transactions = libraryManager.getTransactions(book);
80 request.setAttribute(Constants.TRANSACTIONS,transactions.toArray());
81
82
83 final long reader = libraryManager.getPossessor(book);
84 Reader rd = new Reader();
85 rd.setId(reader);
86 if (reader != Constants.CHECKED_IN) {
87 rd = libraryManager.retrieveReader(reader);
88 }
89 request.setAttribute(Constants.POSSESSOR,rd);
90
91 } catch (final Throwable t) {
92 final String errString = messages.getMessage("error.trans.retrieve.sql");
93 logger.error(errString,t);
94 errors.add(new LibraryException(errString,t));
95 }
96 return standardForward(mapping,request,errors);
97 }
98 }