Search in sources :

Example 11 with QueryType

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

the class TestQueryConvertor method testShadowKindTypeQuery.

@Test
public void testShadowKindTypeQuery() throws Exception {
    displayTestTitle("testShadowKindTypeQuery");
    SearchFilterType filterType = PrismTestUtil.parseAtomicValue(FILTER_BY_TYPE_FILE, SearchFilterType.COMPLEX_TYPE);
    ObjectQuery query;
    try {
        ObjectFilter kindFilter = QueryBuilder.queryFor(ShadowType.class, getPrismContext()).item(ShadowType.F_KIND).eq(ShadowKindType.ACCOUNT).buildFilter();
        query = ObjectQuery.createObjectQuery(kindFilter);
        assertNotNull(query);
        ObjectFilter filter = query.getFilter();
        assertTrue("filter is not an instance of type filter", filter instanceof EqualFilter);
        EqualFilter typeFilter = (EqualFilter) filter;
        assertEquals(typeFilter.getSingleValue().getRealValue(), ShadowKindType.ACCOUNT);
        QueryType convertedQueryType = toQueryType(query);
        toObjectQuery(ShadowType.class, convertedQueryType);
        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) Test(org.testng.annotations.Test)

Example 12 with QueryType

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

the class TestQueryConvertor method test430OrgFilterDefaultScope.

@Test
public void test430OrgFilterDefaultScope() throws Exception {
    final String TEST_NAME = "test430OrgFilterDefaultScope";
    displayTestTitle(TEST_NAME);
    // default scope is SUBTREE
    String queryXml = "<?xml version='1.0'?><query><filter><org>\n" + "        <orgRef>\n" + "            <oid>333</oid>\n" + "        </orgRef>\n" + "    </org></filter></query>";
    QueryType queryJaxb = toQueryType(queryXml);
    displayQueryType(queryJaxb);
    ObjectQuery query = toObjectQuery(OrgType.class, queryJaxb);
    displayQuery(query);
    ObjectQuery expectedQuery = QueryBuilder.queryFor(OrgType.class, getPrismContext()).isChildOf("333").build();
    // primitive way of comparing queries
    assertEquals("Parsed query is wrong", expectedQuery.toString(), query.toString());
    // now reserialize the parsed query and compare with XML - the XML contains explicit scope=SUBTREE (as this is set when parsing original queryXml)
    checkQueryRoundtripFile(OrgType.class, query, TEST_NAME);
}
Also used : QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) Test(org.testng.annotations.Test)

Example 13 with QueryType

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

the class TestQueryConvertor method testGenericQuery.

@Test
public void testGenericQuery() throws Exception {
    displayTestTitle("testGenericQuery");
    SearchFilterType queryType = unmarshalFilter(FILTER_AND_GENERIC_FILE);
    ObjectQuery query = toObjectQuery(GenericObjectType.class, queryType);
    displayQuery(query);
    // check parent filter
    assertNotNull(query);
    ObjectFilter filter = query.getFilter();
    PrismAsserts.assertAndFilter(filter, 2);
    // check first condition
    ObjectFilter first = getFilterCondition(filter, 0);
    PrismAsserts.assertEqualsFilter(first, GenericObjectType.F_NAME, PolyStringType.COMPLEX_TYPE, new ItemPath(GenericObjectType.F_NAME));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) first, createPolyString("generic object"));
    // check second condition
    ObjectFilter second = getFilterCondition(filter, 1);
    PrismAsserts.assertEqualsFilter(second, intExtensionDefinition, DOMUtil.XSD_INT, new ItemPath(ObjectType.F_EXTENSION, new QName(NS_EXTENSION, "intType")));
    PrismAsserts.assertEqualsFilterValue((EqualFilter) second, 123);
    QueryType convertedQueryType = toQueryType(query);
    assertNotNull("Re-serialized query is null ", convertedQueryType);
    assertNotNull("Filter in re-serialized query must not be null.", convertedQueryType.getFilter());
    displayQueryType(convertedQueryType);
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Example 14 with QueryType

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

the class PageRepositoryQuery method updateRequestWithMidpointQuery.

private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request, QName objectType, String queryText, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    PrismContext prismContext = getPrismContext();
    if (objectType == null) {
        objectType = ObjectType.COMPLEX_TYPE;
    }
    @SuppressWarnings("unchecked") Class<? extends ObjectType> clazz = (Class<? extends ObjectType>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
    if (clazz == null) {
        throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
    }
    QueryType queryType = prismContext.parserFor(queryText).xml().parseRealValue(QueryType.class);
    request.setType(clazz);
    ObjectQuery objectQuery = QueryJaxbConvertor.createObjectQuery(clazz, queryType, prismContext);
    ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new ExpressionVariables(), getExpressionFactory(), getPrismContext(), "evaluate query expressions", task, result);
    request.setQuery(queryWithExprEvaluated);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContext(com.evolveum.midpoint.prism.PrismContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 15 with QueryType

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

the class TestCorrelationConfiramtionEvaluator method test004CorrelationMatchCaseInsensitive.

@Test
public void test004CorrelationMatchCaseInsensitive() throws Exception {
    String TEST_NAME = "test004CorrelationMatchCaseInsensitive";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task task = taskManager.createTaskInstance(TEST_NAME);
    OperationResult result = task.getResult();
    //		importObjectFromFile(USER_JACK_FILENAME);
    PrismObject<UserType> userType = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
    //assert jack
    assertNotNull(userType);
    ShadowType shadow = parseObjectType(ACCOUNT_SHADOW_JACK_DUMMY_FILE, ShadowType.class);
    ConditionalSearchFilterType query = PrismTestUtil.parseAtomicValue(new File(CORRELATION_CASE_INSENSITIVE), ConditionalSearchFilterType.COMPLEX_TYPE);
    //		List<QueryType> queries = new ArrayList<QueryType>();
    //		queries.add(query);
    //		
    ResourceType resourceType = parseObjectType(RESOURCE_DUMMY_FILE, ResourceType.class);
    resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().clear();
    resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().add(query);
    userType.asObjectable().setName(new PolyStringType("JACK"));
    ObjectSynchronizationType objectSynchronizationType = resourceType.getSynchronization().getObjectSynchronization().get(0);
    try {
        boolean matchedUsers = evaluator.matchUserCorrelationRule(UserType.class, shadow.asPrismObject(), userType, objectSynchronizationType, resourceType, getSystemConfiguration(), task, result);
        System.out.println("matched users " + matchedUsers);
        AssertJUnit.assertTrue(matchedUsers);
    } catch (Exception ex) {
        LOGGER.error("exception occured: {}", ex.getMessage(), ex);
        throw ex;
    }
//		assertNotNull("Correlation evaluator returned null collection of matched users.", matchedUsers);
//		assertEquals("Found more than one user.", 1, matchedUsers.size());
//		
//		PrismObject<UserType> jack = matchedUsers.get(0);
//		assertUser(jack, "c0c010c0-d34d-b33f-f00d-111111111111", "jack", "Jack Sparrow", "Jack", "Sparrow");
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) ObjectSynchronizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ConditionalSearchFilterType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConditionalSearchFilterType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

QueryType (com.evolveum.prism.xml.ns._public.query_3.QueryType)57 QueryType (net.opengis.cat.csw.v_2_0_2.QueryType)41 Test (org.junit.Test)40 QueryImpl (ddf.catalog.operation.impl.QueryImpl)37 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)36 QName (javax.xml.namespace.QName)34 Test (org.testng.annotations.Test)33 JAXBElement (javax.xml.bind.JAXBElement)27 SearchFilterType (com.evolveum.prism.xml.ns._public.query_3.SearchFilterType)24 ArrayList (java.util.ArrayList)24 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)20 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)17 Matchers.anyString (org.mockito.Matchers.anyString)14 Task (com.evolveum.midpoint.task.api.Task)13 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)13 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Holder (javax.xml.ws.Holder)12 GetFeatureType (ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)12