Search in sources :

Example 6 with QOrgClosure

use of com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure in project midpoint by Evolveum.

the class OrgHierarchyPerfTest method test100Xxx.

@Test
public void test100Xxx() throws Exception {
    given("there are orgs and users, closure is not yet updated");
    OperationResult operationResult = createOperationResult();
    display("Orgs: " + count(QOrg.CLASS));
    display("Users: " + count(QUser.class));
    assertThat(count(new QOrgClosure())).isZero();
    OrgType org1x1x1 = searchObjects(OrgType.class, prismContext.queryFor(OrgType.class).item(ObjectType.F_NAME).eq(PolyString.fromOrig("org1x1x1")).build(), operationResult).get(0);
    when("search for user under some org is initiated");
    SearchResultList<UserType> result = searchObjects(UserType.class, prismContext.queryFor(UserType.class).isChildOf(org1x1x1.getOid()).build(), operationResult);
    then("non-empty result is returned and org closure has been initialized");
    assertThat(result).isNotEmpty();
    assertThat(count(new QOrgClosure())).isPositive();
    display("Orgs: " + count(QOrg.CLASS));
    display("Org closure: " + count(new QOrgClosure()));
    display("Users: " + count(QUser.class));
}
Also used : QOrgClosure(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) SqaleRepoBaseTest(com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)

Example 7 with QOrgClosure

use of com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure in project midpoint by Evolveum.

the class SqaleRepositoryService method isAncestor.

@Override
public <O extends ObjectType> boolean isAncestor(PrismObject<O> object, String descendantOrgOid) {
    Validate.notNull(object, "object must not be null");
    Validate.notNull(descendantOrgOid, "descendantOrgOid must not be null");
    logger.trace("Querying if object {} is ancestor of {}", object.getOid(), descendantOrgOid);
    // object is not considered ancestor of itself
    if (object.getOid() == null || object.getOid().equals(descendantOrgOid)) {
        return false;
    }
    long opHandle = registerOperationStart(OP_IS_ANCESTOR, OrgType.class);
    try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
        jdbcSession.executeStatement("CALL m_refresh_org_closure()");
        QOrgClosure oc = new QOrgClosure();
        long count = jdbcSession.newQuery().from(oc).where(oc.ancestorOid.eq(UUID.fromString(object.getOid())).and(oc.descendantOid.eq(UUID.fromString(descendantOrgOid)))).fetchCount();
        return count != 0L;
    } finally {
        registerOperationFinish(opHandle);
    }
}
Also used : QOrgClosure(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure)

Example 8 with QOrgClosure

use of com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure in project midpoint by Evolveum.

the class OrgFilterProcessor method process.

@Override
public Predicate process(OrgFilter filter) throws QueryException {
    // necessary for lazy refresh of org closure
    context.markContainsOrgFilter();
    FlexibleRelationalPathBase<?> path = context.root();
    if (!(path instanceof QObject)) {
        throw new QueryException("Org filter can only be used for objects," + " not for path " + path + " of type " + path.getClass());
    }
    QObject<?> objectPath = (QObject<?>) path;
    if (filter.isRoot()) {
        QObjectReference<MObject> ref = getNewRefAlias();
        return subQuery(ref).where(ref.ownerOid.eq(objectPath.oid)).notExists();
    }
    if (filter.getOrgRef() == null) {
        throw new QueryException("No organization reference defined in the search query.");
    }
    String oidParam = filter.getOrgRef().getOid();
    if (oidParam == null) {
        throw new QueryException("No oid specified in organization reference " + filter.getOrgRef().debugDump());
    }
    QName relation = filter.getOrgRef().getRelation();
    // null means ANY (not "default") here, so we only search/normalize non-nulls
    Integer relationId = relation != null ? context.repositoryContext().searchCachedRelationId(relation) : null;
    if (filter.getScope() == OrgFilter.Scope.ONE_LEVEL) {
        QObjectReference<MObject> ref = getNewRefAlias();
        SQLQuery<?> subQuery = subQuery(ref).where(ref.ownerOid.eq(objectPath.oid).and(ref.targetOid.eq(UUID.fromString(oidParam))));
        if (relationId != null) {
            subQuery.where(ref.relationId.eq(relationId));
        }
        return subQuery.exists();
    } else if (filter.getScope() == OrgFilter.Scope.SUBTREE) {
        QObjectReference<MObject> ref = getNewRefAlias();
        QOrgClosure oc = getNewClosureAlias();
        SQLQuery<?> subQuery = subQuery(ref).join(oc).on(oc.descendantOid.eq(ref.targetOid)).where(ref.ownerOid.eq(objectPath.oid).and(oc.ancestorOid.eq(UUID.fromString(oidParam))));
        if (relationId != null) {
            subQuery.where(ref.relationId.eq(relationId));
        }
        return subQuery.exists();
    } else if (filter.getScope() == OrgFilter.Scope.ANCESTORS) {
        QOrgClosure oc = getNewClosureAlias();
        return subQuery(oc).where(oc.ancestorOid.eq(objectPath.oid).and(oc.descendantOid.eq(UUID.fromString(oidParam))).and(oc.ancestorOid.ne(oc.descendantOid))).exists();
    } else {
        throw new QueryException("Unknown scope if org filter: " + filter);
    }
}
Also used : QName(javax.xml.namespace.QName) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) SQLQuery(com.querydsl.sql.SQLQuery) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) QOrgClosure(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) QObjectReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference)

Aggregations

QOrgClosure (com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)6 SqaleRepoBaseTest (com.evolveum.midpoint.repo.sqale.SqaleRepoBaseTest)3 QObject (com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)3 SQLQuery (com.querydsl.sql.SQLQuery)3 Test (org.testng.annotations.Test)3 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)2 MObject (com.evolveum.midpoint.repo.sqale.qmodel.object.MObject)2 QOrg (com.evolveum.midpoint.repo.sqale.qmodel.org.QOrg)2 QObjectReference (com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference)2 SqlPerformanceMonitorImpl (com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl)2 FlexibleRelationalPathBase (com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase)2 com.evolveum.midpoint.schema (com.evolveum.midpoint.schema)2 SchemaConstants (com.evolveum.midpoint.schema.constants.SchemaConstants)2 SQLException (java.sql.SQLException)2 AuditEventRecord (com.evolveum.midpoint.audit.api.AuditEventRecord)1 AuditEventStage (com.evolveum.midpoint.audit.api.AuditEventStage)1 AuditEventType (com.evolveum.midpoint.audit.api.AuditEventType)1 CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1