Examples of JPASubQuery


Examples of com.mysema.query.jpa.JPASubQuery

        List<BooleanExpression> expressions = new ArrayList<BooleanExpression>();
        expressions.add(userDomain.domain.id.eq(orgId));

        if (includeGroups) {
            JPASubQuery groupSubQuery = subQuery().from(group).where(group.organization.id.eq(orgId));
            JPASubQuery groupUserDomainsSubQuery = subQuery().from(userDomain).where(userDomain.domain.in(groupSubQuery.list(group)));

            expressions.add(userDomain.in(groupUserDomainsSubQuery.list(userDomain)));
        }

        JPASubQuery userIdSubQuery = subQuery().from(userDomain).where(BooleanExpression.anyOf(expressions.toArray(new BooleanExpression[expressions.size()]))).groupBy(userDomain.user.id);
        ListSubQuery<Long> userIds = userIdSubQuery.list(userDomain.user.id);

        return cacheableQuery().from(user)
                .where(user.id.in(userIds))
                .distinct().count();
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

    @Override
    public List<Group> getAdministeredGroupsForUser(User user) {

        // All UserDomains for User with UserRole.ROLE_ORG_ADMIN
        JPASubQuery userDomainsOrgAdmin = subQuery().from(userDomain)
                .where(userDomain.user.eq(user),
                        userDomain.role.authority.eq(UserRole.ROLE_ORG_ADMIN.toString()));

        // All UserDomains for User with UserRole.ROLE_GROUP_ADMIN
        JPASubQuery userDomainsGroupAdmin = subQuery().from(userDomain)
                .where(userDomain.user.eq(user),
                        userDomain.role.authority.eq(UserRole.ROLE_GROUP_ADMIN.toString()));

        // GroupAdmin domains
        JPASubQuery groupAdminDomains = subQuery().from(domain)
                .where(domain.in(
                        userDomainsGroupAdmin.list(userDomain.domain)
                ));

        // All Organizations which the User is an admin
        JPASubQuery adminOrganizations = subQuery().from(organization)
                .where(organization.in(
                        subQuery().from(domain)
                                .where(domain.in(
                                        userDomainsOrgAdmin.list(userDomain.domain))
                                ).list(domain.as(organization.getClass()))
                ).and(getActiveOrganizationBooleanExpression(organization, user)));

        // All groups which are part of an organization which the users is an admin of
        JPASubQuery adminOrganizationGroups = subQuery().from(group)
                .where(group.organization.in(
                        adminOrganizations.list(organization)
                ));

        // Main Query - All Groups which the user is a direct admin (ROLE_GROUP_ADMIN) or through organizations which the user is an admin (ROLE_ORG_ADMIN)
        JPAQuery mainQuery = cacheableQuery().from(group)
                .where((group.in(
                        adminOrganizationGroups.list(group))
                        .or(group.in(groupAdminDomains.list(domain.as(group.getClass()))))).and(getActiveOrganizationBooleanExpression(group.organization, user))
                );

        return mainQuery.distinct().list(group);
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

        return mainQuery.distinct().list(group);
    }

    @Override
    public List<Group> getGroupsForUser(User user) {
        JPASubQuery userGroups = getAllGroupsForUser(user);

        // Main query - All Groups which the user is a direct member (ROLE_GROUP_ADMIN or ROLE_GROUP_USER) or through organizations which the user is an admin (ROLE_ORG_ADMIN)
        JPAQuery mainQuery = cacheableQuery().from(group)
                .where(group.in(
                        userGroups.list(group)));

        return mainQuery.distinct().list(group);
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

        return mainQuery.distinct().list(group);
    }

    @Override
    public List<Group> getGroupsForUserActiveOrganization(User user) {
        JPASubQuery userGroups = getAllGroupsForUser(user);

        // Main query - All Groups which the user is a direct member (ROLE_GROUP_ADMIN or ROLE_GROUP_USER) or through organizations which the user is an admin (ROLE_ORG_ADMIN)
        JPAQuery mainQuery = query().from(group)
                .join(group.organization, organization)
                .where(group.in(userGroups.list(group))
                        .and(getActiveOrganizationBooleanExpression(organization, user)));

        return mainQuery.distinct().list(group);
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

    /**
     * @return JPASubQuery
     */
    public JPASubQuery subQuery() {
        return new JPASubQuery();
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

    @Override
    public List<ApplicationVersion> getAllByApplicationForUser(long applicationId, User user) {

        List<AppState> downloadableAppStates = AppState.getAllDownloadable();

        JPASubQuery availableApplicationsForUser = subQuery().from(application).where(getApplicationForUserBooleanExpression(user));

        // ApplicationVersion belongs to a group which a users has access
        BooleanExpression applicationVersionOwnedGroup = applicationVersion.in(subQuery().from(applicationVersion).join(applicationVersion.application, application).where(application.ownedGroup.in(getAllGroupsForUser(user).list(group))).list(applicationVersion));

        // ApplicationVersion is shared to a Guest Group which a user belongs
        BooleanExpression applicationVersionGuestGroup = applicationVersion.in(subQuery().from(applicationVersion).join(applicationVersion.guestGroups, group).where(group.in(getAllGroupsForUser(user).list(group))).list(applicationVersion));

        BooleanExpression applicationVersionOrgPublish = applicationVersion.appState.eq(AppState.ORGANIZATION_PUBLISH)
                .and(applicationVersion.in(subQuery().from(applicationVersion)
                        .join(applicationVersion.application, application)
                        .join(application.ownedGroup, group)
                        .join(group.organization, organization)
                        .where(organization.in(getExplicitOrganizationsForUser(user).list(organization))).list(applicationVersion)));

        return cacheableQuery().from(applicationVersion)
                .where(applicationVersion.application.id.eq(applicationId) /* ApplicationVersion belongs to specified Application */
                        .and(applicationVersion.application.in(availableApplicationsForUser.list(application))) /* ApplicationVersion belongs to an application which the user has access */
                        .and(getApplicationVersionAppStateExpression(downloadableAppStates.toArray(new AppState[downloadableAppStates.size()]))) /* ApplicationVersion is in a downloadable AppState */
                        .and(applicationVersionOwnedGroup /* ApplicationVersion belongs to a group which a users has access */
                                .or(applicationVersionGuestGroup) /* ApplicationVersion is shared to a Guest Group which a user belongs */
                                .or(applicationVersionOrgPublish)
                        )
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

    }

    @Override
    public List<Category> getAllForUser(User user, ApplicationType deviceType) {

        JPASubQuery applicationsForUser = getApplicationsForUser(user, ApplicationType.getAllForUserDeviceType(deviceType).toArray(new ApplicationType[]{}));

        return cacheableQuery().from(category)
                .where(category.in(applicationsForUser.list(application.category)))
                .distinct().list(category);
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

        return query().from(invitation).where(invitation.domain.id.eq(domainId)).distinct().count();
    }

    @Override
    public long countAllForOrganizationIncludingGroups(long organizationId) {
        JPASubQuery invitationIdSubQuery = subQuery().from(invitation)
                .where(invitation.domain.id.in(
                        subQuery().from(group)
                                .where(group.organization.id.eq(organizationId))
                                .list(group.id)
                ).or(invitation.domain.id.eq(organizationId)));
        ListSubQuery<Invitation> invitationEmails = invitationIdSubQuery.list(invitation);

        return query().from(invitation).where(invitation.in(invitationEmails)).count();
    }
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

        // Boolean expression for organization
        domainExpressions.add(invitation.domain.id.eq(organizationId));

        if (includeGroups) {
            // SubQuery to get all groups for an Organization
            JPASubQuery groupsForOrganization = subQuery().from(group).where(group.organization.id.eq(organizationId));

            // Boolean expression for groups
            domainExpressions.add(invitation.domain.id.in(groupsForOrganization.list(group.id)));
        }

        ListSubQuery<String> emailListSubQuery = subQuery().from(invitation)
                .where(invitation.email.in(emails)
                        .and(BooleanExpression.anyOf(domainExpressions.toArray(new BooleanExpression[domainExpressions.size()])))
View Full Code Here

Examples of com.mysema.query.jpa.JPASubQuery

public class PackagelessEntityTest {
   
    @SuppressWarnings("unchecked")
    @Test
    public void PackageLess_Path() {
        JPASubQuery query = new JPASubQuery();
        PathBuilder builder = new PathBuilder(PackagelessEntityTest.class,"entity");
        query.from(builder);
        assertEquals("select entity\nfrom PackagelessEntityTest entity", query.toString());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.