Search in sources :

Example 46 with ModelExecuteOptions

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

the class AccCertUpdateHelper method modifyObjectViaModel.

<T extends ObjectType> void modifyObjectViaModel(Class<T> objectClass, String oid, Collection<ItemDelta<?, ?>> itemDeltas, Task task, OperationResult result) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException {
    ObjectDelta<T> objectDelta = ObjectDelta.createModifyDelta(oid, itemDeltas, objectClass, prismContext);
    try {
        ModelExecuteOptions options = ModelExecuteOptions.createRaw().setPreAuthorized();
        modelService.executeChanges(Collections.singletonList(objectDelta), options, task, result);
    } catch (SecurityViolationException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException e) {
        throw new SystemException("Unexpected exception when modifying " + objectClass.getSimpleName() + " " + oid + ": " + e.getMessage(), e);
    }
}
Also used : ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) F_EVENT(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType.F_EVENT) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException)

Example 47 with ModelExecuteOptions

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

the class TestPreviewChanges method doPreview.

private void doPreview(Collection<ObjectDelta<? extends ObjectType>> deltas, ObjectChecker<ModelContext<UserType>> checker, Task task, OperationResult result) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    display("Input deltas: ", deltas);
    // WHEN
    ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
    // THEN
    display("Preview context", modelContext);
    checker.check(modelContext);
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 48 with ModelExecuteOptions

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

the class TestPreviewChanges method doPreviewFail.

private void doPreviewFail(Collection<ObjectDelta<? extends ObjectType>> deltas, Task task, OperationResult result) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    display("Input deltas: ", deltas);
    try {
        // WHEN
        ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
        AssertJUnit.fail("Expected exception, but it haven't come");
    } catch (SchemaException e) {
        // This is expected
        display("Expected exception", e);
    }
    result.computeStatus();
    TestUtil.assertFailure(result);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 49 with ModelExecuteOptions

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

the class ResourceContentPanel method deleteAccountConfirmedPerformed.

private void deleteAccountConfirmedPerformed(AjaxRequestTarget target, OperationResult result, List<ShadowType> selected) {
    Task task = getPageBase().createSimpleTask(OPERATION_DELETE_OBJECT);
    ModelExecuteOptions opts = createModelOptions();
    for (ShadowType shadow : selected) {
        try {
            ObjectDelta<ShadowType> deleteDelta = getPageBase().getPrismContext().deltaFactory().object().createDeleteDelta(ShadowType.class, shadow.getOid());
            getPageBase().getModelService().executeChanges(MiscUtil.createCollection(deleteDelta), opts, task, result);
        } catch (Throwable e) {
            result.recordPartialError("Could not delete " + shadow + ", reason: " + e.getMessage(), e);
            LOGGER.error("Could not delete {}, using option {}", shadow, opts, e);
        }
    }
    result.computeStatusIfUnknown();
    getPageBase().showResult(result);
    getTable().refreshTable(target);
    target.add(getPageBase().getFeedbackPanel());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions)

Example 50 with ModelExecuteOptions

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

the class ResourceContentPanel method updateResourceObjectStatusPerformed.

protected void updateResourceObjectStatusPerformed(ShadowType selected, AjaxRequestTarget target, boolean enabled) {
    List<ShadowType> selectedShadow = getSelectedShadowsList(selected);
    OperationResult result = new OperationResult(OPERATION_UPDATE_STATUS);
    Task task = getPageBase().createSimpleTask(OPERATION_UPDATE_STATUS);
    if (selectedShadow == null || selectedShadow.isEmpty()) {
        result.recordWarning(createStringResource("updateResourceObjectStatusPerformed.warning").getString());
        getPageBase().showResult(result);
        target.add(getPageBase().getFeedbackPanel());
        return;
    }
    ModelExecuteOptions opts = createModelOptions();
    for (ShadowType shadow : selectedShadow) {
        ActivationStatusType status = enabled ? ActivationStatusType.ENABLED : ActivationStatusType.DISABLED;
        try {
            ObjectDelta<ShadowType> deleteDelta = getPageBase().getPrismContext().deltaFactory().object().createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_ACTIVATION_ADMINISTRATIVE_STATUS, status);
            getPageBase().getModelService().executeChanges(MiscUtil.createCollection(deleteDelta), opts, task, result);
        } catch (ObjectAlreadyExistsException | ObjectNotFoundException | SchemaException | ExpressionEvaluationException | CommunicationException | ConfigurationException | PolicyViolationException | SecurityViolationException e) {
            result.recordPartialError(getPageBase().createStringResource("ResourceContentPanel.message.updateResourceObjectStatusPerformed.partialError", status, shadow).getString(), e);
            LOGGER.error("Could not update status (to {}) for {}, using option {}", status, shadow, opts, e);
        }
    }
    result.computeStatusIfUnknown();
    getPageBase().showResult(result);
    getTable().refreshTable(target);
    target.add(getPageBase().getFeedbackPanel());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

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