Search in sources :

Example 36 with CommonException

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

the class ResourceContentRepositoryPanel method createTotalsModel.

private LoadableModel<Integer> createTotalsModel(final SynchronizationSituationType situation) {
    return new LoadableModel<Integer>(false) {

        private static final long serialVersionUID = 1L;

        @Override
        protected Integer load() {
            PrismContext prismContext = getPageBase().getPrismContext();
            ObjectFilter resourceFilter = prismContext.queryFor(ShadowType.class).item(ShadowType.F_RESOURCE_REF).ref(ResourceContentRepositoryPanel.this.getResourceModel().getObject().getOid()).buildFilter();
            if (resourceFilter == null) {
                return 0;
            }
            ObjectFilter filter = createQuery().getFilter();
            if (filter == null) {
                return 0;
            }
            Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
            Task task = getPageBase().createSimpleTask(OPERATION_GET_TOTALS);
            OperationResult result = new OperationResult(OPERATION_GET_TOTALS);
            try {
                ObjectFilter situationFilter = prismContext.queryFor(ShadowType.class).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
                ObjectQuery query = prismContext.queryFactory().createQuery(prismContext.queryFactory().createAnd(filter, situationFilter));
                return getPageBase().getModelService().countObjects(ShadowType.class, query, options, task, result);
            } catch (CommonException | RuntimeException ex) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count shadows", ex);
            }
            return 0;
        }
    };
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) PrismContext(com.evolveum.midpoint.prism.PrismContext) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 37 with CommonException

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

the class RepoObjectResolver method resolve.

@Override
public <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType, Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription, Object task, OperationResult result) throws ObjectNotFoundException, SchemaException {
    String oid = ref.getOid();
    Class<?> typeClass = null;
    QName typeQName = ref.getType();
    if (typeQName != null) {
        typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
    }
    if (typeClass != null && expectedType.isAssignableFrom(typeClass)) {
        expectedType = (Class<O>) typeClass;
    }
    try {
        return cacheRepositoryService.getObject(expectedType, oid, options, result).asObjectable();
    } catch (SystemException ex) {
        throw ex;
    } catch (ObjectNotFoundException ex) {
        throw ex;
    } catch (CommonException ex) {
        throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 38 with CommonException

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

the class ModelObjectResolver method resolve.

@Override
public <O extends ObjectType> O resolve(ObjectReferenceType ref, Class<O> expectedType, Collection<SelectorOptions<GetOperationOptions>> options, String contextDescription, Object task, OperationResult result) throws ObjectNotFoundException, SchemaException {
    String oid = ref.getOid();
    Class<?> typeClass = null;
    QName typeQName = ref.getType();
    if (typeQName != null) {
        typeClass = prismContext.getSchemaRegistry().determineCompileTimeClass(typeQName);
    }
    if (typeClass != null && expectedType.isAssignableFrom(typeClass)) {
        expectedType = (Class<O>) typeClass;
    }
    try {
        return getObject(expectedType, oid, options, (Task) task, result);
    } catch (SystemException ex) {
        throw ex;
    } catch (ObjectNotFoundException ex) {
        throw ex;
    } catch (CommonException ex) {
        LoggingUtils.logException(LOGGER, "Error resolving object with oid {}", ex, oid);
        // Add to result only a short version of the error, the details will be in subresults
        result.recordFatalError("Couldn't get object with oid '" + oid + "': " + ex.getOperationResultMessage(), ex);
        throw new SystemException("Error resolving object with oid '" + oid + "': " + ex.getMessage(), ex);
    }
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) QName(javax.xml.namespace.QName) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 39 with CommonException

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

the class MappingEvaluator method createFocusMapping.

public <V extends PrismValue, D extends ItemDefinition, F extends FocusType, T extends FocusType> Mapping<V, D> createFocusMapping(final MappingFactory mappingFactory, final LensContext<F> context, final MappingType mappingType, ObjectType originObject, ObjectDeltaObject<F> focusOdo, PrismObject<T> defaultTargetObject, AssignmentPathVariables assignmentPathVariables, Integer iteration, String iterationToken, PrismObject<SystemConfigurationType> configuration, XMLGregorianCalendar now, String contextDesc, final Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (!Mapping.isApplicableToChannel(mappingType, context.getChannel())) {
        LOGGER.trace("Mapping {} not applicable to channel {}, skipping.", mappingType, context.getChannel());
        return null;
    }
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        private ItemPath outputPath;

        private ItemDefinition outputDefinition;

        @Override
        public void setOutputPath(ItemPath outputPath) {
            this.outputPath = outputPath;
        }

        @Override
        public void setOutputDefinition(ItemDefinition outputDefinition) {
            this.outputDefinition = outputDefinition;
        }

        @Override
        public StringPolicyType resolve() {
            // TODO need to switch to ObjectValuePolicyEvaluator
            if (outputDefinition.getName().equals(PasswordType.F_VALUE)) {
                ValuePolicyType passwordPolicy = credentialsProcessor.determinePasswordPolicy(context.getFocusContext(), task, result);
                if (passwordPolicy == null) {
                    return null;
                }
                return passwordPolicy.getStringPolicy();
            }
            if (mappingType.getExpression() != null) {
                List<JAXBElement<?>> evaluators = mappingType.getExpression().getExpressionEvaluator();
                if (evaluators != null) {
                    for (JAXBElement jaxbEvaluator : evaluators) {
                        Object object = jaxbEvaluator.getValue();
                        if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
                            ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
                            try {
                                ValuePolicyType valuePolicyType = mappingFactory.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getName() + " value", task, new OperationResult("Resolving value policy"));
                                if (valuePolicyType != null) {
                                    return valuePolicyType.getStringPolicy();
                                }
                            } catch (CommonException ex) {
                                throw new SystemException(ex.getMessage(), ex);
                            }
                        }
                    }
                }
            }
            return null;
        }
    };
    ExpressionVariables variables = new ExpressionVariables();
    FOCUS_VARIABLE_NAMES.forEach(name -> variables.addVariableDefinition(name, focusOdo));
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, iteration);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken);
    variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, configuration);
    Collection<V> targetValues = computeTargetValues(mappingType.getTarget(), defaultTargetObject, variables, mappingFactory.getObjectResolver(), contextDesc, task, result);
    Mapping.Builder<V, D> mappingBuilder = mappingFactory.<V, D>createMappingBuilder(mappingType, contextDesc).sourceContext(focusOdo).targetContext(defaultTargetObject.getDefinition()).variables(variables).originalTargetValues(targetValues).originType(OriginType.USER_POLICY).originObject(originObject).stringPolicyResolver(stringPolicyResolver).rootNode(focusOdo).now(now);
    mappingBuilder = LensUtil.addAssignmentPathVariables(mappingBuilder, assignmentPathVariables);
    Mapping<V, D> mapping = mappingBuilder.build();
    ItemPath itemPath = mapping.getOutputPath();
    if (itemPath == null) {
        // no output element, i.e. this is a "validation mapping"
        return mapping;
    }
    if (defaultTargetObject != null) {
        Item<V, D> existingTargetItem = (Item<V, D>) defaultTargetObject.findItem(itemPath);
        if (existingTargetItem != null && !existingTargetItem.isEmpty() && mapping.getStrength() == MappingStrengthType.WEAK) {
            LOGGER.trace("Mapping {} is weak and target already has a value {}, skipping.", mapping, existingTargetItem);
            return null;
        }
    }
    return mapping;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) JAXBElement(javax.xml.bind.JAXBElement) Item(com.evolveum.midpoint.prism.Item) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) GenerateExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorType) CommonException(com.evolveum.midpoint.util.exception.CommonException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 40 with CommonException

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

the class PageAccounts method createTotalsModel.

private LoadableModel<Integer> createTotalsModel(final SynchronizationSituationType situation) {
    return new LoadableModel<Integer>(false) {

        @Override
        protected Integer load() {
            ObjectFilter resourceFilter = createResourceQueryFilter();
            if (resourceFilter == null) {
                return 0;
            }
            ObjectFilter filter = createObjectQuery().getFilter();
            Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createRaw());
            Task task = createSimpleTask(OPERATION_GET_TOTALS);
            OperationResult result = new OperationResult(OPERATION_GET_TOTALS);
            try {
                ObjectFilter situationFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
                ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.createAnd(filter, situationFilter));
                return getModelService().countObjects(ShadowType.class, query, options, task, result);
            } catch (CommonException | RuntimeException ex) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't count shadows", ex);
            }
            return 0;
        }
    };
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

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