Polish | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Code Block | ||
---|---|---|
| ||
@ScheduledTask @ScheduledTaskScript( "js/example-form.js" ) public class ExampleScheduledTask { @Define public void definition( ScheduledTaskDefinitionBuilder builder ) { builder .id( "example-scheduled-task" ) .name( "example.scheduled.task.name" ) .description( "example.scheduled.task.desc" ) .cancelable() .parameter() .id( "scheduled-task-param" ) .name( "example.scheduled.task.param.name" ) .description( "example.scheduled.task.param.desc" ) .type( Types.STRING ) .create(); } public void execute( @Param( value = "scheduled-task-param" ) String param ) { // Ciało zadania zaplanowanego ... } } |
Note | ||
---|---|---|
| ||
Od wersji 4.1.2 jest możliwość dodawania nowych parametry do istniejących zadań zaplanowanych pod warunkiem spełnienia minimum jednego z warunków:
Przed tą wersją bezpośrednie rozszerzanie istniejących zadań zaplanowanych nie jest wspierane. |
Implementacja metody execute
Zadanie zaplanowane musi posiadać metodę o nazwie execute. Metoda może posiadać następujące typy parametrów:
- pojedynczy parametr zadania zaplanowanego - typ parametru musi być zgodny ze zdefiniowanym typem oraz musi być poprzedzony adnotacją @Param. Obsługiwane typy parametrów:
- STRING
- BOOLEAN
- INTEGER
- FLOAT
- DATE - mapowane do org.joda.time.LocalDate (format yyyy-MM-dd)
- DATETIME - mapowane do org.joda.time.LocalDateTime (format yyyy-MM-dd HH:mm:ss)
- FILE - mapowanie do com.suncode.pwfl.customfile.ComponentFile
- STRING_ARRAY
- BOOLEAN_ARRAY
- INTEGER_ARRAY
- FLOAT_ARRAY
- DATE_ARRAY
- DATETIME_ARRAY
- FILE_ARRAY
- zawiera wszystkie zdefiniowane parametry zadania zaplanowanego wraz z ich wartościami, jest to alternatywa dla pobierania parametru za pomocą wyżej wspomnianej adnotacji @Param,Javadoc displayValue Parameters property javadoc.plusworkflow className com.suncode.pwfl.component.Parameters
- translator dla tego komponentu. Więcej informacji tutaj,Javadoc displayValue Translator property javadoc.plusworkflow className com.suncode.pwfl.translation.Translator
- przechowuje informację o tym, czy użytkownik w GUI kliknął przycisk Anuluj wykonywanie. Sam mechanizm anulowania zadania musi zaimplementować twórca komponentu. Przycisk Anuluj wykonywanie pokaże się tylko, jeżeli w builderze została wywołana metoda cancelable,Javadoc displayValue CancelationHandler property javadoc.plusworkflow className com.suncode.pwfl.administration.scheduledtask.context.CancelationHandler - Logger - logger do logowania własnych komunikatów w komponencie. Komunikaty są zapisywane do plików (skonfigurowanych w Log4j) oraz zostaną wyświetlone w historii wykonywania zadania.
- obiekt, w którym ustawić można aktualny progress wykonywania zadania zaplanowanego (liczba między 0 a 1). Progress ten zostanie wyświetlony w GUI.Javadoc displayValue ProgressHolder property javadoc.plusworkflow className com.suncode.pwfl.administration.scheduledtask.context.ProgressHolder
- obiekt przechowujący informacje o danej instancji zadania zaplanowanego.Javadoc property javadoc.plusworkflow className com.suncode.pwfl.administration.scheduledtask.ScheduledTaskInstanceInfo
Rejestracja zadania zaplanowanego we wtyczce
Jeżeli zadanie zaplanowane jest definiowane we wtyczce to należy dodatkowo zaznaczyć, że wtyczka ta udostępnia komponenty. W tym celu należy w pliku suncode-plugin.xml dodać wpis:
Code Block | ||
---|---|---|
| ||
<!-- Udostępnianie komponentów (m.in. zadań zaplanowanych) --> <workflow-components key="components" /> |
Metoda jako zadanie zaplanowane we wtyczce
Zadanie zaplanowane we wtyczce nie musi być komponentem. Może zostać stworzone tak samo, jak zadania zaplanowane definiowane w projektach klienckich - zadanie zaplanowane jako wywołanie publicznej metody.
Np. po stworzeniu klasy we wtyczce:
Code Block | ||
---|---|---|
| ||
package com.suncode.plugin; public class SomePluginClass { public void someMethod( String text, Integer number ) { System.out.println( "Text: " + text + ", number: " + number ); } public void someMethod2( String text, Double number ) { System.out.println( "Text: " + text + ", number: " + number ); } } |
Po wpisaniu com.suncode.plugin.SomePluginClass w pole Nazwa klasy w oknie dodawania nowego zadania zaplanowanego wyświetlone zostaną metody someMethod oraz someMethod2, które można wybrać i dodać jako zadanie zaplanowane.
Takie zadania mają jednak ograniczenia:
- nie można użyć adnotacji
do nadania nazwy, opisu itd. dla zadania zaplanowanegoJavadoc displayValue AdvancedTask property javadoc.plusworkflow className com.plusmpm.util.scheduledTasks.annotation.AdvancedTask - nie można przerwać takiego zadania
- nie można ustawić progresu dla takiego zadania
- nie można logować
Ze względu na powyższe ograniczenia funkcjonalność ta powinna służyć jedynie do testowania własnych klas we wtyczkach. Preferowane jest, aby docelowo zadania zaplanowane we wtyczkach były komponentami.
Info | ||
---|---|---|
| ||
Jeśli zadanie zaplanowane jest napisane jako rozszerzenie klasy AbstractAdvancedTask i ma włączoną adnotację cancelable = true to by przerwać wykonywanie takiego zadania należy w kodzie metody dodać warunek:
|
Dynamiczny formularz
Dynamiczny formularz umożliwia zdefiniowanie formularza parametrów zadania zaplanowanego.
Rejestracja dynamicznego formularza
Dynamiczny formularz rejestrowany jest poprzez przekazanie ścieżki do skryptu js (z classpath wtyczki) zawierającego definicję formularza dynamicznego w adnotacji @ScheduledTaskScript dodanej na poziomie klasy komponentu zadania zaplanowanego.
Przykładowa rejestracja skryptu na klasie po stronie Javy:
Code Block | ||||
---|---|---|---|---|
| ||||
@ScheduledTask @ScheduledTaskScript( "js/example-form.js" ) public class ExampleScheduledTask { @Define public void definition( ScheduledTaskDefinitionBuilder builder ) { builder .id( "example-scheduled-task" ) // identyfikator zadania zaplanowanego ... // pozostałe parametry } ... } |
Przykładowa zawartość skryptu rejestrującego dynamiczny formularz po stronie Javascript:
Code Block | ||||
---|---|---|---|---|
| ||||
// kluczem w metodzie register jest identyfikator zadania zaplanowanego
PW.ScheduledTasks.register('example-scheduled-task', {
buildParams: function (form) {
form.addCombobox({
id: 'example-scheduled-task',
values: [
['wartosc1', 'Wartosc 1'],
['wartosc2', 'Wartosc 2'],
['wartosc3', 'Wartosc 3']
]
});
}
} |
Dostępne funkcje dynamicznego formularza
Funkcja | Parametry | Opis | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
addField(definition, [position]) | definition - identyfikator dodawanego parametru lub obiekt zawierający definicję pola
position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza. | Przykład dodania parametru:
Przykład dodania parametru z reagowaniem na zmianę wartości:
| ||||||||||||||||||||
addTextArea(definition, [position]) | definition - identyfikator dodawanego parametru lub obiekt zawierający definicję pola position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza. listeners- obiekt definiujacy funkcje zdarzeń na zmiennej
| Dodanie parametru jako pole typu `TextArea`.
Przykład:
lub
| ||||||||||||||||||||
addCombobox(definition, [position]) | definition - obiekt zawierający definicję pola Definicja powinna zawierać nastepujące pola:
position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza
Endpoint zdalnego comboboxa ma następującą strukturę: Parametry wysyłane:
Dane zwracane:
| Dodanie parametru jako pole typu `Combobox`. Przykład dodania pola typu 'Combobox' lokalnego (local):
Przykład dodania pola typu 'Combobox' zdalnego (remote):
| ||||||||||||||||||||
setComboboxRemoteUrl(elementId, url) | elementId - identyfikator elementu url - ades URL | Docelowy element musi być combobox'em typu zdalnego. Przykład:
| ||||||||||||||||||||
setComboboxRemoteParams(elementId, params) | elementId - identyfikator elementu params - obiekt zawierający pola z dokładanymi parametrami do żądań http
| Docelowy element musi być combobox'em typu zdalnego. Przykład:
| ||||||||||||||||||||
addCheckbox(definition, [position]) | definition - identyfikator dodawanego parametru lub obiekt zawierający definicję pola position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza. listeners- obiekt definiujacy funkcje zdarzeń na zmiennej
| Przykład:
Jeżeli podpinamy to pod parametr komponentu, to typ tego parametru musi być boolean. | ||||||||||||||||||||
addRow( [definition] ) | definition - definicja wiersza. Zawiera następujące pola:
| Dodaje i zwraca "pusty" wiersz. Zwrócony wiersz umożliwia dodanie do niego pol. Pola będą dodawane obok siebie. Przykład:
| ||||||||||||||||||||
addButton(definition, [position] ) | definition - definicja przycisku.
position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza | Dodanie przycisku na formularzu. Przykład:
| ||||||||||||||||||||
addPassword(definition, [position]) | definition - identyfikator dodawanego parametru lub obiekt zawierający definicję pola position - pozycja na której dodany mam zostać parametr. Gdy position nie zostanie podany, parametr zostanie dodany na końcu formularza. listeners- obiekt definiujacy funkcje zdarzeń na zmiennej
| Dodanie parametru jako pole typu 'Password'.
Przykład:
lub
| ||||||||||||||||||||
hide(elementId) | elementId - identyfikator elementu | Ukrywa pole o podanym id. Przykład
| ||||||||||||||||||||
show(elementId) | elementId - identyfikator elementu | Pokazuje pole o podanym id. Przykład:
| ||||||||||||||||||||
disable(elementId) | elementId - identyfikator elementu | Wyłącza możliwość edycji pola o podanym id. Przykład:
| ||||||||||||||||||||
enable(elementId) | elementId - identyfikator elementu | Włącza możliwość edycji pola o podanym id. Przykład:
| ||||||||||||||||||||
getValue(elementId) | elementId - identyfikator elementu | Pobiera wartość parametru o podanym id. Przykład:
| ||||||||||||||||||||
setValue(elementId, value) | elementId - identyfikator elementu value - wartość do ustawienia | Ustawia przekazaną wartość do parametru o podanym id. Dla typów tablicowych wartością jest tablica wartości. Przykład:
| ||||||||||||||||||||
setRequired(elementId, value) Dostępne od wersji 4.1.3 | elementId - identyfikator elementu value - wymagalność parametru | Dostępne od wersji 4.1.3. Ustawia wymagalność parametru o podanym id. Tylko parametry zadeklarowane wstępnie jako opcjonalne mogą mieć zmienioną wymagalność na formularzu. Przykład:
| ||||||||||||||||||||
mask(onlyForm) | onlyForm - prawda by nałożyć maskę tylko na formularz parametrów, fałsz by nałożyć maskę na zawartość całego okna. | Nakłada maskę na formularz parametrów lub zawartość okna. Przykład:
| ||||||||||||||||||||
unmask(onlyForm) | onlyForm - prawda by usunąć maskę tylko z formularza parametrów, fałsz by usunąć maskę z zawartości całego okna | Usuwa maskę z formularza parametrów lub zawartości okna. Przykład:
|
English | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Code Block | ||
---|---|---|
| ||
@ScheduledTask @ScheduledTaskScript( "js/example-form.js" ) public class ExampleScheduledTask { @Define public void definition( ScheduledTaskDefinitionBuilder builder ) { builder .id( "example-scheduled-task" ) .name( "example.scheduled.task.name" ) .description( "example.scheduled.task.desc" ) .cancelable() .parameter() .id( "scheduled-task-param" ) .name( "example.scheduled.task.param.name" ) .description( "example.scheduled.task.param.desc" ) .type( Types.STRING ) .create(); } public void execute( @Param( value = "scheduled-task-param" ) String param ) { // Body of scheduled task ... } } |
Implementation of the execute method
A scheduled task must have a method named execute. The method can have the following parameter types:
- a single scheduled task parameter - the parameter type must conform to the defined type and must be preceded by the @Param annotation. Supported parameter types:
- STRING
- BOOLEAN
- INTEGER
- FLOAT
- DATE - mapping to org.joda.time.LocalDate (yyyy-MM-dd format)
- DATETIME - mapping to org.joda.time.LocalDateTime (yyyy-MM-dd HH:mm:ss format)
- FILE - mapping to com.suncode.pwfl.customfile.ComponentFile
- STRING_ARRAY
- BOOLEAN_ARRAY
- INTEGER_ARRAY
- FLOAT_ARRAY
- DATE_ARRAY
- DATETIME_ARRAY
- FILE_ARRAY
- contains all the defined parameters of a scheduled task along with their values, this is an alternative to retrieving a parameter using the mentioned @Param annotationJavadoc displayValue Parameters property javadoc.plusworkflow className com.suncode.pwfl.component.Parameters
- translator for this component. More information here,Javadoc displayValue Translator property javadoc.plusworkflow className com.suncode.pwfl.translation.Translator
- stores information about whether the user in the GUI clicked the Cancel execution button. The task cancellation mechanism itself must be implemented by the component developer. The Cancel Execution button will only show up if the cancelable method has been called in the builder,Javadoc displayValue CancelationHandler property javadoc.plusworkflow className com.suncode.pwfl.administration.scheduledtask.context.CancelationHandler - Logger - a logger for logging custom messages in the component. Messages are saved to files (configured in Log4j) and will be displayed in the task execution history.
- object, in which you can set the current progress of the scheduled task execution (a number between 0 and 1). This progress will be displayed in the GUIJavadoc displayValue ProgressHolder property javadoc.plusworkflow className com.suncode.pwfl.administration.scheduledtask.context.ProgressHolder
- an object that stores information about a given instance of a scheduled taskJavadoc property javadoc.plusworkflow className com.suncode.pwfl.administration.scheduledtask.ScheduledTaskInstanceInfo
Registration of a scheduled task in the plugin
If the scheduled task is defined in the plugin then you need to additionally indicate that the plugin provides components. To do this, add an entry in the suncode-plugin.xml file:
Code Block | ||
---|---|---|
| ||
<!-- Sharing components (among other scheduled tasks) --> <workflow-components key="components" /> |
Method as a task scheduled in a plugin
A scheduled task in a plugin does not have to be a component. It can be created in the same way as scheduled tasks defined in client projects - a scheduled task as a public method call.
For example, after creating a class in a plug-in
Code Block | ||
---|---|---|
| ||
package com.suncode.plugin; public class SomePluginClass { public void someMethod( String text, Integer number ) { System.out.println( "Text: " + text + ", number: " + number ); } public void someMethod2( String text, Double number ) { System.out.println( "Text: " + text + ", number: " + number ); } } |
After typing com.suncode.plugin.SomePluginClass in the Class Name field, the window for adding a new scheduled task will display someMethod1 and someMethod2 methods, which can be selected and added as a scheduled task.
However, such tasks have limitations:
- annotation
cannot be used to give a name, description, etc. for a scheduled taskJavadoc displayValue AdvancedTask property javadoc.plusworkflow className com.plusmpm.util.scheduledTasks.annotation.AdvancedTask - you cannot abort that kind of task
- you cannot set progression for this kind of task
- you cannot log
Due to the above limitations, this functionality should only be used for testing custom classes in plugins. It is preferred that ultimately the tasks scheduled in plugins are components.
Info | ||
---|---|---|
| ||
If a scheduled task is written as an extension of the AbstractAdvancedTask class and has the cancelable = true annotation enabled, then to stop the execution of such a task you need to add a condition in the method code:
|
Dynamic form
The dynamic form allows you to define a scheduled task parameter form.
Dynamic form registration
Code Block | ||||
---|---|---|---|---|
| ||||
PW.ScheduledTasks.register('example-scheduled-task', { buildParams: function (form) { form.addCombobox({ id: 'example-scheduled-task', values: [ ['wartosc1', 'Wartosc 1'], ['wartosc2', 'Wartosc 2'], ['wartosc3', 'Wartosc 3'] ] }); } } |
Tip |
---|
If, when adding an element to the form, you define the id of the element and this value refers to the id of the parameter defined in the component, then all properties for the field will be read from the parameter definition (name, description, requirement, type). If, on the other hand, you want to add a field that is not related to any parameter, then you should define the name, description, type and requirement. |
Available functions of the dynamic form
Function | Parameters | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
addField(definition, [position]) | definition - identifier of the added parameter or object containing the definition of the field position - the position at which the parameter is to be added. listeners- an object that defines the function of events on the variable
| Adding parameter. Example:
If we add a field unrelated to the component parameter, we can specify what type the field should be. The following types are available: string, integer, float, date, datetime, boolean, string[], integer[], float[], date[], datetime[], boolean[].
| ||||||||||||||||||||
addTextArea(definition, [position]) | definition - identifier of the added parameter or object containing the definition of the field position - the position at which the parameter is to be added. When position is not specified, the paramter will be added at the end of the form. listeners- an object that defines the function of events on the variable
| Adding a parameter as a field of type `TextArea`.
Example
or
| ||||||||||||||||||||
addCombobox(definition, [position]) | definition - object containing the definition of a field The definition should contain the following fields:
position - The position on which the parameter is to be added. When position is not specified, the parameter will be added to the end of the form
| Adding a parameter as a field of type `Combobox`. Example of adding a field of type `Combobox` local (local):
Example of adding a field of type 'Combobox' remote (remote):
| ||||||||||||||||||||
addCheckbox(definition, [position]) | definition - identifier of the added parameter or object containing the definition of the field position - the position at which the parameter is to be added. When position is not specified, the paramter will be added at the end of the form. listeners- an object that defines the function of events on the variable change - a function called when the value of a field changes.The function can use the following parameters:
| Example:
If we pin this to a component parameter, the type of this parameter must be boolean. | ||||||||||||||||||||
addRow( [definition] ) | definition - definition of a row. It contains the following fields:
| Adds and returns an "empty" row. The returned row allows you to add fields to it. The fields will be added side by side. Example:
| ||||||||||||||||||||
addButton(definition, [position] ) | definition - button definition.
position - the position at which the parameter is to be added. When position is not specified, the paramter will be added at the end of the form. | Adding a button on the form. Example:
| ||||||||||||||||||||
addPassword(definition, [position]) | definition - the identifier of the added parameter or the object containing the field definition position - the position at which the parameter is to be added If position is not specified, the parameter will be added at the end of the form. listeners- an object that defines event functions on the variable
| Adding a parameter as a field of type 'Password'.
Example
or
| ||||||||||||||||||||
hide(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| ||||||||||||||||||||
show(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| ||||||||||||||||||||
disable(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| ||||||||||||||||||||
enable(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| ||||||||||||||||||||
getValue(elementId) | elementId - element identifier | Hides the field with the specified id. Example
| ||||||||||||||||||||
setValue(elementId, value) | elementId - element identifier value - value to be set | Sets the forwarded value to the parameter with the specified id. For array types, the value is an array of values. Example
| ||||||||||||||||||||
mask(onlyForm) | onlyForm - true - to apply the mask only to the parameter form, false - to apply the mask to the contents of the entire window. | Applies a mask to a parameter form or window content. Example
| ||||||||||||||||||||
unmask(onlyForm) | onlyForm - true - to apply the mask only to the parameter form, false - to apply the mask to the contents of the entire window. | Applies a mask to a parameter form or window content. Example
|