Skip to content

3 Configuration file

Repository configuration file. Once we have defined our application's database(s), represented by *.sqlite file(s) in the data directory, we need a repository configuration file.

Example: /data/repos.xml

<repos>
    <repo dbFile="inspeccionesvinedo.sqlite" id="variedadRepo" dbTable="variedad"/>
    <repo dbFile="inspeccionesvinedo.sqlite" id="tipoPlagaRepo" dbTable="tipo_plaga"/>
    <repo dbFile="inspeccionesvinedo.sqlite" id="severidadRepo" dbTable="severidad" >
        <mapping fk="tipo_plaga_id" property="tipoPlaga" repo="tipoPlagaRepo"/>
    </repo>
    <repo dbFile="inspeccionesvinedo.sqlite" id="provinciaRepo" dbTable="provincia" />
    <repo dbFile="inspeccionesvinedo.sqlite" id="municipioRepo" dbTable="municipio">
        <mapping fk="c_provincia_id" property="provincia" repo="provinciaRepo"/>
    </repo>

    <repo dbFile="inspeccionesvinedo.sqlite" id="plagaRepo" dbTable="plaga">
        <meta properties="all">
            <property name="location" columnName="location" converter="string" calculated="jexl" expression="${location.asWKT}" evalOn="insert"/>
            <property name="f_actuacion" converter="date" pattern="seconds" evalOn="update" expression="${date.now}" />
            <keyGenerator type="numericUUID"/>
        </meta>
        <mapping fk="variedad_id" property="variedad" repo="variedadRepo"/>
        <mapping fk="tipo_plaga_id" property="tipoPlaga" repo="tipoPlagaRepo"/>
        <mapping fk="severidad_id" property="severidad" repo="severidadRepo"/>

    </repo>
    <repo dbFile="inspeccionesvinedo.sqlite" id="plagaImagesRepo" dbTable="plaga_foto">
        <meta>
            <keyGenerator type="numericUUID"/>
            <property name="f_actuacion" converter="date" pattern="seconds" evalOn="update" expression="${date.now}" />
        </meta>
        <mapping fk="plaga_id" property="plaga" repo="plagaRepo"/>
    </repo>

    <filerepo defaultExtension="jpg" folder="pictures/estado_fen" id="estadoFenImages" />

</repos>

Database: /data/inspeccionesvinedo.sqlite

CREATE TABLE "variedad" (
    variedad_id integer primary key AUTOINCREMENT,
    nombre text
);

CREATE TABLE "tipo_plaga" (
    tipo_plaga_id TEXT primary key,
    tipo_plaga TEXT
);

CREATE TABLE "severidad" (
    severidad_id  INTEGER PRIMARY KEY AUTOINCREMENT,
    tipo_plaga_id INTEGER,
    codigo_severidad INTEGER,
    descripcion_severidad TEXT,
    FOREIGN KEY(tipo_plaga_id) REFERENCES tipo_plaga(tipo_plaga_id)
);

CREATE TABLE "provincia"(
    "c_provincia_id" INTEGER PRIMARY KEY,
    "d_provincia" TEXT,
    "c_orden_provincia" INTEGER
);

CREATE TABLE "municipio"(
    "c_municipio" TEXT,
    "c_provmuni_id" TEXT PRIMARY KEY,
    "c_provincia_id" INTEGER,
    "d_nombre" TEXT,
    FOREIGN KEY(c_provincia_id) REFERENCES provincia(c_provincia_id)
);

CREATE TABLE plaga (
    plaga_id INTEGER PRIMARY KEY,
    tipo_plaga_id TEXT,
    ref_sigpac TEXT,
    estado_fenologico_id TEXT,
    observaciones TEXT,
    location TEXT, 
    fecha_inspeccion TEXT, 
    variedad_id INTEGER,
    severidad_id INTEGER,
    f_actuacion INTEGER,
    f_sincro INTEGER,
    FOREIGN KEY(variedad_id) REFERENCES variedad(variedad_id),
    FOREIGN KEY(severidad_id) REFERENCES severidad(severidad_id),
    FOREIGN KEY(tipo_plaga_id) REFERENCES tipo_plaga(tipo_plaga_id)
);

CREATE TABLE plaga_foto (
    plaga_foto_id INTEGER PRIMARY KEY,
    plaga_id INTEGER,
    image TEXT,
    f_actuacion INTEGER,
    f_sincro INTEGER,
    FOREIGN KEY(plaga_id) REFERENCES plaga(plaga_id)
);

3.1 Tag repo

Attribute Description
id Unique identifier for the component. If not defined, the base filename will be used. This identifier is used in forms to specify which table (dbTable) from the database (dbFile) the form component will use to retrieve or store data.
dbFile References the database, *.sqlite file in the /data folder.
dbTable Table serving as a base to query/store entities.
<repo dbFile="inspeccionesvinedo.sqlite" id="variedadRepo" dbTable="variedad"/>

3.1.1 Tag mapping

Attribute Description
id Unique identifier for the component. If not defined, the base filename will be used. This identifier is used in forms to specify which table (dbTable) from the database (dbFile) the form component will use to retrieve or store data.
fk Foreign key.
property Name of the property of the main entity where the related entity will be stored.
repo Repository identifier.
insertable Default=true. If true, when the main entity is inserted, the related entity is also inserted.
updatable Default=true. If true, when the main entity is stored, the related entity is also updated.
deletable Default=false. If true, when the main entity is deleted, the related entity is also deleted.
 <mapping fk="c_provincia_id" property="provincia" repo="provinciaRepo"/>

3.1.2 Tag meta

3.1.2.1 Tag keyGenerator

Attribute Description
type Entity key generation strategy. Possible values:
  • MAXROWID: The new key for the entity will be the maximum value of rowid incremented by 1.
  • TIMESTAMP: The new key for the entity will be the current date in timestamp format.
  • UUID: The new key for the entity will be generated using UUID.
  • NUMERICUUID: The new key for the entity will be the current date in timestamp format concatenated with 5 random digits.
<keyGenerator type="numericUUID"/>

3.1.2.2 Tag property

Attribute Description
name Property name of the entity.
expression
columnName Property name of the entity.
expressionType Type used to represent the retrieved column value.
converter Instance of the converter to apply to the entity's property.
evalOn select, insert, update
calculated jext|sql
pattern Pattern to convert calculated values (only calculated ones) before inserting them into the database.
<property name="f_actuacion" converter="date" pattern="seconds" evalOn="update" expression="${date.now}" />

3.2 Tag filerepo

Attribute Description
id Unique identifier for the component.
folder Base folder containing the repository's images. If relative, the URL is interpreted from the project's folder.
defaultExtension Default extension
<filerepo defaultExtension="jpg" folder="pictures/estado_fen" id="estadoFenImages" />