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
All model entites used by system are defined in XML files. Every plugin has one directory model which contains xml files with definition of entities used by this plugin.
<model name="sampleModel" 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:
- name - is a name of defined entity, it must be unique within the plugin scope
Structure of field definition
<fieldType options />
or
<fieldType options> // HERE YOU PUT VALIDATORS </fieldType>
Where:
- fieldType - is a type of field
- options - options of field
Field types
- BelongsTo Field — belongsTo - many-to-one relation.
- Boolean field — boolean - true/false value.
- Date field — date - date.
- Datetime field — datetime - date with time.
- Decimal field — decimal - decimal number.
- Dictionary Field — dictionary - value from dictionary.
- Enum Field — enum - predefined value.
- HasMany Field — hasMany - one-to-many relation.
- Integer field — integer - integer number.
- ManyToMany Field — manyToMany - many-to-many relation.
- Password Field — password - password.
- Priority Field — priority - priority.
- String field — string - short text.
- Text field — text - long text.
- Tree Field — tree - tree-structured one-to-many relation.
Structure of validator definition
Validators are attached to fields.
<validatorType validatorOptions />
Where:
- validatorType - type of validator
- validatorOptions - options of validator
Validator types
Entity 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.
<identifierExpression value="#number + ' - ' + #name"/>
Structure of hook definition
Validators are attached to fields.
<validatorType validatorOptions />
Where:
- validatorType - type of validator
- validatorOptions - options of validator
Hook types
2.6.1 model event hook declaration
You can create custom event hook and attach it to defined model. To do it first you must create custom method (see this link). After that you can insert hook declaration:
<eventName class="className" method="methodName" />
Where:
- eventName - name of event (see below)
- className - definies path and name to object with your custom method
- methodName - definies custom method name
OnSave hook
Event fired before entity is saved (created or updated).
<onSave class="com.sample.SampleHook" method="updateModifiedAt" />
OnCreate hook
Event fired before entity is created.
<onCreate class="com.sample.SampleHook" method="generateNumber" />
OnUpdate hook
Event fired before entity is updated.
<onUpdate class="com.sample.SampleHook" method="markAsModified" />
OnCopy hook
Event fired before entity is copied.
<onCopy class="com.sample.SampleHook" method="resetStatus" />
ValidatesWith hook
Event fired to validate whole entity.
<validatesWith class="com.sample.SampleHook" method="checkIfFirstnameMatchesGender" />
Examples
These examples definies three simple entities.
<?xml version="1.0" encoding="UTF-8"?> <qcd:models plugin="products" xmlns:qcd="http://www.qcadoo.com/model"> <model name="product"> <string name="number"> <validatesPresence /> <validatesUniqueness /> <validatesLength max="40" /> </string> <string name="name"> <validatesPresence /> </string> <enum name="typeOfMaterial" values="01component,02intermediate,03product,04waste"> <validatesPresence /> </enum> <string name="ean" /> <dictionary name="category" dictionary="categories" /> <dictionary name="unit" dictionary="units" > <validatesPresence /> </dictionary> <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" cascade="nullify" /> <hasMany name="orders" model="order" joinField="product" cascade="nullify"/> <hasMany name="operationProductInComponents" model="operationProductInComponent" joinField="product" cascade="nullify"/> <hasMany name="operationProductOutComponents" model="operationProductOutComponent" joinField="product" cascade="nullify"/> <hasMany name="substituteComponents" model="substituteComponent" joinField="product" cascade="nullify"/> <identifierExpression value="#number + ' - ' + #name"/> </model> <model name="substitute"> <string name="number"> <validatesPresence /> <validatesUniqueness /> <validatesLength max="40" /> </string> <string name="name"> <validatesPresence /> </string> <belongsTo name="product" model="product" lookupField="name" lazy="false"> <validatesPresence /> </belongsTo> <hasMany name="components" model="substituteComponent" joinField="substitute" cascade="delete" copyable="true" /> <priority name="priority" scope="product" /> <validatesWith bean="com.qcadoo.mes.products.ProductService" method="checkIfProductIsNotRemoved" /> <identifierExpression value="#number + ' - ' + #name"/> </model> <model name="substituteComponent"> <belongsTo name="product" model="product" lookupField="name"> <validatesPresence /> </belongsTo> <belongsTo name="substitute" model="substitute" lookupField="name"> <validatesPresence /> </belongsTo> <decimal name="quantity"> <validatesPresence /> <validatesRange from="0" inclusive="false" /> <validatesPrecision max="7" /> <validatesScale max="3" /> </decimal> <validatesWith bean="com.qcadoo.mes.products.ProductService" method="checkIfSubstituteIsNotRemoved" /> <validatesWith bean="com.qcadoo.mes.products.ProductService" method="checkSubstituteComponentUniqueness" /> <identifierExpression value="#product['number'] + ' - ' + #product['name']"/> </model> </qcd:models>