use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptsOptionsType in project midpoint by Evolveum.
the class ModelWebService method doExecuteScripts.
private ExecuteScriptsResponseType doExecuteScripts(List<JAXBElement<?>> scriptsToExecute, ExecuteScriptsOptionsType options, Task task, OperationResult result) {
ExecuteScriptsResponseType response = new ExecuteScriptsResponseType();
ScriptOutputsType outputs = new ScriptOutputsType();
response.setOutputs(outputs);
try {
for (JAXBElement<?> script : scriptsToExecute) {
Object scriptValue = script.getValue();
if (!(scriptValue instanceof ScriptingExpressionType)) {
throw new SchemaException("Expected that scripts will be of type ScriptingExpressionType, but it was " + scriptValue.getClass().getName());
}
ScriptExecutionResult executionResult = scriptingService.evaluateExpression((ScriptingExpressionType) script.getValue(), task, result);
SingleScriptOutputType output = new SingleScriptOutputType();
outputs.getOutput().add(output);
output.setTextOutput(executionResult.getConsoleOutput());
if (options == null || options.getOutputFormat() == null || options.getOutputFormat() == OutputFormatType.XML) {
output.setDataOutput(prepareXmlData(executionResult.getDataOutput(), null));
} else {
// temporarily we send serialized XML in the case of MSL output
PipelineDataType jaxbOutput = prepareXmlData(executionResult.getDataOutput(), null);
output.setMslData(prismContext.xmlSerializer().serializeAnyData(jaxbOutput, SchemaConstants.C_VALUE));
}
}
result.computeStatusIfUnknown();
} catch (ScriptExecutionException | JAXBException | SchemaException | RuntimeException | SecurityViolationException e) {
result.recordFatalError(e.getMessage(), e);
LoggingUtils.logException(LOGGER, "Exception while executing script", e);
}
result.summarize();
response.setResult(result.createOperationResultType());
return response;
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptsOptionsType in project midpoint by Evolveum.
the class RunScript method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
Options options = new Options();
options.addOption(OPT_HELP, "help", false, "Print this help information");
options.addOption(OPT_SCRIPT, "script", true, "Script file (XML for the moment)");
options.addOption(OPT_URL, true, "Endpoint URL (default: " + DEFAULT_ENDPOINT_URL + ")");
options.addOption(OPT_USER, "user", true, "User name (default: " + ADM_USERNAME + ")");
options.addOption(OPT_PASSWORD, "password", true, "Password");
options.addOption(OPT_FILE_FOR_DATA, "file-for-data", true, "Name of the file to write resulting XML data into");
options.addOption(OPT_FILE_FOR_CONSOLE, "file-for-console", true, "Name of the file to write resulting console output into");
options.addOption(OPT_FILE_FOR_RESULT, "file-for-result", true, "Name of the file to write operation result into");
options.addOption(OPT_HIDE_DATA, "hide-data", false, "Don't display data output");
options.addOption(OPT_HIDE_SCRIPT, "hide-script", false, "Don't display input script");
options.addOption(OPT_HIDE_CONSOLE, "hide-console", false, "Don't display console output");
options.addOption(OPT_HIDE_RESULT, "hide-result", false, "Don't display detailed operation result (default: showing if not SUCCESS)");
options.addOption(OPT_SHOW_RESULT, "show-result", false, "Always show detailed operation result (default: showing if not SUCCESS)");
options.addOption(OptionBuilder.withArgName("property=value").hasArgs(2).withValueSeparator().withDescription("use value for given property").create("D"));
CommandLineParser parser = new GnuParser();
CommandLine cmdline = parser.parse(options, args);
if (!cmdline.hasOption(OPT_SCRIPT) || cmdline.hasOption("h")) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("runscript", options);
System.exit(0);
}
ExecuteScriptsType request = new ExecuteScriptsType();
String script = readXmlFile(cmdline.getOptionValue(OPT_SCRIPT));
script = replaceParameters(script, cmdline.getOptionProperties("D"));
// todo fix this hack
request.setMslScripts(script);
ExecuteScriptsOptionsType optionsType = new ExecuteScriptsOptionsType();
// todo fix this hack
optionsType.setOutputFormat(OutputFormatType.MSL);
request.setOptions(optionsType);
if (!cmdline.hasOption(OPT_HIDE_SCRIPT)) {
System.out.println("\nScript to execute:\n" + script);
}
System.out.println("=================================================================");
ModelPortType modelPort = createModelPort(cmdline);
ExecuteScriptsResponseType response = modelPort.executeScripts(request);
System.out.println("=================================================================");
for (SingleScriptOutputType output : response.getOutputs().getOutput()) {
if (!cmdline.hasOption(OPT_HIDE_DATA)) {
System.out.println("Data:\n" + output.getMslData());
System.out.println("-----------------------------------------------------------------");
}
if (cmdline.hasOption(OPT_FILE_FOR_DATA)) {
IOUtils.write(output.getMslData(), new FileOutputStream(cmdline.getOptionValue(OPT_FILE_FOR_DATA)), "UTF-8");
}
if (!cmdline.hasOption(OPT_HIDE_CONSOLE)) {
System.out.println("Console output:\n" + output.getTextOutput());
}
if (cmdline.hasOption(OPT_HIDE_CONSOLE)) {
IOUtils.write(output.getMslData(), new FileWriter(cmdline.getOptionValue(OPT_FILE_FOR_CONSOLE)));
}
}
System.out.println("=================================================================");
System.out.println("Operation result: " + getResultStatus(response.getResult()));
if (!cmdline.hasOption(OPT_HIDE_RESULT) && (cmdline.hasOption(OPT_SHOW_RESULT) || response.getResult() == null || response.getResult().getStatus() != OperationResultStatusType.SUCCESS)) {
System.out.println("\n\n" + marshalResult(response.getResult()));
}
if (cmdline.hasOption(OPT_FILE_FOR_RESULT)) {
IOUtils.write(marshalResult(response.getResult()), new FileWriter(cmdline.getOptionValue(OPT_FILE_FOR_RESULT)));
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.ExecuteScriptsOptionsType in project midpoint by Evolveum.
the class BulkAction method executeAction.
@Override
protected void executeAction() throws Exception {
ModelPortType port = createModelPort();
try {
ExecuteScriptsOptionsType options = new ExecuteScriptsOptionsType();
options.setExecuteAsynchronously(getParams().isAsync());
options.setObjectLimit(getParams().getLimit());
options.setOutputFormat(getParams().getOutput());
ExecuteScriptsType parameters = new ExecuteScriptsType();
parameters.setOptions(options);
parameters.setMslScripts(getParams().getMslScript());
//todo implement xml support
//parameters.setXmlScripts(xml);
ExecuteScriptsResponseType response = port.executeScripts(parameters);
//todo implement
} catch (FaultMessage ex) {
handleError("Couldn't execute scripts", ex);
}
}
Aggregations