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;
}
}
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);
}
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);
}
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);
}
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");
}
Aggregations