Search in sources :

Example 1 with ObjectFilter

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

the class AbstractRoleMemberPanel method initMemberTable.

private void initMemberTable(TableId tableId, Form form) {
    WebMarkupContainer memberContainer = new WebMarkupContainer(ID_CONTAINER_MEMBER);
    memberContainer.setOutputMarkupId(true);
    memberContainer.setOutputMarkupPlaceholderTag(true);
    form.add(memberContainer);
    MainObjectListPanel<ObjectType> childrenListPanel = new MainObjectListPanel<ObjectType>(ID_MEMBER_TABLE, ObjectType.class, tableId, getSearchOptions(), getPageBase()) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void objectDetailsPerformed(AjaxRequestTarget target, ObjectType object) {
            detailsPerformed(target, object);
        }

        @Override
        protected boolean isClickable(IModel<SelectableBean<ObjectType>> rowModel) {
            if (rowModel == null || rowModel.getObject() == null || rowModel.getObject().getValue() == null) {
                return false;
            }
            Class<?> objectClass = rowModel.getObject().getValue().getClass();
            return WebComponentUtil.hasDetailsPage(objectClass);
        }

        @Override
        protected void newObjectPerformed(AjaxRequestTarget target) {
            AbstractRoleMemberPanel.this.createFocusMemberPerformed(null, target);
        }

        @Override
        protected List<IColumn<SelectableBean<ObjectType>, String>> createColumns() {
            return createMembersColumns();
        }

        @Override
        protected IColumn<SelectableBean<ObjectType>, String> createActionsColumn() {
            return new InlineMenuHeaderColumn(createMembersHeaderInlineMenu());
        }

        @Override
        protected List<InlineMenuItem> createInlineMenu() {
            return new ArrayList<>();
        }

        @Override
        protected ObjectQuery createContentQuery() {
            ObjectQuery q = super.createContentQuery();
            ObjectQuery members = AbstractRoleMemberPanel.this.createContentQuery();
            List<ObjectFilter> filters = new ArrayList<>();
            if (q != null && q.getFilter() != null) {
                filters.add(q.getFilter());
            }
            if (members != null && members.getFilter() != null) {
                filters.add(members.getFilter());
            }
            if (filters.size() == 1) {
                return ObjectQuery.createObjectQuery(filters.iterator().next());
            }
            return ObjectQuery.createObjectQuery(AndFilter.createAnd(filters));
        }
    };
    childrenListPanel.setOutputMarkupId(true);
    memberContainer.add(childrenListPanel);
}
Also used : MainObjectListPanel(com.evolveum.midpoint.gui.api.component.MainObjectListPanel) IModel(org.apache.wicket.model.IModel) InlineMenuHeaderColumn(com.evolveum.midpoint.web.component.data.column.InlineMenuHeaderColumn) ArrayList(java.util.ArrayList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)

Example 2 with ObjectFilter

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

the class PageUsers method mergePerformed.

private void mergePerformed(AjaxRequestTarget target, final UserType selectedUser) {
    List<QName> supportedTypes = new ArrayList<>();
    supportedTypes.add(UserType.COMPLEX_TYPE);
    ObjectFilter filter = InOidFilter.createInOid(selectedUser.getOid());
    ObjectFilter notFilter = NotFilter.createNot(filter);
    ObjectBrowserPanel<UserType> panel = new ObjectBrowserPanel<UserType>(getMainPopupBodyId(), UserType.class, supportedTypes, false, PageUsers.this, notFilter) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSelectPerformed(AjaxRequestTarget target, UserType user) {
            hideMainPopup(target);
            mergeConfirmedPerformed(selectedUser, user, target);
        }
    };
    panel.setOutputMarkupId(true);
    showMainPopup(panel, target);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) QName(javax.xml.namespace.QName) ObjectBrowserPanel(com.evolveum.midpoint.gui.api.component.ObjectBrowserPanel) ArrayList(java.util.ArrayList) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 3 with ObjectFilter

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

the class AccCertQueryHelper method searchOpenWorkItems.

// public because of testing
// principal == null => take all work items
public List<AccessCertificationWorkItemType> searchOpenWorkItems(ObjectQuery baseWorkItemsQuery, MidPointPrincipal principal, boolean notDecidedOnly, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException, ObjectNotFoundException {
    // enhance filter with reviewerRef + enabled
    ObjectQuery newQuery;
    ObjectFilter reviewerAndEnabledFilter = getReviewerAndEnabledFilterForWI(principal);
    ObjectFilter filterToAdd;
    if (notDecidedOnly) {
        ObjectFilter noResponseFilter = QueryBuilder.queryFor(AccessCertificationWorkItemType.class, prismContext).item(F_OUTPUT, F_OUTCOME).isNull().buildFilter();
        filterToAdd = AndFilter.createAnd(reviewerAndEnabledFilter, noResponseFilter);
    } else {
        filterToAdd = reviewerAndEnabledFilter;
    }
    newQuery = replaceFilter(baseWorkItemsQuery, filterToAdd);
    // retrieve cases, filtered
    List<AccessCertificationWorkItemType> workItems = repositoryService.searchContainers(AccessCertificationWorkItemType.class, newQuery, options, result);
    return workItems;
}
Also used : ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) AccessCertificationWorkItemType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationWorkItemType)

Example 4 with ObjectFilter

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

the class AccCertQueryHelper method getCase.

public AccessCertificationCaseType getCase(String campaignOid, long caseId, Task task, OperationResult result) throws SchemaException, SecurityViolationException {
    ObjectFilter filter = AndFilter.createAnd(InOidFilter.createOwnerHasOidIn(campaignOid), InOidFilter.createInOid(String.valueOf(caseId)));
    ObjectQuery query = ObjectQuery.createObjectQuery(filter);
    List<AccessCertificationCaseType> caseList = repositoryService.searchContainers(AccessCertificationCaseType.class, query, null, result);
    if (caseList.isEmpty()) {
        return null;
    } else if (caseList.size() == 1) {
        return caseList.get(0);
    } else {
        throw new IllegalStateException("More than one certification case with ID " + caseId + " in campaign " + campaignOid);
    }
}
Also used : ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 5 with ObjectFilter

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

the class SearchEvaluator method evaluate.

public <T extends ObjectType> PipelineData evaluate(SearchExpressionType searchExpression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
    Validate.notNull(searchExpression.getType());
    boolean noFetch = expressionHelper.getArgumentAsBoolean(searchExpression.getParameter(), PARAM_NO_FETCH, input, context, false, "search", globalResult);
    @SuppressWarnings({ "unchecked", "raw" }) Class<T> objectClass = (Class<T>) ObjectTypes.getObjectTypeFromTypeQName(searchExpression.getType()).getClassDefinition();
    ObjectQuery objectQuery = null;
    if (searchExpression.getQuery() != null) {
        try {
            objectQuery = QueryJaxbConvertor.createObjectQuery(objectClass, searchExpression.getQuery(), prismContext);
        } catch (SchemaException e) {
            throw new ScriptExecutionException("Couldn't parse object query due to schema exception", e);
        }
    } else if (searchExpression.getSearchFilter() != null) {
        // todo resolve variable references in the filter
        objectQuery = new ObjectQuery();
        try {
            ObjectFilter filter = QueryConvertor.parseFilter(searchExpression.getSearchFilter(), objectClass, prismContext);
            objectQuery.setFilter(filter);
        } catch (SchemaException e) {
            throw new ScriptExecutionException("Couldn't parse object filter due to schema exception", e);
        }
    }
    final String variableName = searchExpression.getVariable();
    final PipelineData oldVariableValue = variableName != null ? context.getVariable(variableName) : null;
    final PipelineData outputData = PipelineData.createEmpty();
    final MutableBoolean atLeastOne = new MutableBoolean(false);
    ResultHandler<T> handler = (object, parentResult) -> {
        context.checkTaskStop();
        atLeastOne.setValue(true);
        if (searchExpression.getScriptingExpression() != null) {
            if (variableName != null) {
                context.setVariable(variableName, PipelineData.create(object.getValue()));
            }
            JAXBElement<?> childExpression = searchExpression.getScriptingExpression();
            try {
                outputData.addAllFrom(scriptingExpressionEvaluator.evaluateExpression((ScriptingExpressionType) childExpression.getValue(), PipelineData.create(object.getValue()), context, globalResult));
                globalResult.setSummarizeSuccesses(true);
                globalResult.summarize();
            } catch (ScriptExecutionException e) {
                // todo think about this
                if (context.isContinueOnAnyError()) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Exception when evaluating item from search result list.", e);
                } else {
                    throw new SystemException(e);
                }
            }
        } else {
            outputData.addValue(object.getValue());
        }
        return true;
    };
    try {
        Collection<SelectorOptions<GetOperationOptions>> options = operationsHelper.createGetOptions(searchExpression.getOptions(), noFetch);
        modelService.searchObjectsIterative(objectClass, objectQuery, handler, options, context.getTask(), globalResult);
    } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        // TODO continue on any error?
        throw new ScriptExecutionException("Couldn't execute searchObjects operation: " + e.getMessage(), e);
    }
    if (atLeastOne.isFalse()) {
        String matching = objectQuery != null ? "matching " : "";
        // temporary hack, this will be configurable
        context.println("Warning: no " + matching + searchExpression.getType().getLocalPart() + " object found");
    }
    if (variableName != null) {
        context.setVariable(variableName, oldVariableValue);
    }
    return outputData;
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationsHelper(com.evolveum.midpoint.model.impl.scripting.helpers.OperationsHelper) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) Trace(com.evolveum.midpoint.util.logging.Trace) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ExpressionHelper(com.evolveum.midpoint.model.impl.scripting.helpers.ExpressionHelper) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ResultHandler(com.evolveum.midpoint.schema.ResultHandler) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) JAXBElement(javax.xml.bind.JAXBElement) Collection(java.util.Collection) ExecutionContext(com.evolveum.midpoint.model.impl.scripting.ExecutionContext) LoggingUtils(com.evolveum.midpoint.util.logging.LoggingUtils) QueryConvertor(com.evolveum.midpoint.prism.marshaller.QueryConvertor) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) QueryJaxbConvertor(com.evolveum.midpoint.prism.query.QueryJaxbConvertor) Component(org.springframework.stereotype.Component) ScriptingExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.ScriptingExpressionType) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) ObjectTypes(com.evolveum.midpoint.schema.constants.ObjectTypes) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SearchExpressionType(com.evolveum.midpoint.xml.ns._public.model.scripting_3.SearchExpressionType) Validate(org.apache.commons.lang.Validate) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ScriptExecutionException(com.evolveum.midpoint.model.api.ScriptExecutionException) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) PipelineData(com.evolveum.midpoint.model.impl.scripting.PipelineData) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) JAXBElement(javax.xml.bind.JAXBElement) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions)

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