Michal Doubek Free University of Bozen - Bolzano J2ME Exam Project P6 Expense Management 1. Contents: 1. Contents:...1 2. The System functions...2 2.1. Client...2 2.2. Server...2 3. The Human Computer Interaction...2 4. The Structure of the Code...5 4.1. Client...5 4.1.1. Main...5 4.1.2. InitForms...6 4.1.3. Expense...6 4.1.4. Settings...6 4.1.5. Memory...6 4.1.6. UpDown...6 4.1.7. Connect...7 4.1.8. Converter...7 4.1.9. ConverterCompute...7 4.2. Server...7 4.2.1. Servlets...7 4.2.2. Database...7 4.2.3. Beans...7 4.2.4. CSVGenerator...7 5. The Major Technical Problems...8 6. Conclusion...8 7. Future Improvements...8
2. The System functions 2.1. Client Keep record of your expenses o Date: the date of the expense o Description: short description o Amount: the amount you paid o Payment method: the payment method used to pay o Category: the category of the expense Plastic settings of payment methods Upload the expenses to the server (missing expenses synchronization) Persistent login data Currency converter Rates update 2.2. Server Login management (sessions) Receiving and checking expenses from clients Generating CSV file from expenses Updating of currency rates using Web Service 3. The Human Computer Interaction Identification of typical tasks o Add, edit and remove expense.
o Upload expenses to server, user can upload data directly or edit login data first and then do the upload.
o Convert amount to certain currency (EUR, USD, GBP) or update rates using server. Identification of expected user Expert daily user needs minimum of actions, abbreviations, macros, plastic interface. Regarding to this fact there isn t any invitation form; user directly opens the list of expenses and is able to add new expense. To give user partial plasticity, there is a possibility to manage methods (by user s settings). Login and upload is possible directly from first form, login data are stored in memory, and then user doesn t have to type them by each login. These data are available to change in user s settings. Data are saved by successful login.
4. The Structure of the Code 4.1. Client FORMS: 4.1.1. Main This is core of Expense MIDlet. This class contains nine forms and seventeen commands. Of course it contains MIDlet standard methods (startapp, pauseapp, destroyapp and CommandAction). In addition to these methods there is a method run, main class implements interface Runnable. As the connection to server could take a long time, it runs in its own thread and main thread shows to user a ticker that application is working, please wait. NAME addexpensef addmethodf connectingf editmethodsf expensef loginf settingsf showexpensef statusf DESCRIPTION Form for adding expenses, contains three TextFields for date, descripton and amount. There are two ChoiceGroup for methods and categories. Form for adding method to the memory. Form for ticker, when application is working this form is displayed. Form for editing method and saving to memory. This is first form, which is displayed after start of application, shows to user list of current expenses. Form contains login data, user can edit them and submit. When user is successfully logged in, these data are saved to memory. Form for navigation to various settings, edit method, categories (not implemented) or login data. Viewing single expense. Result form, show user a result of his action, only possibility to leave this form is to main form (expensef). COMMANDS: NAME addmethodc addmethodtextc categorysetupc deleteallc deleteexpensec exitc ExpensesC loginc methodsetupc addexpensec removemethodc DESCRIPTION Adds method, opens a new form for inputting a name of method. Submits a name of method to add. Not implemented Deletes all expenses from memory. Deletes one expense from the list. Shuts down the application. Returns user to the main form (list of expenses). Shows user form for editing login data. Shows user a list of methods. Shows user a form for adding expense. Removes selected method.
resetc saveexpensec settingsc showexpensec submitc uploadc Resets memory (adding test expenses, removing login data, stored number of session) Saves current expense. Redirects user to settings form. Shows selected expense. Tries to login to server with inserted data. Logins to the server, downloads a session number, which is stored in memory, then this number is used for verification by each user action. 4.1.2. InitForms Class for initializing forms, contains methods of which input and output is single form, appends certain items to each forms. It s also used as interface to settings and expense class. In addition to init methods it has methods for add, edit and remove expenses, methods and login data. 4.1.3. Expense This class represents certain expense having its variables. It has methods for communication with memory (saveexpense, loadexpense). Before storing expense to memory each expense is coded i.e. all parts are divided by symbol # and send to memory class as one string. It has also a method for coding expense before sending to the server, because url can t contain a symbols space or hash, so they are coded to %20 or %2B (by ASCII table). 4.1.4. Settings Similar class to Expense, this class also communicates with own instance of memory and saves names of methods, login data. 4.1.5. Memory This is modified class from lectures; only bigger modification is method getvalue, there is a defined value, if element is not in the Hashtable, method returns value String def, not null, this avoids NullPointerExceptions in further operations. 4.1.6. UpDown This class is created for communication with server. Method login constructs a url with login parameters. After that it processes the response from Server. Method upload constructs a url with coded expense and number of session for verification. UpDown also has a method downloadrates, which asks server for up-to-date currency rates. Method getdata is just working method for decoding response.
4.1.7. Connect This class is for connection to the server. Main method is ConnectGET(String URL), which connects to the server using received parameter url and returns a response. Parameters are sent in URL using method GET. 4.1.8. Converter This is second MIDlet, it s created as a core of Currency Converter, contains three forms, one is for input data, one shows the result of conversion and the last one is ticker, which is shown, when the MIDlet is downloading the up-to-date rates. It uses class UpDown for communication with server. 4.1.9. ConverterCompute This class computes the conversions itself and using class Memory it stores them into a memory. 4.2. Server Server is made of four packages and jsp files as interface for standard web browsers. 4.2.1. Servlets This package is designed for communication with cell phone client, it contains four classes. MyServlet is for login and generating session number. RecieveExpense gets expenses from client, decodes them and search if expense is already on the server or not. If not expense is stored into the server database. SendMessage is not yet fully implemented; it s for sending expenses to the client. Rates this class uses a web service to get up-to-date currency rates and sends them to the client. 4.2.2. Database This package is created for communication with hsqldb database, queries data for entities and checks if session numbers are still active. Each session has one hour expiration time. 4.2.3. Beans This package contains classes representing all entities (Expense, User and Session) and list of entities (ListOfExpenses, ListOfUsers, ListOfSessions) for saving and loading entity classes use database.manager. 4.2.4. CSVGenerator
This package contains only one class for generating CSV files for expenses. 5. The Major Technical Problems 6. Conclusion Easy install database In my previous J2EE application I used MySQL for database, but for easier installation and manipulation I found hsqldb http://hsqldb.org/, which is fully implement in java, then it could be easily linked to war file and then there isn t any installation. Synchronization problem - How to know which expense is already in server database and which not. How to recognize different expenses e.g. each day user can eat in cafeteria and pay same amount of money, type same description etc. Solution: when is new expense created it gets its own value of time and date, which is significant as ID (used on both sides, server/client). Generating CSV file, when items contains signs like commas or quotation marks, it could make a mess in generated file. To solve commas each item in file is closed between quotation marks, to solve quotation marks in description, there is methods which substitute one question mark by three to fulfill CSV requirements. E.g. Shopping in Spar, Bolzano -> Shopping in Spar, Bolzano How to verify client by server and not ask for a login each time during the expenses transfer. User gets a session number which is valid for half an hour and each time when it is used, expiration date is extended. This is advantageous, when user would use other password protected service from service (could be implemented in future). I implement nice application, which covers many technologies - J2ME, servelts and JSP, hsqldb, web service. Of course it s not perfect e.g. downloading expenses from server is not finished or editing categories like methods is not implemented, but instead of repeating the same code I ve implemented some new interesting features like Currency Converter with web service update. I did it alone and spend more than forty hours on this project, but gained experience enriched me a lot and I would like to continue working on this project and add some new functions and fine-tune the rest. See the list below. 7. Future Improvements Possibility to download expenses from server Editing categories like methods Increase number of currencies (now there are just USP, GBP and EUR) Improve code quality referenced to Currency Converter Improve viewing, sorting and searching of expenses on server 2 layered system on server (admin, users)
Allow user to choose between : to save or not save his username and password in cell phone memory (increase settings possibility) Improve display design, add graphic items Add more commentary to code Automatically pre-filled window with date, when user add a new expense Replace hashes with other symbol in coding of expenses, when hashes are used for coding, there is a limitation, that user cannot use them in expenses Implementation of https protocol to improve security Possibility to automatically back up old expenses in cell phone and display expenses only not older than week.