use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test084QueryUserAssignmentTargetRefManagerUnqualified.
@Test
public void test084QueryUserAssignmentTargetRefManagerUnqualified() throws Exception {
Session session = open();
try {
ObjectReferenceType ort = new ObjectReferenceType().oid("123").type(OrgType.COMPLEX_TYPE).relation(QNameUtil.nullNamespace(SchemaConstants.ORG_MANAGER));
ObjectQuery query = prismContext.queryFor(UserType.class).item(F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(ort.asReferenceValue()).build();
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
String real = rQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + " (\n" + " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation in (:relation) and\n" + " a.targetRef.targetType = :targetType\n" + " )\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 test082QueryUserAssignmentTargetRefManagerStandardQualified.
@Test
public void test082QueryUserAssignmentTargetRefManagerStandardQualified() throws Exception {
Session session = open();
try {
ObjectReferenceType ort = new ObjectReferenceType().oid("123").type(OrgType.COMPLEX_TYPE).relation(SchemaConstants.ORG_MANAGER);
ObjectQuery query = prismContext.queryFor(UserType.class).item(F_ASSIGNMENT, AssignmentType.F_TARGET_REF).ref(ort.asReferenceValue()).build();
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
String real = rQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" + "where\n" + " (\n" + " a.targetRef.targetOid = :targetOid and\n" + " a.targetRef.relation in (:relation) and\n" + " a.targetRef.targetType = :targetType\n" + " )\n");
@SuppressWarnings("unchecked") Collection<String> relationParameter = (Collection<String>) rQuery.getQuerySource().getParameters().get("relation").getValue();
System.out.println("relationParameter: " + relationParameter);
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 test128QueryOrgTreeFindUsersRelationManager.
@Test
public void test128QueryOrgTreeFindUsersRelationManager() throws Exception {
Session session = open();
try {
ObjectQuery query = prismContext.queryFor(UserType.class).isChildOf(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 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<>(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 test005QueryOrganizationNorm.
@Test
public void test005QueryOrganizationNorm() throws Exception {
Session session = open();
try {
/*
* ### user: Equal (organization, "...", PolyStringNorm)
*/
ObjectQuery query = prismContext.queryFor(UserType.class).item(UserType.F_ORGANIZATION).eqPoly("guľôčka v jamôčke").matchingNorm().build();
RQueryImpl rQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
String real = rQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " u.oid, u.fullObject\n" + "from\n" + " RUser u\n" + " left join u.organization o\n" + "where\n" + " o.norm = :norm");
assertEquals("Wrong parameter value", "gulocka v jamocke", rQuery.getQuerySource().getParameters().get("norm").getValue());
} finally {
close(session);
}
}
use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.
the class QueryInterpreterTest method test017QueryGenericLong.
@Test
public void test017QueryGenericLong() throws Exception {
Session session = open();
try {
/*
* ### generic: And (Equal (name, "generic object", PolyStringNorm),
* Equal (c:extension/p:intType, 123))
* ==> from RGenericObject g
* left join g.longs l (l.ownerType = com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType.EXTENSION and l.name = 'http://example.com/p#intType')
* where
* g.name.norm = 'generic object' and
* l.value = 123
*/
RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, GenericObjectType.class, getQuery(new File(TEST_DIR, "query-and-generic.xml"), GenericObjectType.class), false, null);
String real = realQuery.getQuery().getQueryString();
assertThat(real).isEqualToIgnoringWhitespace("select\n" + " g.oid, g.fullObject\n" + "from\n" + " RGenericObject g\n" + " left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" + "where\n" + " ( g.nameCopy.norm = :norm and l.value = :value )\n");
assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
} finally {
close(session);
}
}
Aggregations