finished basic account add
[Bookkeeping.git] / src / com / interrupt / bookkeeping / http / ARServlet.java
blob276b655060b636b49193919ec9b86e4a05ff0ea5
1 package com.interrupt.bookkeeping.http;
3 import javax.servlet.ServletException;
4 import javax.servlet.SingleThreadModel;
5 import javax.servlet.http.HttpServlet;
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
9 import org.apache.log4j.Logger;
10 import org.exist.EXistException;
11 import org.exist.storage.BrokerPool;
12 import org.exist.util.Configuration;
13 import org.exist.util.DatabaseConfigurationException;
15 import java.io.File;
16 import java.io.FileReader;
17 import java.io.BufferedReader;
18 import java.io.PrintWriter;
19 import java.io.IOException;
20 import java.util.List;
21 import java.util.Map;
22 import java.util.Set;
23 import java.util.Iterator;
25 import com.interrupt.bob.base.Bob;
26 import com.interrupt.bob.base.IBob;
27 import com.interrupt.bookkeeping.ISystem;
28 import com.interrupt.bookkeeping.account.IAccount;
29 import com.interrupt.bookkeeping.account.IAccounts;
30 import com.interrupt.bookkeeping.cc.ExpressionVisitor;
31 import com.interrupt.bookkeeping.cc.ReplaceVisitor;
32 import com.interrupt.bookkeeping.cc.analysis.DepthFirstAdapter;
33 import com.interrupt.bookkeeping.cc.bkell.Bkell;
34 import com.interrupt.bookkeeping.cc.bkell.aauth.Aauthentication;
35 import com.interrupt.bookkeeping.cc.bkell.command.AddCommand;
36 import com.interrupt.bookkeeping.cc.bkell.command.GOption;
37 import com.interrupt.bookkeeping.cc.bkell.command.GOptions;
38 import com.interrupt.bookkeeping.cc.bkell.command.GResult;
39 import com.interrupt.bookkeeping.cc.bkell.command.GToken;
40 import com.interrupt.bookkeeping.cc.bkell.command.ICommand;
41 import com.interrupt.bookkeeping.cc.bkell.command.IResult;
42 import com.interrupt.bookkeeping.cc.bkell.command.ITokens;
43 import com.interrupt.bookkeeping.cc.bkell.command.ListCommand;
44 import com.interrupt.bookkeeping.cc.bkell.command.RemoveCommand;
45 import com.interrupt.bookkeeping.http.BookkeepingSystemFacade;
46 import com.interrupt.bookkeeping.http.ServletInputParams;
47 import com.interrupt.bookkeeping.journal.IEntries;
48 import com.interrupt.bookkeeping.journal.IEntry;
49 import com.interrupt.bookkeeping.journal.IJournal;
50 import com.interrupt.bookkeeping.journal.IJournals;
51 import com.interrupt.bookkeeping.system.BookkeepingSystem;
52 import com.interrupt.bookkeeping.users.IUserSession;
53 import com.interrupt.bookkeeping.users.UserSession;
54 import com.interrupt.util.IdGenerator;
57 public class ARServlet extends HttpServlet {
60 private Logger logger = Logger.getLogger(ARServlet.class);
63 /**
64 * Initialise the bookkeeping system
66 public void init() throws ServletException {
69 //** initialising the servlet
70 String valueDBUrl = getServletConfig().getInitParameter("db.url");
71 String valueExistInit = getServletConfig().getInitParameter("exist.initdb");
72 String valueExistHome = getServletConfig().getInitParameter("exist.home");
73 String valueSaxValidation = getServletConfig().getInitParameter("org.xml.sax.features.validation");
74 String valueEndorsedDirs = getServletConfig().getInitParameter("java.endorsed.dirs");
75 String valueConfFile = getServletConfig().getInitParameter("configuration");
77 logger.debug("");
78 logger.debug("db.url > "+ valueDBUrl);
79 logger.debug("exist.initdb > "+ valueExistInit);
80 logger.debug("exist.home > "+ valueExistHome);
81 logger.debug("org.xml.sax.features.validation > "+ valueSaxValidation);
82 logger.debug("java.endorsed.dirs > "+ valueEndorsedDirs);
84 if(valueDBUrl != null)
85 System.getProperties().setProperty("db.url", valueDBUrl);
87 if(valueExistInit != null)
88 System.getProperties().setProperty("exist.initdb", valueExistInit);
90 if(valueExistHome != null)
91 System.getProperties().setProperty("exist.home", valueExistHome);
93 if(valueSaxValidation != null)
94 System.getProperties().setProperty("org.xml.sax.features.validation", valueSaxValidation);
96 if(valueEndorsedDirs != null)
97 System.getProperties().setProperty("java.endorsed.dirs", valueEndorsedDirs);
101 public void doGet(HttpServletRequest req, HttpServletResponse resp)
102 throws ServletException, IOException {
105 logger.debug( "doGet CALLED >>> " );
108 public void doPost(HttpServletRequest req, HttpServletResponse resp)
109 throws ServletException, IOException {
112 logger.debug( "doPost CALLED >>> " );
114 try {
116 if(req.getSession(false) == null) {
119 logger.debug( "CREATING a new session" );
121 BookkeepingSystemFacade bsfacade =
122 (BookkeepingSystemFacade)(req.getSession(true).getAttribute(BookkeepingSystemFacade.FACADE_NAME));
123 if(bsfacade == null) {
125 logger.debug( "CREATING a new bsfacade" );
126 bsfacade = new BookkeepingSystemFacade();
127 bsfacade.initialise();
131 bsfacade.performAsRoot(req, resp);
132 String xmlResult= bsfacade.getBkell().getPreviousCommandResult().toXML(false);
133 logger.debug( "END ARServlet RESULT: " + xmlResult );
135 req.getSession().setAttribute(BookkeepingSystemFacade.FACADE_NAME, bsfacade);
138 catch(InterruptedException e) {
139 throw new ServletException(e);