Search in sources :

Example 1 with BRANCH

use of com.b2international.index.revision.Commit.Fields.BRANCH in project snow-owl by b2ihealthcare.

the class CommitInfoSearchRequest method addSecurityFilter.

private void addSecurityFilter(final ExpressionBuilder builder, RepositoryContext context) {
    final User user = context.service(User.class);
    if (user.isAdministrator() || user.hasPermission(Permission.requireAll(Permission.OPERATION_BROWSE, Permission.ALL))) {
        return;
    }
    final List<Permission> readPermissions = user.getPermissions().stream().filter(p -> Permission.ALL.equals(p.getOperation()) || Permission.OPERATION_BROWSE.equals(p.getOperation())).collect(Collectors.toList());
    final Set<String> exactResourceIds = readPermissions.stream().flatMap(p -> p.getResources().stream()).filter(resource -> !resource.endsWith("*")).collect(Collectors.toSet());
    final Set<String> resourceIdPrefixes = readPermissions.stream().flatMap(p -> p.getResources().stream()).filter(resource -> isWildCardResource(resource)).map(resource -> resource.substring(0, resource.length() - 1)).collect(Collectors.toSet());
    SetView<String> resourceIds = Sets.union(exactResourceIds, resourceIdPrefixes);
    ExpressionBuilder branchFilter = Expressions.builder();
    ResourceRequests.prepareSearch().filterByIds(resourceIds).setLimit(resourceIds.size()).setFields(ResourceDocument.Fields.ID, ResourceDocument.Fields.BRANCH_PATH, ResourceDocument.Fields.RESOURCE_TYPE).buildAsync().getRequest().execute(context).stream().filter(TerminologyResource.class::isInstance).map(TerminologyResource.class::cast).forEach(r -> {
        if (resourceIdPrefixes.contains(r.getId())) {
            final String branchPattern = String.format("%s(/[a-zA-Z0-9.~_\\-]{1,%d})?", r.getBranchPath(), DEFAULT_MAXIMUM_BRANCH_NAME_LENGTH);
            branchFilter.should(regexp(BRANCH, branchPattern));
        }
    });
    builder.filter(branchFilter.build());
}
Also used : TerminologyResource(com.b2international.snowowl.core.TerminologyResource) Expressions(com.b2international.index.revision.Commit.Expressions) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) ResourceRequests(com.b2international.snowowl.core.request.ResourceRequests) Hits(com.b2international.index.Hits) DEFAULT_MAXIMUM_BRANCH_NAME_LENGTH(com.b2international.index.revision.RevisionBranch.DEFAULT_MAXIMUM_BRANCH_NAME_LENGTH) Collection(java.util.Collection) Set(java.util.Set) Commit(com.b2international.index.revision.Commit) SetView(com.google.common.collect.Sets.SetView) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument) Expressions.regexp(com.b2international.index.query.Expressions.regexp) List(java.util.List) SearchIndexResourceRequest(com.b2international.snowowl.core.request.SearchIndexResourceRequest) Expressions(com.b2international.index.query.Expressions) Permission.isWildCardResource(com.b2international.snowowl.core.identity.Permission.isWildCardResource) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Expression(com.b2international.index.query.Expression) Permission(com.b2international.snowowl.core.identity.Permission) User(com.b2international.snowowl.core.identity.User) BRANCH(com.b2international.index.revision.Commit.Fields.BRANCH) User(com.b2international.snowowl.core.identity.User) Permission(com.b2international.snowowl.core.identity.Permission) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder)

Aggregations

Hits (com.b2international.index.Hits)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)1 Expressions.regexp (com.b2international.index.query.Expressions.regexp)1 Commit (com.b2international.index.revision.Commit)1 Expressions (com.b2international.index.revision.Commit.Expressions)1 BRANCH (com.b2international.index.revision.Commit.Fields.BRANCH)1 DEFAULT_MAXIMUM_BRANCH_NAME_LENGTH (com.b2international.index.revision.RevisionBranch.DEFAULT_MAXIMUM_BRANCH_NAME_LENGTH)1 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)1 RepositoryContext (com.b2international.snowowl.core.domain.RepositoryContext)1 Permission (com.b2international.snowowl.core.identity.Permission)1 Permission.isWildCardResource (com.b2international.snowowl.core.identity.Permission.isWildCardResource)1 User (com.b2international.snowowl.core.identity.User)1 ResourceDocument (com.b2international.snowowl.core.internal.ResourceDocument)1 ResourceRequests (com.b2international.snowowl.core.request.ResourceRequests)1 SearchIndexResourceRequest (com.b2international.snowowl.core.request.SearchIndexResourceRequest)1 Sets (com.google.common.collect.Sets)1 SetView (com.google.common.collect.Sets.SetView)1 Collection (java.util.Collection)1