Custom code execution method and device of process engine and computer equipment
By adding custom task nodes and event listeners to the Activiti process engine and executing JavaScript code in combination with NashornSandBox sandbox environment, the traditional process engine lacks flexibility and security risks in business process customization and modification, achieving high efficiency , safe process design and optimization.
Patent Information
- Application Number
- CN202411652566.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-02-18
AI Technical Summary
Traditional process engines lack flexibility in business process customization and modification, limiting the participation of non-technical personnel, and process logic adjustments require code modification and system redeployment, resulting in high time cost and complexity and security risks.
Add custom task nodes to the front-end design module of the Activiti process engine, and set up custom event listeners for these nodes. Use the NashornSandBox sandbox environment to compile and execute JavaScript custom code, obtain execution results and record them in the log of the process engine middle.
It improves the flexibility of process design and user participation, so that non-technical personnel can also participate in process design and optimization, realizes real-time testing and application of business logic, shortens the cycle from modification to verification, and enhances system security.
Smart Images

Figure CN119473506A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of process engines, and in particular to a method, apparatus, computer device, computer-readable storage medium, and computer program product for executing custom code of a process engine. Background Art
[0002] In traditional applications of the process engine Activiti, process design usually requires developers or professional process designers to define process models (such as BPMN) through specialized tools or codes and configure fixed business logic. As a key element in the process, the behavior and subsequent operations of user tasks (UserTask) are usually predefined, which is not convenient for business users to flexibly adjust according to actual needs. In addition, changes in business logic often require modifying the code or process definition file and then redeploying it, which leads to a long process adjustment cycle and is not conducive to rapid response to market changes.
[0003] In traditional workflow systems, the customization and modification of business processes requires a technical background, which limits the participation of non-technical personnel in process design and optimization. Adjustment of process logic involves code modification and system redeployment, which increases time cost and complexity. Direct execution of user-submitted code may lead to system security risks, such as injection attacks. Users cannot see the effects of business logic adjustments immediately, which affects efficiency and experience.
[0004] Therefore, there is an urgent need for a custom code execution method, apparatus, computer device, computer-readable storage medium and computer program product for a process engine that can enhance the flexibility of process design and user participation in the customization and modification of business processes. Summary of the invention
[0005] Based on this, it is necessary to provide a custom code execution method, device, computer equipment, computer-readable storage medium and computer program product for a process engine that can improve the flexibility of process design and user participation in the customization and modification of business processes in order to address the above technical problems.
[0006] In a first aspect, the present application provides a custom code execution method for a process engine, comprising:
[0007] Add a custom task node to the front-end design module of the Activiti process engine, and set a custom event listener for the custom task node;
[0008] Starting the process virtual machine to execute the custom event listener;
[0009] According to the custom event listener, compile the JavaScript custom code in the NashornSandBox sandbox environment, and execute the JavaScript custom code;
[0010] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0011] In one embodiment, before compiling the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, the method further includes:
[0012] Create a preset number of sandbox instances in the NashornSandBox sandbox environment, set parameters and initialize each sandbox instance, and place the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool;
[0013] Use the Freemarker template engine to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
[0014] In one embodiment, compiling the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener includes:
[0015] Select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance;
[0016] The custom event listener is used to monitor and process task events corresponding to the JavaScript custom code.
[0017] In one embodiment, the step of setting and initializing parameters for each sandbox instance includes:
[0018] Set the file system access permissions and network access permissions of the sandbox instance, as well as the CPU execution time and memory usage of the sandbox instance.
[0019] In one embodiment, before executing the JavaScript custom code, the method further includes:
[0020] When a preset condition is triggered, the JavaScript custom code is filtered; the preset condition includes: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
[0021] In one embodiment, adding a custom task node in the front-end design module of the Activiti process engine and setting a custom event listener for the custom task node include:
[0022] Add a custom task node to the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a java object and save it, and set a custom event listener for the custom task node to listen to and process task events;
[0023] The type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
[0024] In a second aspect, the present application also provides a custom code execution device for a process engine, comprising:
[0025] The node setting module is used to add a custom task node to the front-end design module of the Activiti process engine and set a custom event listener for the custom task node;
[0026] A process execution module, used to start the process virtual machine to execute the custom event listener;
[0027] A code compilation module, used to compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code;
[0028] The result acquisition module is used to obtain the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0029] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0030] Add a custom task node to the front-end design module of the Activiti process engine, and set a custom event listener for the custom task node;
[0031] Starting the process virtual machine to execute the custom event listener;
[0032] According to the custom event listener, compile the JavaScript custom code in the NashornSandBox sandbox environment, and execute the JavaScript custom code;
[0033] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0034] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0035] Add a custom task node to the front-end design module of the Activiti process engine, and set a custom event listener for the custom task node;
[0036] Starting the process virtual machine to execute the custom event listener;
[0037] According to the custom event listener, compile the JavaScript custom code in the NashornSandBox sandbox environment, and execute the JavaScript custom code;
[0038] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0039] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0040] Add a custom task node to the front-end design module of the Activiti process engine, and set a custom event listener for the custom task node;
[0041] Starting the process virtual machine to execute the custom event listener;
[0042] According to the custom event listener, compile the JavaScript custom code in the NashornSandBox sandbox environment, and execute the JavaScript custom code;
[0043] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0044] The above-mentioned custom code execution method, device, computer equipment, computer-readable storage medium and computer program product of the process engine, by adding custom task nodes in the front-end design module of the Activiti process engine and setting custom event listeners for these nodes, allows business users to directly modify JavaScript code on the front-end page to define the custom behavior of the task without writing background code or deploying processes. This greatly improves the flexibility of process design and user participation, allowing non-technical personnel to participate in process design and optimization. After the user dynamically edits the JavaScript method on the front end, NashornSandbox immediately executes and verifies the new logic in the sandbox environment, realizing instant testing and application of business logic, shortening the cycle from modification to verification, and thus speeding up the iteration speed of business processes. As an isolated environment, NashornSandbox restricts access to external resources when executing user scripts, effectively preventing malicious code execution, ensuring system security, and avoiding system security risks that may be caused by directly executing user-submitted code. After execution, the execution results are parsed by ScriptObjectMirror and recorded in the node log of Activiti, which not only provides instant feedback, but also facilitates auditing and troubleshooting, and improves the efficiency and experience of business logic adjustment.
[0045] To sum up, this invention improves the adaptability and management efficiency of business processes by combining the comprehensive solution of front-end dynamic scripting, sandbox execution environment and BPMN model, which is particularly suitable for low-code platforms and SAAS applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0047] FIG1 is an application environment diagram of a custom code execution method of a process engine in one embodiment;
[0048] FIG2 is a schematic diagram of a process flow of a custom code execution method of a process engine in one embodiment;
[0049] FIG3 is a flow chart of a method for executing custom code of a process engine in another embodiment;
[0050] FIG4 is a framework diagram of the overall operation process of the JavaScript custom code in another embodiment;
[0051] FIG5 is a structural block diagram of a custom code execution device of a process engine in one embodiment;
[0052] FIG. 6 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0054] The custom code execution method of the process engine provided in the embodiment of the present application can be applied to the application environment shown in Figure 1. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers.
[0055] A custom task node is added in terminal 102 (the front-end design module of the Activiti process engine), and a custom event listener is set for the custom task node; the server 104 starts the process virtual machine to execute the custom event listener; according to the custom event listener, the JavaScript custom code is compiled in the NashornSandBox sandbox environment, and the JavaScript custom code is executed; the execution result of the JavaScript custom code is obtained and recorded in the log record table of the Activiti process engine.
[0056] The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car devices, projection devices, etc. Portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. Head-mounted devices may be virtual reality (VR) devices, augmented reality (AR) devices, smart glasses, etc. The server 104 may be an independent physical server, a server cluster or distributed system consisting of multiple physical servers, or a cloud server that provides cloud computing services.
[0057] In an exemplary embodiment, as shown in FIG2 , a method for executing custom code of a process engine is provided, and the method is applied to the server in FIG1 as an example for explanation, including the following steps S202 to S208 . Among them:
[0058] Step S202, add a custom task node in the front-end design module of the Activiti process engine, and set a custom event listener for the custom task node.
[0059] Specifically, Activiti is an open source workflow engine for automated business process management (BPM), which allows users to define business processes through the BPMN 2.0 standard. By extending the Activiti process engine, the function of customizing task nodes is added, which means that in the process design of Activiti, users can add new node types, which are not just standard BPMN elements, but behaviors that can be customized according to specific business needs.
[0060] In the front-end design module of Activiti, users can create a new task node, which can be any non-standard task customized according to specific business logic. This custom task node can have its own properties and behaviors, which can be defined by users according to business needs.
[0061] TaskListener is a mechanism used in Activiti to listen to task events (such as task creation, completion, etc.). Setting a custom event listener on a custom task node means that the user can define the logic to be executed when a specific event occurs. For example, when a task starts or ends, a specific JavaScript code can be triggered.
[0062] By setting custom event listeners, users can write JavaScript code to implement custom business logic, which can be conditional judgment, data operation, interaction with other systems, etc., completely customized according to business needs. When the process executes to the custom task node, Activiti will trigger the corresponding event listener and execute the user-defined JavaScript code. In this way, users can flexibly expand the functions of the process engine and implement complex business logic without modifying the core code of Activiti.
[0063] Step S204, start the process virtual machine to execute the custom event listener.
[0064] Specifically, the core of the Activiti process engine is a process virtual machine, which is responsible for managing and executing business processes. This virtual machine can be understood as the "brain" of the process, which guides the execution of the process according to the process definition (BPMN model).
[0065] When a process instance is started, the process virtual machine starts executing the process according to the start event (StartEvent) in the process definition. The process virtual machine executes each node in the process (such as task nodes, gateways, event nodes, etc.) one by one in the order in the process definition. When the process virtual machine executes to a node configured with a custom event listener, it triggers these custom event listeners. Custom event listeners can contain user-defined logic, such as calling external services, executing database operations, and calculating logic.
[0066] It should be noted that in this solution, the JavaScript code in the custom event listener is executed in the NashornSandBox sandbox environment. This is a security mechanism used to isolate and restrict the execution environment of JavaScript code to prevent malicious code from causing damage to the system.
[0067] Step S206, compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code.
[0068] Specifically, NashornSandBox is a secure execution environment that allows JavaScript code to be safely executed in Java applications. The main purpose of the sandbox is to restrict script access to system resources, prevent malicious code execution, and ensure system security. When a custom event listener is triggered, the process virtual machine passes the user-defined JavaScript code to NashornSandBox. NashornSandBox compiles this JavaScript code and prepares it for execution.
[0069] After the compilation is complete, NashornSandBox will execute the JavaScript code. During this process, all operations are performed in a sandbox environment, which means that even if there are errors or malicious behaviors in the JavaScript code, it will not affect the host system. After the JavaScript code is executed, NashornSandBox will return the execution result.
[0070] Step S208, obtain the execution result of the JavaScript custom code and record it in the log record table of the Activiti process engine.
[0071] Specifically, after executing the JavaScript custom code in the NashornSandBox sandbox environment, there will be a return value or execution result. This result may be a simple value, such as a Boolean value, a number, or a string, or it may be a complex object or array.
[0072] In the environment where Java and JavaScript interact, the Nashorn engine uses the ScriptObjectMirror class to represent JavaScript objects. This class provides a way for Java code to access and manipulate JavaScript objects. The execution result is usually encapsulated into a JSExecuteResult object, which contains all the output of JavaScript code execution, including the return value and possible exceptions.
[0073] The Activiti process engine provides a logging function to record key information about process execution, including changes in process variables, entry and exit of process nodes, and any abnormal events. Logging the execution results of custom JavaScript code to the Activiti log can help developers and business analysts track the execution of the process and understand the specific behavior of each step in the process. There are one or more database tables in the Activiti process engine for storing log information, usually including ACT_HI_ACTINST (historical activity instance table), ACT_HI_TASKINST (historical task instance table), etc. Execution results can be recorded in these tables, usually associated with specific process instances and activity nodes. In addition to troubleshooting and auditing, logging can also be used to monitor the performance of the process. By analyzing the data in the log, bottlenecks and performance issues in the process can be identified.
[0074] In the custom code execution method of the above process engine, by adding custom task nodes in the front-end design module of the Activiti process engine and setting custom event listeners for these nodes, business users are allowed to modify JavaScript code directly on the front-end page to define custom behaviors of tasks without writing back-end code or deploying processes. This greatly improves the flexibility of process design and user participation, allowing non-technical personnel to participate in process design and optimization. After the user dynamically edits the JavaScript method on the front end, NashornSandbox immediately executes and verifies the new logic in the sandbox environment, realizing instant testing and application of business logic, shortening the cycle from modification to verification, and thus speeding up the iteration of business processes. As an isolated environment, NashornSandbox restricts access to external resources when executing user scripts, effectively preventing malicious code execution, ensuring system security, and avoiding system security risks that may be caused by directly executing user-submitted code. After execution, the execution results are parsed by ScriptObjectMirror and recorded in the node log of Activiti, which not only provides instant feedback, but also facilitates auditing and troubleshooting, and improves the efficiency and experience of business logic adjustment.
[0075] In an exemplary embodiment, in step S206, before compiling the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, as shown in FIG3 , the following is further included:
[0076] Step S302, creating a preset number of sandbox instances in the NashornSandBox sandbox environment, setting parameters and initializing each sandbox instance, and placing the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool;
[0077] Step S304, using the Freemarker template engine, setting Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
[0078] Specifically, as shown in FIG4 , FIG4 discloses a framework diagram of the overall operation process of JavaScript custom code; in the NashornSandBox sandbox environment, a certain number of sandbox instances need to be created first. These sandbox instances are isolated execution environments for running JavaScript code to ensure the security of code execution. Each sandbox instance requires parameter setting and initialization. This includes setting limits on CPU time and memory size, as well as other possible security and performance-related parameters. During the initialization process, some necessary libraries and frameworks may be loaded to support the execution of JavaScript code.
[0079] The initialized sandbox instance is placed in a sandbox pool. The sandbox pool is used to manage all available sandbox instances so that sandbox resources can be quickly allocated and reclaimed when JavaScript code needs to be executed.
[0080] Specifically, Freemarker is a template engine that can use templates to generate text output. In this case, it is used to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment. Through the Freemarker template, references and configurations of Java tool classes (such as logging tools, database access tools, etc.) can be passed to JavaScript code. In this way, JavaScript code can safely use these tool classes in the sandbox environment. Similarly, system parameters (such as environment variables, configuration parameters, etc.) can also be passed to JavaScript code through the Freemarker template. This enables JavaScript code to access and use these parameters without directly interacting with the Java system environment.
[0081] In this embodiment, by isolating and executing JavaScript code in a sandbox environment, malicious code can be prevented from causing damage to the host system. The restrictions of the sandbox ensure that the code can only access limited resources. By setting Java tool classes and system parameters, JavaScript code can perform more complex tasks, such as database operations, file processing, etc., while still remaining in a safe sandbox environment.
[0082] In an exemplary embodiment, according to the custom event listener, compiling the JavaScript custom code in the NashornSandBox sandbox environment includes:
[0083] Select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance;
[0084] Use custom event listeners to listen to and process task events corresponding to JavaScript custom codes.
[0085] Specifically, when JavaScript custom code needs to be executed, the system selects a target sandbox instance from the sandbox pool. This selection may be based on polling, least-used principle, or other load balancing strategies to ensure efficient use of sandbox resources. Once the target sandbox instance is selected, it prepares for the JavaScript code to be executed. This may include resetting the sandbox state, loading necessary libraries and frameworks, etc.
[0086] Pass the JavaScript custom code to the target sandbox instance, which will compile the code. The compilation process may involve syntax checking, code optimization, and other steps to ensure that the code can be executed correctly. During the compilation process, the sandbox instance may optimize the JavaScript code to improve execution efficiency. This may include pre-compilation and caching of the code. After the compilation is completed, the sandbox instance will prepare the execution environment, including setting necessary variables and parameters.
[0087] When the process executes to a node with a custom event listener configured, the Activiti process engine triggers these custom event listeners. Custom event listeners listen to and process task events related to JavaScript custom code.
[0088] Specifically, the custom event listener will call the target sandbox instance to execute the compiled JavaScript code. This may involve passing process variables, task parameters, etc. to the sandbox instance. As shown in Figure 4, after the JavaScript code is executed, the execution parser is used to generate the execution result, and the event listener will process the execution result and send it to the Activiti execution log framework. This may include updating process variables, changing the process flow, recording logs, etc. If exceptions occur during the execution of the JavaScript code, the event listener also needs to handle these exceptions, which may include recording error logs, rolling back transactions, etc.
[0089] In this embodiment, in this way, the Activiti process engine can flexibly integrate and execute custom JavaScript logic while ensuring the security and stability of the process. This method improves the automation of the process and also enhances the scalability and adaptability of the process.
[0090] In an exemplary embodiment, parameter setting and initialization are performed on each sandbox instance, including:
[0091] Set the file system access permissions and network access permissions of the sandbox instance, as well as the CPU execution time and memory usage of the sandbox instance.
[0092] Specifically, the purpose of setting the file system access rights of the sandbox instance is to limit the sandbox instance's access to the file system and prevent malicious code or improper operations from damaging the host system files. This includes setting:
[0093] No access rights: You can set the sandbox instance to have no access to the host system's file system, ensuring that the code can only run inside the sandbox.
[0094] Restricted access rights: If necessary, you can set up a sandbox instance to have access only to specific directories or files, for example, only allowing reading of specific configuration files or writing of specific log files.
[0095] The purpose of setting the network access rights of the sandbox instance is to control the sandbox instance's access to the external network and prevent potential security risks, such as data leakage or malware download. This includes the following settings:
[0096] No network access: You can set up a sandbox instance to have no access to the external network at all.
[0097] Restricted network access: If necessary, you can set up the sandbox instance to only access specific IP addresses or domain names, or limit the ports used.
[0098] The purpose of setting the CPU execution time of a sandbox instance is to limit the CPU time that a sandbox instance can use, so as to prevent a single sandbox instance from occupying too many resources and affecting the performance of the host system and other sandbox instances. Specifically, you can set a CPU time limit for each sandbox instance. If this limit is exceeded, the sandbox instance will be forced to stop or suspend.
[0099] The purpose of setting the memory usage of the sandbox instance is to limit the amount of memory that the sandbox instance can use to prevent memory leaks or excessive consumption from causing performance degradation of the host system. Specifically, you can set a memory usage limit for each sandbox instance. If this limit is exceeded, the sandbox instance may not be able to perform new operations or be forced to stop.
[0100] In this embodiment, through these detailed settings and initialization steps, it is possible to ensure that the sandbox environment is both safe and efficient, while meeting business needs and system performance requirements. This method helps to improve the stability and reliability of the system while reducing potential security risks.
[0101] In an exemplary embodiment, before executing the JavaScript custom code, the process further includes:
[0102] When preset conditions are triggered, the JavaScript custom code is filtered; the preset conditions include: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
[0103] Specifically, the purpose of filtering infinite loops in JavaScript custom code is to prevent infinite loops in JavaScript code from occupying too much CPU resources, causing the performance of the sandbox instance or the host system to degrade. Specifically, as shown in Figure 4, the filter uses a static code analysis tool to check JavaScript code before code execution to identify possible infinite loop structures. During code execution, the CPU usage and execution time are monitored, and if an abnormality is detected (such as long-term high CPU usage), the execution is forcibly terminated.
[0104] The purpose of filtering JavaScript custom code operations on host functions is to prevent JavaScript code from executing operations that may affect the security and stability of the host system, such as file system access and network access. Specifically, before the code is executed, check whether there are attempts to access sensitive resources such as the file system and network in the JavaScript code. Ensure that the restrictions of the sandbox environment are set appropriately, so that even if the code attempts to perform sensitive operations, it cannot actually affect the host.
[0105] The purpose of filtering the proportion of Java resources occupied by JavaScript custom code is to prevent JavaScript code from over-consuming Java resources and affecting the performance of the host system and other sandbox instances. Specifically, it includes: monitoring the memory and CPU usage during the execution of JavaScript code. Setting a resource usage threshold, once the threshold is reached or exceeded, restricting further execution of the code or forcibly terminating the execution.
[0106] Record all filtering operations and resource usage for problem tracking and system optimization. For JavaScript code that violates preset conditions, in addition to terminating execution, detailed error information should be recorded and the system administrator or developer should be notified as needed. Based on monitoring data and log records, adjust the resource limits and code filtering policies of the sandbox instance to optimize system performance and resource utilization.
[0107] In this embodiment, through these filtering operations, the sandbox environment and the host system can be effectively protected from potential malicious code and resource abuse, ensuring the security and stability of the system. At the same time, these measures also help to improve the system's responsiveness and service quality.
[0108] In an exemplary embodiment, a custom task node is added to the front-end design module of the Activiti process engine, and a custom event listener is set for the custom task node, including:
[0109] Add a custom task node to the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a Java object and save it, and set a custom event listener for the custom task node to listen to and process task events;
[0110] Among them, the type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
[0111] Specifically, in the front-end design module of Activiti, users can add new custom task nodes to the process design. These nodes are displayed as graphical elements that can be dragged and configured on the interface. Activiti uses the BPMN XML converter (BpmnXMLConverter) to parse the BPMN 2.0 XML file, which defines the process model. By extending this converter, the configuration of the custom task node can be converted from XML format to Java objects.
[0112] The type attribute of the custom task node is inherited from the UserTask of the Activiti process engine. This means that the custom task node inherits all the properties and behaviors of the UserTask, and can add additional custom properties and behaviors. The definition of the custom task node is extracted from the BPMN XML file and converted into a Java object through the BPMN XML converter. This conversion process involves parsing the node definition in the XML file and mapping it to the corresponding Java class.
[0113] Save the converted Java object to a database or other persistent storage. In this way, the definition of the custom task node can be recognized and used in the Activiti process engine. Set a custom event listener for the custom task node so that the predefined logic is executed when a specific task event occurs (such as task start, completion, assignment, etc.). With the custom event listener, additional business logic can be executed on the task node, such as calling external services, performing database operations, etc.
[0114] In this embodiment, by adding custom task nodes to the front-end design module of the Activiti process engine, converting the configuration files of these nodes into Java objects for storage using the BPMN XML converter, and setting custom event listeners for these nodes, users can expand the functions of the Activiti process engine and implement more complex business logic and process automation. This method not only improves the flexibility of process design, but also enhances the automation and intelligence level of the process.
[0115] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0116] Based on the same inventive concept, the embodiment of the present application also provides a process engine custom code execution device for implementing the process engine custom code execution method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the embodiments of the custom code execution device for one or more process engines provided below can refer to the limitations of the process engine custom code execution method above, and will not be repeated here.
[0117] In an exemplary embodiment, as shown in FIG5 , a custom code execution device of a process engine is provided, comprising:
[0118] The node setting module 502 is used to add a custom task node in the front-end design module of the Activiti process engine and set a custom event listener for the custom task node;
[0119] A process execution module 504 is used to start a process virtual machine to execute a custom event listener;
[0120] The code compilation module 508 is used to compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code;
[0121] The result acquisition module 512 is used to obtain the execution result of the JavaScript custom code and record it in the log record table of the Activiti process engine.
[0122] In an exemplary embodiment, the parameter configuration module 506 is used to create a preset number of sandbox instances in the NashornSandBox sandbox environment, set parameters and initialize each sandbox instance, and place the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool; use the Freemarker template engine to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
[0123] In an exemplary embodiment, the code compilation module 508 is specifically used to select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance; and use a custom event listener to listen to and process task events corresponding to the JavaScript custom code.
[0124] In an exemplary embodiment, the parameter configuration module 506 is specifically used to set the file system access permissions and network access permissions of the sandbox instance, and to set the CPU execution time and memory usage of the sandbox instance.
[0125] In an exemplary embodiment, the code filtering module 510 is used to filter the JavaScript custom code when a preset condition is triggered; the preset conditions include: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
[0126] In an exemplary embodiment, the node setting module 502 is specifically used to add a custom task node in the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a java object and save it, and set a custom event listener for the custom task node to listen to and process task events; wherein the type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
[0127] Each module in the custom code execution device of the above-mentioned process engine can be implemented in whole or in part by software, hardware and their combination. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0128] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG6. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store the execution result data of the JavaScript custom code. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a custom code execution method of a process engine is implemented.
[0129] Those skilled in the art will understand that the structure shown in FIG. 6 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0130] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0131] Add a custom task node in the front-end design module of the Activiti process engine and set a custom event listener for the custom task node;
[0132] Start the process virtual machine to execute the custom event listener;
[0133] Compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code;
[0134] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0135] In one embodiment, when the processor executes the computer program, the following steps are also implemented:
[0136] Create a preset number of sandbox instances in the NashornSandBox sandbox environment, set parameters and initialize each sandbox instance, and place the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool;
[0137] Use the Freemarker template engine to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
[0138] In one embodiment, when the processor executes the computer program, the following steps are also implemented:
[0139] Select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance;
[0140] Use custom event listeners to listen to and process task events corresponding to JavaScript custom codes.
[0141] In one embodiment, when the processor executes the computer program, the following steps are also implemented:
[0142] Set the file system access permissions and network access permissions of the sandbox instance, as well as the CPU execution time and memory usage of the sandbox instance.
[0143] In one embodiment, when the processor executes the computer program, the following steps are also implemented:
[0144] When preset conditions are triggered, the JavaScript custom code is filtered; the preset conditions include: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
[0145] In one embodiment, when the processor executes the computer program, the following steps are also implemented:
[0146] Add a custom task node to the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a Java object and save it, and set a custom event listener for the custom task node to listen to and process task events;
[0147] Among them, the type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
[0148] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0149] Add a custom task node in the front-end design module of the Activiti process engine and set a custom event listener for the custom task node;
[0150] Start the process virtual machine to execute the custom event listener;
[0151] Compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code;
[0152] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0153] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0154] Create a preset number of sandbox instances in the NashornSandBox sandbox environment, set parameters and initialize each sandbox instance, and place the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool;
[0155] Use the Freemarker template engine to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
[0156] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0157] Select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance;
[0158] Use custom event listeners to listen to and process task events corresponding to JavaScript custom codes.
[0159] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0160] Set the file system access permissions and network access permissions of the sandbox instance, as well as the CPU execution time and memory usage of the sandbox instance.
[0161] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0162] When preset conditions are triggered, the JavaScript custom code is filtered; the preset conditions include: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
[0163] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0164] Add a custom task node to the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a Java object and save it, and set a custom event listener for the custom task node to listen to and process task events;
[0165] Among them, the type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
[0166] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0167] Add a custom task node in the front-end design module of the Activiti process engine and set a custom event listener for the custom task node;
[0168] Start the process virtual machine to execute the custom event listener;
[0169] Compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code;
[0170] Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
[0171] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0172] Create a preset number of sandbox instances in the NashornSandBox sandbox environment, set parameters and initialize each sandbox instance, and place the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool;
[0173] Use the Freemarker template engine to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
[0174] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0175] Select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance;
[0176] Use custom event listeners to listen to and process task events corresponding to JavaScript custom codes.
[0177] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0178] Set the file system access permissions and network access permissions of the sandbox instance, as well as the CPU execution time and memory usage of the sandbox instance.
[0179] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0180] When preset conditions are triggered, the JavaScript custom code is filtered; the preset conditions include: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
[0181] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0182] Add a custom task node to the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a Java object and save it, and set a custom event listener for the custom task node to listen to and process task events;
[0183] Among them, the type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
[0184] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0185] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0186] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0187] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A custom code execution method for a process engine, characterized in that: The method comprises: Add a custom task node to the front-end design module of the Activiti process engine, and set a custom event listener for the custom task node; Starting the process virtual machine to execute the custom event listener; According to the custom event listener, compile the JavaScript custom code in the NashornSandBox sandbox environment, and execute the JavaScript custom code; Get the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
2. The method according to claim 1, characterized in that According to the custom event listener, before compiling the JavaScript custom code in the NashornSandBox sandbox environment, the method further includes: Create a preset number of sandbox instances in the NashornSandBox sandbox environment, set parameters and initialize each sandbox instance, and place the sandbox instance after parameter setting and initialization in the NashornSandBox sandbox pool; Use the Freemarker template engine to set Java tool class parameters and Java system parameters in the NashornSandBox sandbox environment.
3. The method according to claim 2, characterized in that Compiling the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener includes: Select a target sandbox instance from the NashornSandBox sandbox pool and compile the JavaScript custom code in the target sandbox instance; The custom event listener is used to monitor and process task events corresponding to the JavaScript custom code.
4. The method according to claim 2, characterized in that: The parameter setting and initialization of each sandbox instance includes: Set the file system access permissions and network access permissions of the sandbox instance, as well as the CPU execution time and memory usage of the sandbox instance.
5. The method according to claim 1, characterized in that Before executing the JavaScript custom code, the method further includes: When a preset condition is triggered, the JavaScript custom code is filtered; the preset condition includes: the JavaScript custom code has an infinite loop execution process, the JavaScript custom code operates the host function, and the proportion of Java resources occupied by the JavaScript custom code reaches a threshold.
6. The method according to claim 1, characterized in that The step of adding a custom task node to the front-end design module of the Activiti process engine and setting a custom event listener for the custom task node includes: Add a custom task node to the front-end design module of the Activiti process engine, use the BPMN XML converter to convert the configuration file of the custom task node into a java object and save it, and set a custom event listener for the custom task node to listen to and process task events; The type attribute of the custom task node includes the type attribute of the user task UserTask of the Activiti process engine.
7. A custom code execution device for a process engine, characterized in that: The device comprises: The node setting module is used to add a custom task node to the front-end design module of the Activiti process engine and set a custom event listener for the custom task node; A process execution module, used to start the process virtual machine to execute the custom event listener; A code compilation module, used to compile the JavaScript custom code in the NashornSandBox sandbox environment according to the custom event listener, and execute the JavaScript custom code; The result acquisition module is used to obtain the execution results of the JavaScript custom code and record them in the log table of the Activiti process engine.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Code running method and device related to large model service, equipment and medium
CN122226499A
