Skip to content

Commit

Permalink
name change
Browse files Browse the repository at this point in the history
  • Loading branch information
notedhelms committed Apr 16, 2024
1 parent a3b2571 commit 75da585
Show file tree
Hide file tree
Showing 4 changed files with 603 additions and 0 deletions.
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>
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);
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>

Large diffs are not rendered by default.

0 comments on commit 75da585

Please sign in to comment.