miércoles, 20 de enero de 2021

36. My Wonderful Web Framework. (1) Actions. YAML definition

 1.  Actions

Falta definir els métodes de la classe actual. Cal fer un wrapper per a que una classe  que assumisca una cride d'una altra i que herede de BaseExecute!!!!!


An action consists of executing a method from a class. The actions can be defined in menus and forms:

  1. Actions that are executed in a "MenuItem" of type "action" ("command" and "1" are synonymous). Only one action per "MenuItem" is allowed
  2. Actions that are executed inside a form (represented by a class) in a "MenuItem" of type "form" (take into account that there are several types of forms: default(2), custom(3) and yaml (4)
An action is defined by:
  1. The class that contains the method to execute
  2. The method to execute
  3. The parameters that accept the class. That can be fixed and/or asked by means of a form
  4. The type of action: the possible values are: inner: In this case the class to execute is in the same Vaadin module, shell: In this case a call to a shell script in the property "execution.folder" of the property file "app.properties", socket: This is very important as delegates the execution to another server by means of sending messages through sockets, avoiding java RMI
  5.  Optional information: role group that is allowed to execute the program, icon to show, ask for confirmation, char to show in combo in grid form, if need a record id to operate,

2. Defining the actions

Here is a snippet of YAML code defining both types of actions $$$


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
menuItems: 
  [
    #1. MenuItem with an action of type socket (executed in another server (action: socket type))
    { description: firstcontrolloadyaml_control, className: openadmin.actions.SocketActions, icon: fa-upload,   
     type: action, defaultActions: false,
     actions: 
       [ 
         { name: dataLoad,  type: socket, method: execute,    
           fixParams: '[STRING:JAVA_PATH -jar JARS_FOLDER/IF/MiJar.jar FIRSTCONTROLLOAD]', 
           roleGroup: gadmin, icon: fa-upload, executedInGrid: false, needId: false  
         } 
       ]
    },  

    #2. MenuItem with an action of type inner (executed in a class included in the "war" file (action: inner type))
    { className: openadmin.actions.u.request.MetadataLoader, icon: fa-upload,   
      type: action, defaultActions: false, 
      actions: 
        [ 
          { name: dataLoad,  method: dataLoad,  fixParams: '[DAO-METADATA]',   
            roleGroup: gadmin,   icon: fa-upload, executedInGrid: false, needId: false  
          } 
        ]
    },
   
    #3. A form of type custom that shows the "users" and has som actions 
    { className: openadmin.model.control.User, description: User_Custom, icon: fa-user, combo: false, type: custom,
      actions: 
        [ 
          #3.1 Action in the form that calls a java program in another server (action: socket type)
          { name: getFactures, confirm: false, idChar: E, type: socket, method: execute, 
            fixParams: '[STRING:JAVA_PATH -jar JARS_FOLDER/IF/MiJar.jar AYTOSOPERATION]', 
            formParams: '{name: s_n, type: STRING, length: 1, value: S, required: true }', 
            roleGroup: gnew,   icon: fa-file-invoice-dollar, executedInGrid: false, needId: false  
          } ,
          
          #3.2 Example where the class of the action is a shell script executed in the same server (action: shell type)
          { name: dni,  confirm: false, idChar: 7, method: verifyDNI, roleGroup: gadmin,  type: shell, icon: fa-id-card, 
            fixParams: '[STRING:bshComprobaciones.sh];[ID];[STRING:verifyDNI]'    
          } ,

          #3.3 Example where the class of the action is the same class (action: inner type)
          { name: kkerr, confirm: false,   idChar: 8, type: inner,  method: kk1,            
            fixParams: '[ID]', roleGroup: gadmin,   icon: fa-cloud-showers-heavy    
          },  
          
          #3.4 Action in the form that calls a shell script in another server (action: socket type)
          { name: prova, confirm: true,    idChar: C, type: socket, executedInGrid: false,  
           fixParams: '[STRING:SHELL_PATH/shProva01.sh]', roleGroup: gadmin,   icon: fa-beer    
          } 
        
        ]
    }
  ] 


Line 4 defines a "menuitem" that is of type action, so it has only one action of type socket

Line 14 defines a "menuitem" that is of type action, so it has only one action of type inner


Line 26 defines a form with 4 actions of different types Socket (external java program execution), shell (in the same server), inner with a method of the "entity class" and another Socket (external shell script in another server)

Here are some important parameters:
  • className: The class that owns the method to execute, by default is the class shown in the form
  • method: the name of method of the class to execute. By default is the "execute"
  • name: The name that will be shown to the user and will be converted to i18n (internationalization)
  • roleGroup: the authorized group top execute the method
  • idChar: The char to show in the group of actions (in the combo) to be executed in a form. It must be set when the actions are executed from a form. Each action should have a unique "idChar"
  • icon: The name of the "font-awesome icon" to show.
  • needId: If the action is executed on one record (that is identified by its Id). The Id is supplied by the current record.
  • executedInGrid: If this action can be executed in a record of the grid and showed in the combo of options
  • confirm: If ask for confirmation of the user before executing the action. 

3. The fixParams parameter

This parameter is important as it has a peculiar format. It is a list of constant parameters. Every parameter must be between "square brackets" "[ ]" and separated by a colon ";"

Here is an example:


fixParams: '[DAO-H2];[ID];[INT:2];[LONG:9];[STRING:cat];[SERVER:0]', 

Where:
  • DAO-H2 is the DAO Object form the H2 database, there ara also other DAOs to other persistence units.
  • ID is the id of the Base Object
  • INT:2 is the integer value "2"
  • LONG:9 is the long value "9"
  • STRING:cat is the String value "cat"
  • SERVER:0 returns the server + ":" + port for specifiying a socket to a server to pass messages.
Al all these parameters are stored in a List

4. The formParams parameter

This parameter is important as it has a peculiar format. It is a list of parameters that will be required within a form to the user.

Each parameter is defined between brackets "{ }" and forms a YAML structure.


formParams: '{name: year, type: INT, length: 4, value: $YEAR, required: true }, {name: registro, type: INT, length: 6, value: 0, required: true }',

The labels of the parameters are:
  • name: name of the parameter
  • type: INT, LONG, STRING ...
  • length: max number of chars of the parameter 
  • required; true of false
  • value: default value. It can be:
    • $YEAR : Actual year
    • $YEAR_PREVIUOS_MONTH: Year of the previous month
    • $MONTH: Actual month (1 to 12) 
    • $PREVIOUS_MONTH: The previous month (1 to 12)
    • A constant

No hay comentarios:

Publicar un comentario