Search in sources :

Example 36 with SearchFilterType

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

the class QueryJaxbConvertor method createQueryType.

public static QueryType createQueryType(ObjectQuery query, PrismContext prismContext) throws SchemaException {
    ObjectFilter filter = query.getFilter();
    QueryType queryType = new QueryType();
    if (filter != null) {
        SearchFilterType filterType = new SearchFilterType();
        MapXNode filterXNode = QueryConvertor.serializeFilter(filter, prismContext);
        filterType.setFilterClauseXNode(filterXNode);
        queryType.setFilter(filterType);
    }
    queryType.setPaging(PagingConvertor.createPagingType(query.getPaging()));
    return queryType;
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType)

Example 37 with SearchFilterType

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

the class TestParseResource method assertResourcePrism.

private void assertResourcePrism(PrismObject<ResourceType> resource, boolean isSimple) throws SchemaException {
    PrismContext prismContext = getPrismContext();
    AssertJUnit.assertEquals("Wrong oid (prism)", TestConstants.RESOURCE_OID, resource.getOid());
    //		assertEquals("Wrong version", "42", resource.getVersion());
    PrismObjectDefinition<ResourceType> resourceDefinition = resource.getDefinition();
    assertNotNull("No resource definition", resourceDefinition);
    PrismAsserts.assertObjectDefinition(resourceDefinition, new QName(SchemaConstantsGenerated.NS_COMMON, "resource"), ResourceType.COMPLEX_TYPE, ResourceType.class);
    assertEquals("Wrong class in resource", ResourceType.class, resource.getCompileTimeClass());
    ResourceType resourceType = resource.asObjectable();
    assertNotNull("asObjectable resulted in null", resourceType);
    assertPropertyValue(resource, "name", PrismTestUtil.createPolyString("Embedded Test OpenDJ"));
    assertPropertyDefinition(resource, "name", PolyStringType.COMPLEX_TYPE, 0, 1);
    if (!isSimple) {
        assertPropertyValue(resource, "namespace", TestConstants.RESOURCE_NAMESPACE);
        assertPropertyDefinition(resource, "namespace", DOMUtil.XSD_ANYURI, 0, 1);
    }
    PrismReference connectorRef = resource.findReference(ResourceType.F_CONNECTOR_REF);
    assertNotNull("No connectorRef", connectorRef);
    PrismReferenceValue connectorRefVal = connectorRef.getValue();
    assertNotNull("No connectorRef value", connectorRefVal);
    assertEquals("Wrong type in connectorRef value", ConnectorType.COMPLEX_TYPE, connectorRefVal.getTargetType());
    SearchFilterType filter = connectorRefVal.getFilter();
    assertNotNull("No filter in connectorRef value", filter);
    if (!isSimple) {
        ObjectFilter objectFilter = QueryConvertor.parseFilter(filter, ConnectorType.class, prismContext);
        assertTrue("Wrong kind of filter: " + objectFilter, objectFilter instanceof EqualFilter);
        EqualFilter equalFilter = (EqualFilter) objectFilter;
        // should be extension/x:extConnType
        ItemPath path = equalFilter.getPath();
        PrismAsserts.assertPathEqualsExceptForPrefixes("Wrong filter path", namespaces ? new ItemPath(new QName("extension"), new QName("http://x/", "extConnType")) : new ItemPath(new QName("extension"), new QName("extConnType")), path);
        PrismPropertyValue filterValue = (PrismPropertyValue) equalFilter.getValues().get(0);
        assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((RawType) filterValue.getValue()).getParsedRealValue(String.class).trim());
    //assertEquals("Wrong filter value", "org.identityconnectors.ldap.LdapConnector", ((String) filterValue.getValue()).trim());
    }
    EvaluationTimeType resolutionTime = connectorRefVal.getResolutionTime();
    if (isSimple) {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.RUN, resolutionTime);
    } else {
        assertEquals("Wrong resolution time in connectorRef value", EvaluationTimeType.IMPORT, resolutionTime);
    }
    PrismContainer<?> configurationContainer = resource.findContainer(ResourceType.F_CONNECTOR_CONFIGURATION);
    assertContainerDefinition(configurationContainer, "configuration", ConnectorConfigurationType.COMPLEX_TYPE, 1, 1);
    PrismContainerValue<?> configContainerValue = configurationContainer.getValue();
    List<Item<?, ?>> configItems = configContainerValue.getItems();
    assertEquals("Wrong number of config items", isSimple ? 1 : 4, configItems.size());
    PrismContainer<?> ldapConfigPropertiesContainer = configurationContainer.findContainer(ICFC_CONFIGURATION_PROPERTIES);
    assertNotNull("No icfcldap:configurationProperties container", ldapConfigPropertiesContainer);
    PrismContainerDefinition<?> ldapConfigPropertiesContainerDef = ldapConfigPropertiesContainer.getDefinition();
    assertNotNull("No icfcldap:configurationProperties container definition", ldapConfigPropertiesContainerDef);
    assertEquals("icfcldap:configurationProperties container definition maxOccurs", 1, ldapConfigPropertiesContainerDef.getMaxOccurs());
    List<Item<?, ?>> ldapConfigPropItems = ldapConfigPropertiesContainer.getValue().getItems();
    assertEquals("Wrong number of ldapConfigPropItems items", 7, ldapConfigPropItems.size());
    PrismContainer<Containerable> schemaContainer = resource.findContainer(ResourceType.F_SCHEMA);
    if (isSimple) {
        assertNull("Schema sneaked in", schemaContainer);
    } else {
        assertNotNull("No schema container", schemaContainer);
    }
    PrismContainer<?> schemaHandlingContainer = resource.findContainer(ResourceType.F_SCHEMA_HANDLING);
    if (isSimple) {
        assertNull("SchemaHandling sneaked in", schemaHandlingContainer);
    } else {
        assertNotNull("No schemaHandling container", schemaHandlingContainer);
    }
    if (!isSimple) {
        PrismProperty<SynchronizationType> synchronizationProp = resource.findProperty(ResourceType.F_SYNCHRONIZATION);
        SynchronizationType synchronizationType = synchronizationProp.getRealValue();
        ObjectSynchronizationType objectSynchronizationType = synchronizationType.getObjectSynchronization().get(0);
        List<ConditionalSearchFilterType> correlations = objectSynchronizationType.getCorrelation();
        assertEquals("Wrong number of correlation expressions", 1, correlations.size());
        ConditionalSearchFilterType correlationFilterType = correlations.get(0);
        System.out.println("\nCorrelation filter");
        System.out.println(correlationFilterType.debugDump());
        ObjectFilter objectFilter = QueryConvertor.parseFilter(correlationFilterType.serializeToXNode(), prismContext);
        PrismAsserts.assertAssignableFrom(EqualFilter.class, objectFilter);
        EqualFilter equalsFilter = (EqualFilter) objectFilter;
        equalsFilter.getFullPath();
        assertNull("Unexpected values in correlation expression", equalsFilter.getValues());
        ExpressionWrapper expression = equalsFilter.getExpression();
        assertNotNull("No expressions in correlation expression", expression);
        ExpressionType expressionType = (ExpressionType) expression.getExpression();
        assertEquals("Wrong number of expression evaluators in correlation expression", 1, expressionType.getExpressionEvaluator().size());
        ItemPathType itemPathType = (ItemPathType) expressionType.getExpressionEvaluator().get(0).getValue();
        // $account/c:attributes/my:yyy
        PrismAsserts.assertPathEqualsExceptForPrefixes("path in correlation expression", namespaces ? new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName(SchemaConstantsGenerated.NS_COMMON, "attributes")), new NameItemPathSegment(new QName("http://myself.me/schemas/whatever", "yyy"))) : new ItemPath(new NameItemPathSegment(new QName("account"), true), new NameItemPathSegment(new QName("attributes")), new NameItemPathSegment(new QName("yyy"))), itemPathType.getItemPath());
    //PrismAsserts.assertAllParsedNodes(expression);
    // TODO
    }
}
Also used : NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) EqualFilter(com.evolveum.midpoint.prism.query.EqualFilter) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 38 with SearchFilterType

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

the class TestQueryConvertor method testAccountFilter.

@Test
public void testAccountFilter() throws Exception {
    displayTestTitle("testAccountFilter");
    SearchFilterType filterType = unmarshalFilter(FILTER_ACCOUNT_FILE);
    ObjectQuery query = toObjectQuery(ShadowType.class, filterType);
    displayQuery(query);
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, ShadowType.F_FAILED_OPERATION_TYPE, FAILED_OPERATION_TYPE_QNAME, new ItemPath(ShadowType.F_FAILED_OPERATION_TYPE));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, FailedOperationTypeType.ADD);
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, ShadowType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(ShadowType.F_NAME));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, createPolyString("someName"));
    QueryType convertedQueryType = toQueryType(query);
    System.out.println("Re-converted query type");
    System.out.println(convertedQueryType.debugDump());
    SearchFilterType convertedFilterType = convertedQueryType.getFilter();
    MapXNode xFilter = convertedFilterType.serializeToXNode();
    PrismAsserts.assertSize(xFilter, 1);
    PrismAsserts.assertSubnode(xFilter, AndFilter.ELEMENT_NAME, MapXNode.class);
    MapXNode xandmap = (MapXNode) xFilter.get(AndFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xandmap, 1);
    PrismAsserts.assertSubnode(xandmap, EqualFilter.ELEMENT_NAME, ListXNode.class);
    ListXNode xequalsList = (ListXNode) xandmap.get(EqualFilter.ELEMENT_NAME);
    PrismAsserts.assertSize(xequalsList, 2);
    Element filterClauseElement = convertedFilterType.getFilterClauseAsElement(getPrismContext());
    System.out.println("Serialized filter (JAXB->DOM)");
    System.out.println(DOMUtil.serializeDOMToString(filterClauseElement));
    DomAsserts.assertElementQName(filterClauseElement, AndFilter.ELEMENT_NAME);
    DomAsserts.assertSubElements(filterClauseElement, 2);
    Element firstSubelement = DOMUtil.getChildElement(filterClauseElement, 0);
    DomAsserts.assertElementQName(firstSubelement, EqualFilter.ELEMENT_NAME);
    Element firstValueElement = DOMUtil.getChildElement(firstSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(firstValueElement, "add");
    Element secondSubelement = DOMUtil.getChildElement(filterClauseElement, 1);
    DomAsserts.assertElementQName(secondSubelement, EqualFilter.ELEMENT_NAME);
    Element secondValueElement = DOMUtil.getChildElement(secondSubelement, PrismConstants.Q_VALUE);
    DomAsserts.assertTextContent(secondValueElement, "someName");
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) ListXNode(com.evolveum.midpoint.prism.xnode.ListXNode) Element(org.w3c.dom.Element) MapXNode(com.evolveum.midpoint.prism.xnode.MapXNode) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 39 with SearchFilterType

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

the class TestQueryConvertor method testUserQuery.

@Test
public void testUserQuery() throws Exception {
    displayTestTitle("testUserQuery");
    File[] userQueriesToTest = new File[] { new File(TEST_DIR, "filter-user-by-fullName.xml"), new File(TEST_DIR, "filter-user-by-name.xml"), new File(TEST_DIR, "filter-user-substring-fullName.xml"), new File(TEST_DIR, "filter-user-substring-employeeType.xml") };
    // prismContext.silentMarshalObject(queryTypeNew, LOGGER);
    for (File file : userQueriesToTest) {
        SearchFilterType filterType = PrismTestUtil.parseAtomicValue(file, SearchFilterType.COMPLEX_TYPE);
        LOGGER.info("===[ query type parsed ]===");
        ObjectQuery query;
        try {
            query = QueryJaxbConvertor.createObjectQuery(UserType.class, filterType, getPrismContext());
            LOGGER.info("query converted: ");
            LOGGER.info("QUERY DUMP: {}", query.debugDump());
            LOGGER.info("QUERY Pretty print: {}", query.toString());
            System.out.println("QUERY Pretty print: " + query.toString());
            QueryType convertedQueryType = QueryJaxbConvertor.createQueryType(query, getPrismContext());
            LOGGER.info(DOMUtil.serializeDOMToString(convertedQueryType.getFilter().getFilterClauseAsElement(getPrismContext())));
        } catch (Exception ex) {
            LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
            throw ex;
        }
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) File(java.io.File) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Test(org.testng.annotations.Test)

Example 40 with SearchFilterType

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

the class TestQueryConvertor method testTypeFilterQuery.

@Test
public void testTypeFilterQuery() throws Exception {
    displayTestTitle("testConnectorQuery");
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
    ObjectQuery query;
    try {
        query = QueryJaxbConvertor.createObjectQuery(ConnectorType.class, filterType, getPrismContext());
        displayQuery(query);
        assertNotNull(query);
        ObjectFilter filter = query.getFilter();
        assertTrue("filter is not an instance of type filter", filter instanceof TypeFilter);
        TypeFilter typeFilter = (TypeFilter) filter;
        assertEquals(typeFilter.getType(), UserType.COMPLEX_TYPE);
        assertNotNull("filter in type filter must not be null", typeFilter.getFilter());
        ItemPath namePath = new ItemPath(UserType.F_NAME);
        PrismPropertyDefinition ppd = getUserDefinition().findPropertyDefinition(namePath);
        PrismAsserts.assertEqualsFilter(typeFilter.getFilter(), ppd.getName(), ppd.getTypeName(), namePath);
        PrismAsserts.assertEqualsFilterValue((EqualFilter) typeFilter.getFilter(), PrismTestUtil.createPolyString("some name identificator"));
        //			PrismAsserts.assertEqualsFilter(query.getFilter(), ConnectorType.F_CONNECTOR_TYPE, DOMUtil.XSD_STRING,
        //					new ItemPath(ConnectorType.F_CONNECTOR_TYPE));
        //			PrismAsserts.assertEqualsFilterValue((EqualsFilter) filter, "org.identityconnectors.ldap.LdapConnector");
        QueryType convertedQueryType = toQueryType(query);
        displayQueryType(convertedQueryType);
    } catch (Exception ex) {
        LOGGER.error("Error while converting query: {}", ex.getMessage(), ex);
        throw ex;
    }
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) 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