use of org.apache.openejb.jee.oejb2.QueryType in project midpoint by Evolveum.
the class AbstractSearchIterativeTaskHandler method createQueryFromTask.
/**
* Ready-made implementation of createQuery - gets and parses objectQuery extension property.
*/
protected ObjectQuery createQueryFromTask(H handler, TaskRunResult runResult, Task task, OperationResult opResult) throws SchemaException {
Class<? extends ObjectType> objectClass = getType(task);
LOGGER.trace("Object class = {}", objectClass);
QueryType queryFromTask = getObjectQueryTypeFromTask(task);
if (queryFromTask != null) {
ObjectQuery query = QueryJaxbConvertor.createObjectQuery(objectClass, queryFromTask, prismContext);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Using object query from the task: {}", query.debugDump());
}
return query;
} else {
// Search all objects
return new ObjectQuery();
}
}
use of org.apache.openejb.jee.oejb2.QueryType 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;
}
use of org.apache.openejb.jee.oejb2.QueryType 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");
}
use of org.apache.openejb.jee.oejb2.QueryType 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;
}
}
}
use of org.apache.openejb.jee.oejb2.QueryType 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;
}
}
Aggregations