View Javadoc

1   package org.sourceforge.vlibrary.user.forms;
2   
3   import java.util.ArrayList;
4   
5   import javax.servlet.http.HttpServletRequest;
6   
7   import org.apache.log4j.Logger;
8   import org.apache.struts.action.ActionErrors;
9   import org.apache.struts.action.ActionMapping;
10  import org.apache.struts.util.MessageResources;
11  import org.sourceforge.vlibrary.Constants;
12  import org.sourceforge.vlibrary.user.domain.Location;
13  import org.sourceforge.vlibrary.user.domain.Reader;
14  
15  /**
16   * Action Form used in checkin/checkout transactions
17   * @version $Revision$ $Date$
18   */
19  
20  public class TransactionForm extends LibraryForm {
21      private static final long serialVersionUID = 0;
22  
23      /** log4j Logger */
24      private static Logger logger =
25       Logger.getLogger(TransactionForm.class.getName());
26  
27      /** Message Resources */
28      private static MessageResources messages =
29       MessageResources.getMessageResources(Constants.APPLICATION_RESOURCES);
30  
31      private long book = 0;
32      private String transaction="";
33      private String deskPhone="";
34      private String uid="";
35      private long reader = 0;
36      private long location = 0;
37      private ArrayList<Reader> readers = null;
38      private ArrayList<Location> locations = null;
39  
40      public String getClassName() {
41          return TransactionForm.class.getName();
42      }
43  
44      public long getBook() {
45          return book;
46      }
47  
48      public void setBook(long book) {
49          this.book = book;
50      }
51  
52      public String getTransaction() {
53          return transaction;
54      }
55  
56      public void setTransaction(String transaction) {
57          this.transaction = transaction;
58      }
59  
60      /** Getter for property reader.
61       * @return Value of property reader.
62       */
63      public long getReader() {
64          return reader;
65      }
66  
67      /** Setter for property reader.
68       * @param reader New value of property reader.
69       */
70      public void setReader(long reader) {
71          this.reader = reader;
72      }
73  
74      /**
75       * Obsolete: to be removed
76       * Getter for property deskPhone.
77       * @return Value of property deskPhone.
78       */
79      public String getDeskPhone() {
80          return deskPhone;
81      }
82  
83      /**
84       * Obsolete: to be removed
85       * Setter for property deskPhone.
86       * @param deskPhone New value of property deskPhone.
87       */
88      public void setDeskPhone(String deskPhone) {
89          this.deskPhone = deskPhone;
90      }
91  
92      /**
93       * Sets the uid of the user making the transaction
94       *
95       * @param uid the user ID value to set
96       */
97      public void setUid(String uid) {
98          this.uid = uid;
99      }
100 
101     /**
102      * @return the uid of the user making the transaction
103      */
104     public String getUid() {
105         return this.uid;
106     }
107 
108     /**
109      * Sets the location for a check-in transaction
110      * @param id ID of the location
111      */
112     public void setLocation(long id) {
113         this.location = id;
114     }
115 
116     /**
117      * @return the ID of the location of the transaction
118      */
119     public long getLocation() {
120         return this.location;
121     }
122 
123     /**
124      * For all CHECKIN transactions and CHECKOUT transactions that have a
125      * uid, looks up the reader by uid and sets the <code>reader</code>
126      * property to the returned id.
127      */
128     public ActionErrors validate(ActionMapping mapping,
129      HttpServletRequest request) {
130 
131         if (logger.isDebugEnabled()) {
132             logger.debug(messages.getMessage("entering.validate"));
133             logger.debug("reader = " + reader + "uid =  " + uid);
134         }
135 
136         ActionErrors errors = new ActionErrors();
137 
138         long readerByUID = 0;
139 
140         if (
141                 (transaction.equals(Constants.CHECKIN) ||
142                  transaction.equals(Constants.CHECKOUT))
143                 && (uid!= null && uid.length() > 0)
144            ) {
145             // Look up the uid and fill in the reader id
146             // if the user has entered a uid.  Otherwise,
147             // reader id will be picked up from the pulldown list
148 
149             try {
150                 readerByUID = libraryManager.retrieveByUid(uid).getId();
151             } catch (Throwable le) {
152                 logger.error("uid = " + uid);
153                 logger.error("len = " + uid.length());
154                 logger.error(messages.getMessage("error.reader.retrieve"),le);
155             }
156         }
157 
158         if (readerByUID > 0) {
159             reader = readerByUID;
160         }
161 
162         if (logger.isDebugEnabled() && errors.isEmpty()) {
163             logger.debug(messages.getMessage("validate.successful"));
164         }
165 
166         return errors;
167     }
168 
169     /** Getter for property readers.
170      * @return Value of property readers.
171      */
172     public ArrayList<Reader> getReaders() {
173         return readers;
174     }
175 
176     /** Setter for property readers.
177      * @param readers New value of property readers.
178      */
179     public void setReaders(ArrayList<Reader> readers) {
180         this.readers = readers;
181     }
182 
183     /**
184      * @return currently defined locations
185      */
186     public ArrayList<Location> getLocations() {
187         return locations;
188     }
189 
190     /**
191      * Sets the locations property.
192      *
193      * @param locations new locations list
194      */
195     public void setLocations(ArrayList<Location> locations) {
196         this.locations = locations;
197     }
198 }