1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.gwe.app.client.web.servlet;
18
19 import java.io.PrintWriter;
20 import java.io.Serializable;
21 import java.io.StringWriter;
22 import java.io.Writer;
23 import java.rmi.RemoteException;
24 import java.util.List;
25
26 import org.gwe.api.ServerAPIConnectionException;
27 import org.gwe.api.Session4ClientAPIEnhancer;
28 import org.gwe.api.exceptions.PasswordMismatchException;
29 import org.gwe.app.client.web.request.Operation;
30 import org.gwe.app.client.web.request.PageModel;
31 import org.gwe.app.client.web.request.Param;
32 import org.gwe.persistence.model.OrderInfo;
33 import org.gwe.persistence.model.order.p2el.POrderDescriptor;
34 import org.gwe.utils.rex.REXException;
35
36
37
38
39
40 public class QueueOrderServlet extends GWEClusterSelectedServlet {
41
42 public QueueOrderServlet() { super("queue"); }
43
44 protected void specificPageModelPopulation(PageModel pageModel, Session4ClientAPIEnhancer session) {
45 String p2el = pageModel.getParam(Param.P2EL);
46 if (p2el == null || "".equals(p2el)) return;
47 Operation mode = pageModel.getOperation();
48 try {
49 POrderDescriptor<Serializable> descriptor = (POrderDescriptor) getConfig().createOrderDescriptor(p2el);
50 switch (mode) {
51 case PREVIEW:
52 pageModel.addIdentifiedObject(Param.OPER, getParsedP2EL(descriptor));
53 preview(pageModel, session, descriptor);
54 break;
55 case QUEUE:
56 queue(pageModel, session, descriptor);
57 break;
58 }
59 } catch (REXException e) {
60
61 }
62 }
63
64 private String getParsedP2EL(POrderDescriptor<Serializable> descriptor) {
65 try {
66 return descriptor.getP2ELStatementObj().toStringFormatted("", "\n");
67 } catch (Exception e) {
68 Writer result = new StringWriter();
69 e.printStackTrace(new PrintWriter(result));
70 return "Invalid P2EL statement: " + result.toString();
71 }
72 }
73
74 private void queue(PageModel pageModel, Session4ClientAPIEnhancer session, POrderDescriptor<Serializable> descriptor) {
75 try {
76 OrderInfo order = new OrderInfo(descriptor);
77 order = session.queueOrder(order);
78 pageModel.addIdentifiedObject(Param.P2EL, order);
79 pageModel.setParam(Param.P2EL, null);
80 } catch (PasswordMismatchException e) {
81
82 } catch (RemoteException e) {
83
84 } catch (ServerAPIConnectionException e) {
85
86 }
87 }
88
89 private void preview(PageModel pageModel, Session4ClientAPIEnhancer session, POrderDescriptor<Serializable> descriptor) {
90 try {
91 OrderInfo order = new OrderInfo(descriptor);
92 List<String> commands = session.previewOrder(order);
93 pageModel.addIdentifiedObject(Param.COMMANDS, commands);
94 } catch (PasswordMismatchException e) {
95
96 } catch (RemoteException e) {
97
98 } catch (ServerAPIConnectionException e) {
99
100 } catch (Exception e) {
101
102 }
103 }
104 }
105
106
107