此内容没有您所选择的语言版本。
Chapter 6. Example projects and business assets in Business Central
Business Central contains example projects with example business assets that you can use as a reference for the rules, processes, or other assets that you create in your own Red Hat Process Automation Manager projects. Each sample project is designed differently to demonstrate process automation, decision management, or business optimization assets and logic in Red Hat Process Automation Manager.
The following example projects are available in Business Central:
- Evaluation_Process: (Process automation) Example evaluation process using business process assets. Evaluates employees based on performance.
- Mortgage_Process: (Process automation) Example loan approval process using business process and decision assets. Determines loan eligibility based on applicant data and qualifications.
- IT_Orders: (Process automation and case management) Example ordering case using business process and case management assets. Places an IT hardware order based on needs and approvals.
- Mortgages: (Decision management) Example loan approval process using decision assets. Determines loan eligibility based on applicant data and qualifications.
- Employee_Rostering: (Business optimization) Example employee rostering optimization using decision and solver assets. Assigns employees to shifts based on skills.
- OptaCloud: (Business optimization) Example resource allocation optimization using decision and solver assets. Assigns processes to computers with limited resources.
You can use the example projects in Business Central to explore example business assets as a reference for the rules or other assets that you create in your own Red Hat Process Automation Manager projects.
Prerequisites
- Business Central is installed and running. For installation options, see Planning a Red Hat Process Automation Manager installation.
Procedure
In Business Central, go to Menu
Design Projects and click Try Samples. If a project already exists, click the three vertical dots in the upper-right corner of the Projects page and click Try Samples.
- Review the descriptions for each sample project to determine which project you want to explore. Each sample project is designed differently to demonstrate process automation, decision management, or business optimization assets and logic in Red Hat Process Automation Manager.
- Select one or more sample projects and click Ok to add the projects to your space.
- In the Projects page of your space, select one of the new example projects to view the example assets for that project.
- Select each example asset to explore how the project is designed to achieve the specified goal or workflow.
In the upper-right corner of the project Assets page, click Build to build the sample project or Deploy to build the project and then deploy it to Process Server.
To review project deployment details (if applicable), go to Menu
Deploy Execution Servers.
6.2. Executing rules 复制链接链接已复制到粘贴板!
After you identify example rules or create your own rules in Business Central, you can build and deploy the associated project and execute rules locally or on Process Server to test the rules.
Prerequisites
- Business Central and Process Server are installed and running. For installation options, see Planning a Red Hat Process Automation Manager installation.
Procedure
-
In Business Central, go to Menu
Design Projects and click the project name. In the upper-right corner of the project Assets page, click Deploy to build the project and deploy it to Process Server. If the build fails, address any problems described in the Alerts panel at the bottom of the screen.
For more information about deploying projects, see Packaging and deploying a Red Hat Process Automation Manager project.
Create a Maven or Java project outside of Business Central, if not created already, that you can use for executing rules locally or that you can use as a client application for executing rules on Process Server. The project must contain a
pom.xmlfile and any other required components for executing the project resources.For example test projects, see "Other methods for creating and executing DRL rules".
Open the
pom.xmlfile of your test project or client application and add the following dependencies, if not added already:-
kie-ci: Enables your client application to load Business Central project data locally usingReleaseId -
kie-server-client: Enables your client application to interact remotely with assets on Process Server -
slf4j: (Optional) Enables your client application to use Simple Logging Facade for Java (SLF4J) to return debug logging information after you interact with Process Server
Example dependencies for Red Hat Process Automation Manager 7.2 in a client application
pom.xmlfile:<!-- For local execution --> <dependency> <groupId>org.kie</groupId> <artifactId>kie-ci</artifactId> <version>7.14.0.Final-redhat-00002</version> </dependency> <!-- For remote execution on Process Server --> <dependency> <groupId>org.kie.server</groupId> <artifactId>kie-server-client</artifactId> <version>7.14.0.Final-redhat-00002</version> </dependency> <!-- For debug logging (optional) --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.7.25</version> </dependency>For available versions of these artifacts, search the group ID and artifact ID in the Nexus Repository Manager online.
NoteInstead of specifying a Red Hat Process Automation Manager
<version>for individual dependencies, consider adding the Red Hat Business Automation bill of materials (BOM) dependency to your projectpom.xmlfile. The Red Hat Business Automation BOM applies to both Red Hat Decision Manager and Red Hat Process Automation Manager. When you add the BOM files, the correct versions of transitive dependencies from the provided Maven repositories are included in the project.Example BOM dependency:
<dependency> <groupId>com.redhat.ba</groupId> <artifactId>ba-platform-bom</artifactId> <version>7.2.0.GA-redhat-00002</version> <scope>import</scope> <type>pom</type> </dependency>For more information about the Red Hat Business Automation BOM, see What is the mapping between Red Hat Process Automation Manager and the Maven library version?.
-
Ensure that the dependencies for artifacts containing model classes are defined in the client application
pom.xmlfile exactly as they appear in thepom.xmlfile of the deployed project. If dependencies for model classes differ between the client application and your projects, execution errors can occur.To access the project
pom.xmlfile in Business Central, select any existing asset in the project and then in the Project Explorer menu on the left side of the screen, click the Customize View gear icon and select Repository Viewpom.xml. For example, the following
Personclass dependency appears in both the client and deployed projectpom.xmlfiles:<dependency> <groupId>com.sample</groupId> <artifactId>Person</artifactId> <version>1.0.0</version> </dependency>If you added the
slf4jdependency to the client applicationpom.xmlfile for debug logging, create asimplelogger.propertiesfile on the relevant classpath (for example, insrc/main/resources/META-INFin Maven) with the following content:org.slf4j.simpleLogger.defaultLogLevel=debugIn your client application, create a
.javamain class containing the necessary imports and amain()method to load the KIE base, insert facts, and execute the rules.For example, a
Personobject in a project contains getter and setter methods to set and retrieve the first name, last name, hourly rate, and the wage of a person. The followingWagerule in a project calculates the wage and hourly rate values and displays a message based on the result:package com.sample; import com.sample.Person; dialect "java" rule "Wage" when Person(hourlyRate * wage > 100) Person(name : firstName, surname : lastName) then System.out.println("Hello" + " " + name + " " + surname + "!"); System.out.println("You are rich!"); endTo test this rule locally outside of Process Server (if desired), configure the
.javaclass to import KIE services, a KIE container, and a KIE session, and then use themain()method to fire all rules against a defined fact model:Executing rules locally
import org.kie.api.KieServices; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; public class RulesTest { public static final void main(String[] args) { try { // Identify the project in the local repository: ReleaseId rid = new ReleaseId(); rid.setGroupId("com.myspace"); rid.setArtifactId("MyProject"); rid.setVersion("1.0.0"); // Load the KIE base: KieServices ks = KieServices.Factory.get(); KieContainer kContainer = ks.newKieContainer(rid); KieSession kSession = kContainer.newKieSession(); // Set up the fact model: Person p = new Person(); p.setWage(12); p.setFirstName("Tom"); p.setLastName("Summers"); p.setHourlyRate(10); // Insert the person into the session: kSession.insert(p); // Fire all rules: kSession.fireAllRules(); kSession.dispose(); } catch (Throwable t) { t.printStackTrace(); } } }To test this rule on Process Server, configure the
.javaclass with the imports and rule execution information similarly to the local example, and additionally specify KIE services configuration and KIE services client details:Executing rules on Process Server
package com.sample; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.kie.api.command.BatchExecutionCommand; import org.kie.api.command.Command; import org.kie.api.KieServices; import org.kie.api.runtime.ExecutionResults; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; import org.kie.server.api.marshalling.MarshallingFormat; import org.kie.server.api.model.ServiceResponse; import org.kie.server.client.KieServicesClient; import org.kie.server.client.KieServicesConfiguration; import org.kie.server.client.KieServicesFactory; import org.kie.server.client.RuleServicesClient; import com.sample.Person; public class RulesTest { private static final String containerName = "testProject"; private static final String sessionName = "myStatelessSession"; public static final void main(String[] args) { try { // Define KIE services configuration and client: Set<Class<?>> allClasses = new HashSet<Class<?>>(); allClasses.add(Person.class); String serverUrl = "http://$HOST:$PORT/kie-server/services/rest/server"; String username = "$USERNAME"; String password = "$PASSWORD"; KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(serverUrl, username, password); config.setMarshallingFormat(MarshallingFormat.JAXB); config.addExtraClasses(allClasses); KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(config); // Set up the fact model: Person p = new Person(); p.setWage(12); p.setFirstName("Tom"); p.setLastName("Summers"); p.setHourlyRate(10); // Insert Person into the session: KieCommands kieCommands = KieServices.Factory.get().getCommands(); List<Command> commandList = new ArrayList<Command>(); commandList.add(kieCommands.newInsert(p, "personReturnId")); // Fire all rules: commandList.add(kieCommands.newFireAllRules("numberOfFiredRules")); BatchExecutionCommand batch = kieCommands.newBatchExecution(commandList, sessionName); // Use rule services client to send request: RuleServicesClient ruleClient = kieServicesClient.getServicesClient(RuleServicesClient.class); ServiceResponse<ExecutionResults> executeResponse = ruleClient.executeCommandsWithResults(containerName, batch); System.out.println("number of fired rules:" + executeResponse.getResult().getValue("numberOfFiredRules")); } catch (Throwable t) { t.printStackTrace(); } } }Run the configured
.javaclass from your project directory. You can run the file in your development platform (such as Red Hat JBoss Developer Studio) or in the command line.Example Maven execution (within project directory):
mvn clean install exec:java -Dexec.mainClass="com.sample.app.RulesTest"Example Java execution (within project directory)
javac -classpath "./$DEPENDENCIES/*:." RulesTest.java java -classpath "./$DEPENDENCIES/*:." RulesTest- Review the rule execution status in the command line and in the server log. If any rules do not execute as expected, review the configured rules in the project and the main class configuration to validate the data provided.