Search in sources :

Example 11 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class RecomputeExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean dryRun = getParamDryRun(expression, input, context, globalResult);
    for (PipelineItem item : input.getData()) {
        PrismValue value = item.getValue();
        OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
        context.checkTaskStop();
        if (value instanceof PrismObjectValue && FocusType.class.isAssignableFrom(((PrismObjectValue) value).asPrismObject().getCompileTimeClass())) {
            PrismObject<FocusType> focalPrismObject = ((PrismObjectValue) value).asPrismObject();
            FocusType focusType = focalPrismObject.asObjectable();
            long started = operationsHelper.recordStart(context, focusType);
            Throwable exception = null;
            try {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Recomputing object {} with dryRun={}: context:\n{}", focalPrismObject, dryRun);
                }
                ObjectDelta<? extends FocusType> emptyDelta = ObjectDelta.createEmptyDelta(focusType.getClass(), focusType.getOid(), prismContext, ChangeType.MODIFY);
                operationsHelper.applyDelta(emptyDelta, ModelExecuteOptions.createReconcile(), dryRun, context, result);
                LOGGER.trace("Recomputing of object {}: {}", focalPrismObject, result.getStatus());
                operationsHelper.recordEnd(context, focusType, started, null);
            } catch (Throwable e) {
                operationsHelper.recordEnd(context, focusType, started, e);
                exception = processActionException(e, NAME, value, context);
            }
            context.println((exception != null ? "Attempted to recompute " : "Recomputed ") + focalPrismObject.toString() + drySuffix(dryRun) + exceptionSuffix(exception));
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismObject<FocusType>"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return input;
}
Also used : PrismObjectValue(com.evolveum.midpoint.prism.PrismObjectValue) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 12 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class ResolveExecutor method execute.

@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    boolean noFetch = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_NO_FETCH, input, context, false, NAME, 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 PrismReferenceValue) {
            PrismReferenceValue prismReferenceValue = (PrismReferenceValue) value;
            String oid = prismReferenceValue.getOid();
            QName targetTypeQName = prismReferenceValue.getTargetType();
            if (targetTypeQName == null) {
                throw new ScriptExecutionException("Couldn't resolve reference, because target type is unknown: " + prismReferenceValue);
            }
            Class<? extends ObjectType> typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(targetTypeQName);
            if (typeClass == null) {
                throw new ScriptExecutionException("Couldn't resolve reference, because target type class is unknown for target type " + targetTypeQName);
            }
            try {
                PrismObjectValue<? extends ObjectType> resolved = operationsHelper.getObject(typeClass, oid, noFetch, context, result).getValue();
                output.add(new PipelineItem(resolved, item.getResult()));
            } catch (Throwable e) {
                //noinspection ThrowableNotThrown
                processActionException(e, NAME, value, context);
                // to keep track of failed item (may trigger exceptions downstream)
                output.add(item);
            }
        } else {
            //noinspection ThrowableNotThrown
            processActionException(new ScriptExecutionException("Item is not a PrismReference"), NAME, value, context);
        }
        operationsHelper.trimAndCloneResult(result, globalResult, context);
    }
    return output;
}
Also used : PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) QName(javax.xml.namespace.QName) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 13 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class TestScriptingBasic method test540SearchUserResolveNamesForRoleMembershipRef.

@Test
public void test540SearchUserResolveNamesForRoleMembershipRef() throws Exception {
    final String TEST_NAME = "test540SearchUserResolveNamesForRoleMembershipRef";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_RESOLVE_NAMES_FOR_ROLE_MEMBERSHIP_REF_FILE);
    // WHEN
    ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
    // THEN
    dumpOutput(output, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(2, output.getFinalOutput().getData().size());
    for (PipelineItem item : output.getFinalOutput().getData()) {
        PrismAsserts.assertHasTargetName((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_ROLE_MEMBERSHIP_REF));
        PrismAsserts.assertHasNoTargetName((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_LINK_REF));
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 14 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class TestScriptingBasic method test510GeneratePasswords.

@Test
public void test510GeneratePasswords() throws Exception {
    final String TEST_NAME = "test510GeneratePasswords";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    PrismProperty<ScriptingExpressionType> expression = parseAnyData(GENERATE_PASSWORDS_FILE);
    addObject(PASSWORD_POLICY_GLOBAL_FILE);
    List<ItemDelta<?, ?>> itemDeltas = DeltaBuilder.deltaFor(SecurityPolicyType.class, prismContext).item(SecurityPolicyType.F_CREDENTIALS, CredentialsPolicyType.F_PASSWORD, PasswordCredentialsPolicyType.F_PASSWORD_POLICY_REF).add(new PrismReferenceValue(PASSWORD_POLICY_GLOBAL_OID)).asItemDeltas();
    modifySystemObjectInRepo(SecurityPolicyType.class, SECURITY_POLICY_OID, itemDeltas, result);
    // 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();
        UserType user = ((PrismObjectValue<UserType>) value).asObjectable();
        ProtectedStringType passwordValue = user.getCredentials().getPassword().getValue();
        assertNotNull("clearValue for password not set", passwordValue.getClearValue());
        realOids.add(user.getOid());
    }
    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) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 15 with PipelineItem

use of com.evolveum.midpoint.model.api.PipelineItem in project midpoint by Evolveum.

the class TestScriptingBasic method test545SearchUserResolveRoleMembershipRef.

@Test
public void test545SearchUserResolveRoleMembershipRef() throws Exception {
    final String TEST_NAME = "test545SearchUserResolveRoleMembershipRef";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(DOT_CLASS + TEST_NAME);
    OperationResult result = task.getResult();
    PrismProperty<SearchExpressionType> expression = parseAnyData(SEARCH_FOR_USERS_RESOLVE_ROLE_MEMBERSHIP_REF_FILE);
    // WHEN
    ExecutionContext output = scriptingExpressionEvaluator.evaluateExpression(expression.getAnyValue().getValue(), task, result);
    // THEN
    dumpOutput(output, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertEquals(2, output.getFinalOutput().getData().size());
    for (PipelineItem item : output.getFinalOutput().getData()) {
        PrismAsserts.assertHasObject((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_ROLE_MEMBERSHIP_REF));
        PrismAsserts.assertHasNoObject((PrismContainerValue) item.getValue(), new ItemPath(UserType.F_LINK_REF));
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) PipelineItem(com.evolveum.midpoint.model.api.PipelineItem) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

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