Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

Le code du script devra être de la forme : {Prefix}_WebhookRules_{entityname}.

Script de surcharge de règles : Il est obligatoire même pour un webhook spécifique.

...

Script de surcharge de définition : FINAL_WebhookDefinitionOverload_supplier

Vu qu’il s’agit d’un webhook entièrement spécifique, on aurait pu laisser uniquement le squelette de “FINAL_WebhookDefinitionOverload_supplier“ et mettre le code nécessaire au fonctionnement directement dans “FINAL_WebhookDefinition_supplier“.

Bloc de code
languagenone
// FINAL_WebhookDefinitionOverload_supplier

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'simpleFieldsList': 'CodeSupplier,label,city',
    'extendedFieldsListToExclude': '',
    'relatedTablesCount': 2,
    'relatedTables': [ 'final_customer_ID', 'final_suppliercategory_ID' ],
    'authorizedTables': [ {'tableName':'supplier'}, {'tableName':'final_supplieraddress'}, {'tableName':'product'} ],
    'cascadeDeleteTables': [ {'tableName':'final_supplieraddress'} ],
    'fieldsList': {
      'final_customer_ID': {
        'targetTableName': 'sw_data_customer',
        'targetFieldName': 'name'
      },
      'final_suppliercategory_ID': {
        'canGetDefinitionList': 1,
        'definitionLabelFieldName': 'final_label'
      }
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Script de règles : FINAL_WebhookRules_supplier

Il s’agit ici uniquement du squelette nécessaire au bon fonctionnement car nous nous n’avons pas implémenté de règle métier dans notre exemple.

Bloc de code
languagenone
// FINAL_WebhookRules_supplier

code      = TRANSLATE( "<varscript>arg1</varscript>" )
verb      = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput = TRANSLATE( "<varscript>arg3</varscript>" )

tableName               = "supplier"
entity                  = "supplier"
internalcode            = ""
codeTableName           = TRANSLATE( "code<varscript>tableName</varscript>" )
codeEntityName          = TRANSLATE( "code<varscript>entity</varscript>" )
internalcodeEntityName  = TRANSLATE( "internalcode<varscript>entity</varscript>" )
scriptOverload          = TRANSLATE( "FINAL_WebhookRulesOverload_<varscript>entity</varscript>" )

jsonResponse                        = DOCUMENT_CREATE_DOCUMENT()
ruleFields                          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFields" )
ruleOverloadFields                  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFields" )
ruleFieldsAdditionalTables          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFieldsAdditionalTables" )
ruleOverloadFieldsAdditionalTables  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFieldsAdditionalTables" )

// STANDARD RULES

IF( EQUALS( verb, "PUT" ) )THEN
  
  IF ( JSON_EXISTS_FROM_PATH( dataInput, entity ) == 0 ) THEN
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "0" )
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Standard rules error: Missing <varscript>entity</varscript> object in json data" )
    
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
    
  ENDIF
    
  jsonDataInput = JSON_GET_FROM_PATH( dataInput, entity )
  VARINITIALIZE_SCRIPT_BYJSON( jsonDataInput )
  
  
  IF ((LEN( code ) == 0) && (JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ))) THEN
    
    code = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" )
    
  ENDIF
  
  IF ( JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" ) ) THEN
    
    internalcode = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" )
    
  ENDIF
  
  row_ID  = CALL_SCRIPT( "Func_GetIDFromCode", "sw_data_<varscript>tableName</varscript>", "<varscript>code</varscript>", "<varscript>internalcode</varscript>" )
  
ENDIF

// Rule overload
ruleOverloadJsonResponse = CALL_SCRIPT( scriptOverload, code, verb, dataInput, ruleOverloadFields )

IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
  
  response = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "response" )
      
  IF( EQUALS( response, "0" ) )THEN
    
    IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
      
      errorMessage = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "errorMessage" )
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", errorMessage )

    ELSE
      
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Specific rules error: No error message defined" )
      
    ENDIF
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", response )
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
  
  ENDIF

ENDIF

DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "1" )
response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

...

Bloc de code
languagenone
// FINAL_WebhookDefinitionOverload_suppliercategory

languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'fieldsList': {

    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Créer webhook sur table

...

standard si scripts déjà existants

Création d’un nouveau webhook sur la table spécifique standard “sw_data_final_supplieraddress”symptom”.

Dictionnaire Script d’entrée :

...

FINAL_WebhookSymptom

Bloc de code
languagenone
tableName   = "symptom"
entityName  = "symptom"

INCLUDE( "FuncWebhook_BuildEndpoint" )

Script de définition : WebhookDefinition_symptom

Le script de définition “WebhookDefinition_symptom“ existe déjà en standard. Donc on y touche pas.

Script de surcharge de définition : WebhookDefinitionOverload_symptom

Le script de surcharge de définition “WebhookDefinitionOverload_symptom“ est déjà prévu en standard. Il suffit donc de surcharger ce script si besoin.

Bloc de code
languagenone
// WebhookDefinitionOverload_symptom
 
languageCode     = VARGET_SHELL( "languageCode", "WebhookDefinition" )

specificOverload = TRANSLATE( "
  {
    'extendedFieldsListToExclude': '',
    'relatedTablesCount': 3,
    'relatedTables': [ 'equipmenttype_ID', 'equipmentkind_ID', 'symptom_ID_parent' ],
    'authorizedTables': [{'tableName':'symptom'}, {'tableName':'symptomauthorization'}],
    'cascadeDeleteTables': [ {'tableName':'symptomauthorization'} ],
    'fieldsList': {
      'equipmentkind_ID':{
        'canGetDefinitionList': 1
      },
      'equipmenttype_ID':{
        'canGetDefinitionList': 1
      }
    },
    strictFilters: [
      
    ],
    'strictOrderBy': [
      
    ],
    'outOfMainTableFields': [
      
    ]
  }
" )

RETURN( "<varscript>specificOverload</varscript>" )

Script de règles : FINAL_WebhookRules_symptom

Par contre le script des règles métiers n’existe pas en standard. Il suffit donc de le créer en spécifique.

Bloc de code
// FINAL_WebhookRules_symptom

code      = TRANSLATE( "<varscript>arg1</varscript>" )
verb      = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput = TRANSLATE( "<varscript>arg3</varscript>" )

tableName               = "symptom"
entity                  = "symptom"
internalcode            = ""
codeTableName           = TRANSLATE( "code<varscript>tableName</varscript>" )
codeEntityName          = TRANSLATE( "code<varscript>entity</varscript>" )
internalcodeEntityName  = TRANSLATE( "internalcode<varscript>entity</varscript>" )
scriptOverload          = TRANSLATE( "FINAL_WebhookRulesOverload_<varscript>entity</varscript>" )

jsonResponse                        = DOCUMENT_CREATE_DOCUMENT()
ruleFields                          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFields" )
ruleOverloadFields                  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFields" )
ruleFieldsAdditionalTables          = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleFieldsAdditionalTables" )
ruleOverloadFieldsAdditionalTables  = DOCUMENT_CREATE_OBJECT( jsonResponse, "ruleOverloadFieldsAdditionalTables" )

// STANDARD RULES

IF( EQUALS( verb, "PUT" ) )THEN
  
  IF ( JSON_EXISTS_FROM_PATH( dataInput, entity ) == 0 ) THEN
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "0" )
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Standard rules error: Missing <varscript>entity</varscript> object in json data" )
    
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
    
  ENDIF
    
  jsonDataInput = JSON_GET_FROM_PATH( dataInput, entity )
  VARINITIALIZE_SCRIPT_BYJSON( jsonDataInput )
  
  
  IF ((LEN( code ) == 0) && (JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" ))) THEN
    
    code = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>codeEntityName</varscript>" )
    
  ENDIF
  
  IF ( JSON_EXISTS_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" ) ) THEN
    
    internalcode = JSON_GET_FROM_PATH( jsonDataInput, "<varscript>internalcodeEntityName</varscript>" )
    
  ENDIF
  
  row_ID  = CALL_SCRIPT( "Func_GetIDFromCode", "sw_data_<varscript>tableName</varscript>", "<varscript>code</varscript>", "<varscript>internalcode</varscript>" )
  
ENDIF

// Rule overload
ruleOverloadJsonResponse = CALL_SCRIPT( scriptOverload, code, verb, dataInput, ruleOverloadFields )

IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
  
  response = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "response" )
      
  IF( EQUALS( response, "0" ) )THEN
    
    IF( JSON_EXISTS_FROM_PATH( ruleOverloadJsonResponse, "response" ) )THEN
      
      errorMessage = JSON_GET_FROM_PATH( ruleOverloadJsonResponse, "errorMessage" )
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", errorMessage )

    ELSE
      
      DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "errorMessage", "Specific rules error: No error message defined" )
      
    ENDIF
    
    DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", response )
    response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
    RETURN( response )
  
  ENDIF

ENDIF

DOCUMENT_ADD_PROPERTY_TO_OBJECT( jsonResponse, "response", "1" )
response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Script de surcharge de règles : FINAL_WebhookRulesOverload_symptom

Evidemment ce script n’existait pas en standard. Il suffit donc de le créer en spécifique.

Bloc de code
languagenone
// FINAL_WebhookRulesOverload_symptom

code          = TRANSLATE( "<varscript>arg1</varscript>" )
verb          = TRANSLATE( "<varscript>arg2</varscript>" )
dataInput     = TRANSLATE( "<varscript>arg3</varscript>" )
ruleFields    = TRANSLATE( "<varscript>arg4</varscript>" )

jsonResponse = DOCUMENT_CREATE_DOCUMENT()

response = DOCUMENT_SERIALIZE( jsonResponse, "json" )
RETURN( response )

Créer webhook sur table spécifique

Création d’un nouveau webhook sur la table spécifique “sw_data_final_supplieraddress”.

Dictionnaire :

...

Script d’entrée : FINAL_WebhookSupplierAddress

...