-
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.
Merge branch 'master' into MODORDERS-1162
- Loading branch information
Showing
17 changed files
with
286 additions
and
25 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
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
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
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.rest.RestConstants.PATH_PARAM_PLACE_HOLDER; | ||
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 url = CONSORTIA_USER_TENANTS_ENDPOINT.replace(PATH_PARAM_PLACE_HOLDER, consortiumId); | ||
var requestEntry = new RequestEntry(url) | ||
.withOffset(0) | ||
.withLimit(Integer.MAX_VALUE) | ||
.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
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
Oops, something went wrong.