-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3b2571
commit 75da585
Showing
4 changed files
with
603 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...Transactional-Rule-Project-Samples/March-2024 DM Community/DS/browser/browser.sample.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<script type="text/javascript" src="decisionServiceBundle.js"></script> | ||
<script> | ||
window.onload = (event) => { | ||
restoreInputPayload(); | ||
}; | ||
function restoreInputPayload() { | ||
const payload = window.localStorage.getItem('CorticonJSPayload'); | ||
if ( payload !== null ) | ||
document.getElementById("payloadId").value = payload; | ||
} | ||
|
||
async function runDecisionService() { | ||
// Here is where everything starts: we execute the rule with the sample payload and we | ||
// output the result to an alert dialog. Errors and exceptions are shown in alert dialog too. | ||
try { | ||
const payloadString = document.getElementById("payloadId").value; | ||
const payload = JSON.parse(payloadString); | ||
// save it in local storage for restore on reload | ||
try { | ||
window.localStorage.setItem('CorticonJSPayload', payloadString); | ||
} | ||
catch (e) { | ||
// Some browser in private mode may throw exception when using local storage | ||
} | ||
|
||
const configuration = { logLevel: 0}; | ||
// const configuration = { logLevel: 1 }; | ||
/* | ||
******************************************************* | ||
Configuration Properties for Rule Messages | ||
******************************************************* | ||
/*const configuration = { | ||
logLevel: 0, | ||
ruleMessages: { | ||
logRuleMessages: false, // If true the rule messages will be logged to console | ||
executionProperties: { | ||
restrictInfoRuleMessages: true, // If true Restricts Info Rule Messages | ||
restrictWarningRuleMessages: true, // If true Restricts Warning Rule Messages | ||
restrictViolationRuleMessages: true, // If true Restricts Violation Rule Messages | ||
restrictResponseToRuleMessagesOnly: true, // If true the response returned has only rule messages | ||
}, | ||
}, | ||
};*/ | ||
const result = await window.corticonEngine.execute(payload, configuration); | ||
|
||
// We always display the result of execution - if there was an error we will additionally display an alert. | ||
document.getElementById("resultId").value = JSON.stringify(result, null, 2); | ||
if( result.corticon !== undefined ) { | ||
if ( result.corticon.status !== 'success' ) { | ||
alert('Error executing the rules.\n' + JSON.stringify(result, null, 2)); | ||
} | ||
} | ||
else { | ||
alert('Unknown error executing the rules.\n' + JSON.stringify(result, null, 2)); | ||
} | ||
} | ||
catch ( e ) { | ||
alert('Unexpected exception executing the rules ' + e); | ||
} | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<h2>Sample Calling Corticon JavaScript Decision Service</h2> | ||
|
||
<p> | ||
Enter the payload to pass to the decision service: | ||
<table width="100%"> | ||
<tr> | ||
<td width="50%"> | ||
<textarea style="width: 100%; height: 500px;" id="payloadId"></textarea> | ||
</td> | ||
<td width="50%"> | ||
<textarea style="width: 100%; height: 500px;" id="resultId"></textarea> | ||
</td> | ||
</tr> | ||
</table> | ||
</p> | ||
<p> | ||
Use the link below to run the decision service. | ||
</p> | ||
|
||
<a href="#" onclick="runDecisionService(); return false;">Run Decision Service</a> | ||
|
||
</body> | ||
</html> |
2 changes: 2 additions & 0 deletions
2
...s/Transactional-Rule-Project-Samples/March-2024 DM Community/DS/browser/browser.sample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/*** Sample Embedding Corticon JS Engine in browser ***/ | ||
window.corticonEngine.execute(payload); |
96 changes: 96 additions & 0 deletions
96
...al-Rule-Project-Samples/March-2024 DM Community/DS/browser/browser.sample.multipleDS.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<script type="text/javascript" src="decisionServiceBundle.js"></script> | ||
<script type="text/javascript" src="decisionServiceBundle2.js"></script> | ||
<script> | ||
window.onload = (event) => { | ||
restoreInputPayload(); | ||
}; | ||
function restoreInputPayload() { | ||
const payload1 = window.localStorage.getItem('CorticonJSPayload1'); | ||
if ( payload1 !== null ) | ||
document.getElementById("payloadId1").value = payload1; | ||
|
||
const payload2 = window.localStorage.getItem('CorticonJSPayload2'); | ||
if ( payload2 !== null ) | ||
document.getElementById("payloadId2").value = payload2; | ||
} | ||
|
||
async function runDecisionService() { | ||
if ( window.corticonEngines === undefined ) { | ||
alert("Ensure that you provide 2 decision service files called decisionServiceBundle.js and decisionServiceBundle2.js in the same directory as where this html file resides"); | ||
return; | ||
} | ||
|
||
if ( window.corticonEngines.length < 2 ) { | ||
alert("Ensure that you provide a second decision service file called decisionServiceBundle2.js in the same directory as where this html file resides"); | ||
return; | ||
} | ||
|
||
// Here is where everything starts: we execute the rule with the sample payload and we | ||
// output the result to an alert dialog. Errors and exceptions are shown in alert dialog too. | ||
try { | ||
const payloadString1 = document.getElementById("payloadId1").value; | ||
const payload1 = JSON.parse(payloadString1); | ||
const payloadString2 = document.getElementById("payloadId2").value; | ||
const payload2 = JSON.parse(payloadString2); | ||
|
||
// save them in local storage for restore on reload | ||
try { | ||
window.localStorage.setItem('CorticonJSPayload1', payloadString1); | ||
window.localStorage.setItem('CorticonJSPayload2', payloadString2); | ||
} | ||
catch (e) { | ||
// Some browser in private mode may throw exception when using local storage | ||
} | ||
|
||
const configuration = { logLevel: 0}; | ||
const result1 = await window.corticonEngines[0].execute(payload1, configuration); | ||
const result2 = await window.corticonEngines[1].execute(payload2, configuration); | ||
document.getElementById("resultId1").value = JSON.stringify(result1, null, 2); | ||
document.getElementById("resultId2").value = JSON.stringify(result2, null, 2); | ||
|
||
// For examples on how to process errors from the decision service, please refer to browser.sample.html | ||
} | ||
catch ( e ) { | ||
alert('There was an exception executing the rules ' + e); | ||
} | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<h2>Sample Calling Multiple Corticon.js Decision Services on same Html Page</h2> | ||
|
||
<p> | ||
Ensure that you provide a second decision service file called decisionServiceBundle2.js in the same directory as where this html file resides (by default there won't be one). | ||
</p> | ||
<p> | ||
Enter the payloads to pass to the 2 decision services: | ||
<table width="100%"> | ||
<tr> | ||
<td width="50%"> | ||
<textarea style="width: 100%; height: 250px;" id="payloadId1"></textarea> | ||
</td> | ||
<td width="50%"> | ||
<textarea style="width: 100%; height: 250px;" id="resultId1"></textarea> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td width="50%"> | ||
<textarea style="width: 100%; height: 250px;" id="payloadId2"></textarea> | ||
</td> | ||
<td width="50%"> | ||
<textarea style="width: 100%; height: 250px;" id="resultId2"></textarea> | ||
</td> | ||
</tr> | ||
</table> | ||
</p> | ||
<p> | ||
Use the link below to run the 2 separate decision services. | ||
</p> | ||
|
||
<a href="#" onclick="runDecisionService(); return false;">Run Decision Services</a> | ||
|
||
</body> | ||
</html> |
415 changes: 415 additions & 0 deletions
415
...actional-Rule-Project-Samples/March-2024 DM Community/DS/browser/decisionServiceBundle.js
Large diffs are not rendered by default.
Oops, something went wrong.