Tutorial 22 - Document Generation
Tutorial 22 - Document Generation
22 - Document generation
Table of contents
1. OBJECTIVE......................................................................................................... 2
2. BASE DOCUMENT............................................................................................. 2
3. DOCUMENT TO CREATE................................................................................ 2
3.1. LOGICAL DESCRIPTION OF THE DOCUMENT (SHARED PART)............................. 2
3.2. VISUAL REPRESENTATION (CLIENT PART)........................................................ 2
3.3. SERVER IMPLEMENTATION .............................................................................. 2
4. DOCUMENT GENERATION SERVER RULE .............................................. 2
4.1. DESCRIPTION OF THE RULE .............................................................................. 2
4.2. ADDING THE RULE ........................................................................................... 2
5. PROPERTIES FILES.......................................................................................... 2
5.1. BUSINESS UNIT ................................................................................................ 2
5.2. BINDER AND DOCUMENT LIBRARY ................................................................. 2
5.3. MODULE PROPERTIES FILES ............................................................................. 2
5.3.1. un.asytutorialAdv.properties ..................................................................... 2
5.3.2. un.asytutorialAdv.tutorial22.person.properties file .................................. 2
5.3.3. un.asytutorialAdv.tutorial22.child.properties file ..................................... 2
Figures
FIGURE1 - THIS IS AN EXAMPLE OF FIGURE........................................................................... 2
FIGURE2 - PERSON DOCUMENT............................................................................................. 2
FIGURE3 - CHILD DOCUMENT VISUAL REPRESENTATION ...................................................... 2
Source code
SOURCE 1 - THIS IS AN EXAMPLE OF SOURCE CODE ................................................................ 2
SOURCE 2 - C_CHILD FILE ..................................................................................................... 2
SOURCE 3 - DEFINITION OF THE MAIN DATA MODEL OF THE DOCUMENT IN THE D_CHILD
CLASS 2
SOURCE 4 - DEFINITION OF THE DATA MODEL FOR THE CHILDREN DESCRIPTION IN THE
DS_CHILD CLASS ................................................................................................................ 2
SOURCE 5 - CREATING THE TABLE IN THE VISUAL PAGE VP_CHILD ....................................... 2
SOURCE 6 - ABSTRACT OF THE S_CHILD CLASS ..................................................................... 2
SOURCE 7 - SERVER RULE, SR_CREATECHILD: GENERATE THE CHILD DOCUMENT ................ 2
SOURCE 8 - ADDING THE SERVER RULE IN S_PERSON.JAVA FILE............................................ 2
SOURCE 9 - ASYTUTORIALADV_CREATE.XML FILE MODIFICATIONS ....................................... 2
SOURCE 10 - BUSINESS UNIT DECLARATION IN THE INSTALL_SRC.XML FILE ............................ 2
SOURCE 11 - ABSTRACT OF THE INSTALL_SRC.XML FILE ......................................................... 2
SOURCE 12 - UN.ASYTUTORIALADV.PROPERTIES ..................................................................... 2
SOURCE 13 - DEFINITION OF A SERVER BINDER PROPERTY ....................................................... 2
SOURCE 14 - UN.ASYTUTORIALADV.TUTORIAL22.PERSON.PROPERTIES FILE MODIFICATION ... 2
SOURCE 15 - UN.ASYTUTORIALADV.TUTORIAL22.CHILD.PROPERTIES FILE ............................. 2
Keyword Definition
Source 1 -
This is an example
of source code Source code.
1. Objective
In this document you will learn
How to generate a document with a server rule
Required element
Knowledge on server rules
The objective of this tutorial is to explain how to generate a document automatically with a
server rule.
To do this, two documents must be created:
• The original document: for convenience, this one will be created by replicating the
last basic tutorial (use the replicator tool on the Tutorial 9 document)
• The document to generate: this one has to be created entirely. It will be another
representation of the original document.
2. Base document
In this part, the original document is described. This document is the one used in “basic
tutorials”, defining a person and his children.
To create it, use the “replicator” tool to copy the “un.asytutorialAdv.tutorial9” and define
this document as the “un.asytutorialAdv.tutorial22.Person” document.
A server rule will be added to the document further.
3. Document to create
In this part, the document to generate is described. Despite of the limited usage of this new
document (containing the same information, but presented in a different way), it is the
opportunity to present a new component: the “KTable” component.
This table component will be used to show the children of a person.
Source 2 -
C_Child file package un.asytutorialAdv.tutorial22.Child;
import so.kernel.core.Operation;
/**
* Definition of the Constant data
*
*/
// Status
public static final String ST_NULL = null;
public static final String ST_CREATED = "Created";
// Operation name
public static final String OP_CREATE = Operation.CREATE_OPERATION_NAME;
public static final String OP_VIEW = Operation.VIEW_OPERATION_NAME;
public static final String OP_DELETE = Operation.DELETE_OPERATION_NAME;
// Operation identificator
public static final int OI_CREATE = Operation.CREATE_OPERATION_ID;
public static final int OI_VIEW = Operation.VIEW_OPERATION_ID;
public static final int OI_DELETE = Operation.DELETE_OPERATION_ID;
/**
* Data Model.
*/
// Key
public final static String INSTANCE_ID = "INSTANCE_ID";
public static final String CBD = "CBD"; // child Birth date
public static final String CFN = "CFN"; // child first name
public static final String CHD = "CHD"; // Segment Child
public final static String FNA = "FNA"; //First name
public final static String IDE = "IDE"; //Segment identity
public final static String LNA = "LNA"; //Last name
// Data name
The Data Object Model of this document looks like the one of the original document. In
fact, fields have been removed to keep a refine vision of a person and his children.
Source 3 -
Definition of the …
main data model of /**
the document in the * Definition of the Data Model
*/
D_Child class public void define_DataModel() {
define_DataInformation();
// End of the definition of the Data Model
}
…
Source 4 -
Definition of the …
data model for the /**
children description * Definition of the Data Model
*/
in the DS_Child public void define_DataModel() {
class add(CFN); // Child name
add(CBD); // Child birth date
define_DataInformation();
// End of the definition of the Data Model
}
Source 5 -
Creating the table …
in the visual page public class VP_Child extends ElfVisualPage implements C_Child {
VP_Child
// Definition of controls
transient private ElfField fld_FirstName = elfFieldPool.getElfField();
transient private ElfField fld_LastName = elfFieldPool.getElfField();
transient private KTable tbl_Children = new KTable();
public VP_Child() { … }
// Add controls
add(170, 20, 150, 20, fld_FirstName, lng("First name"));
add(170, 50, 150, 20, fld_LastName, lng("Last name"));
/**
* Retrieves a property string in the current working language.
*
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("TutorialAdv", property);
}
}
The server class must define a create operation. This operation will be used in the server
rule generating the document.
Source 6 -
Abstract of the package un.asytutorialAdv.tutorial22.Child.server;
S_Child class
import so.kernel.core.Operation;
import so.kernel.core.Operations;
import so.kernel.server.ConnectionManager;
import so.kernel.server.DPP;
import so.kernel.server.GCFServerBinder;
import so.kernel.server.OperationFactory;
import so.kernel.server.Server;
import un.asytutorialAdv.tutorial22.Child.C_Child;
/**
* Name of the resource table identifier for the Customs database tables
*/
public static final String PERSON_TAB = "TUTORIALADV_PERSON_TAB2";
/**
* Name of the identifier for the database link URL. The actual name will be
* loaded from the resource file.
*/
public static final String DB_URL_PROPERTY = S_Child.class.getName() +
"#TUTORIALADV_TUTORIAL22_DataBaseURL";
/**
* Name of the database identifier for the user name. The actual name will
* be loaded from the resource file.
*/
public static final String DB_USR_PROPERTY = S_Child.class.getName() +
"#TUTORIALADV_TUTORIAL22_DataBaseUser";
/**
* Name of the database identifier for the user password. The actual name
* will be loaded from the resource file.
*/
public static final String DB_PWD_PROPERTY = S_Child.class.getName() +
"#TUTORIALADV_TUTORIAL22_DataBasePassword";
/**
* Constructor
*
*/
public S_Child() {
super();
}
/**
* Creation of the Document Processing Path
*/
protected DPP createDPP() {
DPP dpp = new DPP();
return dpp;
}
/**
* Define binders
*/
public void defineBinder() {
TC_Child tc = new TC_Child(this, getConnectionManager(0));
addServerRule(tc);
/**
* Define the universe of operations
*/
protected Operations createValidOperations() {
setDefaultOperationFlag(FIND);
Operations ops = super.createValidOperations();
// Create operation
Operation op_Create = OperationFactory.makeCreateOperation(OI_CREATE,
OP_CREATE);
ops.add(op_Create);
// View operation
Operation op_View = OperationFactory.makeViewOperation(OI_VIEW, OP_VIEW);
ops.add(op_View);
// Delete operation
Operation op_Delete = OperationFactory.makeDeleteOperation(OI_DELETE,
OP_DELETE);
ops.add(op_Delete);
return ops;
}
/**
* Database initialisation
*/
public void initializeDatabase() {
ConnectionManager manager = createConnectionManager(DB_URL_PROPERTY,
DB_USR_PROPERTY, DB_PWD_PROPERTY);
if (manager == null) {
System.err.println("TutorialAdv database not found");
}
}
The two tables used in the child document need two table connectors. These one are not
presented here because they are very similar to the one of the Person document (table
connectors presented in basic tutorials).
Source 7 -
Server rule, package un.asytutorialAdv.tutorial22.Person.server;
SR_CreateChild:
generate the child import java.util.Enumeration;
document import so.kernel.core.DataSet;
import so.kernel.core.Document;
import so.kernel.core.KNumberedSubDataSet;
import so.kernel.core.KernelEvent;
import so.kernel.core.interfaces.DocumentInterface;
import so.kernel.server.GCFServerEvent;
import so.kernel.server.OperationRunner;
import so.kernel.server.ServerBinder;
import so.kernel.server.ServerRule;
import un.asytutorialAdv.tutorial22.Child.C_Child;
import un.asytutorialAdv.tutorial22.Person.C_Person;
/**
* Constructor
*
* @param serverbinder
*/
public SR_CreateChild(ServerBinder serverbinder) {
super(serverbinder);
}
/**
* Application of the rule
*
* @param kernelevent
*/
/**
* Application of the rule
* @param kernelevent
*/
protected void apply(KernelEvent kernelevent) {
GCFServerEvent event = (GCFServerEvent) kernelevent;
UserTransactionEnvironment ute = event.getUserTransactionEnvironment();
DataSet doc =ute.getFinalDocument().ds(DocumentInterface.NORMAL_ID);
/**
* Retrieves a property string in the current working language.
*
*/
public static String lng(String property) {
return so.i18n.IntlObj.createMessage("TutorialAdv", property);
}
}
Source 8 -
Adding the server …
rule in public void defineBinder() {
S_Person.java file …
// Create the Child document
addServerRule(new SR_CreateChild(this), OE_REGISTER);
setDefaultOperationFlag(FIND);
Operations ops = super.createValidOperations();
…
}
…
5. Properties files
We have to prepare all configuration files.
Notice that we declare two files used for database automatic installation.
• asytutorialAdv_create.xml for the automatic creation of the tables in the
database.
• asytutorialAdv_insert.xml for the automatic insertion of records in the
tables.
These files are located in:
un\asytutorialAdv\server\src\un\asytutorialAdv\server\som\db
In this part, the modifications of the xml file for the database creation are presented. Two new
tables are defined, used for the “child” document.
Source 9 -
<create>
asytutorialAdv_cre
…………
ate.xml file <table name="TUTORIAL22_PERSON_TAB">
modifications <column name="INSTANCE_ID" type="INTEGER" null="false"/>
<column name="IDE_FNA" type="VARCHAR" size="35"/>
<column name="IDE_LNA" type="VARCHAR" size="35"/>
<column name="IDE_MNA" type="VARCHAR" size="35"/>
<column name="IDE_BDA" type="TIMESTAMP"/>
<column name="IDE_PIC" type="LONGVARBINARY"/>
<column name="IDE_SEX" type="INTEGER"/>
<column name="IDE_FLG" type="INTEGER"/>
<column name="JOB_JBC" type="INTEGER"/>
<column name="COO_ADR" type="VARCHAR" size="50"/>
<column name="COO_CPO" type="VARCHAR" size="6"/>
<column name="COO_TEL" type="VARCHAR" size="20"/>
<column name="COO_CIT" type="VARCHAR" size="25"/>
<column name="USR_LOG" type="VARCHAR" size="20"/>
<column name="USR_PWD" type="VARCHAR" size="20"/>
<column name="CJT_INSTANCE_ID" type="INTEGER"/>
<primary_key>
<column name="INSTANCE_ID"/>
</primary_key>
</table>
<table name="TUTORIAL22_CHILD_TAB">
<column name="INSTANCE_ID" type="INTEGER" null="false"/>
<column name="RNK" type="INTEGER" null="false"/>
<column name="CHD_NAM" type="VARCHAR" size="35"/>
<column name="CHD_BDA" type="TIMESTAMP"/>
</table>
<table name="TUTORIAL22_PERSON_TAB2">
<column name="INSTANCE_ID" type="INTEGER" null="false"/>
<column name="IDE_FNA" type="VARCHAR" size="35"/>
<column name="IDE_LNA" type="VARCHAR" size="35"/>
<primary_key>
<column name="INSTANCE_ID"/>
</primary_key>
</table>
<table name="TUTORIAL22_CHILD_TAB2">
<column name="INSTANCE_ID" type="INTEGER" null="false"/>
<column name="RNK" type="INTEGER" null="false"/>
<column name="CHD_NAM" type="VARCHAR" size="35"/>
<column name="CHD_BDA" type="TIMESTAMP"/>
</table></create>
Source 10 -
business unit
declaration in the <BU name="BUasytutorialAdv">Advanced tutorial</BU>
install_src.xml file
The Business Units on a document could be defined manually filling this file or using the
ASYCUDA client application. The defined Business Units will be added automatically in
ASYCUDA environment with the appropriated rights if they are defined in the
install_src.xml file.
Shortcut is usually situated after binder tags definition within <DL> XML tags.
Source 11 -
Abstract of the …
install_src.xml file <BU name="BUasytutorialAdv">asytutorialAdv BU</BU>
…
<binder name="B_TUT22_PERSON" status="">
<field name="server"
value="un.asytutorialAdv.tutorial22.Person.server.S_Person"/>
<field name="dom"
value="un.asytutorialAdv.tutorial22.Person.D_Person"/>
<field name="client"
value="un.asytutorialAdv.tutorial22.Person.client.DC_Person"/>
<access bu="BUasytutorialAdv">
<full/>
</access>
</binder>
5.3.1. un.asytutorialAdv.properties
This file is common to all the reference tables of the module.
Source 12 -
un.asytutorialAdv.p …
roperties @include un.asytutorialAdv.tutorial22.Person.properties
@include un.asytutorialAdv.tutorial22.Child.properties
…
To be able to generate the document “child” from the document “person”, its binder name is
needed. This value is set in the “person” document properties file as a property of the server
binder of the “person” document.
A server binder property is defined as follow:
Source 13 -
Definition of a
server binder <package>.<module>.<document>.server.S_XXX#<property name>=<value>
property
Source 14 -
un.asytutorialAdv.t
utorial22.Person.pr un.asytutorialAdv.tutorial22.Person.server.S_Person#TUTORIALADV_TUTORIAL22_DataB
operties file aseURL=$[un.asytutorialAdv_URL]
un.asytutorialAdv.tutorial22.Person.server.S_Person#TUTORIALADV_TUTORIAL22_DataB
modification aseUser=$[un.asytutorialAdv_User]
un.asytutorialAdv.tutorial22.Person.server.S_Person#TUTORIALADV_TUTORIAL22_DataB
asePassword=$[un.asytutorialAdv_Password]
un.asytutorialAdv.tutorial22.Person.server.S_Person#TUTORIALADV_PERSON_TAB=TUT
ORIAL22_PERSON_TAB
un.asytutorialAdv.tutorial22.Person.server.S_Person#TUTORIALADV_CHILD_TAB=TUTOR
IAL22_CHILD_TAB
un.asytutorialAdv.tutorial22.Person.server.S_Person$attached_finder#CONJOINT=un.asytu
torialAdv B_TUT22_PERSON
un.asytutorialAdv.tutorial22.Person.server.S_Person#Child=un.asytutorialAdv
B_TUT22_CHILD
Source 15 -
un.asytutorialAdv.t un.asytutorialAdv.tutorial22.Child.server.S_Child#
utorial22.Child.pro TUTORIALADV_TUTORIAL22_DataBaseURL= $[un.asytutorialAdv_URL]
perties file un.asytutorialAdv.tutorial22.Child.server.S_Child#
TUTORIALADV_TUTORIAL22_DataBaseUser= $[un.asytutorialAdv_User]
un.asytutorialAdv.tutorial22.Child.server.S_Child#
TUTORIALADV_TUTORIAL22_DataBasePassword=$[un.asytutorialAdv_Password]
un.asytutorialAdv.tutorial22.Child.server.S_Child#
TUTORIALADV_PERSON_TAB2=TUTORIAL22_PERSON_TAB2
un.asytutorialAdv.tutorial22.Child.server.S_Child#
TUTORIALADV_CHILD_TAB2=TUTORIAL22_CHILD_TAB2
Now you can compile and deploy your module with Ant tools.