use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test126QueryOrgTreeFindUsersRelationDefault.
@Test
public void test126QueryOrgTreeFindUsersRelationDefault() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(UserType.class).isChildOf(itemFactory().createReferenceValue("some oid").relation(SchemaConstants.ORG_DEFAULT)).build();
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
String real = rQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid in (select descendantOid from ROrgClosure where ancestorOid = :orgOid))\n");
@SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
assertEquals("Wrong relation parameter value", new HashSet<>(getVariantsOfDefaultRelation()), new HashSet<>(relationParameter));
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test122QueryOrgTreeFindUsersRelationManager.
@Test
public void test122QueryOrgTreeFindUsersRelationManager() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(UserType.class).isDirectChildOf(itemFactory().createReferenceValue("some oid").relation(SchemaConstants.ORG_MANAGER)).build();
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
String real = rQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid,\n" + " u.fullObject\n" + "from\n" + " RUser u\n" + "where\n" + " u.oid in (select ref.ownerOid from RObjectReference ref where ref.referenceType = 0 and ref.relation in (:relation) and ref.targetOid = :orgOid)\n");
@SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
assertEquals("Wrong relation parameter value", new HashSet<>(Arrays.asList(RUtil.qnameToString(QNameUtil.nullNamespace(SchemaConstants.ORG_MANAGER)), RUtil.qnameToString(SchemaConstants.ORG_MANAGER))), new HashSet<>(relationParameter));
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test164QueryObjectTypeByTypeAndExtensionAttribute.
@Test
public void test164QueryObjectTypeByTypeAndExtensionAttribute() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(ObjectType.class).type(UserType.class).item(UserType.F_EXTENSION, new QName("http://example.com/p", "weapon")).eq("some weapon name").build();
RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ObjectType.class, query, false, null);
assertThat(realQuery.getQuery().getQueryString()).isEqualToIgnoringWhitespace("select\n" + " o.oid, o.fullObject\n" + "from\n" + " RObject o\n" + " left join o.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" + "where\n" + " (\n" + " o.objectTypeClass = :objectTypeClass and\n" + " s.value = :value\n" + " )\n");
assertEquals("Wrong property ID for 'weapon'", weaponDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test182QueryGenericBoolean.
@Test
public void test182QueryGenericBoolean() throws Exception {
Session session = open();
try {
ObjectQuery objectQuery = prismContext.queryFor(GenericObjectType.class).item(ObjectType.F_EXTENSION, SKIP_AUTOGENERATION_QNAME).eq(true).build();
RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, GenericObjectType.class, objectQuery, false, null);
assertThat(realQuery.getQuery().getQueryString()).isEqualToIgnoringWhitespace("select\n" + " g.oid, g.fullObject\n" + "from\n" + " RGenericObject g\n" + " left join g.booleans b with ( b.ownerType = :ownerType and b.itemId = :itemId )\n" + "where\n" + " b.value = :value\n");
assertEquals("Wrong property ID for 'skipAutogeneration'", skipAutogenerationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> objects = repositoryService.searchObjects(GenericObjectType.class, objectQuery, null, result);
result.computeStatus();
assertTrue(result.isSuccess());
AssertJUnit.assertNotNull(objects);
assertEquals(1, objects.size());
PrismObject<GenericObjectType> obj = objects.get(0);
assertEquals(GenericObjectType.class, obj.getCompileTimeClass());
result = new OperationResult("count");
long count = repositoryService.countObjects(GenericObjectType.class, objectQuery, null, result);
result.computeStatus();
assertTrue(result.isSuccess());
assertEquals(1, count);
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test708QuerySearchForAssignmentHolderType.
@Test
public void test708QuerySearchForAssignmentHolderType() throws Exception {
Session session = open();
try {
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, AssignmentHolderType.class, null, false, null);
String real = rQuery.getQuery().getQueryString();
System.out.println("Query parameters:\n" + rQuery.getQuerySource().getParameters());
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " o.oid,\n" + " o.fullObject\n" + "from\n" + " RObject o\n" + "where\n" + " o.objectTypeClass in (:objectTypeClass)");
} finally {
close(session);
}
}
Aggregations