applicationOrExpressions.add(application.ownedGroup.in(getExplicitGroupsForUser(user).list(group))); /*All apps which belong to a group which the user belongs to*/
applicationOrExpressions.add(application.in(getApplicationsWithVersionsInOrgPublishStateForUser(user).list(application))); /*All apps which have versions published to organization for which user belongs to*/
applicationOrExpressions.add(application.ownedGroup.in(getAdminOrganizationGroupsForUser(user).list(group))); /*All apps for organization admins which belong to groups of their organizations*/
applicationOrExpressions.add(application.in(getGuestApplicationsForUser(user).list(application))); /*All apps which have a version with guest access to a group that a user belongs to*/
BooleanExpression applicationOrExpression = BooleanExpression.anyOf(applicationOrExpressions.toArray(new BooleanExpression[applicationOrExpressions.size()]));
// Applications with correct ApplicationTypes
BooleanExpression applicationTypesExpression = null;
if (applicationTypes != null && applicationTypes.length > 0) {
applicationTypesExpression = application.applicationType.in(applicationTypes);
}
// Application Versions are not empty
BooleanExpression applicationVersionsNotEmptyExpression = application.applicationVersions.isNotEmpty();
// Application Versions with downloadable AppState
List<AppState> downloadableAppStates = AppState.getAllDownloadable();
BooleanExpression applicationVersionsDownloadableAppStateExpression = getApplicationVersionAppStateExpression(downloadableAppStates.toArray(new AppState[downloadableAppStates.size()]));
// Applications with Versions in downloadable AppState
BooleanExpression downloadableApplicationVersionsExpression = application.in(subQuery().from(applicationVersion).where(applicationVersionsDownloadableAppStateExpression).list(applicationVersion.application));
// Both Application Versions are not empty and Application contains at least one version not disabled
BooleanExpression applicationVersionsDownloadableExpression = BooleanExpression.allOf(applicationVersionsNotEmptyExpression, downloadableApplicationVersionsExpression);
// Application belongs to Organization which is set as Active Organization on User
BooleanExpression activeOrganizationBooleanExpression = getActiveOrganizationBooleanExpression(organization, user);
BooleanExpression applicationActiveOrg = null;
if(activeOrganizationBooleanExpression != null) {
applicationActiveOrg = application.in(
subQuery().from(application)
.join(application.ownedGroup, group)
.join(group.organization, organization)