In this tutorial you will learn how replicate the users data from the PBX to your app.
Conventions
The used file and class names in this example are based on a newly created App with the name NewApp1 and the company name innovaphone. Your filenames might be different according to your settings.
To be able to replicate, the app needs to have access to PbxTableUsers and need the name of the PBX.
Testing and expected behaviour
For testing the app we need to have several users on the PBX. When editing an user, the changes should be relicated to your database. You could check if the users and the changes are been replicated to your app by checking your database using for example Putty.
You can connect to your database with Putty setting as Host Name the IP address of your AP Platform, as Port the 22 and as Connection type SSH. Then you have to login using your admin credentials provided by the installer and connecting to your database using PostgreSQL commands.
Connecting to your database
psql -d databasename;
Reading your users table
select * from users;
Step by step
Task 1: Create your replicator object
On the constructor of your app instance, the replicator has to be declared. Here you can check the Replicator functions.
After declaring the object, you can add fields to the replicator. There you can link the name of a data field from the PBX to a column from your database.
Include the replicator and tasks_postgresql header files.
Allow the AppInstance class to use JsonApiContext as base class and the UReplicator.
Declare the replicator object as public global variable from the app instance class on the header file.
Create a new object replicator using the IReplicator class on your app instance constructor.
Register your replicator object as a Json Api calling the function RegisterJsonApi.
Call the AddColumn function to start the synchronization of h323 field to your username column.
Do the same for the cn field and your cn column.
When an AppWebsocket connection is established, it needs to be added to the JsonApiContext.
Include the replicator and tasks_postgresql header file NewApp1.h
The table to save the replicated data from the PBX needs to be added. Here you can check the Database functions. You can also check this
Database Tutorial about how to use the database.
Initialize the users table.
Add id, username and cn columns to the table.
Add a constraint to the username, which must be unique.
Add the Init callbacks to the NewApp1 class and the TaskDatabaseInit task.
Initialize the users table and add id, username and cn columns to the table.
The table to save the replicated data from the PBX needs to be added. Here you can check the Database functions. You can also check this
Database Tutorial about how to use the database.
When DatabaseConnectComplete is called the database can be initialized.
When DatabaseInitComplete is called the replicator must be started.
When the replicator has started, the webserverPlugin Listen functions can be called. The replicator->Update() function has to be called to set the PBX name.
When DatabaseConnectComplete is called the database can be initialized.
When DatabaseInitComplete the replicator must be started.
void NewApp1::DatabaseInitComplete(class TaskDatabaseInit * task)
{
replicator->Initialize("BIGINT REFERENCES users(id) ON DELETE CASCADE NOT NULL");
}
When the replicator has started, the webserverPlugin Listen functions can be called. The replicator->Update() function has to be called to set the PBX name.
Task 6: Add groups table to your database and replicate the groups data
The table to save the replicated data from the PBX needs to be added. Here you can check the Database functions. You can also check this
Database Tutorial about how to use the database.
Add the groups table and the id, group_name, active, mode and dyn columns.
Add id, group_name, active, mode and dyn columns to the replicator.
Add the groups table and the id, group_name, active, mode and dyn columns.