Polish | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Funkcje pozwalają na deklaratywne przetwarzanie danych bez konieczności pisania własnego kodu. Rozwiązanie to opiera się na wywoływaniu wybranej funkcji (użytkownicy mogą dostarczać własne specyficzne implementacje) i przekazaniu wyniku tej funkcji dalej np. do zadania automatycznego. W przypadku podstawowych działań matematycznych, kwotowych, tekstowych czy logicznych możliwe jest zrealizowanie prostych przekształceń bez napisania linijki kodu.
Tworzone funkcje powinny być ja najbardziej ogólne i elastyczne. Pozwoli to na wykorzystanie ich w większej liczbie przypadków. System pozwala na rejestrowanie i wykorzystywanie predefiniowanych funkcji zarówno po stronie serwera jak i po stronie przeglądarki.
FunctionAPIWszystkie operacje związane z działaniami na funkcjach stanowią FunctionAPI.
Rejestracja funkcji
Rejestracja na serwerzeRejestracja funkcji dostępnych w systemie odbywa się podczas uruchomienia systemu oraz dynamicznie dla dynamicznych zasobów, takich jak wtyczki. Za rejestrację i przechowywanie funkcji odpowiada
Rejestrowana funkcja musi:
Poniższy przykład przedstawia definicję prostej funkcji zwracającej wartość większej liczby.
Można określić, czy funkcja dotyczy tylko serwera (można jej użyć tylko na serwerze), czy tylko przeglądarki (można jej użyć tylko w javascript), czy obu miejsc. Odpowiada za to parametr accessibility, który można ustawić w adnotacji @
Brak ustawionego parametru accessibility odpowiada wartości ALL. Poniższy przykład pokazuje definicję funkcji, która jest dostępna tylko dla komponentów serwerowych. Funkcja zwraca imię i nazwisko użytkownika na podstawie jego loginu.
Jeżeli robimy funkcję tylko dla przeglądarki, to na serwerze również musi być funkcja zdefiniowana, ale jej implementacja nie musi nic robić. Służyć ona ma tylko do pobrania nazwy i parametrów funkcji i wyświetlania jej w PWE. Kontekst funkcjiKontekst funkcji zawiera identyfikator oraz definicję aktualnie przetwarzanego procesu i zadania. Pobranie kontekstu możliwe jest tylko po stronie serwera za pomocą poniższego kodu.
Rejestracja po stronie przeglądarkiUżywanie stworzonej funkcji po stronie przeglądarki (na formularzu zadania) wymaga od programisty dostarczenia jej implementacji w języku JavaScript. Taka implementacja wykorzystywana jest podczas dynamicznych obliczeń po stronie przeglądarki klienta. W przypadku funkcji z implementacją JavaScript należy dodatkowo wskazać poprzez adnotację
classpath . Zasób przechowywany w src/main/resources/functions/basic-functions.js wskażemy tak:
Funkcje rejestrowane są z wykorzystaniem API
PW.Functions ):
Podczas rejestracji funkcji niezbędne jest zdefiniowanie:
Tak zarejestrowana funkcja zostanie wywołana tylko dla wywołań z argumentami które będą pasowały do zdefiniowanych typów. Możliwe typy opisane są w Wbudowane typy. Rejestracja we wtyczceRejestracja funkcji we wtyczce jest taka sama jak zostało to opisane powyżej, jednak należy dodatkowo zaznaczyć, że wtyczka ta udostępnia funkcje do zarejestrowania. W tym celu należy w pliku suncode-plugin.xml dodać wpis:
Taki wpis spowoduje automatyczne wyszukanie wszystkich zdefiniowanych we wtyczce funkcji. Tłumaczenia opisów funkcji i parametrówFunkcje tłumaczone są automatycznie, jeżeli dostępne są tłumaczenia funkcji stworzone z wykorzystaniem mechanizmu internacjonalizacji. Poniżej opisano zasady tworzenia kluczy tłumaczeń. Tłumaczeniu podlegają:
Klucze tłumaczeń funkcji muszą być tworzone z zachowaniem następujących zasad:
Przykład: Dla funkcji zdefiniowanej w następujący sposób:
Tłumaczenia wyglądały będą następująco:
Dla przestarzałej funkcji zdefiniowanej w następujący sposób:
Tłumaczenia wyglądały będą następująco:
Tłumaczenie przeciążeń funkcjiKażda funkcja może mieć wiele przeciążeń, które przyjmują inne parametry. Może istnieć potrzeba nadania innych opisów dla tych parametrów lub innego opisu funkcji. Jest to możliwe poprzez dodanie do nazwy funkcji wykorzystywanej w kluczu tłumaczenia typów parametrów rozdzielonych podkreślnikiem (_). Domyślnym tłumaczeniem jest to bez typów parametrów. Nazwy typów dostępne są tutaj: Wbudowane typy Przykład: Dla funkcji zdefiniowanej w następujący sposób:
Tłumaczenia wyglądały będą następująco:
|
English | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Functions allow declarative processing of data without writing custom code. The solution is based on calling a selected function (users can provide their own specific implementations) and passing the result of this function on to, for example, an automated task. In the case of basic mathematical, quotient, textual or logical operations, it is possible to realize simple transformations without writing a line of code.
The functions created should be as general and flexible as possible. This will allow them to be used in more cases. The system allows you to register and use predefined functions both on the server side and on the browser side.
FunctionAPIAll operations related to actions on functions represent FunctionAPI.
Function registration
Registration on the serverThe registration of functions available in the system is done at system startup and dynamically for dynamic resources such as plugins. The registration and storage of functions is the responsibility of
The registered function must:
The following example shows the definition of a simple function that returns the value of a larger number.
You can specify whether the function applies only to the server (can be used only on the server), only to the browser (can be used only in javascript), or both places. The accessibility parameter, which can be set in the annotation @
No accessibility parameter set corresponds to the value of ALL. The following example shows the definition of a function that is available only to server components. The function returns the name of the user based on his login.
If the function is created for the browser then there must also be a function defined on the server, but its implementation does not have to do anything. It is only to retrieve the name and parameters of the function and display it in the PWE. Function contextThe function context contains the identifier and definition of the currently processed process and task. Retrieving the context is possible only on the server side using the following code.
Browser-side registrationUsing the created function on the browser side (on the task form) requires the programmer to provide its implementation in JavaScript. Such an implementation is used during dynamic calculations on the client's browser side. In the case of functions with JavaScript implementations, you must additionally indicate by annotation
Functions are registered using the API
When registering a function, it is necessary to define:
A function registered in this way will be called only for calls with arguments that match the defined types. The possible types are described in Build-in types. Registration in the pluginThe registration of functions in the plugin is the same as described above, but it should be noted in addition that the plugin provides functions to be registered. To do this, add an entry in the suncode-plugin.xml file:
This entry will automatically search for all functions defined in the plugin. Translations of function and parameter descriptionsFunctions are translated automatically if function translations created using the internationalization mechanism are available. The rules for creating translation keys are described below. Subject of translation:
Translation keys of functions must be created with the following rules:
Example: For a function defined as follows:
The translations will be as follows:
For an obsolete function defined as follows:
Translations will be as follows:
Translation of function overloadsEach function may have multiple overloads that take different parameters. You may need to give different descriptions for these parameters or a different function description. This is possible by adding parameter types separated by an underscore (_) to the function name used in the translation key. The default translation is this without parameter types. The names of the types are available here: Built-in types Example: For a function defined as follows:
The translations will be as follows:
|