Configuration

The configuration of business objects has to be loaded at startup of the application:

var bo = require('business-objects');

// Initialize business objects.
bo.initialize('/config/business-objects.js');

The initialize() method expects a string argument which is the relative path of the configuration file. It can be a JSON file or a JavaScript file that returns an object with the following properties:

  • connectionManager
    A required string that returns the relative path of the connection manager.
    For more information see ConnectionManager class.

  • daoBuilder
    An optional string that returns the relative path of the data access object builder.
    For more information see daoBuilder function.

  • userReader
    An optional string that returns the relative path of a method that returns the current user. The default method returns null, i.e. anonymous user is assumed.
    For more information see getUser function.

  • localeReader
    An optional string that returns the relative path of a method that returns the current locale. The default method returns an empty string, i.e. the business objects will use the default messages.
    For more information see getLocale function.

  • pathOfLocales
    An optional string that returns the relative path of the directory containing project locales. If not supplied, the business objects cannot interpret the first message argument as the message key, i.e. the first message argument must be the message text.
    For more information see Project localization page.

  • noAccessBehavior
    An optional string that returns the default behavior for unauthorized operations.
    Valid options are:

    • throwError: Failed authorization rule throws an authorization error.
    • showError: The result of a failed rule is a broken rule with error severity.
    • showWarning: The result of a failed rule is a broken rule with warning severity.
    • showInformation: The result of a failed rule is a broken rule with information severity.

    For more information see Authorization rules and Error handling pages.

An example configuration:

module.exports = {
  connectionManager: '/models/connection-manager.js',
  daoBuilder: '/models/dao-builder.js',
  userReader: '/lib/get-user.js',
  localeReader: '/lib/get-locale.js',
  pathOfLocales: '/locales',
  noAccessBehavior: 'throwError'
};