Search in sources :

Example 21 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter 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() {
            ObjectFilter resourceFilter = QueryBuilder.queryFor(ShadowType.class, getPageBase().getPrismContext()).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 = QueryBuilder.queryFor(ShadowType.class, getPageBase().getPrismContext()).item(ShadowType.F_SYNCHRONIZATION_SITUATION).eq(situation).buildFilter();
                ObjectQuery query = ObjectQuery.createObjectQuery(AndFilter.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) 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)

Example 22 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class PageResourceEdit method updateConnectorRef.

/**
     * Method which attempts to resolve connector reference filter to actual connector (if necessary).
     *
     * @param resource {@link PrismObject} resource
     */
private void updateConnectorRef(PrismObject<ResourceType> resource, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    if (resource == null) {
        return;
    }
    PrismReference resourceRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
    if (resourceRef == null || resourceRef.getValue() == null) {
        return;
    }
    PrismReferenceValue refValue = resourceRef.getValue();
    if (StringUtils.isNotEmpty(refValue.getOid())) {
        return;
    }
    if (refValue.getFilter() == null) {
        return;
    }
    SchemaRegistry registry = getPrismContext().getSchemaRegistry();
    PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(ConnectorType.class);
    ObjectFilter filter = QueryConvertor.parseFilter(refValue.getFilter(), objDef);
    List<PrismObject<ConnectorType>> connectors = getModelService().searchObjects(ConnectorType.class, ObjectQuery.createObjectQuery(filter), null, task, result);
    if (connectors.size() != 1) {
        return;
    }
    PrismObject<ConnectorType> connector = connectors.get(0);
    refValue.setOid(connector.getOid());
    refValue.setTargetType(ConnectorType.COMPLEX_TYPE);
    refValue.setFilter(null);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ConnectorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) PrismReference(com.evolveum.midpoint.prism.PrismReference) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry)

Example 23 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class AssignmentEvaluator method resolveTargetsFromFilter.

@NotNull
private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Class<O> targetClass, SearchFilterType filter, AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(lensContext, null, ctx.task, ctx.result));
    try {
        PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(ctx.result);
        ExpressionVariables variables = Utils.getDefaultExpressionVariables(segment.source, null, null, systemConfiguration.asObjectable());
        variables.addVariableDefinition(ExpressionConstants.VAR_SOURCE, segment.getOrderOneObject());
        AssignmentPathVariables assignmentPathVariables = LensUtil.computeAssignmentPathVariables(ctx.assignmentPath);
        if (assignmentPathVariables != null) {
            Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
        }
        ObjectFilter origFilter = QueryConvertor.parseFilter(filter, targetClass, prismContext);
        ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), prismContext, " evaluating resource filter expression ", ctx.task, ctx.result);
        if (evaluatedFilter == null) {
            throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + segment.source);
        }
        return repository.searchObjects(targetClass, ObjectQuery.createObjectQuery(evaluatedFilter), null, ctx.result);
    // we don't check for no targets here; as we don't care for referential integrity
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class Clockwork method triggerReconcileAffected.

private <F extends ObjectType> HookOperationMode triggerReconcileAffected(LensContext<F> context, Task task, OperationResult result) throws SchemaException {
    // check applicability
    if (!ModelExecuteOptions.isReconcileAffected(context.getOptions())) {
        return HookOperationMode.FOREGROUND;
    }
    if (context.getFocusClass() == null || !RoleType.class.isAssignableFrom(context.getFocusClass())) {
        LOGGER.warn("ReconcileAffected requested but not available for {}. Doing nothing.", context.getFocusClass());
        return HookOperationMode.FOREGROUND;
    }
    // check preconditions
    if (context.getFocusContext() == null) {
        throw new IllegalStateException("No focus context when expected it");
    }
    PrismObject<RoleType> role = (PrismObject) context.getFocusContext().getObjectAny();
    if (role == null) {
        throw new IllegalStateException("No role when expected it");
    }
    // preparing the recompute/reconciliation task
    Task reconTask;
    if (task.isPersistent()) {
        reconTask = task.createSubtask();
    } else {
        reconTask = task;
    }
    assert !reconTask.isPersistent();
    // creating object query
    PrismPropertyDefinition propertyDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_OBJECT_QUERY);
    PrismReferenceValue referenceValue = new PrismReferenceValue(context.getFocusContext().getOid(), RoleType.COMPLEX_TYPE);
    ObjectFilter refFilter = QueryBuilder.queryFor(FocusType.class, prismContext).item(FocusType.F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(referenceValue).buildFilter();
    SearchFilterType filterType = QueryConvertor.createSearchFilterType(refFilter, prismContext);
    QueryType queryType = new QueryType();
    queryType.setFilter(filterType);
    PrismProperty<QueryType> property = propertyDef.instantiate();
    property.setRealValue(queryType);
    reconTask.addExtensionProperty(property);
    // other parameters
    reconTask.setName("Recomputing users after changing role " + role.asObjectable().getName());
    reconTask.setBinding(TaskBinding.LOOSE);
    reconTask.setInitialExecutionStatus(TaskExecutionStatus.RUNNABLE);
    reconTask.setHandlerUri(RecomputeTaskHandler.HANDLER_URI);
    reconTask.setCategory(TaskCategory.RECOMPUTATION);
    taskManager.switchToBackground(reconTask, result);
    result.setBackgroundTaskOid(reconTask.getOid());
    result.recordStatus(OperationResultStatus.IN_PROGRESS, "Reconciliation task switched to background");
    return HookOperationMode.BACKGROUND;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 25 with ObjectFilter

use of com.evolveum.midpoint.prism.query.ObjectFilter in project midpoint by Evolveum.

the class PageDebugList method exportSelected.

private void exportSelected(AjaxRequestTarget target, DebugObjectItem item) {
    List<DebugObjectItem> selected = getSelectedData(target, item);
    if (selected.isEmpty()) {
        return;
    }
    List<String> oids = new ArrayList<>();
    for (DebugObjectItem dItem : selected) {
        oids.add(dItem.getOid());
    }
    ObjectFilter filter = InOidFilter.createInOid(oids);
    DebugSearchDto searchDto = searchModel.getObject();
    initDownload(target, searchDto.getType().getClassDefinition(), ObjectQuery.createObjectQuery(filter));
}
Also used : ArrayList(java.util.ArrayList) DebugSearchDto(com.evolveum.midpoint.web.page.admin.configuration.dto.DebugSearchDto) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) DebugObjectItem(com.evolveum.midpoint.web.page.admin.configuration.dto.DebugObjectItem)

Aggregations

ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)64 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)30 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)25 Task (com.evolveum.midpoint.task.api.Task)21 ArrayList (java.util.ArrayList)14 Test (org.testng.annotations.Test)13 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 QName (javax.xml.namespace.QName)12 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)8 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)8 NoneFilter (com.evolveum.midpoint.prism.query.NoneFilter)7 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)7 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5