use of com.evolveum.prism.xml.ns._public.query_3.QueryType in project midpoint by Evolveum.
the class ModelWebServiceTest method badPagingSearch.
@Test(expectedExceptions = FaultMessage.class)
public void badPagingSearch() throws FaultMessage, SchemaException, IOException, JAXBException {
PagingType paging = new PagingType();
paging.setMaxSize(-1);
paging.setOffset(-1);
final UserType expectedUser = (UserType) PrismTestUtil.parseObject(new File(TEST_FOLDER_CONTROLLER, "./addObject/add-user-without-name.xml")).asObjectable();
setSecurityContext(expectedUser);
try {
QueryType queryType = new QueryType();
queryType.setPaging(paging);
modelService.searchObjects(UserType.COMPLEX_TYPE, queryType, null, new Holder<ObjectListType>(), new Holder<OperationResultType>());
} catch (FaultMessage ex) {
ModelTUtil.assertIllegalArgumentFault(ex);
} finally {
SecurityContextHolder.getContext().setAuthentication(null);
}
Assert.fail("Illegal argument exception was not thrown.");
}
use of com.evolveum.prism.xml.ns._public.query_3.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 com.evolveum.prism.xml.ns._public.query_3.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 com.evolveum.prism.xml.ns._public.query_3.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 com.evolveum.prism.xml.ns._public.query_3.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;
}
}
}
Aggregations