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
17
18
19
20 public class TransactionForm extends LibraryForm {
21 private static final long serialVersionUID = 0;
22
23
24 private static Logger logger =
25 Logger.getLogger(TransactionForm.class.getName());
26
27
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
61
62
63 public long getReader() {
64 return reader;
65 }
66
67
68
69
70 public void setReader(long reader) {
71 this.reader = reader;
72 }
73
74
75
76
77
78
79 public String getDeskPhone() {
80 return deskPhone;
81 }
82
83
84
85
86
87
88 public void setDeskPhone(String deskPhone) {
89 this.deskPhone = deskPhone;
90 }
91
92
93
94
95
96
97 public void setUid(String uid) {
98 this.uid = uid;
99 }
100
101
102
103
104 public String getUid() {
105 return this.uid;
106 }
107
108
109
110
111
112 public void setLocation(long id) {
113 this.location = id;
114 }
115
116
117
118
119 public long getLocation() {
120 return this.location;
121 }
122
123
124
125
126
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
146
147
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
170
171
172 public ArrayList<Reader> getReaders() {
173 return readers;
174 }
175
176
177
178
179 public void setReaders(ArrayList<Reader> readers) {
180 this.readers = readers;
181 }
182
183
184
185
186 public ArrayList<Location> getLocations() {
187 return locations;
188 }
189
190
191
192
193
194
195 public void setLocations(ArrayList<Location> locations) {
196 this.locations = locations;
197 }
198 }