IBM BPM, V8.0.1, All platforms > Programming IBM BPM > Business rule management programming > Examples
Example 1: Retrieve and print all business rule groups
This example will retrieve all business rule groups and print out the attributes, the properties, and the operations for each business rule group.
package com.ibm.websphere.sample.brules.mgmt; import java.util.Iterator; import java.util.List;For the business rules management classes, be sure to use those classes in the com.ibm.wbiserver.brules.mgmt package and not the com.ibm.wbiserver.brules package or other package. These other packages are for IBM internal classes.
import com.ibm.wbiserver.brules.mgmt.BusinessRuleGroup; import com.ibm.wbiserver.brules.mgmt.BusinessRuleManagementException; import com.ibm.wbiserver.brules.mgmt.BusinessRuleManager; import com.ibm.wbiserver.brules.mgmt.Operation; import com.ibm.wbiserver.brules.mgmt.Property; import com.ibm.wbiserver.brules.mgmt.PropertyList; public class Example1 { static Formatter out = new Formatter(); static public String executeExample1() { try { out.clear();The BusinessRuleManager class is the main class to retrieve business rule groups and to publish changes to business rule groups. This includes working with and changing any rule artifacts such as rule sets and decision tables. There are a number of methods on the BusinessRuleManager class that simplify the retrieval of specific business rule groups by name and namespace and properties.
// Retrieve all business rule groups List<BusinessRuleGroup> brgList = BusinessRuleManager .getBusinessRuleGroups(0, 0); Iterator<BusinessRuleGroup> iterator = brgList.iterator(); BusinessRuleGroup brg = null; // Iterate through the list of business rule groups while (iterator.hasNext()) { brg = iterator.next(); // Output attributes for each business rule group out.printlnBold("Business Rule Group");The basic attributes of the business rule group can be retrieved and displayed.
out.println("Name: " + brg.getName()); out.println("Namespace: " + brg.getTargetNameSpace()); out.println("Display Name: " + brg.getDisplayName()); out.println("Description: " + brg.getDescription()); out.println("Presentation Time zone: " + brg.getPresentationTimezone()); out.println("Save Date: " + brg.getSaveDate());The properties for the business rule group can also be retrieved and modified.
PropertyList propList = brg.getProperties(); Iterator<Property> propIterator = propList.iterator(); Property prop = null; // Output property names and values while (propIterator.hasNext()) { prop = propIterator.next(); out.println("Property Name: " + prop.getName()); out.println("Property Value: " + prop.getValue());}The operations for the business rule group are also available and are the way to retrieve the business rule artifacts such as rule sets and decision tables.
List<Operation> opList = brg.getOperations(); Iteration<Operation> opIterator = opList.iterator(); Operation op = null; // Output operations for the business rule group while (opIterator.hasNext()) { op = opIterator.next(); out.println("Operation: " + op.getName());} out.println("");} } catch (BusinessRuleManagementException e) { e.printStackTrace(); out.println(e.getMessage());} return out.toString();} }
Web browser output for example 1.
Executing example1 Business Rule Group Name: ApprovalValues Namespace: http://BRSamples/com/ibm/websphere/sample/brules Display Name: ApprovalValues Description: null Presentation Time zone: LOCAL Save Date: Sun Jan 06 17:56:51 CST 2008 Property Name: IBMSystemVersion Property Value: 6.2.0 Property Name: Department Property Value: Accounting Property Name: RuleType Property Value: regulatory Property Name: IBMSystemTargetNameSpace Property Value: http://BRSamples/com/ibm/websphere/sample/brules Property Name: IBMSystemName Property Value: ApprovalValues Property Name: IBMSystemDisplayName Property Value: ApprovalValues Operation: getApprover Business Rule Group Name: ConfigurationValues Namespace: http://BRSamples/com/ibm/websphere/sample/brules Display Name: ConfigurationValues Description: null Presentation Time zone: LOCAL Save Date: Sun Jan 06 17:56:51 CST 2008 Property Name: IBMSystemVersion Property Value: 6.2.0 Property Name: Department Property Value: General Property Name: RuleType Property Value: messages Property Name: IBMSystemTargetNameSpace Property Value: http://BRSamples/com/ibm/websphere/sample/brules Property Name: IBMSystemName Property Value: ConfigurationValues Property Name: IBMSystemDisplayName Property Value: ConfigurationValues Operation: getMessages Business Rule Group Name: DiscountRules Namespace: http://BRSamples/com/ibm/websphere/sample/brules Display Name: DiscountRules Description: null Presentation Time zone: LOCAL Save Date: Sun Jan 06 17:56:51 CST 2008 Property Name: Department Property Value: Accounting Property Name: IBMSystemVersion Property Value: 6.2.0 Property Name: RuleType Property Value: monetary Property Name: IBMSystemTargetNameSpace Property Value: http://BRSamples/com/ibm/websphere/sample/brules Property Name: IBMSystemName Property Value: DiscountRules Property Name: IBMSystemDisplayName Property Value: DiscountRules Operation: calculateOrderDiscount Operation: calculateShippingDiscount