JS script engine self-defining method based on Naporn

By introducing Nashorn-based JS script engine customization method in the low-code platform, the flexibility and customization limitations of the low-code platform when dealing with complex business needs is solved, and the safe and efficient execution of complex business logic and data processing is achieved, improving the efficiency of the implementation of complex business logic and data processing. The applicability and scalability of the platform.

CN118963910APending Publication Date: 2024-11-15SHANGHAI ZHENZHI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410954369.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-17
Publication Date
2024-11-15

AI Technical Summary

Technical Problem

Low-code platforms are limited in dealing with complex or specific business needs, cannot meet users' customization and flexibility needs, and the existing technology cannot effectively implement complex business logic and data processing.

Method used

Design a custom method for JS scripting engine based on Nashorn. By providing a script editor in a low-code designer, it allows users to write JavaScript code and execute in a sandbox environment, implementing complex business logic and data processing to ensure security and efficient.

Benefits of technology

Improves the flexibility and functionality of the low-code platform, meets the needs of different business scenarios, reduces development costs and time, enhances the scalability and applicability of the platform, and allows users to realize complex business logic while ensuring security. and data processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963910A_ABST
    Figure CN118963910A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of software programs, in particular to a JS script engine customizing method based on Naporn. The method specifically comprises the following steps: S1, configuration of a low-code view designer: providing a script editor for inputting a JS script in the low-code designer of the ITSMSAAS system; s2, functional page rendering: after the functional page is rendered in a browser, if a default value exists in the page, a script is maintained through a script editor of a low-code view designer or a certain button maintains the script through the script editor, a JS script engine is called; and S3, executing the JS script engine: after the standard JavaScript code and the general function are transmitted to the JS script engine, the JS script engine performs corresponding processing logic on business object field acquisition, general function analysis and environment variable reading, translates and splices into a final JavaScript, transmits the final JavaScript to a nashorn sandbox for execution, and returns a result. Compared with the prior art, the flexibility and functionality of the platform are effectively enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of software programs, in particular to a JS script engine customization method based on Nashorn. Background Art

[0002] Nashorn is a JavaScript engine introduced in Java 8, which allows JavaScript code to be executed in a Java environment. Nashorn uses a sandbox mechanism to isolate the execution environment, which is very important for security and controllability. In the field of computer security, sandbox usually refers to a controlled execution environment that is used to limit program access rights to protect the system from potential malicious code or erroneous behavior. In Nashorn, the sandbox mechanism ensures that JavaScript code cannot directly access Java system resources or perform dangerous operations during execution, thereby ensuring security and stability. In summary, Nashorn's sandbox mechanism provides a secure execution environment that allows JavaScript code running in Java applications to be effectively controlled and restricted.

[0003] A low-code platform is a platform that allows users to create applications through a graphical interface and model-driven logic rather than the traditional hand-written code method. These platforms greatly simplify the application development process, enabling non-professional programmers to easily build and deploy applications. However, low-code platforms usually have some limitations: Balance between standardization and customization: Although low-code platforms provide a large number of standardized functions, users still need some customized solutions in specific scenarios. For example, there will be more complex and customized processes such as field default values, button triggering behaviors, document splitting rules, etc.

[0004] The need for flexibility: In some cases, the graphical interface and preset components of the low-code platform may not meet all business needs. At this time, developers need a way to write custom code to implement more complex functions or logic. Summary of the invention

[0005] In order to overcome the shortcomings of the prior art, the present invention provides a JS script engine customization method based on Nashorn, which effectively enhances the flexibility and functionality of the platform. The precise implementation of each method ensures the reliability and efficiency of script execution and meets the needs of different business scenarios. Through this script engine, users can implement complex business logic and data processing while ensuring execution security, greatly improving the practicality and applicability of the low-code platform.

[0006] To achieve the above purpose, a JS script engine customization method based on Nashorn is designed, including an ITSMSAAS system, which is characterized by: the specific method is as follows: S1, low-code view designer configuration: A script editor is provided in the low-code designer of the ITSMSAAS system for inputting JS scripts; S2, function page rendering: After the function page is rendered in the browser, if there is a default value in the page that maintains the script through the script editor of the low-code view designer or a button maintains the script through the script editor, the JS script engine will be called; S3, JS script engine execution: After passing the standard JavaScript code and common functions to the JS script engine, the JS script engine will perform corresponding processing logic on obtaining business object fields, common function parsing, and environment variable reading, and then translate and splice them into the final JavaScript script and pass it to the nashorn sandbox for execution and return the result.

[0007] The JS script includes JavaScript code, fields, general functions, and environment variables; the general functions include obtaining field values, querying according to conditions, and calling interface functions.

[0008] The specific process of step S3 is as follows: S31, Creation and management of sandbox environment; S32, custom function injection; S33, execution of expression; S34, thread safety and efficiency; S35, interacting with remote services.

[0009] The specific process of step S31 is as follows: (1) Call Nashorn's creation method to create a new sandbox; (2) Manage the sandbox's threads by calling Nashorn's thread setting method, and create four sub-threads through Java8's thread initialization method to implement multi-threading to enhance the sandbox's high concurrency response capability; (3) Manage the maximum CPU time of the sandbox by calling Nashorn's CUP time control method; (4) Manage the maximum memory usage of the sandbox by calling Nashorn's memory limit method.

[0010] The specific process of step S32 is as follows: (1) Inject the sandbox initialization function to initialize the sandbox thread variables: obtain the personnel information thread variable from the main thread outside the sandbox and set it to the sandbox thread variable through the Yan Qianyun simulated login method; (2) Inject the sandbox printing function to provide printing function: print the information that needs to be printed in the user script through the slf4j log output method; (3) The injection sandbox setting value function provides the function of writing custom parameters in the sandbox: a key-value pair collection is maintained in the sandbox to provide users with custom parameters to write; (4) The injected sandbox read value function provides the function of reading custom parameters in the sandbox: read the custom parameters maintained by the sandbox setting value function.

[0011] The specific process of step S33 is as follows: (1) The Eval expression executes the user-written JS script through Narshorn's JS engine; (2) Get the current time expression through the Java8 function to get the current server time and return it to the sandbox; (3) Get the current person expression by querying the person login ID from the thread variable and obtaining the user object information of the current login person from the database based on the person ID and returning it to the sandbox; (4) Get the current person ID expression by getting the current login person ID from the thread variable and returning it to the sandbox; (5) Get the current date expression through the Java8 function to get the current server date and return it to the sandbox; (6) Get the current tenant expression by obtaining the Yan Qianyun tenant ID of the current login person from the thread variable, and then query the Yan Qianyun tenant of the current login person from the database based on the tenant ID and return it to the sandbox; (7) Get the current tenant ID expression by getting the Yan Qianyun tenant ID of the current login person from the thread variable and returning it to the sandbox; (8) Get the current personnel group expression by obtaining the personnel ID from the thread variable and obtaining the current Yan Qianyun personnel group from the database based on the personnel ID and returning it to the sandbox.

[0012] The specific process of step S34 is as follows: (1) Security: Use thread variables and mapping tables to maintain thread variables of Nashorn sandbox type to ensure that the sandbox of each thread is used independently; (2) Efficiency: Sandboxes in the same thread can be reused, avoiding repeated creation and wasting resources and reducing the execution time of calling the sandbox.

[0013] The specific process of step S35 is as follows: (1) The remote service call method within the cluster obtains the service address of the registration center, calls the service within the microservice cluster and returns the parameters to the sandbox; (2) The remote interface call method outside the cluster is implemented by calling the interface outside the microservice cluster through the Java8 restTemplate method and returning the parameters to the sandbox.

[0014] The Yan Qianyun mentioned above is an enterprise digital management platform that supports document circulation and changes in asset status during asset processing through ITSM's diversified document processes.

[0015] Compared with the prior art, the present invention provides a JS script engine customization method based on Nashorn, which effectively enhances the flexibility and functionality of the platform. The precise implementation of each method ensures the reliability and efficiency of script execution and meets the needs of different business scenarios. Through this script engine, users can implement complex business logic and data processing while ensuring execution security, greatly improving the practicality and applicability of the low-code platform.

[0016] The main purpose of this invention is to enhance the flexibility and customizability of the low-code platform: 1. Improve customization capabilities: Although low-code platforms are known for their ease of use and rapid development capabilities, they may be limited when dealing with complex or specific business needs. By introducing a custom JavaScript scripting engine based on the Nashorn sandbox, the present invention is intended to provide a mechanism that allows developers and advanced users to write and execute custom scripts to meet these specific needs.

[0017] 2. Promote the integration of low-code and traditional coding: Another purpose of the present invention is to build a bridge between low-code platforms and traditional programming. By providing a way to write custom scripts, it allows developers who are more familiar with traditional coding to use their skills in a low-code environment, while also giving low-code users the opportunity to gradually learn and practice more traditional coding methods.

[0018] 3. Increase the scalability of the platform: By allowing users to write custom scripts, the present invention improves the flexibility and scalability of the platform. This means that the low-code platform can better adapt to changing business needs and integrate new technologies, rather than being limited to the original functions of the platform.

[0019] 4. Reduce development costs and time: Although low-code platforms have achieved remarkable results in reducing development time and costs, the implementation of complex functions has also become faster and more economical through this invention. This is because developers can write necessary scripts directly on the platform instead of seeking external solutions or conducting cumbersome custom development. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] Figure 1 It is a schematic diagram of the overall process of the present invention.

[0021] Figure 2 This is a flowchart of the JS script engine execution in the present invention.

[0022] Figure 3 It is a schematic diagram of an implementation case of the present invention. DETAILED DESCRIPTION

[0023] The present invention will be further described below with reference to the accompanying drawings.

[0024] like Figure 1 As shown, the overall description of the invention: S1, low-code view designer configuration: A script editor is provided in the low-code designer of the ITSMSAAS system for entering JS scripts. In addition to standard JavaScript codes, fields, common functions (including obtaining field values, querying based on conditions, and calling interface functions) and environment variables can also be entered; S2, function page rendering: After the function page is rendered in the browser, if there is a default value in the page that maintains the script through the script editor of the low-code view designer or a button maintains the script through the script editor, the JS script engine will be called; S3, JS script engine execution: After passing the standard JavaScript code and common functions to the JS script engine, the JS script engine will perform corresponding processing logic on obtaining business object fields, common function parsing, and environment variable reading, and then translate and splice them into the final JavaScript script and pass it to the nashorn sandbox for execution and return the result.

[0025] like Figure 2 As shown, the specific implementation method of JS script engine execution is: S31, Creation and management of sandbox environment: (1) Call Nashorn's creation method to create a new sandbox; (2) Manage the sandbox's threads by calling Nashorn's thread setting method, and create four sub-threads through Java8's thread initialization method to implement multi-threading to enhance the sandbox's high concurrency response capability; (3) Manage the maximum CPU time of the sandbox by calling Nashorn's CUP time control method; (4) Manage the maximum memory usage of the sandbox by calling Nashorn's memory limit method; S32, custom function injection: (1) Inject the [Sandbox Initialization Function] to initialize the sandbox thread variables: obtain the personnel information thread variables from the main thread outside the sandbox and set them to the sandbox thread variables through the Yan Qianyun simulated login method; (2) Inject [Sandbox Print Function] to provide printing function: print out the information that needs to be printed in the user script through the slf4j log output method; (3) Inject [Sandbox Setting Value Function] to provide the function of writing custom parameters in the sandbox: a key-value pair collection will be maintained in the sandbox to provide users with the ability to write custom parameters; (4) Inject [Sandbox Read Value Function] to provide the function of reading custom parameters in the sandbox: read the custom parameters maintained by [Sandbox Set Value Function].

[0026] S33, execution of expression: (1) [Eval] expression executes the JS script written by the user through Narshorn's JS engine; (2) The [Get current time] expression gets the current server time through the Java 8 function and returns it to the sandbox; (3) The [Get Current Person] expression queries the person login ID from the thread variable and obtains the user object information of the current login person from the database based on the person ID and returns it to the sandbox; (4) The expression [Get current user ID] gets the current login user ID from the thread variable and returns it to the sandbox; (5) The [Get Current Date] expression gets the current server date through the Java 8 function and returns it to the sandbox; (6) The expression [Get Current Tenant] obtains the Yan Qianyun tenant ID of the current login user from the thread variable, and then queries the Yan Qianyun tenant of the current login user from the database based on the tenant ID and returns it to the sandbox; (7) The expression [Get current tenant ID] gets the Yan Qianyun tenant ID of the current login user from the thread variable and returns it to the sandbox; (8) The expression [Get current personnel group] obtains the personnel ID from the thread variable and obtains the current Yan Qianyun personnel group from the database based on the personnel ID and returns it to the sandbox.

[0027] S34, thread safety and efficiency: (1) Security: Use thread variables and mapping tables to maintain thread variables of Nashorn sandbox type to ensure that the sandbox of each thread is used independently; (2) Efficiency: Sandboxes in the same thread can be reused, avoiding repeated creation and wasting resources and reducing the execution time of calling the sandbox.

[0028] S35, Interacting with remote services: (1) The [Intra-cluster remote service call] method obtains the service address of the registration center, calls the service in the microservice cluster and returns the parameters to the sandbox; (2) The [Call remote interface outside the cluster] method implements calling the interface outside the microservice cluster through the Java8 restTemplate method and returns the parameters to the sandbox.

[0029] This invention effectively enhances the flexibility and functionality of the platform. The precise implementation of each method ensures the reliability and efficiency of script execution and meets the needs of different business scenarios. Through this script engine, users can implement complex business logic and data processing while ensuring execution security, greatly improving the practicality and applicability of the low-code platform. Figure 3 shown.

Claims

1. A method for customizing a JS script engine based on Nashorn, including an ITSM SAAS system, characterized by: The specific method is as follows: S1, Low-code view designer configuration: A script editor is provided in the low-code designer of the ITSM SAAS system for entering JS scripts; S2, function page rendering: After the function page is rendered in the browser, if there is a default value on the page that maintains a script through the script editor of the low-code view designer or a button that maintains a script through the script editor, the JS script engine will be called; S3, JS script engine execution: After passing standard JavaScript code and common functions to the JS script engine, the JS script engine will perform corresponding processing logic for obtaining business object fields, parsing common functions, and reading environment variables, and then translate and splice them into the final JavaScript script, pass it to the Nashorn sandbox for execution, and return the result.

2. The method for customizing a JS script engine based on Nashorn according to claim 1, characterized in that: The JS script includes JavaScript code, fields, general functions, and environment variables; the general functions include obtaining field values, querying based on conditions, and calling interface functions.

3. The method for customizing a JS script engine based on Nashorn according to claim 1, characterized in that: The specific process of step S3 is as follows: S31, creation and management of sandbox environments; S32, custom function injection; S33, execution of the expression; S34, thread safety and efficiency; S35, interacting with remote services.

4. The method for customizing a JS script engine based on Nashorn according to claim 3, characterized in that: The specific process of step S31 is as follows: (1) Call Nashorn's creation method to create a new sandbox; (2) Manage the sandbox's threads by calling Nashorn's thread setup method, and create four child threads through Java8's thread initialization method to implement multi-threading to enhance the sandbox's high concurrency response capability; (3) Manage the maximum CPU time of the sandbox by calling Nashorn's CUP time control method; (4) Manage the maximum memory usage of the sandbox by calling Nashorn's memory limit method.

5. The method for customizing a JS script engine based on Nashorn according to claim 3, characterized in that: The specific process of step S32 is as follows: (1) Inject the sandbox initialization function to initialize the sandbox thread variables: obtain the personnel information thread variables from the main thread outside the sandbox and set them into the sandbox thread variables through the Yan Qianyun simulated login method; (2) Inject the sandbox printing function to provide printing function: print the information that needs to be printed in the user script through the slf4j log output method; (3) Injecting the sandbox setting value function provides the function of writing custom parameters in the sandbox: a key-value pair collection will be maintained in the sandbox to provide users with custom parameters to write; (4) The injected sandbox read value function provides the function of reading custom parameters in the sandbox: reading the custom parameters maintained by the sandbox setting value function.

6. The method for customizing a JS script engine based on Nashorn according to claim 3, characterized in that: The specific process of step S33 is as follows: (1) Eval expression executes user-written JS scripts through Narshorn's JS engine; (2) Get the current time expression to get the current server time through the Java8 function and return it to the sandbox; (3) Get the current person expression by querying the person login ID from the thread variable and obtaining the user object information of the current login person from the database based on the person ID and returning it to the sandbox; (4) Get the current person ID expression by getting the current login person ID from the thread variable and returning it to the sandbox; (5) Get the current date expression to get the current server date through the Java8 function and return it to the sandbox; (6) Get the current tenant expression by obtaining the Yanqianyun tenant ID of the current login user from the thread variable, and then query the Yanqianyun tenant of the current login user from the database based on the tenant ID and return it to the sandbox; (7) Get the current tenant ID expression by getting the Yan Qianyun tenant ID of the current login person from the thread variable and returning it to the sandbox; (8) Get the current personnel group expression by getting the personnel ID from the thread variable and getting the current Yan Qianyun personnel group from the database based on the personnel ID and returning it to the sandbox.

7. The method for customizing a JS script engine based on Nashorn according to claim 3, characterized in that: The specific process of step S34 is as follows: (1) Security: Use thread variables and mapping tables to maintain thread variables of Nashorn sandbox type, ensuring that each thread's sandbox is used independently; (2) Efficiency: Sandboxes in the same thread can be reused, avoiding repeated creation and wasting resources and reducing the execution time of calling the sandbox.

8. The method for customizing a JS script engine based on Nashorn according to claim 3, characterized in that: The specific process of step S35 is as follows: (1) The remote service call method in the cluster obtains the service address of the registration center, calls the service in the microservice cluster and returns the parameters to the sandbox; (2) The remote interface call method outside the cluster is implemented by calling the interface outside the microservice cluster through the Java8 restTemplate method and returning the parameters to the sandbox.

9. A method for customizing a JS script engine based on Nashorn according to claim 5 or 6, characterized in that: The aforementioned Yan Qianyun is an enterprise digital management platform that supports document circulation and changes in asset status during asset processing through ITSM's diversified document processes.