Rules Management CLI
The rules-management program is a command-line interface (CLI) tool written in Java. It is designed to generate Drools files based on rule classes and units. This README file provides an overview of the program and instructions for usage.
Table of Contents
- Introduction
- Installation
- Usage
- Options
- Examples
Introduction
The rules-management CLI program allows you to generate Drools files containing various rule classes and units. Each rule class represents a specific type of rule, such as SYN (Syngenta specific), CBI, PII, ETC (Other), AI, MAN (Manual redactions), X (Entity interactions), FA (FileAttribute interactions), and LDS (Local Dictionary Search).
A rule unit is identified by a combination of the rule class and an integer. For example, CBI.1 refers to rule unit 1 in the CBI rule class. Each rule unit may contain multiple rules, which are also identified by integers. For instance, CBI.1.2 represents the second rule in rule unit 1 of the CBI rule class.
The program provides options to specify the input type, input source, output destination, and additional flags for customization.
Installation
To use the rules-management CLI, you need to have Java 17+ and gradle installed on your system. Follow these steps to get started:
Clone the latest main branch.
compile with gradle install
Testing
You can validate the rules you are changing if they are correctly written from a syntax point of view using the
DroolsCompilationTest class. Make sure you also place the changes in the test/resources/<rules_file>.drl and then run the test.
Usage
To run the rules-management program, open a terminal or command prompt and navigate to the directory where the program files are located. Use the following command:
java -jar rules-management.jar [options]
or directly with gradle
gradle run --args='[options]'
Options
The rules-management program supports the following command-line options:
-t, --type: Specifies the input type. Default is "list" (if the recursive flag is set: "file"). Available options:
- "list" or "l": Expects a list of rule identifiers. For example: "MAN, X, LDS, CBI.0, PII.0.1", you can use wildcards such as * or leaving out digits with the identifiers to match multiple rule identifiers. This allows for convenient selection of multiple rule units or rules.
- "file" or "f": Expects the absolute path to a rule file. The file must contain the current Rule Identifiers. This option is useful for migrating rule files to the current state.
- "old" or "o": Expects the absolute path to an old rule file. The program attempts to translate the old rules to new rules based on '"main/resources/old_rules_with_translations.csv"'.
-i, --input: Specifies the input source based on the chosen type. It can be:
- A string of rule identifiers like
"MAN, X, LDS, CBI.0, SYN.*.0, PII.0.1" - path to a rules file
/path/to/old_rules.txt - path to a folder containing rules files named "rules.txt" or "rules.drl" (if the "recursive" flag is set)
/path/to/rules_directory
-o, --output: Specifies the output file path. If a directory is supplied as input, the folder structure is preserved.
-n, --noop: If this flag is set, the input file will not be attempted to be translated or migrated, use this to only escape files. Currently, this only works with input type "file"
-e, --escape: If this flag is set, the output files will be escaped and saved as ".txt", similar to dossier templates.
-r, --recursive: Can only be set in combination with the "file" or "old" type and a directory as input. Searches recursively for files named "rules.txt" or "rules.drl" and attempts to migrate/translate them. The folder structure is preserved in the output folder.
-a, --application: Indicate which application you are targeting. For redact manager use RM. For Documine use DM. If it's not specified it will default to RM.
Examples
Generate Drools files from a list of rule identifiers and save them to the specified output file:
gradle run --args='-t list -i "MAN, X, LDS, CBI.0, PII.0.1" -o /path/to/output/rules.drl'
Migrate an old rule file to the current format and save the translated rules to the specified output file:
gradle run --args='-t old -i /path/to/old_rules.drl -o /path/to/output/translated_rules.drl'
Migrate multiple rule files in a directory (including subdirectories) and save the translated rules:
gradle run --args='-t old -i /path/to/rules_directory -o /path/to/output/translated_rules -r'
Generate Drools files from a rules file and escape the output:
gradle run --args='-t file -i /path/to/rules.txt -o /path/to/output/escaped_rules -e'
Escape Drools file rules.drl as is:
gradle run --args='-t f -n -e -i /path/to/rules.drl -o /path/to/output/rules.txt'