Hauptmenü öffnen

Script (Tarifwerk) (en): Unterschied zwischen den Versionen

 
(5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
[[de:Script (Tarifwerk)]]
 
[[de:Script (Tarifwerk)]]
  
[[File:Script_Tarifwerk.png|frameless|right|super|475x413px|TW Script Editor.png]]Scripte bilden die zentrale Stelle im Tarifwerk um Regeln für [[Zuschlag_(Tarifwerk)|Zuschläge]] und [[Tarifwerk_(Tarifwerk_/_Stammdaten)|Tarifwerke]] aufzubauen. Dies können simple Abfragen sein, wie z.B. prüfen, ob es sich um eine Inselzustellung handelt, oder aber komplexe Konstrukte, die Frachtführer- oder Kundenspezifische Anforderungen umsetzen.
+
[[File:Script_Zuschlag(en).png|frameless|right|super|475x413px|TW Script Editor.png]]Scripts are the central point in the Tarifwerk for creating rules for surcharges and rate structures. These can be simple queries, such as checking whether it is an island delivery, or complex constructs that implement carrier or customer-specific requirements.
 
+
All scripts use the Pegasus parser, a proprietary development of Heidler Strichcode GmbH. The scripting language is based on the Java programming language, which can make some things more complicated, but offers significantly more flexibility and performance.
Alle Scripte verwenden den Pegasus Parser, eine Eigenentwicklung der Heidler Strichcode GmbH. Die Scriptsprache basiert auf der Programmiersprache Java, was manche Dinge komplizierter machen kann, dafür aber deutlich mehr Flexibilität und Performance bietet.
 
  
 
== Scripteditor ==
 
== Scripteditor ==
  
Der Scripteditor ist in drei Bereiche unterteilt:
+
The script editor is divided into three areas:
  
=== Informationspanel ===
+
=== Information panel ===
  
Das Informationspanel befindet sich links oben. Es zeigt Ihnen alle Informationen an, welche Sie für die Scriptentwicklung benötigen.
+
The information panel is located at the top left. It shows you all the information you need for script development.
  
Zunächst wird Ihnen aufgelistet, welche Variablen Sie zur Verfügung haben und welchen Typ (welche Klasse) die Variablen besitzen. Im Tarifwerk erhalten Sie hier meist die Variable shipment, was der aktuellen Sendung entspricht, und eventuell die Variable packageData, was dem aktuellen Packstück entspricht.
+
First of all, it lists which variables you have available and which type (which class) the variables have. In the Tarifwerk, you will usually see the variable shipment, which corresponds to the current shipment, and possibly the variable packageData, which corresponds to the current package.
  
Der Erwartete Rückgabetyp ist der Typ des Wertes, welchen Sie in diesem Script zurückgeben müssen. Im Tarifwerk wird in der Regel nur Boolean (true oder false) oder Double (Gleitkommazahl mit doppelter Präzision) erwartet.
+
The Expected return type is the type of value that you must return in this script. As a rule, only Boolean (true or false) or Double (floating point number with double precision) is expected in the Tarifwerk.
  
=== Button-Leiste ===
+
=== Button bar ===
  
Die Button-Leiste befindet sich rechts oben. Sie können damit zusätzliche Anpassungen und Tests vornehmen.
+
The button bar is located at the top right. You can use it to make additional adjustments and tests.
  
==== Importe ====
+
==== Imports ====
  
Der Button Importe öffnet einen Editor, in dem Sie zusätzliche Klassen (Funktionalitäten) zum aktuellen Script hinzufügen können. Über den Button Suchen können Sie die aktuell eingegebene Klasse suchen. Bei Erfolg wird Ihnen diese Klasse in der Liste darüber angezeigt.
+
The Imports button opens an editor in which you can add additional classes (functionalities) to the current script. You can use the Search button to search for the currently entered class. If successful, this class will be displayed in the list above.
  
Folgende Klassen und Interfaces sind standardmäßig Importiert und müssen nicht angegeben werden:
+
The following classes and interfaces are imported by default and do not need to be specified:
  
 
*java.util.Date  
 
*java.util.Date  
Zeile 34: Zeile 33:
 
*java.util.HashMap  
 
*java.util.HashMap  
  
==== Variablen ====
+
==== Variables ====
  
Der Variableneditor ermöglicht es Ihnen, diverse Testszenarien aufzubauen, indem Sie die Werte der gegebenen Variablen beliebig verändern können. Bei komplexeren Variablen-Typen (wie z.B. Sendung oder Packstück) wird die Variable im JSON-Format angezeigt und editiert. Es gelten die üblichen Regeln für Escape-Zeichen.
+
The variable editor allows you to set up various test scenarios by changing the values of the given variables as required. For more complex variable types (such as shipment or package), the variable is displayed and edited in JSON format. The usual rules for escape characters apply.
  
 
==== Test ====
 
==== Test ====
  
Über den Button Test können Sie Ihr aktuelles Script testen. Falls ein Syntaxfehler vorhanden ist, wird Ihnen dieser mit Angabe der Zeile angezeigt. Zusätzlich können Sie, solange das Ergebnisfenster offen ist, die komplette erstellte Klasse im Ordner Tarifwerk\compile\scriptbase einsehen.
+
You can test your current script using the Test button. If there is a syntax error, this is displayed along with the line. In addition, you can view the complete class created in the folder Tarifwerk\compile\scriptbase as long as the results window is open.
  
 
=== Editor ===
 
=== Editor ===
  
Im Editor können Sie Ihr Script implementieren. Der Editor besitzt einige Features um das Erstellen von Scripten einfacher zu machen:
+
You can implement your script in the editor. The editor has several features to make creating scripts easier:
  
*Falls ein Script einzeilig ist und nicht mit einem Semikolon endet benötigen Sie kein return Statement. Dieses wird automatisch hinzugefügt.  
+
*If a script is single-line and does not end with a semicolon, you do not need a return statement. This is added automatically.  
*Der Scripteditor besitzt Code-Highlighting um Variablen, Kommentare und Klassen voneinander trennen zu können
+
*The script editor has code highlighting to separate variables, comments and classes from each other
*Der Scripteditor besitzt eingeschränkte Code-Vervollständigungs-Features. Diese aktiviert man über die Tastenkombination Strg+Leer
+
*The script editor has limited code completion features. These are activated via the key combination Ctrl+Space
  
== Zusatzfunktionen ==
+
== Additional functions ==
  
Der Scripteditor kommt standardmäßig mit einigen zusätzlichen Funktionen. Viele dieser Funktionen entsprechen den Parserausdrücken aus dem HVS32.
+
The script editor comes with some additional functions as standard. Many of these functions correspond to the parser expressions from the HVS32.
  
Die Detailbeschreibung und Verwendung können Sie der Code-Vervollständigung (Strg+Leer) entnehmen. Oft verwendete und nützliche Funktionen sind:
+
The detailed description and use can be found in the code completion (Ctrl+Space). Frequently used and useful functions are
  
*ATrim: Entfernt alle Leerzeichen am Anfang und Ende des Strings.  
+
*ATrim: Removes all spaces at the beginning and end of the string.  
*Left: Gibt die ersten n Stellen eines String zurück.  
+
*Left: Returns the first n digits of a string.  
*Right: Gibt die letzten n Stellen eines Strings zurück.  
+
*Right: Returns the last n digits of a string.  
*DEBUG: Zeigt den Wert einer Variable in einer Message Box an. (Bitte niemals ein Script speichern was diese Funktionen enthält)  
+
*DEBUG: Displays the value of a variable in a message box. (Please never save a script that contains these functions)  
*DateTimeFormat: Konvertiert einen String in ein Datum.  
+
*DateTimeFormat: Converts a string into a date.  
*FormatDateTime: Konvertiert ein Datum in einen String.  
+
*FormatDateTime: Converts a date into a string.  
*GetListItem: Extrahiert aus einem String das n-te Element was durch ein Trennzeichen getrennt wurde.  
+
*GetListItem: Extracts the nth element from a string that was separated by a separator.  
*LeftPad: Füllt einen String links mit der angegebenen Anzahl Stellen und Zeichen auf
+
*LeftPad: Fills a string on the left with the specified number of digits and characters
  
 
 
 
 
  
== Besonderheiten ==
+
== Special features ==
  
Da der Pegasus Parser auf Java basiert, muss man einige Dinge beachten, die in anderen Scriptsprachen (wie z.B. Javascript) nicht üblich sind.
+
Since the Pegasus parser is based on Java, there are a few things to consider that are not common in other scripting languages (such as Javascript).
  
=== Stringvergleiche ===
+
=== String comparisons ===
  
Zahlen werden wie üblich über ein doppeltes == verglichen:
+
Numbers are compared as usual using a double ==:
 
<pre>int a = 5;
 
<pre>int a = 5;
 
if (a == 5) {
 
if (a == 5) {
 
....</pre>
 
....</pre>
  
Strings können damit leider nicht verglichen werden. Stattdessen muss man die Methode equals() verwenden:
+
Unfortunately, strings cannot be compared using this method. Instead, you have to use the equals() method:
<pre>String a = "test";
+
<pre>String a = “test”;
if (a.equals("test")) {
+
if (a.equals(“test”)) {
 
...</pre>
 
...</pre>
  
Vergleiche ohne Beachtung von Groß- und Kleinschreibung geschehen über die Methode&nbsp;equalsIgnoreCase().
+
Case-insensitive comparisons are made using the&nbsp;equalsIgnoreCase() method.
  
=== Elemente von Variablen ===
+
=== Elements of variables ===
  
Elemente von Variablen (wie z.B. die Zieladress-PLZ der Sendung) werden über Getter- und Setter-Methoden gelesen und gesetzt.
+
Elements of variables (such as the destination address zip code of the shipment) are read and set using getter and setter methods.
  
Diese besitzen immer den Prefix "get" bzw. "set" und das nächste Zeichen wird als Großbuchstabe geschrieben. Bei Boolean wird "is" statt "get"&nbsp;verwendet. Beispiele:
+
These always have the prefix “get” or “set” and the next character is written as an uppercase letter. For Booleans, “is” is used instead of “get”. Examples:
 
<pre>shipment.getReceiverZipcode()
 
<pre>shipment.getReceiverZipcode()
 
shipment.getShipmentWeight()
 
shipment.getShipmentWeight()
Zeile 95: Zeile 94:
 
packageData.getPackageType()</pre>
 
packageData.getPackageType()</pre>
  
=== Direktes definieren von Nicht-int Zahlen. ===
+
=== Direct definition of non-int numbers. ===
  
Wenn Sie einen double, float oder long direkt im Quelltext definieren wollen, benötigen diese nach der Zahl einen entsprechenden&nbsp;Suffix:
+
If you want to define a double, float or long directly in the source code, they require a corresponding suffix after the number:
 
<pre>double d = 4.3d;
 
<pre>double d = 4.3d;
 
float f = 5.4f;
 
float f = 5.4f;
 
long l = 200000l;</pre>
 
long l = 200000l;</pre>
  
== Beispielscripte ==
+
== Example scripts ==
  
=== Prüfen auf Inselzustellung ===
+
=== Check for island delivery ===
 
<pre>shipment.isIsle()</pre>
 
<pre>shipment.isIsle()</pre>
  
Es wird die entsprechende Inseltabelle für den jeweiligen Frachtführer benötigt.
+
The corresponding island table for the respective carrier is required.
  
=== Auf bestimmte Länder prüfen ===
+
=== Check for specific countries ===
<pre>final List<String> zielLaender = java.util.Arrays.asList("DE", "CH", "AT");
+
<pre>final List<String> zielLaender = java.util.Arrays.asList(“DE”, “CH”, “AT”);
 
return zielLaender.contains(shipment.getReceiverCountry());</pre>
 
return zielLaender.contains(shipment.getReceiverCountry());</pre>
  
Die Elemente DE, CH, AT müssen durch die gewünschten Länder im ISO2 Format ersetzt werden.
+
The elements DE, CH, AT must be replaced by the desired countries in ISO2 format.
  
=== Auf bestimmte Versandart prüfen ===
+
=== Check for specific shipping type ===
<pre>shipment.getServiceType().equals("VID")</pre>
+
<pre>shipment.getServiceType().equals(“VID”)</pre>
  
Die Versandart ID "VID" muss durch die Gewünschte ersetzt werden. Falls mehrere Versandarten in Frage kommen, kann man auch hier eine Liste wie im Beispiel darüber erstellen.
+
The dispatch type ID “VID” must be replaced by the desired shipping type. If several dispatch types are possible, you can also create a list here as in the example above.
  
=== Nachnahme-Sendung ===
+
=== Cash on delivery shipment ===
 
<pre>shipment.getCodAmount() > 0d</pre>
 
<pre>shipment.getCodAmount() > 0d</pre>
  
=== Verpackungsart prüfen ===
+
=== Check packaging type ===
<pre>packageData.getPackageType().equals("KT")</pre>
+
<pre>packageData.getPackageType().equals(“KT”)</pre>
  
Die Verpackungsart sollte meist auch nur mit Packstück-Tarifwerken und -Zuschlägen definiert werden.
+
The packaging type should usually only be defined with package rate structures and surcharges.
  
 
&nbsp;
 
&nbsp;

Aktuelle Version vom 18. Oktober 2024, 16:44 Uhr


TW Script Editor.png

Scripts are the central point in the Tarifwerk for creating rules for surcharges and rate structures. These can be simple queries, such as checking whether it is an island delivery, or complex constructs that implement carrier or customer-specific requirements.

All scripts use the Pegasus parser, a proprietary development of Heidler Strichcode GmbH. The scripting language is based on the Java programming language, which can make some things more complicated, but offers significantly more flexibility and performance.

Scripteditor

The script editor is divided into three areas:

Information panel

The information panel is located at the top left. It shows you all the information you need for script development.

First of all, it lists which variables you have available and which type (which class) the variables have. In the Tarifwerk, you will usually see the variable shipment, which corresponds to the current shipment, and possibly the variable packageData, which corresponds to the current package.

The Expected return type is the type of value that you must return in this script. As a rule, only Boolean (true or false) or Double (floating point number with double precision) is expected in the Tarifwerk.

Button bar

The button bar is located at the top right. You can use it to make additional adjustments and tests.

Imports

The Imports button opens an editor in which you can add additional classes (functionalities) to the current script. You can use the Search button to search for the currently entered class. If successful, this class will be displayed in the list above.

The following classes and interfaces are imported by default and do not need to be specified:

  • java.util.Date
  • java.text.SimpleDateFormat
  • java.util.ArrayList
  • java.util.List
  • java.util.Map
  • java.util.HashMap

Variables

The variable editor allows you to set up various test scenarios by changing the values of the given variables as required. For more complex variable types (such as shipment or package), the variable is displayed and edited in JSON format. The usual rules for escape characters apply.

Test

You can test your current script using the Test button. If there is a syntax error, this is displayed along with the line. In addition, you can view the complete class created in the folder Tarifwerk\compile\scriptbase as long as the results window is open.

Editor

You can implement your script in the editor. The editor has several features to make creating scripts easier:

  • If a script is single-line and does not end with a semicolon, you do not need a return statement. This is added automatically.
  • The script editor has code highlighting to separate variables, comments and classes from each other
  • The script editor has limited code completion features. These are activated via the key combination Ctrl+Space

Additional functions

The script editor comes with some additional functions as standard. Many of these functions correspond to the parser expressions from the HVS32.

The detailed description and use can be found in the code completion (Ctrl+Space). Frequently used and useful functions are

  • ATrim: Removes all spaces at the beginning and end of the string.
  • Left: Returns the first n digits of a string.
  • Right: Returns the last n digits of a string.
  • DEBUG: Displays the value of a variable in a message box. (Please never save a script that contains these functions)
  • DateTimeFormat: Converts a string into a date.
  • FormatDateTime: Converts a date into a string.
  • GetListItem: Extracts the nth element from a string that was separated by a separator.
  • LeftPad: Fills a string on the left with the specified number of digits and characters

 

Special features

Since the Pegasus parser is based on Java, there are a few things to consider that are not common in other scripting languages (such as Javascript).

String comparisons

Numbers are compared as usual using a double ==:

int a = 5;
if (a == 5) {
....

Unfortunately, strings cannot be compared using this method. Instead, you have to use the equals() method:

String a = “test”;
if (a.equals(“test”)) {
...

Case-insensitive comparisons are made using the equalsIgnoreCase() method.

Elements of variables

Elements of variables (such as the destination address zip code of the shipment) are read and set using getter and setter methods.

These always have the prefix “get” or “set” and the next character is written as an uppercase letter. For Booleans, “is” is used instead of “get”. Examples:

shipment.getReceiverZipcode()
shipment.getShipmentWeight()
shipment.isIsle()
packageData.getPackageType()

Direct definition of non-int numbers.

If you want to define a double, float or long directly in the source code, they require a corresponding suffix after the number:

double d = 4.3d;
float f = 5.4f;
long l = 200000l;

Example scripts

Check for island delivery

shipment.isIsle()

The corresponding island table for the respective carrier is required.

Check for specific countries

final List<String> zielLaender = java.util.Arrays.asList(“DE”, “CH”, “AT”);
return zielLaender.contains(shipment.getReceiverCountry());

The elements DE, CH, AT must be replaced by the desired countries in ISO2 format.

Check for specific shipping type

shipment.getServiceType().equals(“VID”)

The dispatch type ID “VID” must be replaced by the desired shipping type. If several dispatch types are possible, you can also create a list here as in the example above.

Cash on delivery shipment

shipment.getCodAmount() > 0d

Check packaging type

packageData.getPackageType().equals(“KT”)

The packaging type should usually only be defined with package rate structures and surcharges.