3: Rule management

In Studio it is possible to create and manage file content related rules i.e. content validation rules or business validation rules.

Introduction

 

In Studio it is possible to create and manage file
content related rules i.e. content validation rules
or business validation rules. This is available for XML  and JSON. File structure format definition is always needed to give a basis for rule management - for XML the structures are defined via XML schema / XSD and for JSON we currently support json schema.

One project in Studio is always based on one structure definition. You can select the structure definition in the project creation phase as described in the "Groups and projects" tutorial page. Later on you can change the definition from the project settings page.

Rule views

There are two different views for managing rules.

"Schema view" shows the message structure so that each row in the view represents one element in the message and rules related to that element are in the same row.

"Rule list" shows a list of existing rules with some details grouped by ruleset.

The view selection is in the "Validation rule management" tab as highlighted in the picture below.

2016-09-20-rule-view-selection.png

Rulesets

Rules always belong to a ruleset. Ruleset itself does not do anything but work as a way to group rules related to each other. So you always need to create a new ruleset to the project if you don't have any before it is possible to create any rules.

Rulesets have three properties: name, description and display name. The purpose of name and description are quite obvious, but the display name might need some explanation. Display name is optional property which can be used for giving a different name for the ruleset to be shown in the validation service. This does not affect the behavior of ruleset or rules inside it. By giving a display name to ruleset you can also combine rulesets in validation service so that instead of each ruleset shown as a separate entity, all rulesets with same (display) name are shown as one.

Ruleset creation

By default the newly created projects looks something like the screenshot below. The message structure described by the schema is shown in the left hand side of the middle screen. New ruleset can be created from the button in the upper right corner of the middle container, this is highlighted by red arrow in the picture.

2016-09-20-Schema-tree-empty.PNG

Rulesets can be also created from rule list view. There is a button in the upper left corner which says add new ruleset.

In both cases, you can either select to create a new ruleset from scratch or import one.

Creating from scratch

When creating a ruleset from scratch you will be asked for ruleset name and optionally description and display name. Purpose of display name is described above at the start of the "rulesets" section. After creation the ruleset wont contain any rules.

2016-09-20-add-new-ruleset.png

Copying a ruleset

You can create a new ruleset based on existing ruleset

1) copying the existing ruleset in exportable XML format and

2) importing the XML to create a new ruleset

Exporting ruleset XML

Ruleset XML can be exported from the ruleset menu which opens from the "wrench" icon. The XML can be accessed by selecting the "Ruleset XML view".

2016-09-20-export-ruleset-xml.png

Importing ruleset XML

If you choose to import new ruleset you will be offered an import dialog to which you can choose to paste as text or import as a file a previously exported ruleset.

2016-09-20-Import-new-ruleset.PNG

Copying/Linking from libraries

Existing rulesets can also be reused in the service. This "library rulesets" can be accessed from the right hand side view of the project.

2016-09-20-library-rulesets.PNG

You can either drag'n'drop a ruleset to the schema view or click on the menu button of the ruleset which you wish to use. You can either link or copy the ruleset. Linking means that the ruleset is connected to the original implementation and if you make modifications, these modifications will be applied to all projects using the same linked ruleset. Copying instead makes a local copy of the ruleset to current project only.

There are two types of library rulesets:

  • Group rulesets
    These are visible in all projects in the same group. You can for example set all common rules to one ruleset and reuse the rules in all projects. If new rule is needed, you just add it once to group ruleset and it will exist in all projects using that group ruleset.
  • Global rulesets
    These are free to use rulesets managed by XMLdation. You can use them as they are or take a copy and start making your own modifications.

Changing ruleset type to group ruleset

Ruleset can be upgraded to group ruleset from the ruleset menu which opens from the "wrench" icon. This is shown in the picture below.

2016-09-20-copyto-library-as-group-ruleset.png

Deleting rulesets

You can delete a ruleset from the menu opening from the wrench icon. Linked ruleset can only be unlinked and not deleted from the project. If you wish to delete a group ruleset, please navigate to "Library management" from the upper right corner of Studio.

Rules

Once you have one or more rulesets in a project you can start creating rules.

Creating rules

In schema view you can create new rule by hovering the row of the element for which you want to create the rule and the column of the ruleset in which you want to add the rule. In the selected cell a plus icon will appear. This is illustrated in the picture below - the plus icon highlighted in red.

2016-09-20-add-new-rule-schema-view.png

Clicking the plus icon will open a new rule modal like the one below. First you have some basic details

Field name Field description
Active Activity status of the rule. Inactive rules will not be used in validation.
Name Name of the rule, needs to be unique in one project context.
Description Description of the rule in english or other language.
Wiki URL of the wiki page which contains more information about this rule.
Rule location XPath XPath to the element which this rule concerns. This is defined for rule to be able to apper in correct position in Studio.

 

Only mandatory basic detail is rule name.

2016-09-20-new-rule-modal.PNG

After the basic details there is the validation definition. There is a own section in this wiki dedicated to rule writing so to get more information about that click here.

Modifying rules

Rules can be opened for editing by double clicking the rule box in schema view or clicking the edit button in rules list view.

Rules in project specific rulesets are always freely editable.

Editing rules of linked group rulesets will affect all the projects which use the same ruleset. To avoid accidental edits you need to click the lock icon at the top of the rule modal to open the lock and access the editing.

Testing rule behavior

It is possible to test if the rules are behaving as expected. This can be done from the "Test" menu in the upper right corner of the project. Select "Validate XML" from the menu after which you need to select a file to be tested from your local disk. After this the created rules will be automatically compiled and the file is validated against the rules and validation report is shown.

2016-09-20-validate-xml.png

Producing documentation

Also documentation can be generated from the menu opening from the "Test" button as seen above.

Publishing to validation service

The validation functionality can be published to validation service for others to use by clicking the arrow next to the "Test" button in the upper right corner of the project.