use of eu.bcvsolutions.idm.core.script.evaluator.AbstractScriptEvaluator in project CzechIdMng by bcvsolutions.
the class ScriptEvaluatorTest method createScriptThatCallAnother.
/**
* Create script that call another script, into this script will be include scriptEvaluator for category.
* Also is possible to add own script to end of script. But parameter returnAfterFinish must be set to false
*
* @param scriptCode
* @return
*/
private String createScriptThatCallAnother(IdmScriptDto scriptDto, IdmScriptCategory category, Map<String, String> parameters, boolean returnAfterFinish, String scriptToEnd) {
AbstractScriptEvaluator evaluator = getEvaluatorForCategory(category);
//
IdmScriptAuthority auth = new IdmScriptAuthority();
auth.setType(ScriptAuthorityType.SERVICE);
auth.setClassName(evaluator.getClass().getName());
String[] servicesName = applicationContext.getBeanNamesForType(evaluator.getClass());
auth.setService(servicesName[0]);
//
StringBuilder script = new StringBuilder();
if (returnAfterFinish) {
script.append("return " + AbstractScriptEvaluator.SCRIPT_EVALUATOR + ".evaluate(\n");
} else {
script.append(AbstractScriptEvaluator.SCRIPT_EVALUATOR + ".evaluate(\n");
}
script.append(" " + AbstractScriptEvaluator.SCRIPT_EVALUATOR + ".newBuilder()\n");
script.append(" .setScriptCode('" + scriptDto.getCode() + "')\n");
script.append(" .addParameter('" + AbstractScriptEvaluator.SCRIPT_EVALUATOR + "', " + AbstractScriptEvaluator.SCRIPT_EVALUATOR + ")\n");
//
if (parameters != null) {
for (Entry<String, String> entry : parameters.entrySet()) {
script.append(" .addParameter('" + entry.getKey() + "', " + entry.getValue() + ")\n");
}
}
//
script.append(" .build());\n");
if (scriptToEnd != null) {
script.append(scriptToEnd);
}
return script.toString();
}
Aggregations