特定管理 > 配置您的 Windchill 環境 > 企業規則 > 略過企業規則衝突的範例
略過企業規則衝突的範例
您可能想要顯示某些或全部企業規則失敗,但不阻礙繼續或完成工作流程。建立兩個唯一的企業規則集,一個放置繼續或完成流程所需的規則,另一個放置會報告其失敗但並非完成流程所需的規則。擁有兩個單獨的企業規則集可讓您將工作流程配置為在工作流程中的不同位置呼叫任一規則集。
下列範例顯示如何配置繼續所需的規則集以及非所需的第二個規則集。假設您想要檢查是否已填入某些屬性 (在此情況下為材料)。如果屬性為空,流程會繼續;但發行目標規則必須通過。
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());
}
「解決發行衝突」工作流程任務會繼續再生任務,直到所有衝突均已解決為止。
這是否有幫助?