Skip to content

Commit

Permalink
[MODORDERS-1143] Fix filtering for member tenants
Browse files Browse the repository at this point in the history
  • Loading branch information
Saba-Zedginidze-EPAM committed Sep 19, 2024
1 parent fe1e614 commit 11960d5
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.folio.rest.jaxrs.model.PieceCollection;

import io.vertx.core.Future;
import org.folio.rest.tools.utils.TenantTool;
import org.folio.service.consortium.ConsortiumUserTenantsRetriever;
import org.folio.service.consortium.ConsortiumConfigurationService;

Expand Down Expand Up @@ -136,6 +137,7 @@ public Future<PieceCollection> getAllPieces(int limit, int offset, String query,
private Future<List<Piece>> filterPiecesByUserTenantsIfNecessary(List<Piece> pieces, RequestContext requestContext) {
return consortiumConfigurationService.getConsortiumConfiguration(requestContext)
.compose(consortiumConfiguration -> consortiumConfiguration
.filter(configuration -> shouldFilterPiecesForTenant(configuration.centralTenantId(), requestContext))
.map(configuration -> consortiumUserTenantsRetriever.getUserTenants(configuration.consortiumId(), requestContext)
.map(userTenants -> filterPiecesByUserTenants(pieces, userTenants)))
.orElse(Future.succeededFuture(pieces)));
Expand Down Expand Up @@ -185,4 +187,9 @@ private Future<List<Piece>> getPieceChunkByLineIds(Collection<String> poLineIds,
.map(PieceCollection::getPieces);
}

private static boolean shouldFilterPiecesForTenant(String centralTenantId, RequestContext requestContext) {
var requestTenantId = TenantTool.tenantId(requestContext.getHeaders());
return requestTenantId.equals(centralTenantId);
}

}

0 comments on commit 11960d5

Please sign in to comment.