1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.select.document.web.struts;
17
18 import org.apache.struts.action.ActionMapping;
19 import org.kuali.ole.select.businessobject.OleRequisitionItem;
20 import org.kuali.ole.select.document.OleOrderQueueDocument;
21 import org.kuali.ole.sys.OLEConstants;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.kim.api.services.IdentityManagementService;
24 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25 import org.kuali.rice.kns.web.struts.form.KualiTransactionalDocumentFormBase;
26 import org.kuali.rice.kns.web.ui.ExtraButton;
27 import org.kuali.rice.krad.util.GlobalVariables;
28
29 import javax.servlet.http.HttpServletRequest;
30 import java.sql.Timestamp;
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35
36
37
38
39 public class OleOrderQueueForm extends KualiTransactionalDocumentFormBase {
40
41
42 private String selectedUserId;
43
44 private String selectorUserId;
45
46 private String principalName;
47
48 private Timestamp createdDate;
49
50 private Timestamp modifiedDate;
51
52 private String statusCode;
53
54 private Integer totalPrice;
55
56 private String active;
57
58 private List<OleRequisitionItem> requisitions = new ArrayList<OleRequisitionItem>(0);
59
60 protected boolean selectAllCheckbox;
61
62 private String url;
63
64 private String selectorRoleName = OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE;
65 private String selectorRoleNamespace = OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE_NAMESPACE;
66
67 public String getUrl() {
68 return OLEConstants.DOC_HANDLER_URL;
69 }
70
71 public String getSelectedUserId() {
72 return selectedUserId;
73 }
74
75 public void setSelectedUserId(String selectedUserId) {
76 this.selectedUserId = selectedUserId;
77 }
78
79 public String getSelectorUserId() {
80 return selectorUserId;
81 }
82
83 public void setSelectorUserId(String selectorUserId) {
84 this.selectorUserId = selectorUserId;
85 }
86
87 public Timestamp getCreatedDate() {
88 return createdDate;
89 }
90
91 public void setCreatedDate(Timestamp createdDate) {
92 this.createdDate = createdDate;
93 }
94
95 public Timestamp getModifiedDate() {
96 return modifiedDate;
97 }
98
99 public void setModifiedDate(Timestamp modifiedDate) {
100 this.modifiedDate = modifiedDate;
101 }
102
103 public String getStatusCode() {
104 return statusCode;
105 }
106
107 public void setStatusCode(String statusCode) {
108 this.statusCode = statusCode;
109 }
110
111 public Integer getTotalPrice() {
112 return totalPrice;
113 }
114
115 public void setTotalPrice(Integer totalPrice) {
116 this.totalPrice = totalPrice;
117 }
118
119 public String getActive() {
120 return active;
121 }
122
123 public void setActive(String active) {
124 this.active = active;
125 }
126
127
128
129
130
131
132 public String getPrincipalName() {
133 return principalName;
134 }
135
136
137
138
139
140
141 public void setPrincipalName(String principalName) {
142 this.principalName = principalName;
143 }
144
145
146
147
148
149
150 public List<OleRequisitionItem> getRequisitions() {
151 return requisitions;
152 }
153
154
155
156
157
158
159 public void setRequisitions(List<OleRequisitionItem> requisitions) {
160 this.requisitions = requisitions;
161 }
162
163 public void addRequisitions(OleRequisitionItem data) {
164 this.requisitions.add(data);
165 }
166
167 public boolean isRequisitionAdded() {
168 return this.requisitions.size() > 0;
169 }
170
171
172 private String lookupResultsSequenceNumber;
173
174
175
176
177
178
179 public String getLookupResultsSequenceNumber() {
180 return lookupResultsSequenceNumber;
181 }
182
183
184
185
186
187
188 public void setLookupResultsSequenceNumber(String lookupResultsSequenceNumber) {
189 this.lookupResultsSequenceNumber = lookupResultsSequenceNumber;
190 }
191
192 public boolean isSelectAllCheckbox() {
193 return selectAllCheckbox;
194 }
195
196 public void setSelectAllCheckbox(boolean selectAllCheckbox) {
197 this.selectAllCheckbox = selectAllCheckbox;
198 }
199
200 public String getSelectorRoleName() {
201 return selectorRoleName;
202 }
203
204 public void setSelectorRoleName(String selectorRoleName) {
205 this.selectorRoleName = selectorRoleName;
206 }
207
208 public String getSelectorRoleNamespace() {
209 return selectorRoleNamespace;
210 }
211
212 public void setSelectorRoleNamespace(String selectorRoleNamespace) {
213 this.selectorRoleNamespace = selectorRoleNamespace;
214 }
215
216 @Override
217 public String getRefreshCaller() {
218 return "refreshCaller";
219 }
220
221 public OleOrderQueueForm() {
222 super();
223 setDocument(new OleOrderQueueDocument());
224 setDocTypeName("OLE_ORDQU");
225 }
226
227 @Override
228 public void populate(HttpServletRequest req) {
229 super.populate(req);
230 }
231
232 @Override
233 public void addRequiredNonEditableProperties() {
234 super.addRequiredNonEditableProperties();
235 registerRequiredNonEditableProperty("lookupResultsSequenceNumber");
236 }
237
238 protected boolean canApprove() {
239
240 String nameSpaceCode = OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE_NAMESPACE;
241
242 boolean canApprove = KimApiServiceLocator.getPermissionService().hasPermission(
243 GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
244 OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_APPROVE_REQ);
245 return canApprove;
246 }
247
248 protected boolean canDelete() {
249
250 String nameSpaceCode = OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE_NAMESPACE;
251
252 boolean canDelete = KimApiServiceLocator.getPermissionService().hasPermission(
253 GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
254 OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_APPROVE_REQ);
255 return canDelete;
256 }
257
258 protected boolean canTotal() {
259 return true;
260 }
261
262 protected boolean canAssign() {
263 String documentTypeName = OLEConstants.OrderQueue.DOCUMENT_TYPE;
264 String nameSpaceCode = OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ROLE_NAMESPACE;
265
266 boolean canAssign = SpringContext.getBean(IdentityManagementService.class).hasPermission(GlobalVariables.getUserSession().getPerson().getPrincipalId(), nameSpaceCode,
267 OLEConstants.OleRequisitionItem.ORDER_HOLD_QUEUE_ASSIGN_PERMISSION);
268 return canAssign;
269 }
270
271 protected boolean canCreateNewList() {
272 return true;
273 }
274
275 protected boolean canTotalSelectedItems() {
276 return true;
277 }
278
279 @Override
280 public List<ExtraButton> getExtraButtons() {
281 super.getExtraButtons();
282 Map buttonsMap = createButtonsMap();
283
284 if (canApprove()) {
285 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.massApprove"));
286 }
287 if (canDelete()) {
288 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.delete"));
289 }
290
291
292
293 if (canAssign()) {
294 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.assign"));
295 }
296
297
298
299 if (canTotalSelectedItems()) {
300 extraButtons.add((ExtraButton) buttonsMap.get("methodToCall.totalSelectedItems"));
301 }
302
303 return extraButtons;
304 }
305
306
307
308
309
310
311 protected Map<String, ExtraButton> createButtonsMap() {
312 HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>();
313
314
315
316
317
318 ExtraButton approveButton = new ExtraButton();
319 approveButton.setExtraButtonProperty("methodToCall.massApprove");
320 approveButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}approve.gif");
321 approveButton.setExtraButtonAltText("Approve");
322
323 ExtraButton deleteButton = new ExtraButton();
324 deleteButton.setExtraButtonProperty("methodToCall.delete");
325 deleteButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}cancel requistion.gif");
326 deleteButton.setExtraButtonAltText("Cancel Requisition");
327
328 ExtraButton totalButton = new ExtraButton();
329 totalButton.setExtraButtonProperty("methodToCall.total");
330 totalButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}tinybutton-add1.gif");
331 totalButton.setExtraButtonAltText("Total");
332
333 ExtraButton assignButton = new ExtraButton();
334 assignButton.setExtraButtonProperty("methodToCall.assign");
335 assignButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}assign.gif");
336 assignButton.setExtraButtonAltText("Assign");
337
338 ExtraButton createNewListButton = new ExtraButton();
339 createNewListButton.setExtraButtonProperty("methodToCall.createNewList");
340 createNewListButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_amend.gif");
341 createNewListButton.setExtraButtonAltText("Create New List");
342
343 ExtraButton totalSelectedItemsButton = new ExtraButton();
344 totalSelectedItemsButton.setExtraButtonProperty("methodToCall.totalSelectedItems");
345 totalSelectedItemsButton.setExtraButtonSource("${" + OLEConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}totalselected_items.gif");
346 totalSelectedItemsButton.setExtraButtonAltText("Total Selected Items");
347
348 result.put(approveButton.getExtraButtonProperty(), approveButton);
349 result.put(deleteButton.getExtraButtonProperty(), deleteButton);
350 result.put(totalButton.getExtraButtonProperty(), totalButton);
351 result.put(assignButton.getExtraButtonProperty(), assignButton);
352 result.put(createNewListButton.getExtraButtonProperty(), createNewListButton);
353 result.put(totalSelectedItemsButton.getExtraButtonProperty(), totalSelectedItemsButton);
354
355 return result;
356
357 }
358
359 @Override
360 public void reset(ActionMapping mapping, HttpServletRequest request) {
361 List<OleRequisitionItem> refreshItems = new ArrayList<OleRequisitionItem>(0);
362 List<OleRequisitionItem> orderQueueRequisitions = ((OleOrderQueueDocument) getDocument()).getRequisitionItems();
363 if (orderQueueRequisitions != null) {
364 for (OleRequisitionItem item : orderQueueRequisitions) {
365 item.setItemAdded(false);
366 refreshItems.add(item);
367 }
368
369 ((OleOrderQueueDocument) getDocument()).setRequisitionItems(refreshItems);
370 }
371 if (getLookupResultsSequenceNumber() != null) {
372 setLookupResultsSequenceNumber(null);
373 }
374 super.reset(mapping, request);
375 }
376 }