use of org.identityconnectors.framework.common.objects.ScriptContext in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method convertToScriptContext.
private ScriptContext convertToScriptContext(ExecuteProvisioningScriptOperation executeOp) {
// creating script arguments map form the execute script operation
// arguments
Map<String, Object> scriptArguments = new HashMap<String, Object>();
for (ExecuteScriptArgument argument : executeOp.getArgument()) {
scriptArguments.put(argument.getArgumentName(), argument.getArgumentValue());
}
ScriptContext scriptContext = new ScriptContext(executeOp.getLanguage(), executeOp.getTextCode(), scriptArguments);
return scriptContext;
}
use of org.identityconnectors.framework.common.objects.ScriptContext in project midpoint by Evolveum.
the class ConnectorInstanceConnIdImpl method executeScriptIcf.
private Object executeScriptIcf(StateReporter reporter, ExecuteProvisioningScriptOperation scriptOperation, OperationResult result) throws CommunicationException, GenericFrameworkException {
String icfOpName = null;
if (scriptOperation.isConnectorHost()) {
icfOpName = "runScriptOnConnector";
} else if (scriptOperation.isResourceHost()) {
icfOpName = "runScriptOnResource";
} else {
result.recordFatalError("Where to execute the script?");
throw new IllegalArgumentException("Where to execute the script?");
}
// convert execute script operation to the script context required from
// the connector
ScriptContext scriptContext = convertToScriptContext(scriptOperation);
OperationResult icfResult = result.createSubresult(ConnectorFacade.class.getName() + "." + icfOpName);
icfResult.addContext("connector", connIdConnectorFacade.getClass());
Object output = null;
try {
LOGGER.trace("Running script ({})", icfOpName);
recordIcfOperationStart(reporter, ProvisioningOperation.ICF_SCRIPT, null);
if (scriptOperation.isConnectorHost()) {
InternalMonitor.recordConnectorOperation("runScriptOnConnector");
output = connIdConnectorFacade.runScriptOnConnector(scriptContext, new OperationOptionsBuilder().build());
} else if (scriptOperation.isResourceHost()) {
InternalMonitor.recordConnectorOperation("runScriptOnResource");
output = connIdConnectorFacade.runScriptOnResource(scriptContext, new OperationOptionsBuilder().build());
}
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null);
icfResult.recordSuccess();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Finished running script ({}), script result: {}", icfOpName, PrettyPrinter.prettyPrint(output));
}
} catch (Throwable ex) {
recordIcfOperationEnd(reporter, ProvisioningOperation.ICF_SCRIPT, null, ex);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Finished running script ({}), ERROR: {}", icfOpName, ex.getMessage());
}
Throwable midpointEx = processIcfException(ex, this, icfResult);
result.computeStatus();
// exception
if (midpointEx instanceof CommunicationException) {
throw (CommunicationException) midpointEx;
} else if (midpointEx instanceof GenericFrameworkException) {
throw (GenericFrameworkException) midpointEx;
} else if (midpointEx instanceof SchemaException) {
// Schema exception during delete? It must be a missing UID
throw new IllegalArgumentException(midpointEx.getMessage(), midpointEx);
} else if (midpointEx instanceof RuntimeException) {
throw (RuntimeException) midpointEx;
} else if (midpointEx instanceof Error) {
throw (Error) midpointEx;
} else {
throw new SystemException("Got unexpected exception: " + ex.getClass().getName() + ": " + ex.getMessage(), ex);
}
}
return output;
}
Aggregations