Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PackageProjectUrl>https://www.github.com/JJConsulting/JJMasterData</PackageProjectUrl>
<RepositoryUrl>https://www.github.com/JJConsulting/JJMasterData</RepositoryUrl>
<PackageIcon>JJMasterData.png</PackageIcon>
<Version>4.5.29</Version>
<VersionPrefix>5.0.0</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''">4</VersionSuffix>
<Version>$(VersionPrefix)</Version>
<Version Condition="'$(VersionSuffix)' != ''">$(VersionPrefix)-$(VersionSuffix)</Version>
<PackageVersion>$(Version)</PackageVersion>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<InformationalVersion>$(Version)</InformationalVersion>
<PackageReadmeFile>README.NuGet.md</PackageReadmeFile>
<IncludeSymbols>true</IncludeSymbols>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
Expand Down
6 changes: 3 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageVersion Include="Hangfire.Core" Version="1.8.23" />
<PackageVersion Include="IronPython" Version="3.4.2" />
<PackageVersion Include="IronPython.StdLib" Version="3.4.2" />
<PackageVersion Include="Jint" Version="4.8.0" />
<PackageVersion Include="JJConsulting.Html.Bootstrap" Version="1.0.21" />
<PackageVersion Include="JJConsulting.Html.Bootstrap.TagHelpers" Version="1.0.21" />
<PackageVersion Include="JetBrains.Annotations" Version="2025.2.4" />
Expand All @@ -27,9 +28,8 @@
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="5.8.3" />
<PackageVersion Include="MongoDB.Driver" Version="3.5.2" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="NCalc.DependencyInjection" Version="5.12.0" />
<PackageVersion Include="NCalc.MemoryCache" Version="5.12.0" />
<PackageVersion Include="NCalcSync" Version="5.12.0" />
<PackageVersion Include="NCalc.DependencyInjection" Version="6.1.0" />
<PackageVersion Include="NCalc.MemoryCache" Version="6.1.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="PolySharp" Version="1.14.1" />
<PackageVersion Include="Spectre.Console" Version="0.55.2" />
Expand Down
1 change: 0 additions & 1 deletion JJMasterData.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</Folder>
<Folder Name="/ConsoleApps/">
<Project Path="src\ConsoleApps\MasterData.CommandLine\MasterData.CommandLine.csproj" Type="Classic C#" />
<Project Path="src\ConsoleApps\MasterData.LegacyMetadataMigrator\MasterData.LegacyMetadataMigrator.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/Docs/">
<Project Path="doc\MasterData.Docs\MasterData.Docs.csproj" Type="Classic C#" />
Expand Down
2 changes: 1 addition & 1 deletion doc/MasterData.Docs/MasterData.Docs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>13</LangVersion>
<RootNamespace>JJMasterData.Documentation</RootNamespace>
<AssemblyName>JJMasterData.Documentation</AssemblyName>
Expand Down
3 changes: 1 addition & 2 deletions doc/MasterData.Docs/articles/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
There are three ways to configure an application:
<br><br>

**1)** Add your configuration keys in appsettings.json. On .NET Framework you will need to add `IConfiguration` via `Microsoft.Extensions.Configuration`
**1)** Add your configuration keys in appsettings.json.

> [!TIP]
> To autocomplete with JJMasterData keys in your text editor, put this URL in the JSON Schema of your IDE.
Expand Down Expand Up @@ -70,4 +70,3 @@ You can change any property from:
[Read more](localization.md) about localization.
<br>


Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Custom Rules
# Customizations

If you are looking for declarative validations configured directly in the Data Dictionary UI, see [Rules](rules.md).

There are three ways to customize MasterData

Expand Down Expand Up @@ -82,7 +84,6 @@ IF (MyCustomLogic, you can use your @Parameters)
```

> [!WARNING]
> It is not a best practice write business rules at database, recommended only for simple validations.
> It is not a best practice write business rules as exceptions at the database, please use [Rules](rules.md).
---

6 changes: 3 additions & 3 deletions doc/MasterData.Docs/articles/errors/connection_string.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This is probably the first error you can find setting up JJMasterData. You can easily
solve it in different ways.

## ..NET 8+
## .NET 10
Add a default connection string to appsettings.json.
```json
{
Expand All @@ -14,8 +14,8 @@ Add a default connection string to appsettings.json.
}
```

## .NET Framework 4.8 and .NET Standard 2.0
Using any supported .NET version, you can set programmatically your connection string.
## Programmatic configuration
You can set your connection string programmatically.
```csharp
builder.Services.AddJJMasterDataCore(new MasterDataCoreOptionsConfiguration()
{
Expand Down
3 changes: 1 addition & 2 deletions doc/MasterData.Docs/articles/getting_started.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Getting Started

This tutorial assumes you will use .NET 8+, for .NET Framework 4.8 support,
check our [documentation](miscellaneous/netframework.md).
This tutorial assumes you will use .NET 10.

## 1. Install JJMasterData.Web from NuGet
![JJMasterData Nuget](../media/NuGet.png)
Expand Down
10 changes: 5 additions & 5 deletions doc/MasterData.Docs/articles/miscellaneous/assemblies.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ JJMasterData dependency tree can be represented by the following diagram:
## Assemblies

### JJMasterData.Web
Target Frameworks: ..NET 8
Target Framework: .NET 10
</br>
Razor Class Library with web graphical interfaces to manipulate and render your metadata.

### JJMasterData.WebApi
Target Framework: ..NET 8
Target Framework: .NET 10
</br>
Restful API to consume your metadata at any front-end.

### JJMasterData.Core
Target Frameworks: ..NET 8, .NET Standard 2.0 and .NET Framework 4.8
Target Framework: .NET 10
</br>
Library to access your metadata from .NET and/or render it at HTML components.

### JJMasterData.Commons
Target: .NET Standard 2.0
Target Framework: .NET 10
</br>
Utilities to all assemblies, like database access, l10n, logging and utils.
Utilities to all assemblies, like database access, l10n, logging and utils.
13 changes: 0 additions & 13 deletions doc/MasterData.Docs/articles/miscellaneous/netframework.md

This file was deleted.

193 changes: 193 additions & 0 deletions doc/MasterData.Docs/articles/rules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Rules

Rules allow you to run custom scripts before `insert` and `update` operations in a `FormElement`.

Use them when field-level validations are not enough, and you need to validate combinations of values, check data in the database, or apply custom business rules.

## Where to configure

In the Data Dictionary UI, open your element and go to the `Rules` tab.

Each rule has:

- **Name**: Friendly identification for the rule
- **Rule Type**: Script language used by the rule
- **Script**: The validation logic itself

Currently supported languages:

- `SQL`
- `JavaScript`

## How errors work

Rules must produce validation errors only when something is wrong.

If a rule does not produce any error, the operation continues normally.

## SQL rules

SQL rules execute a query and interpret the returned rows as validation errors.

### Result contract

- Return **no rows**: validation succeeded
- Return **1 column**: general validation error
- Return **2 columns**: field error, where:
- first column = field name
- second column = error message
- Column names do not matter

### Available parameters

You can use form values as parameters with the syntax:

```sql
{FieldName}
```

### SQL examples

General error:

```sql
if exists (
select 1
from Customer
where Document = {Document}
and Id <> isnull({Id}, 0)
)
select 'There is already another customer with this document.'
```

Field error:

```sql
if exists (
select 1
from Customer
where Email = {Email}
and Id <> isnull({Id}, 0)
)
select 'Email', 'This email is already in use.'
```

Multiple errors:

```sql
-- Validation: required
IF @Nome IS NULL OR LTRIM(RTRIM(@Nome)) = ''
BEGIN
SELECT 'Name', 'Name is required';
END;

-- Validation: minimum and maximum length
IF LEN(@Nome) < 2 OR LEN(@Nome) > 100
BEGIN
SELECT 'Name must be between 2 and 100 characters';
END;

-- Validation: only letters and spaces (no numbers or special characters)
IF @Nome LIKE '%[^A-Za-zÀ-ÿ ]%'
BEGIN
SELECT 'Name', 'Name contains invalid characters';
END;

-- Validation: avoid multiple consecutive spaces
IF @Nome LIKE '% %'
BEGIN
SELECT 'Name', 'Name cannot contain consecutive spaces';
END;

-- Validation: blacklist (business rule example)
IF UPPER(@Nome) IN ('ADMIN', 'ROOT', 'SYSTEM')
BEGIN
SELECT 'Name', 'Name not allowed';
END;

-- Validation: avoid unrealistically short names
IF LEN(REPLACE(@Nome, ' ', '')) < 2
BEGIN
SELECT 'Name', 'Invalid name';
END;

-- Specific validation (example business rule)
IF @Nome = 'Bola'
BEGIN
SELECT 'Name', 'Name blocked by internal rule';
END;

```

## JavaScript rules

JavaScript rules run with [Jint](https://github.com/sebastienros/jint).
They are executed **server-side**, not in the browser.

The script receives:

- `values`: object containing form values
- `addError(message)`: adds a general error
- `addError(name, message)`: adds a field error

### JavaScript examples

General error:

```javascript
if (!values.Name && !values.CompanyName) {
addError("Either Name or CompanyName must be filled.");
}
```

Field error:

```javascript
if (!values.Email) {
addError("Email", "Email is required.");
}
```

Multiple errors:

```javascript
if (!values.StartDate) {
addError("StartDate", "Start date is required.");
}

if (!values.EndDate) {
addError("EndDate", "End date is required.");
}

if (values.StartDate && values.EndDate && values.StartDate > values.EndDate) {
addError("EndDate", "End date must be greater than or equal to start date.");
}
```

Cross-field validation:

```javascript
if (values.Type === "Company" && !values.Document) {
addError("Document", "Document is required for companies.");
}
```

## Choosing between SQL and JavaScript

Use `SQL` when:

- validation depends on database queries
- you want to reuse database-side logic
- you need to validate against existing persisted data

Use `JavaScript` when:

- validation depends only on current form values
- you want simpler cross-field logic
- you want a more expressive scripting syntax for conditional rules

## Notes

- Rule field names must match the dictionary field names when you add field errors
- General errors are shown as form-level validation messages
- Field errors are attached to the corresponding field when possible
8 changes: 4 additions & 4 deletions doc/MasterData.Docs/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@
href: actions/cancel_action.md
- name: Back
href: actions/back_action.md
- name: Custom Rules
href: custom_rules.md
- name: Customizations
href: customizations.md
- name: Rules
href: rules.md
- name: TagHelpers
href: taghelpers.md
- name: Localization
Expand Down Expand Up @@ -146,7 +148,5 @@
items:
- name: Multiple Forms Support
href: multiple_forms.md
- name: .NET Framework Support
href: miscellaneous/netframework.md
- name: Assemblies
href: miscellaneous/assemblies.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ With Alignment At Grid at Right:
#### Export
You can define whether or not the field will be exported.

#### Validade Request
On .NET Framework 4.8 systems, the field will validate dangerous values, like Html tags and SQL commands.

## **Panels**
Allows you to separate the dictionary fields into panels.
But only for add, edit and view actions.
Expand Down Expand Up @@ -149,6 +146,14 @@ The Actions field is divided into two, Grid and Toolbar.
- Filter: Shows all filter options for searching items within the table.
- Log: Records and displays the actions performed within the table, including adding, editing and deleting.

## Rules
Within the Rules tab you can create script-based validations executed before `insert` and `update`.

- SQL rules can return rows representing validation errors
- JavaScript rules can call `addError(message)` or `addError(fieldName, message)`

For the complete reference, see [Rules](../rules.md).

## **API**
Within this tab it will be possible to edit each verb responsible for http permissions within the REST API.
- ApplyUseridOn: Name of the field where the user ID filter will be applied.
Expand Down
Loading
Loading