Search in sources :

Example 51 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class FocusListInlineMenuHelper method updateActivationPerformed.

/**
 * This method updates object activation. If selectedObject parameter is not null,
 * than it updates only that objects, otherwise it checks table for selected
 * objects.
 */
private void updateActivationPerformed(AjaxRequestTarget target, boolean enabling, F selectedObject) {
    List<F> objects = getObjectsToActOn(target, selectedObject);
    if (objects.isEmpty()) {
        return;
    }
    OperationResult result = new OperationResult(getOperationName(enabling ? OPERATION_ENABLE_OBJECTS : OPERATION_DISABLE_OBJECTS));
    for (F object : objects) {
        String operationName = getOperationName(enabling ? OPERATION_ENABLE_OBJECT : OPERATION_DISABLE_OBJECT);
        OperationResult subResult = result.createSubresult(operationName);
        try {
            Task task = parentPage.createSimpleTask(operationName);
            ObjectDelta objectDelta = WebModelServiceUtils.createActivationAdminStatusDelta(objectClass, object.getOid(), enabling, parentPage.getPrismContext());
            parentPage.getModelService().executeChanges(MiscUtil.createCollection(objectDelta), null, task, subResult);
            subResult.recordSuccess();
        } catch (CommonException | RuntimeException ex) {
            subResult.recomputeStatus();
            if (enabling) {
                subResult.recordFatalError("FocusListInlineMenuHelper.message.enable.fatalError", ex);
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't enable object", ex);
            } else {
                subResult.recordFatalError("FocusListInlineMenuHelper.message.disable.fatalError", ex);
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't disable object", ex);
            }
        }
    }
    result.recomputeStatus();
    parentPage.showResult(result);
    target.add(parentPage.getFeedbackPanel());
    focusListComponent.clearCache();
    focusListComponent.refreshTable(target);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 52 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class FocusListInlineMenuHelper method reconcilePerformed.

private void reconcilePerformed(AjaxRequestTarget target, F selectedObject) {
    List<F> objects = getObjectsToActOn(target, selectedObject);
    if (objects.isEmpty()) {
        return;
    }
    OperationResult result = new OperationResult(getOperationName(OPERATION_RECONCILE_OBJECTS));
    for (F object : objects) {
        OperationResult opResult = result.createSubresult(getOperationName(OPERATION_RECONCILE_OBJECT));
        try {
            Task task = parentPage.createSimpleTask(OPERATION_RECONCILE_OBJECT);
            ObjectDelta delta = parentPage.getPrismContext().deltaFactory().object().createEmptyModifyDelta(objectClass, object.getOid());
            Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
            parentPage.getModelService().executeChanges(deltas, parentPage.executeOptions().reconcile(), task, opResult);
            opResult.computeStatusIfUnknown();
        } catch (CommonException | RuntimeException ex) {
            opResult.recomputeStatus();
            opResult.recordFatalError(parentPage.createStringResource("FocusListInlineMenuHelper.message.reconcile.fatalError", object).getString(), ex);
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reconcile object " + object + ".", ex);
        }
    }
    result.recomputeStatus();
    parentPage.showResult(result);
    target.add(parentPage.getFeedbackPanel());
    focusListComponent.refreshTable(target);
    focusListComponent.clearCache();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 53 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class PagePostAuthentication method submitRegistration.

@Override
protected void submitRegistration(AjaxRequestTarget target) {
    OperationResult result = new OperationResult(OPERATION_SAVE_USER);
    ObjectDelta<UserType> userDelta = null;
    try {
        userDelta = getUserDelta();
        getPrismContext().adopt(userDelta);
        WebModelServiceUtils.save(userDelta, result, this);
        result.recordSuccessIfUnknown();
    } catch (SchemaException e) {
        LoggingUtils.logException(LOGGER, "Error during saving user.", e);
        result.recordFatalError(getString("PagePostAuthentication.message.submitRegistration.fatalError"), e);
    }
    result.computeStatus();
    if (result.isAcceptable()) {
        runPrivileged(() -> {
            ObjectDelta<UserType> lifecycleDelta = getPrismContext().deltaFactory().object().createModificationDeleteProperty(UserType.class, userModel.getObject().getOid(), UserType.F_LIFECYCLE_STATE, getPostAuthenticationConfiguration().getRequiredLifecycleState());
            OperationResult opResult = new OperationResult(OPERATION_SAVE_USER);
            Task task = createAnonymousTask(OPERATION_SAVE_USER);
            WebModelServiceUtils.save(lifecycleDelta, opResult, task, PagePostAuthentication.this);
            opResult.recordSuccessIfUnknown();
            return opResult;
        });
    }
    result.computeStatus();
    showResult(result, true);
    if (!result.isAcceptable()) {
        target.add(PagePostAuthentication.this);
    } else {
        MidPointPrincipal principal = AuthUtil.getPrincipalUser();
        try {
            getModelInteractionService().refreshPrincipal(principal.getOid(), principal.getFocus().getClass());
            navigateToNext(getMidpointApplication().getHomePage());
        } catch (CommonException e) {
            LOGGER.error("Error while refreshing user: ", e);
            target.add(PagePostAuthentication.this);
        }
    }
    target.add(getFeedbackPanel());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 54 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class CapabilityStep method savePerformed.

private void savePerformed() {
    Task task = getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES);
    OperationResult result = task.getResult();
    ModelService modelService = getPageBase().getModelService();
    boolean saved = false;
    try {
        PrismObject<ResourceType> oldResource;
        final PrismObject<ResourceType> resourceObject = resourceModel.getObject();
        ResourceType resource = resourceObject.asObjectable();
        List<Object> unsupportedCapabilities = new ArrayList<>();
        if (resource.getCapabilities().getConfigured() != null) {
            for (Object o : resource.getCapabilities().getConfigured().getAny()) {
                CapabilityType capabilityType = CapabilityUtil.asCapabilityType(o);
                if (!Capability.supports(capabilityType.getClass())) {
                    unsupportedCapabilities.add(o);
                }
            }
        }
        // AnyArrayList that is used to implement getAny() is really strange (e.g. doesn't support iterator.remove();
        // and its support for clear() is questionable) -- so let's recreate it altogether
        resource.getCapabilities().setConfigured(new CapabilityCollectionType());
        resource.getCapabilities().getConfigured().getAny().addAll(unsupportedCapabilities);
        ObjectFactory capabilityFactory = new ObjectFactory();
        for (CapabilityDto dto : dtoModel.getObject().getCapabilities()) {
            JAXBElement<? extends CapabilityType> jaxbCapability = createJAXBCapability(dto.getCapability(), capabilityFactory);
            if (jaxbCapability != null) {
                resource.getCapabilities().getConfigured().getAny().add(jaxbCapability);
            }
        }
        oldResource = WebModelServiceUtils.loadObject(ResourceType.class, resource.getOid(), getPageBase(), task, result);
        if (oldResource != null) {
            ObjectDelta<ResourceType> delta = parentPage.computeDiff(oldResource, resourceObject);
            if (!delta.isEmpty()) {
                parentPage.logDelta(delta);
                @SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
                modelService.executeChanges(deltas, null, getPageBase().createSimpleTask(OPERATION_SAVE_CAPABILITIES), result);
                parentPage.resetModels();
                saved = true;
            }
        }
    } catch (CommonException | RuntimeException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save capabilities", e);
        result.recordFatalError(getString("CapabilityStep.message.cantSaveCaps"), e);
    } finally {
        result.computeStatusIfUnknown();
        setResult(result);
    }
    if (parentPage.showSaveResultInPage(saved, result)) {
        getPageBase().showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) CapabilityCollectionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CapabilityCollectionType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ModelService(com.evolveum.midpoint.model.api.ModelService) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) CapabilityDto(com.evolveum.midpoint.web.component.wizard.resource.dto.CapabilityDto) PrismObject(com.evolveum.midpoint.prism.PrismObject) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 55 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class SchemaHandlingStep method savePerformed.

private void savePerformed() {
    PrismObject<ResourceType> oldResource;
    @NotNull PrismObject<ResourceType> newResource = resourceModel.getObject();
    Task task = parentPage.createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING);
    OperationResult result = task.getResult();
    ModelService modelService = parentPage.getModelService();
    ObjectDelta delta;
    boolean saved = false;
    removeEmptyContainers(newResource);
    try {
        oldResource = WebModelServiceUtils.loadObject(ResourceType.class, newResource.getOid(), parentPage, task, result);
        if (oldResource == null) {
            throw new IllegalStateException("No resource to apply schema handling to");
        }
        delta = parentPage.computeDiff(oldResource, newResource);
        if (!delta.isEmpty()) {
            parentPage.logDelta(delta);
            @SuppressWarnings("unchecked") Collection<ObjectDelta<? extends ObjectType>> deltas = MiscUtil.createCollection(delta);
            modelService.executeChanges(deltas, null, parentPage.createSimpleTask(OPERATION_SAVE_SCHEMA_HANDLING), result);
            parentPage.resetModels();
            saved = true;
        }
    } catch (RuntimeException | CommonException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save schema handling", e);
        result.recordFatalError(getString("SchemaHandlingStep.message.saveError", e));
    } finally {
        result.computeStatusIfUnknown();
    }
    setResult(result);
    if (parentPage.showSaveResultInPage(saved, result)) {
        parentPage.showResult(result);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) NotNull(org.jetbrains.annotations.NotNull) ModelService(com.evolveum.midpoint.model.api.ModelService) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

CommonException (com.evolveum.midpoint.util.exception.CommonException)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)44 Task (com.evolveum.midpoint.task.api.Task)33 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)14 ArrayList (java.util.ArrayList)12 ModelService (com.evolveum.midpoint.model.api.ModelService)11 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 NotNull (org.jetbrains.annotations.NotNull)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ActivityRunException (com.evolveum.midpoint.repo.common.activity.run.ActivityRunException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 RestartResponseException (org.apache.wicket.RestartResponseException)5 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4