略过业务规则冲突示例
您可能希望显示部分或全部业务规则失败情况,而同时又不妨碍继续或完成工作流。创建两个唯一的业务规则集,其中一个需要规则才能继续或完成进程,而另一个会报告规则失败情况但完成进程不需要规则。拥有两个单独的业务规则集允许您对工作流进程进行配置,以在工作流进程中的不同点调用任一规则集。
下例说明如何配置一组继续操作所需的规则,以及另一组不影响继续操作的规则。假设您要检查是否已填入特定属性 (此时为材料)。如果属性为空,则进程将继续,但必须通过发布目标规则。
1. 创建用于属性检查的非必需业务规则集。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRuleSet SYSTEM "standardX20.dtd">
<BusinessRuleSet>
<ObjectID><localId>wt.businessRules.BusinessRuleSet:10001</localId>
</ObjectID>
<objectContainerPath>/wt.inf.container.OrgContainer=
Demo Organization/wt.pdmlink.PDMLinkProduct=Example1TestProduct
</objectContainerPath>
<key>EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET</key>
<name>EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET</name>
<description>EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET</description>
<enabled>true</enabled>
<overridable>true</overridable>
<updateIfExists>true</updateIfExists>
</BusinessRuleSet>
2. 创建“材料”的属性规则。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRule SYSTEM "standardX20.dtd">
<BusinessRule>
<ObjectID><localId>wt.businessRules.BusinessRule:10002</localId>
</ObjectID>
<objectContainerPath>/wt.inf.container.OrgContainer=
Demo Organization/wt.pdmlink.PDMLinkProduct=Example1TestProduct
</objectContainerPath>
<key>EXAMPLE1_ATTRIBUTE_RULE</key>
<selector>ATTRIBUTE_RULE</selector>
<name>Example 1 Attribute Rule</name>
<description>Example 1 Attribute Rule</description>
<enabled>true</enabled>
<updateIfExists>true</updateIfExists>
<configs>
<config name="objectType" value="com.ptc.Part"></config>
<config name="Material" value="SET"></config>
</configs>
</BusinessRule>
3. 创建属性规则和非必需规则集链接。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRule SYSTEM "standardX20.dtd">
<BusinessRuleLink>
<ObjectID><localId>wt.businessRules.BusinessRuleLink:10003</localId>
</ObjectID>
<ruleSet><ObjectReference><localId>wt.businessRules.BusinessRuleSet:10001
</localId></ObjectReference></ruleSet>
<rule><ObjectReference><localId>wt.businessRules.BusinessRule:10002
</localId></ObjectReference></rule>
<blockNumber>1</blockNumber>
<updateIfExists>true</updateIfExists>
</BusinessRuleLink>
4. 创建发布目标规则的必需业务规则集。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRuleSet SYSTEM "standardX20.dtd">
<BusinessRuleSet>
<ObjectID><localId>wt.businessRules.BusinessRuleSet:20001</localId>
</ObjectID>
<objectContainerPath>/wt.inf.container.OrgContainer=Demo Organization
/wt.pdmlink.PDMLinkProduct=Example1TestProduct</objectContainerPath>
<key>EXAMPLE1_RELEASE_RULE_SET</key>
<name>Example1_ReleaseRuleSet</name>
<enabled>true</enabled>
<description>Example1_ReleaseRuleSet</description>
<overridable>true</overridable>
<updateIfExists>true</updateIfExists>
</BusinessRuleSet>
5. 重新加载站点发布目标规则。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRule SYSTEM "standardX20.dtd">
<BusinessRule>
<ObjectID><localId>wt.businessRules.BusinessRule:20002</localId>
</ObjectID>
<key>RELEASE_TARGET</key>
<selector>RELEASE_TARGET</selector>
<name>com.ptc.windchill.enterprise.change2.change2ClientResource:
RELEASE_TARGET_RULE_NAME</name>
<description>com.ptc.windchill.enterprise.change2.
change2ClientResource:RELEASE_TARGET_RULE_DESC</description>
<enabled>true</enabled>
<updateIfExists>true</updateIfExists>
</BusinessRule>
6. 创建目标规则和必需规则集链接。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE BusinessRuleLink SYSTEM "standardX20.dtd">
<BusinessRuleLink>
<ObjectID><localId>wt.businessRules.BusinessRuleLink:20003</localId>
</ObjectID>
<ruleSet><ObjectReference><localId>wt.businessRules.BusinessRuleSet:
20001</localId></ObjectReference></ruleSet>
<rule><ObjectReference><localId>wt.businessRules.BusinessRule:20002
</localId></ObjectReference></rule>
<blockNumber>1</blockNumber>
<updateIfExists>true</updateIfExists>
</BusinessRuleLink>
7. 执行所有必需和非必需业务规则集。要显示所有必需和非必需规则冲突,请将“审计更改通告”工作流任务条件更新为使用 EXAMPLE1_RELEASE_RULE_SET 和 EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET 两个规则集。
if (wt.change2.ChangeHelper2.isTrackingChange((wt.inf.container.
WTContained)primaryBusinessObject)) {
result = "Revisioning Enabled";
}else {
result = "Revisioning Disabled";
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] beans = new
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] {
// Configure to call non-required rule set
com.ptc.core.businessRules.engine.BusinessRuleSetBean.newBusinessRuleSetBean
("EXAMPLE1_NON_REQUIRED_ATTRIBUTE_RULE_SET", "wt.change2.ChangeRecord2"),
// Configure to call required rule set
com.ptc.core.businessRules.engine.BusinessRuleSetBean.newBusinessRuleSetBean
("EXAMPLE1_RELEASE_RULE_SET", "wt.change2.ChangeRecord2")
};
}
com.ptc.core.businessRules.validation.RuleValidationResultSet resultSet =
wt.businessRules.BusinessRulesHelper.engine.execute(primaryBusinessObject, beans);
if ( resultSet.hasResultsByStatus(com.ptc.core.businessRules.validation.
RuleValidationStatus.FAILURE)) {
businessRulesResultSetGlobal = wt.businessRules.BusinessRulesHelper.
serialize(resultSet);
preReleaseConflictsMsg = new wt.util.WTMessage("com.ptc.windchill.
enterprise.change2.change2ClientResource", com.ptc.windchill.enterprise.
change2.change2ClientResource.BUSINESS_RULES_PRERELEASE_VALIDATION_MSG,
null).getLocalizedMessage();
preReleaseConflictsMsg = preReleaseConflictsMsg + "\n" + resultSet.
getFailedRulesMessage(java.util.Locale.getDefault());
}
8. 执行必需业务规则集。针对必需业务规则,为防止更改通告工作流进程继续执行,请将条件更新为 Resolve Release Conflicts 工作流任务仅使用必需规则集 EXAMPLE1_RELEASE_RULE_SET。
result = "NOT_READY";
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] beans = new
com.ptc.core.businessRules.engine.BusinessRuleSetBean[] {
// Configure to call required rule set only
com.ptc.core.businessRules.engine.BusinessRuleSetBean.
newBusinessRuleSetBean("EXAMPLE1_RELEASE_RULE_SET",
"wt.change2.ChangeRecord2")
};
com.ptc.core.businessRules.validation.RuleValidationResultSet
resultSet = wt.businessRules.BusinessRulesHelper.engine.execute
(primaryBusinessObject, beans);
if ( !resultSet.hasResultsByStatus(com.ptc.core.businessRules.
validation.RuleValidationStatus.FAILURE)) {
result = "PROCEED";
} else {
businessRulesResultSetGlobal = wt.businessRules.BusinessRulesHelper.
serialize(resultSet);
preReleaseConflictsMsg = new wt.util.WTMessage("com.ptc.windchill.
enterprise.change2.change2ClientResource", com.ptc.windchill.enterprise.
change2.change2ClientResource.BUSINESS_RULES_PRERELEASE_VALIDATION_MSG,
null).getLocalizedMessage();
preReleaseConflictsMsg = preReleaseConflictsMsg + "\n" + resultSet.
getFailedRulesMessage(java.util.Locale.getDefault());
}
Resolve Release Conflicts 工作流任务继续重新生成任务,直至全部冲突均已解决为止。