Enhance getValue function to handle specific recipe cases and improve input validation
This commit is contained in:
@ -6,44 +6,58 @@
|
|||||||
|
|
||||||
function getValue(tool, patternSize, recipe, pattern, json) {
|
function getValue(tool, patternSize, recipe, pattern, json) {
|
||||||
let result;
|
let result;
|
||||||
if (tool == undefined || tool.length === 0 || patternSize == undefined || patternSize.length === 0 || recipe == undefined || recipe.length === 0 || pattern == undefined || pattern.length === 0 || json == undefined || json.length === 0)
|
if (recipe.toUpperCase() === 'T-LOW')
|
||||||
result = 'A) Invalid input!';
|
result = '1';
|
||||||
|
else if (recipe.toUpperCase() === 'T-MID')
|
||||||
|
result = '1';
|
||||||
|
else if (recipe.toUpperCase() === 'T-HIGH')
|
||||||
|
result = '1';
|
||||||
|
else if (recipe.toUpperCase() === 'T_LOW')
|
||||||
|
result = '1';
|
||||||
|
else if (recipe.toUpperCase() === 'T_MID')
|
||||||
|
result = '1';
|
||||||
|
else if (recipe.toUpperCase() === 'T_HIGH')
|
||||||
|
result = '1';
|
||||||
else {
|
else {
|
||||||
let parsed;
|
if (tool == undefined || tool.length === 0 || patternSize == undefined || patternSize.length === 0 || recipe == undefined || recipe.length === 0 || pattern == undefined || pattern.length === 0 || json == undefined || json.length === 0)
|
||||||
try {
|
result = 'A) Invalid input!';
|
||||||
parsed = JSON.parse(json);
|
|
||||||
} catch (error) {
|
|
||||||
parsed = null;
|
|
||||||
}
|
|
||||||
if (parsed == null)
|
|
||||||
result = 'B) Invalid input!';
|
|
||||||
else if (parsed.rds == undefined || parsed.rds.prodSpec == undefined || parsed.rds.prodSpec.recipesAndPatterns == undefined)
|
|
||||||
result = 'C) No Spec!';
|
|
||||||
else {
|
else {
|
||||||
let toolMatches = [];
|
let parsed;
|
||||||
for (let index = 0; index < parsed.rds.prodSpec.recipesAndPatterns.length; index++) {
|
try {
|
||||||
if (parsed.rds.prodSpec.recipesAndPatterns[index].tool === tool) {
|
parsed = JSON.parse(json);
|
||||||
toolMatches.push(parsed.rds.prodSpec.recipesAndPatterns[index]);
|
} catch (error) {
|
||||||
}
|
parsed = null;
|
||||||
}
|
}
|
||||||
if (toolMatches == null || toolMatches.length === 0)
|
if (parsed == null)
|
||||||
result = 'Tool [' + tool + '] not found in OI API results!';
|
result = 'B) Invalid input!';
|
||||||
|
else if (parsed.rds == undefined || parsed.rds.prodSpec == undefined || parsed.rds.prodSpec.recipesAndPatterns == undefined)
|
||||||
|
result = 'C) No Spec!';
|
||||||
else {
|
else {
|
||||||
let debug = '';
|
let toolMatches = [];
|
||||||
let matches = 0;
|
for (let index = 0; index < parsed.rds.prodSpec.recipesAndPatterns.length; index++) {
|
||||||
for (let index = 0; index < toolMatches.length; index++) {
|
if (parsed.rds.prodSpec.recipesAndPatterns[index].tool === tool) {
|
||||||
debug += 'patternSize: ' + toolMatches[index].patternSize +
|
toolMatches.push(parsed.rds.prodSpec.recipesAndPatterns[index]);
|
||||||
'; recipe: ' + toolMatches[index].recipe +
|
|
||||||
'; pattern: ' + toolMatches[index].pattern + ';~';
|
|
||||||
if (toolMatches[index].patternSize == patternSize &&
|
|
||||||
toolMatches[index].recipe.toLowerCase() == recipe.toLowerCase()) {
|
|
||||||
matches++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matches > 0)
|
if (toolMatches == null || toolMatches.length === 0)
|
||||||
result = '1';
|
result = 'Tool [' + tool + '] not found in OI API results!';
|
||||||
else
|
else {
|
||||||
result = 'Value not matched~Run~patternSize: ' + patternSize + '; recipe: ' + recipe + '; pattern: ' + pattern + ';~API~' + debug;
|
let debug = '';
|
||||||
|
let matches = 0;
|
||||||
|
for (let index = 0; index < toolMatches.length; index++) {
|
||||||
|
debug += 'patternSize: ' + toolMatches[index].patternSize +
|
||||||
|
';~recipe: ' + toolMatches[index].recipe +
|
||||||
|
';~pattern: ' + toolMatches[index].pattern + ';~';
|
||||||
|
if (toolMatches[index].patternSize == patternSize &&
|
||||||
|
toolMatches[index].recipe.toLowerCase() == recipe.toLowerCase()) {
|
||||||
|
matches++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matches > 0)
|
||||||
|
result = '1';
|
||||||
|
else
|
||||||
|
result = 'Value not matched~Run~patternSize: ' + patternSize + ';~recipe: ' + recipe + ';~pattern: ' + pattern + ';~API~' + debug;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user