...
Table of Contents |
---|
Overview
QCADOO MES system uses Entity.
The Model , which is an in-memory cache of data retrieved from Java Bean or coresonded view, is the major component of the data access architecture. The Model View consists of a collection of Entity objects (related to one another) to specify properities of each field. Entiety can be connected to a method (called hook) started under specified condition e.g. OnSave started after calling save method for an entity. Model is built after reading data to Java Bean.
You can also enforce data integrity by using validators.
Structure
...
Overview
Basically the model in Qcadoo Framework defines the structure of the table in database and maps it into key-value structure.
Additionally it defines fields' contraints and custom methods, called hooks, which are linked with model lifecycle.
All models used by system are defined in separated XML files . Every plugin has one directory model which contains xml files with definition of entities used by this plugin.
...
located under the directory src/main/resources/pluginIdentifier. They are registered in qcadoo-plugin.xml using model module.
Please find below a list of all build-in modules related to model.
Filter by label (Content by label) | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Structure
Name of defined entity must be unique within the plugin scope.
Default value of attribute "auditable" is "false" and the attribute itself is not mandatory. When it's "true" every entity in the database defined by the model will have standard predefined fields: createdate, updatedate, createuser and updateuser. These fields store information about who and when created and last edited the entity.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<model name="sampleModel" auditable="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schema.qcadoo.org/model" xsi:schemaLocation="http://schema.qcadoo.org/model http://schema.qcadoo.org/model.xsd"> <fields> // HERE YOU PUT FIELD DEFINITIONS </fields> <hooks> // HERE YOU PUT HOOK DEFINITIONS </hooks> // HERE YOU PUT IDENTIFIER </model> |
Where:
...
Structure of field definition
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<fieldType options /> |
or
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<fieldType options> // HERE YOU PUT VALIDATORSVALIDATOR DEFINITIONS </fieldType> |
Where:
- fieldType - is a type of field
- options - options of field
Field types
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
Structure of validator definition
Validators are attached to fields.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<validatorType validatorOptions /> |
...
- validatorType - type of validator
- validatorOptions - options of validator
Validator types
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
...
You can create custom event hook and attach it to defined model. To do it first you must create custom method (see this link).
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<eventName class="className" method="methodName"<hookType hookOptions /> |
Where:
- eventName - name of event (see below)
- className - definies path and name to object with your custom method
- methodName - definies custom method name
Hook types
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
Identifier
Role of entity identifier is to convert entity defined in model to a simple text (see expressions overview). It is used for example when showing operation messages.
If not defined, system will use field 'number' of defined entity.
...
If "expression" is givet it is used to evaluate identifier, otherwise "number" field will be taken.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<identifier expression="#number + ' - ' + #name"/> |
Where:
...
Examples
These examples definies three simple entities.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?xml version="1.0" encoding="UTF-8"?> <model name="product" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schema.qcadoo.org/model" xsi:schemaLocation="http://schema.qcadoo.org/model http://schema.qcadoo.org/model.xsd"> <fields> <string name="number" required="true" unique="true"> <validatesLength max="40" /> </string> <string name="name" required="true" /> <enum name="typeOfMaterial" values="01component,02intermediate,03product,04waste" required="true" /> <string name="ean" /> <dictionary name="category" dictionary="categories" /> <dictionary name="unit" dictionary="units" required="true" /> <string name="batch"> <validatesLength max="255" /> </string> <string name="lastUsedBatch"> <validatesLength max="255" /> </string> <boolean name="genealogyBatchReq" /> <hasMany name="substitutes" model="substitute" joinField="product" cascade="delete" copyable="true" /> <hasMany name="technologies" model="technology" joinField="product" /> <hasMany name="orders" model="order" joinField="product" /> <hasMany name="operationProductInComponents" model="operationProductInComponent" joinField="product" /> <hasMany name="operationProductOutComponents" model="operationProductOutComponent" joinField="product" /> <hasMany name="substituteComponents" model="substituteComponent" joinField="product" /> </fields> <hooks /> <identifier expression="#number + ' - ' + #name"/> </model> |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?xml version="1.0" encoding="UTF-8"?> <model name="substitute" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schema.qcadoo.org/model" xsi:schemaLocation="http://schema.qcadoo.org/model http://schema.qcadoo.org/model.xsd"> <fields> <string name="number" required="true" unique="true"> <validatesLength max="40" /> </string> <string name="name" required="true" /> <belongsTo name="product" model="product" lazy="false" required="true" /> <hasMany name="components" model="substituteComponent" joinField="substitute" cascade="delete" copyable="true" /> <priority name="priority" scope="product" /> </fields> <hooks> <validatesWith class="com.qcadoo.mes.products.ProductService" method="checkIfProductIsNotRemoved" /> </hooks> <identifier expression="#number + ' - ' + #name" /> </model> |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?xml version="1.0" encoding="UTF-8"?> <model name="substituteComponent" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schema.qcadoo.org/model" xsi:schemaLocation="http://schema.qcadoo.org/model http://schema.qcadoo.org/model.xsd"> <fields> <belongsTo name="product" model="product" lookupField="name" required="true" /> <belongsTo name="substitute" model="substitute" required="true" /> <decimal name="quantity" required="true"> <validatesRange from="0" exclusively="true" /> <validatesPrecision max="7" /> <validatesScale max="3" /> </decimal> </fields> <hooks> <validatesWith class="com.qcadoo.mes.products.ProductService" method="checkIfSubstituteIsNotRemoved" /> <validatesWith class="com.qcadoo.mes.products.ProductService" method="checkSubstituteComponentUniqueness" /> </hooks> <identifier expression="#product['number'] + ' - ' + #product['name']"/> </model> |