## 2.4. Elements explained

### 2.4.1. Controllers

A controller is a reusable business-workflow (see also above 'Layers in short'). A controller has the following responsibilities:

- create the initialcomponent upon construction

- dispose the controller and subcontrollers upon a call of `doDispose`

A controller can use:

- the Manager classes to do the work (database/filesystem)

- other controllers to delegate tasks to (e.g. to to delegate a user search to the UserSearchController)

- The method `getWindowControl()` to obtain the possiblity to send a info/warning/error msg to the screen and to push a new gui-layer above the current layers (kind of like a modal dialog, e.g. for a user search) and to pop the layer if a subcontroller's work is done.

Please see the javadoc of each controller to see what it is for. Briefly there are:

- generic GUI-Controllers (Layout, Wizard)

- generic Business-Controllers (e.g. UserSearchController, FolderRunController, ForumController)

- specific Business-Controllers (PublishControllers)

See the java classes extending the `Defaultcontroller` class

### 2.4.2. Managers

Managers within OLAT are conceptually responsible for providing the basic functionality to the workflows (i.e. controllers implementing the actual workflows). Managers usually provide persistence functionality such as storage in the database or on the file system. In general, no workflow should directly deal with the filesystem or the database, it's all handled through a dedicated manager implementing this functionality.

### 2.4.3. i18n

We could have used ResourceBundle from the Java SDK, but you cannot clear the cache which is annoying for translation. Since we use java.util.Properties, the encoding is assumed to be iso_8859_1 (see java.util.Properties). However, if you use the online translation tool (Administration / Online translation tool) you can work with input in any encoding (just submit the form...)

The browser always sends it page in utf-8. encodings from resources like html files from content packages are converted automatically

If The browser always sends it page in utf-8. encodings from resources like html files from content packages are converted automatically

### 2.4.4. Mappers

A `Mapper` is used to route a certain url directly to some place in code. This is useful if you want to e.g. deliver static resources.

- user-local mappers: the url routing only applies to the current user

- global mappers: the url routing applies to all users

### 2.4.5. Properties

Properties are used in very many places in OLAT und persisted in the table o_property. A property is a data container and has at least one name apart from its id and lastmodified date. Addionally it has several fields (category, floatvalue, stringvalue, textvalue, etc.) to store more information depending on the context it's used. If some of this fields are not used, they can be null. Creating a new property, you have to think about how to retrieve it. Adding several properties to a already used or new specified category, you can easily retrieve them.

#### 2.4.5.1. How to create, retrieve and delete a property

    PropertyManager pm = PropertyManager.getInstance();
    p = pm.createPropertyInstance(null, null, null, "_o3_", "InfoMsg", null, null, null, "");

    pm.saveProperty(p);

    Property p = pm.findProperty(null, null, null, "_o3_", "InfoMsg");

    pm.deleteProperty(p);

### 2.4.6. db

The `DB` is used as the main and only entry point for all database operations on the low level. It uses a threadlocal variable to keep the current hibernate session and the transaction state. At the end of each UserClick/Servlet Response, the session must be closed by using DB.getInstance().close(), before it can be returned into tomcat's threadpool!

Controllers should only use the `beginTransaction()`, `commit()` and some helper functions to reload an entry from disk if the associated session has been closed (e.g. transactions which would last several userclicks)

Manager classes should encapsulate business logic and thus be the only ones that use the find/save/update methods of the DB class