-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODORDERS-1174] Filter pieces based on user affiliations
- Loading branch information
1 parent
a8b969a
commit fabdc67
Showing
10 changed files
with
163 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/folio/service/consortium/ConsortiumUserTenantsRetriever.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.folio.service.consortium; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.json.JsonObject; | ||
import org.folio.rest.core.RestClient; | ||
import org.folio.rest.core.models.RequestContext; | ||
import org.folio.rest.core.models.RequestEntry; | ||
|
||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.folio.orders.utils.RequestContextUtil.getUserIdFromContext; | ||
import static org.folio.orders.utils.ResourcePathResolver.CONSORTIA_USER_TENANTS; | ||
import static org.folio.orders.utils.ResourcePathResolver.resourcesPath; | ||
import static org.folio.service.pieces.util.UserTenantFields.COLLECTION_USER_TENANTS; | ||
import static org.folio.service.pieces.util.UserTenantFields.TENANT_ID; | ||
import static org.folio.service.pieces.util.UserTenantFields.USER_ID; | ||
|
||
public class ConsortiumUserTenantsRetriever { | ||
|
||
private static final String CONSORTIA_USER_TENANTS_ENDPOINT = resourcesPath(CONSORTIA_USER_TENANTS); | ||
|
||
private final RestClient restClient; | ||
|
||
public ConsortiumUserTenantsRetriever(RestClient restClient) { | ||
this.restClient = restClient; | ||
} | ||
|
||
public Future<List<String>> getUserTenants(String consortiumId, RequestContext requestContext) { | ||
var userId = getUserIdFromContext(requestContext); | ||
var requestEntry = new RequestEntry(CONSORTIA_USER_TENANTS_ENDPOINT) | ||
.withOffset(0) | ||
.withLimit(Integer.MAX_VALUE) | ||
.withId(consortiumId) | ||
.withQueryParameter(USER_ID.getValue(), userId); | ||
return restClient.getAsJsonObject(requestEntry, requestContext) | ||
.map(this::extractTenantIds); | ||
} | ||
|
||
private List<String> extractTenantIds(JsonObject userTenantCollection) { | ||
var userTenants = userTenantCollection.getJsonArray(COLLECTION_USER_TENANTS.getValue()); | ||
return IntStream.range(0, userTenants.size()) | ||
.mapToObj(userTenants::getJsonObject) | ||
.map(userTenant -> userTenant.getString(TENANT_ID.getValue())) | ||
.toList(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/org/folio/service/pieces/util/UserTenantFields.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.folio.service.pieces.util; | ||
|
||
public enum UserTenantFields { | ||
|
||
USER_ID("userId"), | ||
TENANT_ID("tenantId"), | ||
COLLECTION_USER_TENANTS("userTenants"); | ||
|
||
private final String value; | ||
|
||
UserTenantFields(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters