Search in sources :

Example 1 with SearchFilterType

use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.

the class RefinedObjectClassDefinitionImpl method convertToPattern.

private static ResourceObjectPattern convertToPattern(ResourceObjectPatternType patternType, RefinedObjectClassDefinition rAccountDef) throws SchemaException {
    ResourceObjectPattern resourceObjectPattern = new ResourceObjectPattern(rAccountDef);
    SearchFilterType filterType = patternType.getFilter();
    if (filterType != null) {
        ObjectFilter filter = QueryConvertor.parseFilter(filterType, rAccountDef.getObjectDefinition());
        resourceObjectPattern.addFilter(filter);
        return resourceObjectPattern;
    }
    // Deprecated
    if (patternType.getName() != null) {
        RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "name"));
        if (attributeDefinition == null) {
            throw new SchemaException("No ICF NAME attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
        }
        ResourceAttribute<String> attr = attributeDefinition.instantiate();
        attr.setRealValue(patternType.getName());
        resourceObjectPattern.addIdentifier(attr);
    } else if (patternType.getUid() != null) {
        RefinedAttributeDefinition attributeDefinition = rAccountDef.findAttributeDefinition(new QName(SchemaConstants.NS_ICF_SCHEMA, "uid"));
        if (attributeDefinition == null) {
            throw new SchemaException("No ICF UID attribute in schema as specified in the definition of protected objects (this is deprecated syntax anyway, convert it to filter)");
        }
        ResourceAttribute<String> attr = attributeDefinition.instantiate();
        attr.setRealValue(patternType.getUid());
        resourceObjectPattern.addIdentifier(attr);
    } else {
        throw new SchemaException("No filter and no deprecated name/uid in resource object pattern");
    }
    return resourceObjectPattern;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ResourceObjectPattern(com.evolveum.midpoint.common.ResourceObjectPattern) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter)

Example 2 with SearchFilterType

use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.

the class TestFilterExpression method evaluateExpressionAssertFilter.

private ObjectFilter evaluateExpressionAssertFilter(String filename, String input, Class<? extends ObjectFilter> expectedType, Task task, OperationResult result) throws SchemaException, IOException, ObjectNotFoundException, ExpressionEvaluationException {
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, filename), SearchFilterType.COMPLEX_TYPE);
    ObjectFilter filter = QueryJaxbConvertor.createObjectFilter(UserType.class, filterType, prismContext);
    Map<QName, Object> params = new HashMap<>();
    PrismPropertyValue<String> pval = null;
    if (input != null) {
        pval = new PrismPropertyValue<String>(input);
    }
    params.put(ExpressionConstants.VAR_INPUT, pval);
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinitions(params);
    // WHEN
    ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(filter, variables, expressionFactory, prismContext, "evaluating filter with null value not allowed", task, result);
    // THEN
    display("Evaluated filter", evaluatedFilter);
    AssertJUnit.assertTrue("Expression should be evaluated to " + expectedType + ", but was " + evaluatedFilter, expectedType.isAssignableFrom(evaluatedFilter.getClass()));
    return evaluatedFilter;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) HashMap(java.util.HashMap) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) File(java.io.File)

Example 3 with SearchFilterType

use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.

the class ResourceProtectedEditor method addProtectedAccountPerformed.

private void addProtectedAccountPerformed(AjaxRequestTarget target) {
    ResourceObjectPatternType account = new ResourceObjectPatternType();
    account.setFilter(new SearchFilterType());
    changeState = ChangeState.LAST;
    getModel().getObject().add(account);
    target.add(getMainContainer());
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ResourceObjectPatternType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectPatternType)

Example 4 with SearchFilterType

use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.

the class ResourceProtectedEditor method initLayout.

protected void initLayout(final PageResourceWizard parentPage) {
    WebMarkupContainer container = new WebMarkupContainer(ID_CONTAINER);
    container.setOutputMarkupId(true);
    add(container);
    ListView repeater = new ListView<ResourceObjectPatternType>(ID_REPEATER, getModel()) {

        @Override
        protected void populateItem(final ListItem<ResourceObjectPatternType> item) {
            WebMarkupContainer linkCont = new WebMarkupContainer(ID_ACCOUNT_LINK);
            linkCont.setOutputMarkupId(true);
            linkCont.add(new AttributeModifier("href", createCollapseItemId(item, true)));
            item.add(linkCont);
            Label accountLabel = new Label(ID_ACCOUNT_NAME, new AbstractReadOnlyModel<String>() {

                @Override
                public String getObject() {
                    StringBuilder sb = new StringBuilder();
                    ResourceObjectPatternType account = item.getModelObject();
                    sb.append("#").append(item.getIndex() + 1).append(" - ");
                    if (account.getUid() != null) {
                        sb.append(account.getUid()).append(":");
                    }
                    if (account.getName() != null) {
                        sb.append(account.getName());
                    }
                    return sb.toString();
                }
            });
            linkCont.add(accountLabel);
            AjaxLink delete = new AjaxLink(ID_BUTTON_DELETE) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    deleteProtectedAccountPerformed(target, item);
                }
            };
            parentPage.addEditingVisibleBehavior(delete);
            linkCont.add(delete);
            WebMarkupContainer accountBody = new WebMarkupContainer(ID_ACCOUNT_BODY);
            accountBody.setOutputMarkupId(true);
            accountBody.setMarkupId(createCollapseItemId(item, false).getObject());
            if (changeState != ChangeState.SKIP) {
                accountBody.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() {

                    @Override
                    public String getObject() {
                        if (changeState == ChangeState.FIRST && item.getIndex() == 0) {
                            return "panel-collapse collapse in";
                        } else if (changeState == ChangeState.LAST && item.getIndex() == (getModelObject().size() - 1)) {
                            return "panel-collapse collapse in";
                        } else {
                            return "panel-collapse collapse";
                        }
                    }
                }));
            }
            item.add(accountBody);
            //TODO - maybe add some validator and auto-complete functionality?
            TextField name = new TextField<>(ID_NAME, new PropertyModel<String>(item.getModel(), "name"));
            name.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            parentPage.addEditingEnabledBehavior(name);
            accountBody.add(name);
            //TODO - maybe add some validator and auto-complete functionality?
            TextField uid = new TextField<>(ID_UID, new PropertyModel<String>(item.getModel(), "uid"));
            uid.add(new EmptyOnBlurAjaxFormUpdatingBehaviour());
            parentPage.addEditingEnabledBehavior(uid);
            accountBody.add(uid);
            SearchFilterPanel searchFilterPanel = new SearchFilterPanel<>(ID_FILTER_EDITOR, new NonEmptyPropertyModel<SearchFilterType>(item.getModel(), "filter"), parentPage.getReadOnlyModel());
            accountBody.add(searchFilterPanel);
            Label nameTooltip = new Label(ID_T_NAME);
            nameTooltip.add(new InfoTooltipBehavior());
            accountBody.add(nameTooltip);
            Label uidTooltip = new Label(ID_T_UID);
            uidTooltip.add(new InfoTooltipBehavior());
            accountBody.add(uidTooltip);
            Label filterTooltip = new Label(ID_T_FILTER);
            filterTooltip.add(new InfoTooltipBehavior());
            accountBody.add(filterTooltip);
        }
    };
    repeater.setOutputMarkupId(true);
    container.add(repeater);
    AjaxLink add = new AjaxLink(ID_BUTTON_ADD) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addProtectedAccountPerformed(target);
        }
    };
    parentPage.addEditingVisibleBehavior(add);
    add(add);
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) Label(org.apache.wicket.markup.html.basic.Label) EmptyOnBlurAjaxFormUpdatingBehaviour(com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnBlurAjaxFormUpdatingBehaviour) ResourceObjectPatternType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectPatternType) AttributeModifier(org.apache.wicket.AttributeModifier) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) InfoTooltipBehavior(com.evolveum.midpoint.web.util.InfoTooltipBehavior) ListView(org.apache.wicket.markup.html.list.ListView) TextField(org.apache.wicket.markup.html.form.TextField) ListItem(org.apache.wicket.markup.html.list.ListItem) SearchFilterPanel(com.evolveum.midpoint.web.component.input.SearchFilterPanel) AjaxLink(org.apache.wicket.ajax.markup.html.AjaxLink)

Example 5 with SearchFilterType

use of com.evolveum.prism.xml.ns._public.query_3.SearchFilterType in project midpoint by Evolveum.

the class TestQueryConvertors method testFilterTypeUserNone.

@Test
public void testFilterTypeUserNone() throws Exception {
    displayTestTitle("testFilterTypeUserNone");
    SearchFilterType filterType = PrismTestUtil.parseAnyValue(FILTER_TYPE_USER_NONE);
    ObjectQuery query = toObjectQuery(UserType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    assertTrue("Filter is not of TYPE type", filter instanceof TypeFilter);
    ObjectFilter subFilter = ((TypeFilter) filter).getFilter();
    assertTrue("Filter is not of NONE type", subFilter instanceof NoneFilter);
    QueryType convertedQueryType = toQueryType(query);
    System.out.println("Re-converted query type");
    System.out.println(convertedQueryType.debugDump());
    Element filterClauseElement = convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext());
    LOGGER.info(convertedQueryType.getFilter().getFilterClauseXNode().debugDump());
    System.out.println("Serialized filter (JAXB->DOM)");
    String filterAsString = DOMUtil.serializeDOMToString(filterClauseElement);
    System.out.println(filterAsString);
    LOGGER.info(filterAsString);
    DomAsserts.assertElementQName(filterClauseElement, new QName(PrismConstants.NS_QUERY, "type"));
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) PrismTestUtil.createPolyString(com.evolveum.midpoint.prism.util.PrismTestUtil.createPolyString) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Aggregations

SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)48 QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)24 QName (javax.xml.namespace.QName)21 Test (org.testng.annotations.Test)17 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)8 Element (org.w3c.dom.Element)8 MapXNode (com.evolveum.midpoint.prism.xnode.MapXNode)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)5 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)5 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)5 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)5 Holder (javax.xml.ws.Holder)5 Task (com.evolveum.midpoint.task.api.Task)4 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 IOException (java.io.IOException)4 SAXException (org.xml.sax.SAXException)4 PrismContext (com.evolveum.midpoint.prism.PrismContext)3