Search in sources :

Example 6 with ModelExecuteOptions

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

the class TestMapping method test212ModifyUserLocalityRecon.

/**
	 * MID-3661
	 */
@Test
public void test212ModifyUserLocalityRecon() throws Exception {
    final String TEST_NAME = "test212ModifyUserLocalityRecon";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestMapping.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    getDummyResource(RESOURCE_DUMMY_CRIMSON_NAME).resetBreakMode();
    DummyAccount dummyAccountBefore = getDummyAccount(RESOURCE_DUMMY_CRIMSON_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME);
    display("Dummy account before", dummyAccountBefore);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ObjectDelta<UserType> objectDelta = createModifyUserReplaceDelta(USER_GUYBRUSH_OID, new ItemPath(UserType.F_LOCALITY), PrismTestUtil.createPolyString("Scabb Island"));
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(objectDelta);
    ModelExecuteOptions options = ModelExecuteOptions.createReconcile();
    modelService.executeChanges(deltas, options, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess("executeChanges result", result);
    PrismObject<UserType> userAfter = getUser(USER_GUYBRUSH_OID);
    display("User after", userAfter);
    assertUser(userAfter, USER_GUYBRUSH_OID, USER_GUYBRUSH_USERNAME, USER_GUYBRUSH_FULL_NAME, USER_GUYBRUSH_GIVEN_NAME, USER_GUYBRUSH_FAMILY_NAME);
    String accountOid = getSingleLinkOid(userAfter);
    PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    display("Repo shadow after", repoShadow);
    assertNoPostponedOperation(repoShadow);
    // Check account in dummy resource
    DummyAccount dummyAccountAfter = assertDummyAccount(RESOURCE_DUMMY_CRIMSON_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, ACCOUNT_GUYBRUSH_DUMMY_FULLNAME, true);
    display("Dummy account after", dummyAccountAfter);
    assertDummyAccountAttribute(RESOURCE_DUMMY_CRIMSON_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_LOCATION_NAME, "Scabb Island");
    assertDummyAccountAttribute(RESOURCE_DUMMY_CRIMSON_NAME, ACCOUNT_GUYBRUSH_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, "vodka", "whisky", "rum from Scabb Island");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 7 with ModelExecuteOptions

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

the class AbstractModelIntegrationTest method modifyRoleDeleteInducement.

protected void modifyRoleDeleteInducement(String roleOid, long inducementId, boolean reconcileAffected, Task task) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    if (task == null) {
        task = createTask(AbstractModelIntegrationTest.class.getName() + ".modifyRoleDeleteInducement");
    }
    OperationResult result = task.getResult();
    AssignmentType inducement = new AssignmentType();
    inducement.setId(inducementId);
    ObjectDelta<RoleType> roleDelta = ObjectDelta.createModificationDeleteContainer(RoleType.class, roleOid, RoleType.F_INDUCEMENT, prismContext, inducement);
    ModelExecuteOptions options = new ModelExecuteOptions();
    options.setReconcileAffected(reconcileAffected);
    modelService.executeChanges(MiscSchemaUtil.createCollection(roleDelta), options, task, result);
    result.computeStatus();
    if (reconcileAffected) {
        TestUtil.assertInProgressOrSuccess(result);
    } else {
        TestUtil.assertSuccess(result);
    }
}
Also used : AbstractRoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractRoleType) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 8 with ModelExecuteOptions

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

the class AbstractWfTestLegacy method deleteUserFromModel.

protected void deleteUserFromModel(String name) throws SchemaException, ObjectNotFoundException, CommunicationException, ObjectAlreadyExistsException, PolicyViolationException, SecurityViolationException, ConfigurationException, ExpressionEvaluationException {
    OperationResult result = new OperationResult("dummy");
    Task t = taskManager.createTaskInstance();
    t.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
    if (!findUserInRepoUnchecked(name, result).isEmpty()) {
        PrismObject<UserType> user = findUserInRepo(name, result);
        Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
        deltas.add(ObjectDelta.createDeleteDelta(UserType.class, user.getOid(), prismContext));
        modelService.executeChanges(deltas, new ModelExecuteOptions(), t, result);
        LOGGER.info("User " + name + " was deleted");
    } else {
        LOGGER.info("User {} was not found", name);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 9 with ModelExecuteOptions

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

the class TestMiscellaneous method test250SkippingApprovals.

@Test
public void test250SkippingApprovals() throws Exception {
    final String TEST_NAME = "test250SkippingApprovals";
    TestUtil.displayTestTile(this, TEST_NAME);
    login(userAdministrator);
    Task task = createTask(TEST_NAME);
    OperationResult result = task.getResult();
    // GIVEN
    setDefaultUserTemplate(null);
    unassignAllRoles(userJackOid);
    // WHEN
    @SuppressWarnings({ "raw", "unchecked" }) ObjectDelta<? extends ObjectType> delta = (ObjectDelta<? extends ObjectType>) DeltaBuilder.deltaFor(UserType.class, prismContext).item(UserType.F_ASSIGNMENT).add(ObjectTypeUtil.createAssignmentTo(roleRole1aOid, ObjectTypes.ROLE, prismContext)).asObjectDelta(userJackOid);
    ModelExecuteOptions options = ModelExecuteOptions.createPartialProcessing(new PartialProcessingOptionsType().approvals(PartialProcessingTypeType.SKIP));
    modelService.executeChanges(Collections.singletonList(delta), options, task, result);
    // THEN
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertAssignedRole(userJackOid, roleRole1aOid, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Test(org.testng.annotations.Test)

Example 10 with ModelExecuteOptions

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

the class PageAdminObjectDetails method saveOrPreviewPerformed.

public void saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly, Task task) {
    boolean delegationChangesExist = processDeputyAssignments(previewOnly);
    PrismObjectWrapper<O> objectWrapper = getObjectWrapper();
    LOGGER.debug("Saving object {}", objectWrapper);
    // todo: improve, delta variable is quickfix for MID-1006
    // redirecting to user list page everytime user is created in repository
    // during user add in gui,
    // and we're not taking care about account/assignment create errors
    // (error message is still displayed)
    delta = null;
    if (task == null) {
        task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
    }
    ModelExecuteOptions options = getOptions(previewOnly);
    LOGGER.debug("Using execute options {}.", options);
    try {
        reviveModels();
        delta = objectWrapper.getObjectDelta();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("User delta computed from form:\n{}", delta.debugDump(3));
        }
    } catch (Exception ex) {
        result.recordFatalError(getString("pageAdminObjectDetails.message.cantCreateObject"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Create Object failed", ex);
        showResult(result);
        target.add(getFeedbackPanel());
        return;
    }
    switch(objectWrapper.getStatus()) {
        case ADDED:
            try {
                PrismObject<O> objectToAdd = delta.getObjectToAdd();
                WebComponentUtil.encryptCredentials(objectToAdd, true, getMidpointApplication());
                prepareObjectForAdd(objectToAdd);
                getPrismContext().adopt(objectToAdd, getCompileTimeClass());
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before add user:\n{}", delta.debugDump(3));
                }
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    final Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
                    final Collection<SimpleValidationError> validationErrors = performCustomValidation(objectToAdd, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    if (isSaveInBackground() && !previewOnly) {
                        progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
                    } else {
                        progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
                    }
                } else {
                    result.recordSuccess();
                }
            } catch (Exception ex) {
                result.recordFatalError(getString("pageFocus.message.cantCreateFocus"), ex);
                LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
                showResult(result);
            }
            break;
        case NOT_CHANGED:
            try {
                WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
                // preparing of deltas for projections (ADD, DELETE, UNLINK)
                prepareObjectDeltaForModify(delta);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before modify user:\n{}", delta.debugDump(3));
                }
                Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    deltas.add(delta);
                }
                List<ObjectDelta<? extends ObjectType>> additionalDeltas = getAdditionalModifyDeltas(result);
                if (additionalDeltas != null) {
                    for (ObjectDelta additionalDelta : additionalDeltas) {
                        if (!additionalDelta.isEmpty()) {
                            additionalDelta.revive(getPrismContext());
                            deltas.add(additionalDelta);
                        }
                    }
                }
                if (delta.isEmpty() && ModelExecuteOptions.isReconcile(options)) {
                    ObjectDelta emptyDelta = getPrismContext().deltaFactory().object().createEmptyModifyDelta(getCompileTimeClass(), objectWrapper.getObject().getOid());
                    deltas.add(emptyDelta);
                    Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    if (isSaveInBackground() && !previewOnly) {
                        progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
                    } else {
                        progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
                    }
                } else if (!deltas.isEmpty()) {
                    Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    if (isSaveInBackground() && !previewOnly) {
                        progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
                    } else {
                        progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
                    }
                } else if (previewOnly && delta.isEmpty() && delegationChangesExist) {
                    if (isSaveInBackground() && !previewOnly) {
                        progressPanel.executeChangesInBackground(deltas, previewOnly, options, task, result, target);
                    } else {
                        progressPanel.executeChanges(deltas, previewOnly, options, task, result, target);
                    }
                } else {
                    // from previous attempts (useful only if we would call finishProcessing at the end, but that's not the case now)
                    progressPanel.clearProgressPanel();
                    if (!previewOnly) {
                        if (!delegationChangesExist) {
                            result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
                            showResult(result);
                        }
                        redirectBack();
                    } else {
                        if (!delegationChangesExist) {
                            warn(getString("PageAdminObjectDetails.noChangesPreview"));
                            target.add(getFeedbackPanel());
                        }
                    }
                }
            } catch (Exception ex) {
                if (!executeForceDelete(objectWrapper, task, options, result)) {
                    result.recordFatalError(getString("pageUser.message.cantUpdateUser"), ex);
                    LoggingUtils.logUnexpectedException(LOGGER, getString("pageUser.message.cantUpdateUser"), ex);
                } else {
                    result.recomputeStatus();
                }
                showResult(result);
            }
            break;
        // support for add/delete containers (e.g. delete credentials)
        default:
            error(getString("pageAdminFocus.message.unsupportedState", objectWrapper.getStatus()));
    }
    LOGGER.trace("returning from saveOrPreviewPerformed");
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SimpleValidationError(com.evolveum.midpoint.web.util.validation.SimpleValidationError)

Aggregations

ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)80 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)47 Task (com.evolveum.midpoint.task.api.Task)45 Test (org.testng.annotations.Test)30 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 RestartResponseException (org.apache.wicket.RestartResponseException)6 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)3 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)3 ExecuteChangeOptionsDto (com.evolveum.midpoint.web.page.admin.users.component.ExecuteChangeOptionsDto)3 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)3 NotNull (org.jetbrains.annotations.NotNull)3