use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class TestScriptingBasic method test500ScriptingUsers.
@Test
public void test500ScriptingUsers() throws Exception {
final String TEST_NAME = "test500ScriptingUsers";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = createTask(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
PrismProperty<ScriptingExpressionType> expression = parseAnyData(SCRIPTING_USERS_FILE);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
TestUtil.assertSuccess(result);
PipelineData data = output.getFinalOutput();
assertEquals("Unexpected # of items in output", 5, data.getData().size());
Set<String> realOids = new HashSet<>();
for (PipelineItem item : data.getData()) {
PrismValue value = item.getValue();
PrismObject<UserType> user = ((PrismObjectValue<UserType>) value).asPrismObject();
assertEquals("Description not set", "Test", user.asObjectable().getDescription());
realOids.add(user.getOid());
assertSuccess(item.getResult());
}
assertEquals("Unexpected OIDs in output", Sets.newHashSet(Arrays.asList(USER_ADMINISTRATOR_OID, USER_JACK_OID, USER_BARBOSSA_OID, USER_GUYBRUSH_OID, USER_ELAINE_OID)), realOids);
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class TestScriptingBasic method test520GeneratePasswordsFullInput.
@Test
public void test520GeneratePasswordsFullInput() throws Exception {
final String TEST_NAME = "test520GeneratePasswordsFullInput";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
ExecuteScriptType executeScript = parseRealValue(GENERATE_PASSWORDS_2_FILE);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(executeScript, task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
//TestUtil.assertSuccess(result);
PipelineData data = output.getFinalOutput();
List<PipelineItem> items = data.getData();
assertEquals("Unexpected # of items in output", 4, items.size());
assertSuccess(items.get(0).getResult());
assertFailure(items.get(1).getResult());
assertSuccess(items.get(2).getResult());
assertSuccess(items.get(3).getResult());
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class TestScriptingBasic method test530GeneratePasswordsReally.
@Test
public void test530GeneratePasswordsReally() throws Exception {
final String TEST_NAME = "test530GeneratePasswordsReally";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(DOT_CLASS + TEST_NAME);
OperationResult result = task.getResult();
ExecuteScriptType executeScript = parseRealValue(GENERATE_PASSWORDS_3_FILE);
// WHEN
ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(executeScript, task, result);
// THEN
dumpOutput(output, result);
result.computeStatus();
PipelineData data = output.getFinalOutput();
List<PipelineItem> items = data.getData();
assertEquals("Unexpected # of items in output", 3, items.size());
assertFailure(items.get(0).getResult());
assertSuccess(items.get(1).getResult());
assertSuccess(items.get(2).getResult());
checkPassword(items.get(1), USER_GUYBRUSH_OID);
checkPassword(items.get(2), USER_ELAINE_OID);
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class AddExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
PrismValue value = item.getValue();
if (value instanceof PrismObjectValue) {
@SuppressWarnings({ "unchecked", "raw" }) PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to add " : "Added ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.
the class DiscoverConnectorsExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean rebind = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_REBIND_RESOURCES, input, context, false, PARAM_REBIND_RESOURCES, globalResult);
PipelineData output = PipelineData.createEmpty();
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue && ((PrismObjectValue) value).asObjectable() instanceof ConnectorHostType) {
PrismObject<ConnectorHostType> connectorHostTypePrismObject = ((PrismObjectValue) value).asPrismObject();
Set<ConnectorType> newConnectors;
long started = operationsHelper.recordStart(context, connectorHostTypePrismObject.asObjectable());
Throwable exception = null;
try {
newConnectors = modelService.discoverConnectors(connectorHostTypePrismObject.asObjectable(), context.getTask(), result);
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, null);
} catch (CommunicationException | SecurityViolationException | SchemaException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
operationsHelper.recordEnd(context, connectorHostTypePrismObject.asObjectable(), started, e);
exception = processActionException(e, NAME, value, context);
newConnectors = Collections.emptySet();
}
context.println((exception != null ? "Attempted to discover " : "Discovered " + newConnectors.size()) + " new connector(s) from " + connectorHostTypePrismObject + exceptionSuffix(exception));
for (ConnectorType connectorType : newConnectors) {
output.addValue(connectorType.asPrismObject().getValue(), item.getResult());
}
try {
if (rebind) {
rebindConnectors(newConnectors, context, result);
}
} catch (ScriptExecutionException e) {
//noinspection ThrowableNotThrown
// TODO better message
processActionException(e, NAME, value, context);
}
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Input item is not a PrismObject<ConnectorHost>"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
// TODO configurable output (either connector hosts or discovered connectors)
return output;
}
Aggregations