Search in sources :

Example 51 with ModelExecuteOptions

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

the class PageCertDefinition method savePerformed.

// endregion
// region Actions
public void savePerformed(AjaxRequestTarget target) {
    CertDefinitionDto dto = definitionModel.getObject();
    if (StringUtils.isEmpty(dto.getName())) {
        error(getString("CertDefinitionPage.message.cantSaveEmptyName"));
        target.add(getFeedbackPanel());
        return;
    }
    Task task = createSimpleTask(OPERATION_SAVE_DEFINITION);
    OperationResult result = task.getResult();
    try {
        AccessCertificationDefinitionType oldObject = dto.getOldDefinition();
        oldObject.asPrismObject().revive(getPrismContext());
        AccessCertificationDefinitionType newObject = dto.getUpdatedDefinition(getPrismContext());
        newObject.asPrismObject().revive(getPrismContext());
        ObjectDelta<AccessCertificationDefinitionType> delta;
        if (oldObject.getOid() != null) {
            delta = DiffUtil.diff(oldObject, newObject);
        } else {
            delta = DeltaFactory.Object.createAddDelta(newObject.asPrismObject());
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Access definition delta:\n{}", delta.debugDump());
        }
        delta.normalize();
        if (!delta.isEmpty()) {
            getPrismContext().adopt(delta);
            ModelExecuteOptions options = new ModelExecuteOptions(getPrismContext());
            options.raw(true);
            getModelService().executeChanges(MiscUtil.createCollection(delta), options, task, result);
        }
        result.computeStatus();
    } catch (Exception ex) {
        result.recordFatalError(getString("PageCertDefinition.message.savePerformed.fatalError", ex.getMessage()), ex);
    }
    showResult(result);
    if (result.isError()) {
        target.add(getFeedbackPanel());
    } else {
        redirectBack();
    }
}
Also used : CertDefinitionDto(com.evolveum.midpoint.web.page.admin.certification.dto.CertDefinitionDto) Task(com.evolveum.midpoint.task.api.Task) AccessCertificationDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationDefinitionType) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 52 with ModelExecuteOptions

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

the class TreeTablePanel method recomputePerformed.

private void recomputePerformed(SelectableBeanImpl<OrgType> orgToRecompute, AjaxRequestTarget target) {
    Task task = getPageBase().createSimpleTask(OPERATION_RECOMPUTE);
    OperationResult result = new OperationResult(OPERATION_RECOMPUTE);
    if (orgToRecompute.getValue() == null) {
        return;
    }
    try {
        ObjectDelta emptyDelta = getPageBase().getPrismContext().deltaFactory().object().createEmptyModifyDelta(OrgType.class, orgToRecompute.getValue().getOid());
        ModelExecuteOptions options = new ModelExecuteOptions(getPrismContext());
        options.reconcile(true);
        getPageBase().getModelService().executeChanges(MiscUtil.createCollection(emptyDelta), options, task, result);
        result.recordSuccess();
    } catch (Exception e) {
        result.recordFatalError(getString("TreeTablePanel.message.recomputeError"), e);
        LoggingUtils.logUnexpectedException(LOGGER, getString("TreeTablePanel.message.recomputeError"), e);
    }
    getPageBase().showResult(result);
    target.add(getPageBase().getFeedbackPanel());
    getTreePanel().refreshTabbedPanel(target);
}
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) RestartResponseException(org.apache.wicket.RestartResponseException)

Example 53 with ModelExecuteOptions

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

the class PageAdminFocus method showAllAssignmentsPerformed.

public List<AssignmentValueWrapper> showAllAssignmentsPerformed(IModel<PrismContainerWrapper<AssignmentType>> parent) {
    LOGGER.debug("Recompute user assignments");
    Task task = createSimpleTask(OPERATION_RECOMPUTE_ASSIGNMENTS);
    OperationResult result = new OperationResult(OPERATION_RECOMPUTE_ASSIGNMENTS);
    ObjectDelta<F> delta;
    Set<AssignmentValueWrapper> assignmentValueWrapperSet = new TreeSet<>();
    try {
        reviveModels();
        PrismObjectWrapper<F> focusWrapper = getObjectWrapper();
        delta = focusWrapper.getObjectDelta();
        switch(focusWrapper.getStatus()) {
            case ADDED:
                PrismObject<F> focus = delta.getObjectToAdd();
                prepareObjectForAdd(focus);
                getPrismContext().adopt(focus, getCompileTimeClass());
                LOGGER.trace("Delta before add focus:\n{}", delta.debugDumpLazily(3));
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                } else {
                    result.recordSuccess();
                }
                break;
            case NOT_CHANGED:
                prepareObjectDeltaForModify(delta);
                LOGGER.trace("Delta before modify user:\n{}", delta.debugDumpLazily(3));
                List<ObjectDelta<? extends ObjectType>> accountDeltas = getShadowModifyDeltas(result);
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                }
                for (ObjectDelta accDelta : accountDeltas) {
                    if (!accDelta.isEmpty()) {
                        accDelta.revive(getPrismContext());
                    }
                }
                break;
            default:
                error(getString("pageAdminFocus.message.unsupportedState", focusWrapper.getStatus()));
        }
        ModelContext<UserType> modelContext;
        try {
            ModelExecuteOptions options = executeOptions().evaluateAllAssignmentRelationsOnRecompute();
            modelContext = getModelInteractionService().previewChanges(Collections.singleton(delta), options, task, result);
        } catch (NoFocusNameSchemaException e) {
            info(getString("pageAdminFocus.message.noUserName"));
            return null;
        }
        Collection<? extends EvaluatedAssignment<?>> evaluatedAssignments = modelContext.getNonNegativeEvaluatedAssignments();
        if (evaluatedAssignments.isEmpty()) {
            info(getString("pageAdminFocus.message.noAssignmentsAvailable"));
            return null;
        }
        for (EvaluatedAssignment<?> evaluatedAssignment : evaluatedAssignments) {
            if (!evaluatedAssignment.isValid()) {
                continue;
            }
            // roles and orgs
            DeltaSetTriple<? extends EvaluatedAssignmentTarget> targetsTriple = evaluatedAssignment.getRoles();
            Collection<? extends EvaluatedAssignmentTarget> targets = targetsTriple.getNonNegativeValues();
            for (EvaluatedAssignmentTarget target : targets) {
                target.getTarget();
                if (ArchetypeType.class.equals(target.getTarget().getCompileTimeClass())) {
                    continue;
                }
                if (target.appliesToFocusWithAnyRelation(getRelationRegistry())) {
                    AssignmentType assignmentType = target.getAssignment().clone();
                    assignmentType.setDescription(target.getTarget().asObjectable().getDescription());
                    assignmentType.getTargetRef().setTargetName(new PolyStringType(target.getTarget().getName()));
                    assignmentType.getTargetRef().setType(target.getTarget().getComplexTypeDefinition().getTypeName());
                    ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
                    AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, this);
                    assignmentValueWrapper.setDirectAssignment(target.isDirectlyAssigned());
                    assignmentValueWrapper.setAssignmentParent(target.getAssignmentPath());
                    assignmentValueWrapperSet.add(assignmentValueWrapper);
                }
            }
            // all resources
            DeltaSetTriple<EvaluatedResourceObjectConstruction> evaluatedConstructionsTriple = evaluatedAssignment.getEvaluatedConstructions(task, result);
            Collection<EvaluatedResourceObjectConstruction> evaluatedConstructions = evaluatedConstructionsTriple.getNonNegativeValues();
            for (EvaluatedResourceObjectConstruction construction : evaluatedConstructions) {
                if (!construction.isWeak()) {
                    PrismContainerDefinition<AssignmentType> assignmentDef = getPrismContext().getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class);
                    AssignmentType assignmentType = assignmentDef.instantiate().createNewValue().asContainerable();
                    ObjectReferenceType targetRef = new ObjectReferenceType();
                    targetRef.setOid(construction.getResource().getOid());
                    targetRef.setType(ResourceType.COMPLEX_TYPE);
                    targetRef.setTargetName(new PolyStringType(construction.getResource().getName()));
                    assignmentType.setTargetRef(targetRef);
                    ConstructionType constructionType = new ConstructionType();
                    constructionType.setResourceRef(targetRef);
                    constructionType.setKind(construction.getKind());
                    constructionType.setIntent(construction.getIntent());
                    assignmentType.setConstruction(constructionType);
                    assignmentType.setDescription(construction.getResource().asObjectable().getDescription());
                    ValueStatus status = evaluatedAssignment.getAssignment(true) == null ? ValueStatus.ADDED : ValueStatus.NOT_CHANGED;
                    AssignmentValueWrapper assignmentValueWrapper = WebPrismUtil.createNewValueWrapper(parent.getObject(), assignmentType.asPrismContainerValue(), status, this);
                    assignmentValueWrapper.setDirectAssignment(construction.isDirectlyAssigned());
                    assignmentValueWrapper.setAssignmentParent(construction.getAssignmentPath());
                    assignmentValueWrapperSet.add(assignmentValueWrapper);
                }
            }
        }
        return new ArrayList<>(assignmentValueWrapperSet);
    } catch (Exception e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Could not create assignments preview.", e);
        error("Could not create assignments preview. Reason: " + e);
    }
    return null;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) NoFocusNameSchemaException(com.evolveum.midpoint.util.exception.NoFocusNameSchemaException) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ValueStatus(com.evolveum.midpoint.web.component.prism.ValueStatus) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NoFocusNameSchemaException(com.evolveum.midpoint.util.exception.NoFocusNameSchemaException)

Example 54 with ModelExecuteOptions

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

the class PageAssignmentsList method onSingleUserRequestPerformed.

private void onSingleUserRequestPerformed(AjaxRequestTarget target) {
    OperationResult result = new OperationResult(OPERATION_REQUEST_ASSIGNMENTS);
    ObjectDelta<UserType> delta;
    try {
        PrismObject<UserType> user = getTargetUser();
        delta = prepareDelta(user, result);
        ModelExecuteOptions options = createOptions();
        // TODO make this configurable?
        options.initialPartialProcessing(new PartialProcessingOptionsType().inbound(SKIP).projection(SKIP));
        getModelService().executeChanges(Collections.singletonList(delta), options, createSimpleTask(OPERATION_REQUEST_ASSIGNMENTS), result);
        result.recordSuccess();
        SessionStorage storage = getSessionStorage();
        storage.getRoleCatalog().getAssignmentShoppingCart().clear();
    } catch (Exception e) {
        result.recordFatalError(e);
        result.setMessage(createStringResource("PageAssignmentsList.requestError").getString());
        LoggingUtils.logUnexpectedException(LOGGER, "Could not save assignments ", e);
    } finally {
        result.recomputeStatus();
    }
    if (hasBackgroundTaskOperation(result)) {
        result.setMessage(createStringResource("PageAssignmentsList.requestInProgress").getString());
        showResult(result);
        clearStorage();
        setResponsePage(PageAssignmentShoppingCart.class);
        return;
    }
    if (WebComponentUtil.isSuccessOrHandledError(result) || OperationResultStatus.IN_PROGRESS.equals(result.getStatus())) {
        clearStorage();
        result.setMessage(createStringResource("PageAssignmentsList.requestSuccess").getString());
        setResponsePage(PageAssignmentShoppingCart.class);
    } else {
        result.setMessage(createStringResource("PageAssignmentsList.requestError").getString());
        target.add(getFeedbackPanel());
        target.add(PageAssignmentsList.this.get(ID_FORM));
    }
    showResult(result);
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SessionStorage(com.evolveum.midpoint.web.session.SessionStorage) SchemaException(com.evolveum.midpoint.util.exception.SchemaException)

Example 55 with ModelExecuteOptions

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

the class PageAssignmentsList method createOptions.

@NotNull
private ModelExecuteOptions createOptions() {
    OperationBusinessContextType businessContextType;
    if (descriptionModel.getObject() != null) {
        businessContextType = new OperationBusinessContextType();
        businessContextType.setComment(descriptionModel.getObject());
    } else {
        businessContextType = null;
    }
    ModelExecuteOptions options = ExecuteChangeOptionsDto.createFromSystemConfiguration().createOptions(getPrismContext());
    options.requestBusinessContext(businessContextType);
    return options;
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) NotNull(org.jetbrains.annotations.NotNull)

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