Your first SocrateOpen Application - MyBookStore
Prerequisites:
For this tutorial you need:
an Oracle or OracleXE database
Java Development Kit (JDK), version 7.x.
a Glassfish 3.x application server
Download SocrateOpen Community Edition from http://comunitate.bitsoftware.ro/downloads-1
Configure Glassfish and install SocrateOpen according to https://sites.google.com/a/bitsoftware.ro/suport/socratecloud/instalare
Develop MyBookStore application
The minimal workflow for creating an extension to SocrateOpen is:
Create the underlying database table or add new column(s) to an existing one
Create a new Window based on your table
Add the window to the application menu.
All these steps will be made using the SocrateOpen java client, available at http://<your-server-name>/admin -> Web Start
In the login screen enter System for User ID and System for Password:
In the next scree leave the values unchanged:
If the login succeeded you should see the the Java Client Main window:
Create the underlying database table
In order to create the database table for your books, open the window named "Table an Column" located on Application Dictionary -> Table and Column and press the new record button in the selection window:
Fill in the following fields:
DB Table Name = XX_MyBook - this will be the name of the table in the database. As a naming convention all user defined tables should have the XX_ prefix.
Name = My books - this is the name of your table in the SocrateOpen Application Dictionary
Data Access Level = Tenant + Organization - this option allow your table to be accessed at Tenant Level.
Transaction Type = Optional Organization - the records in the table can belong to any organization
Entity Type = User maintained - as convention all user defined objects must have the "User maintained" entity type.
Save it by pressing the save button from the tool bar.
In order to create the mandatory columns, press "Create Columns from DB" button:
This process will create the following columns:
AD_Client_ID NUMBER(10,0) - mandatory in SocrateOpen for all tables
AD_Org_ID NUMBER(10,0) - mandatory in SocrateOpen for all tables
Created DATE+TIME - mandatory in SocrateOpen for all tables
CreatedBy NUMBER(10,0) - mandatory in SocrateOpen for all tables
IsActive CHAR(1) - mandatory in SocrateOpen for all tables
Updated DATE+TIME - mandatory in SocrateOpen for all tables
UpdatedBy NUMBER(10,0) - mandatory in SocrateOpen for all tables
XX_MyBook_ID NUMBER(10,0) - the Primary Key for your table
You can see these columns in the "Column" tab of the "Table and Column" window:
Additionally to these mandatory columns your table should have some specific ones. These can be:
Name: the title of the book
Description: a short description
Comment: your comments about the book
ISBN: the ISBN number of the book.
In order to create the new columns press the "New Record" button followed by the "Grid toggle" while you are in the Column tab of the window:
Fill in the following fields for the Name column:
DB Column Name: Name
System element: Name, then press Enter or Tab and choose Name from the list of available elements:
Name: Name
Length: 60
Reference: choose String
Entity Type: leave User Maintained
Press the "Synchronize column" button In order to create the new column in the database:
Repeat these steps for the Description and Comment columns with the following values:
Description:
DB Column Name: Description
System element: Description
Name: Description
Length: 255
Reference: choose String
Entity Type: leave User Maintained
Comment:
DB Column Name: Help
System element: Help
Name: Comment
Length: 2000
Reference: choose Text
Entity Type: leave User Maintained
Don't forget to press the "Synchronize Column" button for each of them!
For the ISBN column we do not have a System element, so we need to create one. Press New Record and:
DB Column Name: ISBN
System element:
Right Click in the System Element field and choose Zoom:
Define the new element in the "System Element" window by pressing the "New record" button:
Save it using the Save button, close the window and switch back to the Table and Column window.
Right click again in the System Element field and choose ReQuery
Now enter ISBN in the System element field followed by an Enter or Tab
Name: ISBN
Length: 17 (13 digits + 4 separator)
Reference: choose String
Entity Type: leave User Maintained
Don't forget to press the "Synchronize Column" button!
Create a new window for your table
You need an UI window in order to create/view/modify records in the newly created table. The structure of a standard window is: Window -> Tab -> Field where:
Window: is a "container" for Tabs
Tab: each tab is linked to a physical table in the database
Field: each field is linked to a column belonging to the table of the parent tab.
Follow these steps to define a new window:
Open the window named "Window, Tab & Field" located in the Application Dictionary menu, press the New Record button and give it a name (in the Name field).
Click on the "Tab" tab, press New record and, if necessary, the Grid toggle button. Fill in the fields as:
Name: the name of the tab
Entity type: leave User Maintained
Table: XX_MyBooks
Save it and press the "Create Fields" button in order to create the fields of the tab, based on the columns of the XX_MyBooks table. The fields created can be edited in the "Field" tab of the window:
You can specify the order of the fields in the "Field Sequence" tab. The new order should be:
Go back in the Field tab, and hit the Refresh button:
Select the field named Organization, enter in edit mode, by pressing the Grid toggle button, and select the "Same line" option. Selecting this option will place the field in the window on the same line as the preceding field.
Save the change.
Add the new window to the application menu
In order to be able to use the new window it must be added to the application menu. From the main window open the window named Menu, located in "System Admin" -> "General Rules" -> "System Rules" menu. Press Enter in the selection window. You should see the following window:
Press the New Record button and fill in the following fields:
Name: My books
Entity type: leave User Maintained
Action: choose Window
Window: choose My books
Save the new menu entry and close the main SocrateOpen window.
Use your Book Store window
Launch again the SocrateOpen Java Client and log in using the admin account of the Garden World tenant:
User ID: GardenAdmin
Password: GardenAdmin
Press enter, leave/choose for the role GardenWorld - GardenWorld Admin and press again Enter. You should see the following window:
Choose the Menu tab. Now you should see the My books menu entry:
Open it an try to add a new book in your collection:
As you can see no mandatory fields exist. Even the name (title) of the book can be empty. We have two options to enforce the mandatory constraint for a field:
Enforce at database column level
Enforce only for the field, but leave it nullable in the database
Log in again with the System account, open the window named "Table and Column" and search for your table (XX_MyBook):
Open the "Column" tab and edit the column named "Name":
If you choose "Mandatory", the column will be mandatory at database level. If you choose only "Mandatory UI", the field Name will be mandatory in the window(s) but the database column will continue to be nullable (not mandatory).
Don't forget to run "Synchronize Column" if you check the "Mandatory" option!
Log in again using the GardenAdmin account and open the "My books" window. As you can see the Name field became mandatory: