View Javadoc

1   package org.sourceforge.vlibrary.user.actions;
2   
3   import java.util.ArrayList;
4   
5   import javax.servlet.http.HttpServletRequest;
6   import javax.servlet.http.HttpServletResponse;
7   
8   import org.apache.log4j.Logger;
9   import org.apache.struts.action.ActionForm;
10  import org.apache.struts.action.ActionForward;
11  import org.apache.struts.action.ActionMapping;
12  import org.apache.struts.util.MessageResources;
13  import org.sourceforge.vlibrary.Constants;
14  import org.sourceforge.vlibrary.exceptions.LibraryException;
15  import org.sourceforge.vlibrary.user.forms.TransactionForm;
16  import org.sourceforge.vlibrary.user.valuebeans.BookMoveTransaction;
17  
18  
19  /**
20   * <p>Action supporting checkin/checkout operations.
21   * </p>
22   * <p>This action expects the <code>book</code> and <code>reader</code> IDs to
23   * be on the incoming {@link TransactionForm}, along with the
24   * <code>transactionType</code>. The move transaction is accomplished
25   * by invoking
26   * {@link org.sourceforge.vlibrary.user.logic.LibraryManagerFacade#processExchange(long, long, String)}.
27   * The {@link BookMoveTransaction} returned by this method is
28   * placed in the request with the key, {@link Constants#TRANS}.</p>
29   *
30   * @version $Revision$ $Date$
31   */
32  
33  public class MoveBookAction extends LibraryAction {
34  
35      /** log4j Logger */
36      private static Logger logger =
37          Logger.getLogger(MoveBookAction.class.getName());
38  
39  
40      /**
41       * Process checkin/checkout using data on transaction form.
42       *
43       * @param mapping ActionMapping used to select this instance
44       * @param form  TransactionForm associated with this request
45       * @param request HTTP request
46       * @param response  HTTP response* @param messages message resources
47       *
48       * @exception Exception
49       */
50      public ActionForward executeAction(ActionMapping mapping,
51       ActionForm form,
52       HttpServletRequest request,
53       HttpServletResponse response,
54       MessageResources messages)
55       throws Exception {
56  
57          ArrayList<LibraryException> errors = new ArrayList<LibraryException>();
58  
59          // Get the book, reader and location from the form
60          TransactionForm frm = (TransactionForm) form;
61  
62          final long book = frm.getBook();
63          final long reader = frm.getReader();
64          final String transactionType = frm.getTransaction();
65          final long location = frm.getLocation();
66  
67          BookMoveTransaction t = new BookMoveTransaction();
68          try {
69              t = libraryManager.processExchange(reader, book, transactionType, location);
70          } catch (Throwable e) {
71              errors.add(new LibraryException(e.getMessage(), e));
72  
73              logger.error(e.getMessage(), e);
74  
75              return standardForward(mapping,request,errors);
76          }
77  
78          request.setAttribute(Constants.TRANS,t);
79  
80          return standardForward(mapping,request,errors);
81      }
82  }