use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType in project midpoint by Evolveum.
the class ProvisioningUtil method convertToScriptOperation.
public static ExecuteProvisioningScriptOperation convertToScriptOperation(ProvisioningScriptType scriptType, String desc, PrismContext prismContext) throws SchemaException {
ExecuteProvisioningScriptOperation scriptOperation = new ExecuteProvisioningScriptOperation();
PrismPropertyDefinition scriptArgumentDefinition = new PrismPropertyDefinitionImpl(FAKE_SCRIPT_ARGUMENT_NAME, DOMUtil.XSD_STRING, prismContext);
for (ProvisioningScriptArgumentType argument : scriptType.getArgument()) {
ExecuteScriptArgument arg = new ExecuteScriptArgument(argument.getName(), StaticExpressionUtil.getStaticOutput(argument, scriptArgumentDefinition, desc, ExpressionReturnMultiplicityType.SINGLE, prismContext));
scriptOperation.getArgument().add(arg);
}
scriptOperation.setLanguage(scriptType.getLanguage());
scriptOperation.setTextCode(scriptType.getCode());
if (scriptType.getHost() != null && scriptType.getHost().equals(ProvisioningScriptHostType.CONNECTOR)) {
scriptOperation.setConnectorHost(true);
scriptOperation.setResourceHost(false);
}
if (scriptType.getHost() == null || scriptType.getHost().equals(ProvisioningScriptHostType.RESOURCE)) {
scriptOperation.setConnectorHost(false);
scriptOperation.setResourceHost(true);
}
return scriptOperation;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType in project midpoint by Evolveum.
the class ResourceManager method executeScript.
public Object executeScript(String resourceOid, ProvisioningScriptType script, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
PrismObject<ResourceType> resource = getResource(resourceOid, null, task, result);
ConnectorSpec connectorSpec = selectConnectorSpec(resource, ScriptCapabilityType.class);
if (connectorSpec == null) {
throw new UnsupportedOperationException("No connector supports script capability");
}
ConnectorInstance connectorInstance = connectorManager.getConfiguredConnectorInstance(connectorSpec, false, result);
ExecuteProvisioningScriptOperation scriptOperation = ProvisioningUtil.convertToScriptOperation(script, "script on " + resource, prismContext);
try {
StateReporter reporter = new StateReporter(resourceOid, task);
return connectorInstance.executeScript(scriptOperation, reporter, result);
} catch (GenericFrameworkException e) {
// Not expected. Transform to system exception
result.recordFatalError("Generic provisioning framework error", e);
throw new SystemException("Generic provisioning framework error: " + e.getMessage(), e);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ProvisioningScriptType in project midpoint by Evolveum.
the class TestDummy method test135ExecuteScript.
@Test
public void test135ExecuteScript() throws Exception {
final String TEST_NAME = "test135ExecuteScript";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestDummy.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
syncServiceMock.reset();
dummyResource.purgeScriptHistory();
OperationProvisioningScriptsType scriptsType = unmarshallValueFromFile(SCRIPTS_FILE, OperationProvisioningScriptsType.class);
display("Provisioning scripts", PrismTestUtil.serializeAnyDataWrapped(scriptsType));
ProvisioningScriptType script = scriptsType.getScript().get(0);
// WHEN
provisioningService.executeScript(RESOURCE_DUMMY_OID, script, task, result);
// THEN
result.computeStatus();
display("executeScript result", result);
TestUtil.assertSuccess("executeScript has failed (result)", result);
ProvisioningScriptSpec expectedScript = new ProvisioningScriptSpec("Where to go now?");
expectedScript.addArgMulti("direction", "left", "right");
IntegrationTestTools.assertScripts(dummyResource.getScriptHistory(), expectedScript);
assertSteadyResource();
}
Aggregations