-
-
Notifications
You must be signed in to change notification settings - Fork 17
Custom Actions
Die Payroll Engine liefert von Hause aus Case Actions zur Steuerung und Validierung von Benutzereingaben.
Die vorhandenen Case Actions können mit dem Regulation Script-Objekt erweitert werden.
- Implementirung der Case-Action in C#
- Action in Regulation einsetzen
- Action testen
- Action verwenden
Im folgenden Beispiel wird eine Action zur Validierung von Unternehmens-ID erstellt. Geprüft werden soll ob die Prüfsumme der Unternehmens-ID gemäss dem ISO 7064 Standard.
Die Case Action besteht aus Metadaten in Form von C#-Attributen und der Implementierung. Für Validier-Actions werden Fehler mit der AddIssue Methode eingebunden.
1 using PayrollEngine.Client.Scripting;
2 using PayrollEngine.Client.Scripting.Function;
4 namespace ActionPayroll.Scripts;
5
6 [ActionProvider("MyActions", typeof(CaseChangeFunction))]
7 public class MyActions : CaseChangeActionsBase
8 {
9 [ActionIssue("MissingUId", "Missing value (0)", 1)]
10 [ActionIssue("InvalidUId", "(0) with invalid UID (1)", 2)]
11 [CaseValidateAction("CheckUId", "Validate for the UID")]
12 public void CheckUId(CaseChangeActionContext context)
13 {
14 var sourceValue = NewCaseFieldActionValue<string>(context);
15 if (sourceValue?.ResolvedValue == null)
16 {
17 AddIssue(context, "MissingUId", context.CaseFieldName);
18 return;
19 }
20 try
21 {
22 // ISO 7064 digit check with modulus, radix, character-set and double-check-digit option
23 new CheckDigit(11, 1, "0123456789", false).Check(sourceValue.ResolvedValue);
24 }
25 catch (CheckDigitException exception)
26 {
27 AddIssue(context, "InvalidUId", context.CaseFieldName, exception.CheckValue);
28 }
29 }
30 }Der Code im Detail:
-
6: Action provider registration, used as namespaceMyAcions.ActionName(meta data) -
7-30: Actions container class -
9: Missing id issue registration with the keyMissingUId(meta data) -
10: Invalid id issue registration with the keyInvalidUId(meta data) -
11: Action registration with the keyCheckUId(meta data) -
12-29: ActionCheckUIdimplementation -
14-18: Get the action value -
17: Add missing value issue -
23: ISO 7064 digit check usingCheckDigit -
27: Add digit check issue
You can also use the predefine digit checks
Mod11Radix2,Mod37Radix2,Mod97Radix10,Mod661Radix26,Mod1271Radix36
Als nächstes wird der Script mit der Validierfunktion in die Regulierung aufgenommen:
1 "regulations": [
2 {
3 "name": "ActionRegulation",
4 "lookups": [
5 {
6 "name": "MyActions.Actions",
7 "values": [
8 {
9 "key": "InvalidUId",
10 "value": "(0) is invalid: (1)",
11 "valueLocalizations": {
12 "de": "(0) ist ungültig: (1)"
12 }
13 }
14 ]
15 }
16 ],
17 "cases": [
18 {
19 "name": "UId",
20 "caseType": "Employee",
21 "defaultReason": "Test UId",
22 "validateExpression": "true",
23 "fields": [
24 {
25 "name": "UId",
26 "valueType": "String",
27 "timeType": "Period",
28 "valueMandatory": true,
29 "defaultStart": "today",
30 "validateActions": [
31 "MyActions.CheckUId"
32 ]
33 }
34 ]
35 }
36 ],
37 "scripts": [
39 {
39 "name": "MyActions",
40 "functionTypes": [
41 "CaseChange"
42 ],
43 "valueFile": "Scripts\\MyActions.cs"
44 }
45 ]
46 }
47 ]Der Aufbau der Regulierung im Detail:
-
4-16: Lookups zur Lokalisierung der Validiermledungen -
6: Der Lookupname nach der KonventionActionNamespace.Action -
17-36: Der Case mit dem FeldUId -
31: Verwendung der Case ActionMyActions.CheckUId -
37-45: Registrierung des Validierungs-Scripts -
41: Script für Case Change Funktionen verwenden -
43: Lokale Script Quelldatei
Die Validaierungs-Action UId wird mit folgendem Test überprüft:
1 {
2 "$schema": "../../Schemas/PayrollEngine.CaseTest.schema.json",
3 "testName": "Test.UId",
4 "tenantIdentifier": "ActionTenant",
5 "userIdentifier": "lucy.smith@foo.com",
6 "employeeIdentifier": "mario.nuñez@foo.com",
7 "payrollName": "ActionPayroll",
8 "validateTests": [
9 {
10 "testName": "UId.Valid.999999996.Test",
11 "input": {
12 "userIdentifier": "lucy.smith@foo.com",
13 "employeeIdentifier": "mario.nuñez@foo.com",
14 "divisionName": "ActionDivision",
15 "case": {
16 "caseName": "UId",
17 "values": [
18 {
19 "caseFieldName": "UId",
20 "value": "999999996"
21 }
22 ]
23 }
24 },
25 "output": {
26 "values": [
27 {
28 "caseFieldName": "UId",
29 "value": "999999996"
30 }
31 ]
32 }
33 },
34 {
35 "testName": "UId.Invalid.999999997.Test",
36 "input": {
37 "userIdentifier": "lucy.smith@foo.com",
38 "employeeIdentifier": "mario.nuñez@foo.com",
39 "divisionName": "ActionDivision",
40 "case": {
41 "caseName": "UId",
42 "values": [
43 {
44 "caseFieldName": "UId",
45 "value": "999999997"
46 }
47 ]
48 }
49 },
50 "output": {
51 "issues": [
52 {
53 "caseFieldName": "UId",
54 "issueType" : "CaseInvalid",
55 "number": 400
56 }
57 ]
58 }
59 }
60 ]
61 }Die wichtigsten Daten im Detail:
-
9-33: Test mit gültigerUId -
20: Der zu testende Wert999999996 -
29: Der überprüfung des Fallwertes -
34-59: Test mit ungültigerUId -
45: Der zu testende Wert999999997 -
55: Die erwartete HTTP Fehlernummer
Befehl zur Ausführng des Tests
PayrollConsole CaseTest Test.et.json
Schlussendlich wirkt die Validierung auch in der Web Applikation mit einer entsprechenden Fehlermeldung:

- Explore the Payroll Engine Resources
🤝 Thank you for supporting this project with a donation.
⚡ This is a pre-relase version of the initial development, please read the restrictions.
- Payroll Engine