Creatio development guide
PDF
This documentation is valid for Creatio version 7.10.0. We recommend using the newest version of Creatio documentation.

Feature Toggle. Mechanism of disabling functionality

Glossary Item Box

Introduction

Feature toggle is a software development technique that provides support for connecting additional functionality in a running application. This allows to use continuous integration, keep the application working and hide the functionality that is under development process.

The main idea is that there is a block of additional functionality (often not fully implemented) in the source code and conditional operator that defines if the functionality connected.

Storing the functionality datain the database

A list of functionality available for enabling/disabling is stored in the Feature table of the application database, Table is empty by default. Main Feature table fields are given in table 1.

Table 1. Main Feature table fields

Name Type Description
Id uniqueidentifier Unique Id of the record
Name varchar( 250 ) Functionality name.
Code varchar( 50 ) Functionality code.

Information about functionality state (enabled/disabled) stored in the FeatureState field of the AdminUnitFeatureState table (Fig.1). The AdminUnitFeatureState table binds the Feature and SysAdminUnit tables where users and system user groups are defined. Main AdminUnitFeatureState table fields are given in table 2.

Table 2. Main AdminUnitFeatureState table fields

Name Type Description
Id uniqueidentifier Unique Id of the record
FeatureId uniqueidentifier Unique Id of the functionality record.
SysAdminUnitId uniqueidentifier Unique Id of the user record.
FeatureState int Functionality state. 1 – enabled, 0 – disabled.

Fig. 1 Diagram of table relationships

Defining the new functionality in the source code.

To implement the new functionality to the source code it should be defined in the block of the conditional operator that will check the state of the functionality connection (FeatureState).

Client side JavaScript

A conditional template for defining additional functionality in the source code:

// The method defining the additional functionality.
someMethod: function() {
    // Functionality connection check.
    if (Terrasoft.Features.getIsEnabled("functionality code")) {
        // Implementation of additional functionality.
        ...
    }
    // Method Implementation
    ...
}

The getIsFeatureEnabled method is implemented in the BaseSchemaViewModel base schema view model. Therefore, the Terrasoft.Features.getIsEnabled method can be replaced with this.getIsFeatureEnabled("functionality code").

Refresh the browser page after connecting the new functionality to enable it in the client code and load it in the browser.

Server side C#

A set of extending methods of the UserConnection class was implemented to use the Feature toggle in the source code schemas on the server side in the Terrasoft.Configuration.FeatureUtilities class. A list of the extended methods is given in the Table 3. The FeatureState functionality states are enumerated in the same class.

Table 2. Main methods of the DataManager class

Methods. Parameters Description
int GetFeatureState( this UserConnection source, string code )

code – functionality code.

Returns functionality state.
Dictionary <string, int> GetFeatureStates( this UserConnection source ) No. Returns the state of all functionality.
void SetFeatureState( this UserConnection userConnection, string code, int state, bool forAllUsers = false )

code – functionality code;

state – functionality state (0/1);

forAllUsers – a flag of enabling the functionality for all users.

Returns functionality state.
void CreateFeature( this UserConnection source, string code, string name, string description )

code – functionality code;

name – functionality name;

Description – functionality description.

Creates new functionality.
bool GetIsFeatureEnabled( this UserConnection source, string code )

code – functionality code.

Checks if the functionality connected.

A conditional template for defining additional functionality in the source code:

// A namespace in which the ability to switch additional
// functionality is defined.
using Terrasoft.Configuration;
…
// The method in which additional functionality will be defined.
public void AnyMethod() {
    // Check if functionality is enabled.
    if (UserConnection.GetIsFeatureEnabled("functionality code")) {
        // Implementation of additional functionality.
    }
    // Method implementation.
    ...
}

Setting the value of functionality state is executed by call of the SetFeatureState method:

UserConnection.SetFeatureState("functionality code", FeatureState);

© bpm'online 2002-2017.

Did you find this information useful?

How can we improve it?