Search in sources :

Example 6 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test033QueryOrComposite.

@Test
public void test033QueryOrComposite() throws Exception {
    Session session = open();
    try {
        /*
             * ### shadow:
             *      Or (
             *        Equal (intent, "some account type"),
             *        Equal (attributes/f:foo, "foo value"),
             *        Equal (extension/p:stringType, "uid=test,dc=example,dc=com"),
             *        Ref (resourceRef, d0db5be9-cb93-401f-b6c1-86ffffe4cd5e))
             *
             * ==> from RShadow r left join r.strings s1 where
             *       r.intent = 'some account type' or
             *         (s1.ownerType = RObjectExtensionType.ATTRIBUTES and s1.name = 'http://midpoint.evolveum.com/blabla#foo' and s1.value = 'foo value') or
             *         (s1.ownerType = RObjectExtensionType.EXTENSION and s1.name = 'http://example.com/p#stringType' and s1.value = 'uid=test,dc=example,dc=com') or
             *         (r.resourceRef.targetOid = 'd0db5be9-cb93-401f-b6c1-86ffffe4cd5e' and r.resourceRef.relation = '#' and r.resourceRef.type = '...#ResourceType')
             *
             *   [If we used AND instead of OR, this SHOULD BE left join r.strings s1, left join r.strings s2]
             */
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ShadowType.class, getQuery(new File(TEST_DIR, "query-or-composite.xml"), ShadowType.class), false, null);
        /*
                ownerType = ATTRIBUTES (com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType.ATTRIBUTES)
                name = http://midpoint.evolveum.com/blabla#foo
                value = foo value
                ownerType2 = com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType.EXTENSION
                name2 = http://example.com/p#stringType
                value2 = uid=test,dc=example,dc=com
                intent = some account type
                targetOid = d0db5be9-cb93-401f-b6c1-86ffffe4cd5e
                relation = ...
                type = com.evolveum.midpoint.repo.sql.data.common.other.RObjectType.RESOURCE
             */
        assertThat(realQuery.getQuery().getQueryString()).isEqualToIgnoringWhitespace("select\n" + "  s.oid, s.fullObject\n" + "from\n" + "  RShadow s\n" + "    left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + "    left join s.strings s3 with ( s3.ownerType = :ownerType2 and s3.itemId = :itemId2 )\n" + "where\n" + "  (\n" + "    s.intent = :intent or\n" + "    s2.value = :value or\n" + "    s3.value = :value2 or\n" + "    (\n" + "      s.resourceRef.targetOid = :targetOid and\n" + "      s.resourceRef.relation in (:relation)\n" + "    )\n" + "  )\n");
        assertEquals("Wrong property ID for 'foo'", fooDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
        assertEquals("Wrong property ID for 'stringType'", stringTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId2").getValue());
        System.out.println("Query parameters: " + realQuery.getQuerySource().getParameters());
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 7 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test080QueryUserAssignmentTargetRef.

@Test
public void test080QueryUserAssignmentTargetRef() throws Exception {
    Session session = open();
    try {
        /*
             * ### user: Ref (assignment/targetRef, '123', RoleType)
             *
             * ==> select from RUser u left join u.assignments a where
             *        a.assignmentOwner = RAssignmentOwner.FOCUS and
             *        a.targetRef.targetOid = '123' and
             *        a.targetRef.relation = '#' and
             *        a.targetRef.type = RObjectType.ROLE
             */
        ObjectReferenceType ort = new ObjectReferenceType();
        ort.setOid("123");
        ort.setType(RoleType.COMPLEX_TYPE);
        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<>(getVariantsOfDefaultRelation()), new HashSet<>(relationParameter));
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) SelectorOptions.createCollection(com.evolveum.midpoint.schema.SelectorOptions.createCollection) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 8 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test031QueryAccountByAttributeAndExtensionValue.

@Test
public void test031QueryAccountByAttributeAndExtensionValue() throws Exception {
    Session session = open();
    try {
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, ShadowType.class, getQuery(new File(TEST_DIR, "query-account-by-attribute-and-extension-value.xml"), ShadowType.class), false, null);
        assertThat(realQuery.getQuery().getQueryString()).isEqualToIgnoringWhitespace("select\n" + "  s.oid, s.fullObject\n" + "from\n" + "  RShadow s\n" + "    left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" + "    left join s.longs l with ( l.ownerType = :ownerType2 and l.itemId = :itemId2 )\n" + "where\n" + "  (\n" + "    s2.value = :value and\n" + "    l.value = :value2\n" + "  )");
        assertEquals("Wrong property ID for 'a1'", a1Definition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
        assertEquals("Wrong property ID for 'shoeSize'", shoeSizeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId2").getValue());
    } finally {
        close(session);
    }
}
Also used : RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) File(java.io.File) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 9 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test185QueryExtensionEnum.

@Test
public void test185QueryExtensionEnum() throws Exception {
    Session session = open();
    try {
        ObjectQuery query = prismContext.queryFor(UserType.class).item(F_EXTENSION, new QName("overrideActivation")).eq(ActivationStatusType.ENABLED).build();
        RQueryImpl realQuery = (RQueryImpl) getInterpretedQueryWhole(session, UserType.class, query, false, null);
        String real = realQuery.getQuery().getQueryString();
        assertThat(real).isEqualToIgnoringWhitespace("select\n" + "  u.oid, u.fullObject\n" + "from\n" + "  RUser u\n" + "    left join u.strings s with (\n" + "          s.ownerType = :ownerType and\n" + "          s.itemId = :itemId\n" + ")\n" + "where\n" + "  s.value = :value\n");
        assertEquals("Wrong property ID for 'overrideActivation'", overrideActivationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
    } finally {
        close(session);
    }
}
Also used : QName(javax.xml.namespace.QName) RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Example 10 with RQueryImpl

use of com.evolveum.midpoint.repo.sql.query.RQueryImpl in project midpoint by Evolveum.

the class QueryInterpreterTest method test083QueryUserAssignmentTargetRefManagerCustomQualified.

@Test
public void test083QueryUserAssignmentTargetRefManagerCustomQualified() throws Exception {
    Session session = open();
    try {
        QName auditorRelation = new QName("http://x/", "auditor");
        ObjectReferenceType ort = new ObjectReferenceType().oid("123").type(OrgType.COMPLEX_TYPE).relation(auditorRelation);
        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 = :relation and\n" + "    a.targetRef.targetType = :targetType\n" + "  )\n");
        String relationParameter = (String) rQuery.getQuerySource().getParameters().get("relation").getValue();
        assertEquals("Wrong relation parameter value", RUtil.qnameToString(auditorRelation), relationParameter);
    } finally {
        close(session);
    }
}
Also used : QName(javax.xml.namespace.QName) RQueryImpl(com.evolveum.midpoint.repo.sql.query.RQueryImpl) Session(org.hibernate.Session) Test(org.testng.annotations.Test)

Aggregations

RQueryImpl (com.evolveum.midpoint.repo.sql.query.RQueryImpl)18 Session (org.hibernate.Session)17 Test (org.testng.annotations.Test)17 SelectorOptions.createCollection (com.evolveum.midpoint.schema.SelectorOptions.createCollection)7 QName (javax.xml.namespace.QName)4 File (java.io.File)3 QueryEngine (com.evolveum.midpoint.repo.sql.query.QueryEngine)1 RQuery (com.evolveum.midpoint.repo.sql.query.RQuery)1 QueryParameterValue (com.evolveum.midpoint.repo.sql.query.hqm.QueryParameterValue)1 RootHibernateQuery (com.evolveum.midpoint.repo.sql.query.hqm.RootHibernateQuery)1 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1