Search in sources :

Example 46 with CommonException

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

the class PageRegistrationFinish method removeNonceAndSetLifecycleState.

private void removeNonceAndSetLifecycleState(String userOid, NonceType nonce, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
    OperationResult result = parentResult.createSubresult(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
    try {
        runAsChecked(() -> {
            Task task = createSimpleTask(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
            ObjectDelta<UserType> delta = getPrismContext().deltaFactory().object().createModificationDeleteContainer(UserType.class, userOid, ItemPath.create(UserType.F_CREDENTIALS, CredentialsType.F_NONCE), nonce);
            delta.addModificationReplaceProperty(UserType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE);
            WebModelServiceUtils.save(delta, result, task, PageRegistrationFinish.this);
            return null;
        }, administrator);
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError(getString("PageRegistrationConfirmation.message.removeNonceAndSetLifecycleState.fatalError"), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't remove nonce and set lifecycle state", e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 47 with CommonException

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

the class PageRegistrationConfirmation method assignDefaultRoles.

private void assignDefaultRoles(String userOid, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
    List<ObjectReferenceType> rolesToAssign = getSelfRegistrationConfiguration().getDefaultRoles();
    if (CollectionUtils.isEmpty(rolesToAssign)) {
        return;
    }
    OperationResult result = parentResult.createSubresult(OPERATION_ASSIGN_DEFAULT_ROLES);
    try {
        PrismContext prismContext = getPrismContext();
        List<AssignmentType> assignmentsToCreate = rolesToAssign.stream().map(ref -> ObjectTypeUtil.createAssignmentTo(ref, prismContext)).collect(Collectors.toList());
        ObjectDelta<Objectable> delta = prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).addRealValues(assignmentsToCreate).asObjectDelta(userOid);
        runAsChecked(() -> {
            Task task = createSimpleTask(OPERATION_ASSIGN_DEFAULT_ROLES);
            WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
            return null;
        }, administrator);
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError(getString("PageRegistrationConfirmation.message.assignDefaultRoles.fatalError"), e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) PageDescriptor(com.evolveum.midpoint.authentication.api.authorization.PageDescriptor) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) WebModelServiceUtils(com.evolveum.midpoint.gui.api.util.WebModelServiceUtils) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AuthenticationException(org.springframework.security.core.AuthenticationException) StringValue(org.apache.wicket.util.string.StringValue) Label(org.apache.wicket.markup.html.basic.Label) Url(com.evolveum.midpoint.authentication.api.authorization.Url) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) Objectable(com.evolveum.midpoint.prism.Objectable) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Collectors(java.util.stream.Collectors) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) CommonException(com.evolveum.midpoint.util.exception.CommonException) List(java.util.List) Validate(org.apache.commons.lang3.Validate) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) NonceAuthenticationContext(com.evolveum.midpoint.model.api.context.NonceAuthenticationContext) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) Task(com.evolveum.midpoint.task.api.Task) PrismContext(com.evolveum.midpoint.prism.PrismContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Objectable(com.evolveum.midpoint.prism.Objectable) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 48 with CommonException

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

the class PageRegistrationConfirmation method removeNonceAndSetLifecycleState.

private void removeNonceAndSetLifecycleState(String userOid, NonceType nonce, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
    OperationResult result = parentResult.createSubresult(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
    try {
        runAsChecked(() -> {
            Task task = createSimpleTask(OPERATION_REMOVE_NONCE_AND_SET_LIFECYCLE_STATE);
            ObjectDelta<UserType> delta = getPrismContext().deltaFactory().object().createModificationDeleteContainer(UserType.class, userOid, ItemPath.create(UserType.F_CREDENTIALS, CredentialsType.F_NONCE), nonce);
            delta.addModificationReplaceProperty(UserType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_ACTIVE);
            WebModelServiceUtils.save(delta, result, task, PageRegistrationConfirmation.this);
            return null;
        }, administrator);
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError(getString("PageRegistrationConfirmation.message.removeNonceAndSetLifecycleState.fatalError"), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't remove nonce and set lifecycle state", e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 49 with CommonException

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

the class OrgTreeProvider method size.

public long size(TreeSelectableBean<OrgType> node) {
    Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
    OperationResult result = task.getResult();
    String nodeOid = null;
    if (node != null) {
        nodeOid = node.getValue().getOid();
    } else {
        nodeOid = rootOid.getObject();
    }
    Integer orgs = null;
    try {
        ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
        orgs = getModelService().countObjects(OrgType.class, query, null, task, result);
        LOGGER.debug("Found {} sub-orgs.", orgs);
    } catch (CommonException | RuntimeException ex) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
        result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
    } finally {
        result.computeStatus();
    }
    if (WebComponentUtil.showResultInPage(result)) {
        getPageBase().showResult(result);
        throw new RestartResponseException(PageOrgTree.class);
    }
    return orgs == null ? 0 : orgs.longValue();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RestartResponseException(org.apache.wicket.RestartResponseException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 50 with CommonException

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

the class OrgTreeProvider method getChildren.

@Override
public Iterator<? extends TreeSelectableBean<OrgType>> getChildren(TreeSelectableBean<OrgType> node) {
    LOGGER.debug("Getting children for {}", node.getValue());
    String nodeOid = node.getValue().getOid();
    List<TreeSelectableBean<OrgType>> children;
    long currentTime = System.currentTimeMillis();
    if (currentTime > lastFetchOperation + EXPIRATION_AFTER_LAST_FETCH_OPERATION) {
        childrenCache.clear();
    }
    if (childrenCache.containsKey(nodeOid)) {
        LOGGER.debug("Using cached children for {}", node.getValue());
        children = childrenCache.get(nodeOid);
    } else {
        LOGGER.debug("Loading fresh children for {}", node.getValue());
        OperationResult result = new OperationResult(LOAD_ORG_UNITS);
        try {
            ObjectQuery query = getPageBase().getPrismContext().queryFor(OrgType.class).isDirectChildOf(nodeOid).build();
            ObjectFilter customFilter = getCustomFilter();
            if (customFilter != null) {
                query.addFilter(customFilter);
            }
            Task task = getPageBase().createSimpleTask(LOAD_ORG_UNITS);
            ObjectPaging paging = createPaging(node);
            query.setPaging(paging);
            List<PrismObject<OrgType>> orgs = getModelService().searchObjects(OrgType.class, query, null, task, result);
            LOGGER.debug("Found {} sub-orgs.", orgs.size());
            children = new ArrayList<>();
            for (PrismObject<OrgType> org : orgs) {
                children.add(createObjectWrapper(node, org));
            }
            childrenCache.put(nodeOid, children);
        } catch (CommonException | RuntimeException ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load children", ex);
            result.recordFatalError(getPageBase().createStringResource("OrgTreeProvider.message.getChildren.fatalError").getString(), ex);
            children = new ArrayList<>();
        } finally {
            result.computeStatus();
        }
        if (WebComponentUtil.showResultInPage(result)) {
            getPageBase().showResult(result);
            throw new RestartResponseException(PageOrgTree.class);
        }
        children.forEach(orgUnit -> {
            getAvailableData().putIfAbsent(orgUnit.getValue().getOid(), orgUnit);
        });
    }
    LOGGER.debug("Finished getting children.");
    lastFetchOperation = System.currentTimeMillis();
    return children.iterator();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PrismObject(com.evolveum.midpoint.prism.PrismObject) RestartResponseException(org.apache.wicket.RestartResponseException) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) TreeSelectableBean(com.evolveum.midpoint.web.component.util.TreeSelectableBean) CommonException(com.evolveum.midpoint.util.exception.CommonException)

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