Search in sources :

Example 16 with PipelineItem

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 17 with PipelineItem

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());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 18 with PipelineItem

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 19 with PipelineItem

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;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 20 with PipelineItem

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;
}
Also used : ConnectorHostType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorHostType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException)

Aggregations

PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)25 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)20 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)16 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)13 PrismValue (com.evolveum.midpoint.prism.PrismValue)8 ExecutionContext (com.evolveum.midpoint.model.impl.scripting.ExecutionContext)6 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)6 Task (com.evolveum.midpoint.task.api.Task)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)6 Test (org.testng.annotations.Test)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)3 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)2 ActionParameterValueType (com.evolveum.midpoint.xml.ns._public.model.scripting_3.ActionParameterValueType)2 HashSet (java.util.HashSet)2 ValidationResult (com.evolveum.midpoint.model.api.validator.ValidationResult)1 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)1