Steve Jobs Project/POS/Documentation:en

From iDempiere
Jump to navigation Jump to search
This is a project under Cm:Cameroon
User:TheD is translating from the French version original by User:Trigger.

Technical Documentation

Do you know anything about Point Of Sale?
This is an essay about the technical documentation of the source code of OpenBravo Point Of Sale (OBPOS) using Netbeans IDE.
Feel free to use another compatible compiler.

Default Database Configuration Properties

Pos project tree.png

Let's start by describing the data model and show, into the code,
how the script define the DataBase and configuration properties...

I suppose you have imported the project source code successfully.

In NetbeansIDE your project should be like that on the picture below.
When you run the project the first time, the application notifies you because it does not find a database and informs you that it will create a default database. Just click on Yes!

Now take a look at the IDE console. We can see that the class responsible to application configurations is com.openbravo.pos.forms.AppConfig.


The following is an UML Class diagram for com.openbravo.pos.forms.AppConfig


Try to open the file into your IDE and focus on the part of code in which database parameters are configured. Into this class, the method in charge to initialise the default value of configuration parameters is loadDefault.

private void loadDefault() {
m_propsconfig = new Properties();
String dirname = System.getProperty("dirname.path");
dirname = dirname == null ? "./" : dirname;
new File(new File(dirname), "lib/derby.jar").getAbsolutePath());
m_propsconfig.setProperty("db.URL", "jdbc:derby:" + 
new File(new File(System.getProperty("user.home")), 
AppLocal.APP_ID + "-database").getAbsolutePath() +
m_propsconfig.setProperty("db.user", "");
m_propconfig.setProperty("db.password", "");

For those who wish to go further, you can see the value of these variables using the debugger by placing a breakpoint, launching the debugger and verifying the state of the various variables. On my pc, I have the following outcome of which it is important to note that this result depends on the platform used (Windows, Mac, Linux,...). Defautl-variable-values.png

You certainly noticed!!! The method has as aim to initialise other configuration parameters of the application. Once the parameters initialised, watch the script create the data base.

How does POS automatically create the data base by default?

The class responsible for creating tables in the data base iscom.openbravo.pos.forms.JRootApp.The method in which are interested in, in this class initApp has as role, to create a session and a schedule of the data uses the classe com.openbravo.pos.forms.AppViewConnection to connect into the data base by the method getSession(). Then JRootApp calls the method magic!!! the interior of which the creation of the data base is as such created: getBean.
The method getBean creates an object of type com.openbravo.pos.forms.DataLogicAdmin, which is inherited from the class
com.openbravo.pos.forms.BeanFactoryDataSingle, which in turn implements the interface com.openbravo.pos.forms.BeanFactoryApp,
then calls the initial method declared in the interface BeanFactoryApp. It is this which then automatically creates the scheme for the data base(SELECT).

Initialisation and pop up of the window containing the app properties.

Take a look at the method main of the class com.openbravo.pos.form.StartPOS!
As we can see, the method main instanciates an object config of the class AppConfig.
AppConfig implements the interface AppProperties which offer the methods getConfigFile(), getHost()
and getProperty(java.lang.String sKey).


Constructing the object config

The objet config contains two important attributes: m_propsconfig and configfile. During the construction of the object config, the following is executed: init(getDefaultConfig()).


The joint methods getDefaultConfig() resends an object of the type containing the path towards the file which is found by default in the directory « home » with Linux OS (or « user » with Windows OS).

 private File getDefaultConfig() {
      return new File(new File(System.getProperty("user.home")),
           AppLocal.APP_ID + ".properties"); }

The method init( config) initialises the attribute configfile with the object of type
resent by the method getDefaultConfig(), then the attribute m_propsconfig with an instance of type java.util.Properties.

 private void init(File configfile) {
          this.configfile = configfile;
         m_propsconfig = new Properties();"Reading configuration file: " + configfile
                 .getAbsolutePath()); }

After the instantiation of the object config, the method main initialises the attribute m_propsconfig
by the call of the method load(). This then initialises m_propsconfig with the defualt parameters
(through the private method loadDefault()) or from the file through the object config.
As such, it is possible to type the configurations by modifying the file either directly by using
a text editor, or via the software (it suffices to click successively on Maintenance → Resources and then select the file

This is an image of the contents of the file #Openbravo POS. Configuration file. #Wed Aug 20 19:44:58 WAT 2014 payment.commerceid= paper.receipt.height=546 format.time= format.integer= db.driver=org.apache.derby.jdbc.EmbeddedDriver payment.gateway=external machine.printer=screen paper.standard.y=72 paper.standard.x=72 format.datetime= payment.magcardreader=Not defined machine.scanner=Not defined payment.commercepassword=password db.password=crypt\:2A396841DF90414B db.URL=jdbc\:derby\:/home/trigger/openbravopos-database;create\=true db.driverlib=/home/trigger/NetBeansProjects/OpenbravoPOS/./lib/derby.jar user.variant= paper.standard.width=451 paper.standard.height=698 format.percent= machine.scale=Not defined machine.ticketsbag=standard machine.screenmode=window machine.hostname=trigger-VPCEG36EC machine.display=screen machine.printer.3=Not defined paper.standard.mediasizename=A4 machine.printer.2=Not defined user.language=en db.user= paper.receipt.width=190 machine.printername=(Default) machine.uniqueinstance=false format.double= format.currency= payment.testmode=false paper.receipt.y=287 paper.receipt.x=10 paper.receipt.mediasizename=A4

For those who are curious, this is one part of the script of the method loadDefault() which initializes the default configuration parameters of the application.


Construction and printing of the login window

Let us now look at the last instruction of the fonction main :

               if ("fullscreen".equals(screenmode)) {
                  JRootKiosk rootkiosk = new JRootKiosk();
                  rootkiosk.initFrame(config); }
               else {
                  JRootFrame rootframe = new JRootFrame(); 

By default, the popup type is window. The expression "fullscreen".equals(screenmode) has as value false. As such, the command else is executed.
This command comprises two instructions. The first instanciates an object rootframe of type com.openbravo.pos.forms.JRootFrame, which is
inherited from the class javax.swing.JFrame, and the second calls the method initFrame(com.openbravo.pos.forms.AppProperties props) on rootframe.
The method initFrame initialises the attribute m_rootapp, of the class JRootFrame, with one instance of the class com.openbravo.pos.forms.JRootApp.
JRootApp is a descendant class of javax.swing.JPanel. It represents the panel on which the various graphic components of the login window will be
implanted, which(the graphic components) are initialized, by the method initComponent(), during the construction of m_rootapp.

  /** Creates new form JRootApp */
  public JRootApp() {    
      m_aBeanFactories = new HashMap<String, BeanFactory>();
      // Initialize the visual components
      initComponents ();            
      jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35));   

Before popping up, the class JRootApp calls la method initApp(com.openbravo.pos.form.AppPropereties props)
which in turn calls up the method getBean(java.lang.String className). It is important to note that
the method getBean sends an object of type java.lang.Object which explains the operation "changing of type" in
the following instruction :

m_dlSystem = (DataLogicSystem)getBean("com.openbravo.pos.forms.DataLogicSystem");

The method getBean refers to an object which is a parameter in form of a chain of characters. Taking a look at the script of the method permits us to notice, just before the instruction return bf.getBean(), calling the method init(com.openbravo.pos.forms.AppView app) of the interface com.openbravo.pos.forms.BeanFactoryApp. The method init is responsible for the initialization of requesting interrogation of data through objects of type PreparedSentence et StaticSentence.

Before the creation or update of the data base, the object m_rootapp of the class JRootApp reads the version of the data base and does a function of the result of a comparison between the read version and the default version. In our case, since the data base does not exist, only creation will be executed.

// Create or upgrade the database if database version is not the expected
       String sDBVersion = readDataBaseVersion();        
       if (!AppLocal.APP_VERSION.equals(sDBVersion)) {
           // Create or upgrade database

Before seeing the creation of the said database, lets take a look at the reading of the version of the database.

Lecture de la version de l'application dans la base de données

The following sequence diagram represents interactions between objects POS application, from the creation the window JRootFrame to the reading of the version of the application in the data base.