001: package phoneList.presentation;
002:
003: import com.lutris.appserver.server.httpPresentation.*;
004:
005: import phoneList.spec.*;
006:
007: public class DoActionPresentation implements HttpPresentation {
008:
009: public void run(HttpPresentationComms comms) throws Exception {
010: String first = null;
011: try {
012: first = comms.request.getParameter("first");
013: } catch (Exception e) {
014: }
015: String last = null;
016: try {
017: last = comms.request.getParameter("last");
018: } catch (Exception e) {
019: }
020: String phone = null;
021: try {
022: phone = comms.request.getParameter("phone");
023: } catch (Exception e) {
024: }
025: String id = null;
026: try {
027: id = comms.request.getParameter("id");
028: } catch (Exception e) {
029: }
030: String action = null;
031: try {
032: action = comms.request.getParameter("action");
033: } catch (Exception e) {
034: }
035:
036: PhoneList phoneList = PhoneListFactory
037: .getPhoneList("phoneList.business.PhoneListImpl");
038: String okTarget = comms.request
039: .getAppFileURIPath("ListPresentation.po");
040: String errTarget = comms.request
041: .getAppFileURIPath("ErrorPresentation.po");
042: ClientPageRedirectException err = new ClientPageRedirectException(
043: errTarget);
044:
045: if (action.equals("delete")) {
046: if ((id == null) || (id.length() == 0)) {
047: err.addArgument("err", "Error: no id specified.");
048: throw err;
049: }
050: try {
051: phoneList.deletePerson(id);
052: /*
053: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run phoneBookClient_pres )
054: * We need to allow phoneBookClient_pres to be functional
055: */
056: } catch (NullPointerException ex) {
057: err
058: .addArgument("err",
059: "Error: You cannot delete person while runing phoneBookClient_pres!");
060: throw err;
061: }
062: } else if (action.equals("edit")) {
063: if ((id == null) || (id.length() == 0)) {
064: err.addArgument("err", "Error: no id specified.");
065: throw err;
066: }
067: if ((first == null) || (first.length() == 0)) {
068: err.addArgument("err",
069: "Error: no first name specified.");
070: throw err;
071: }
072: if ((last == null) || (last.length() == 0)) {
073: err
074: .addArgument("err",
075: "Error: no last name specified.");
076: throw err;
077: }
078: if ((phone == null) || (phone.length() == 0)) {
079: err.addArgument("err",
080: "Error: no phone number specified.");
081: throw err;
082: }
083: try {
084: phoneList.modifyPerson(id, first, last, phone);
085: //same thing
086: } catch (NullPointerException ex) {
087: err
088: .addArgument("err",
089: "Error: You cannot modify person while runing phoneBookClient_pres!");
090: throw err;
091: }
092:
093: } else if (action.equals("create")) {
094: if ((first == null) || (first.length() == 0)) {
095: err.addArgument("err",
096: "Error: no first name specified.");
097: throw err;
098: }
099: if ((last == null) || (last.length() == 0)) {
100: err
101: .addArgument("err",
102: "Error: no last name specified.");
103: throw err;
104: }
105: if ((phone == null) || (phone.length() == 0)) {
106: err.addArgument("err",
107: "Error: no phone number specified.");
108: throw err;
109: }
110: try {
111: phoneList.addPerson(first, last, phone);
112: //same thing
113: } catch (NullPointerException ex) {
114: err
115: .addArgument("err",
116: "Error: You cannot add person while runing phoneBookClient_pres!");
117: throw err;
118: }
119:
120: } else {
121: // Shouldn't happen.
122: }
123:
124: throw new ClientPageRedirectException(okTarget);
125: }
126:
127: }
|