Skip to content

Commit

Permalink
[MODORDERS-1209-2]. Remove unnecessary tenant validation
Browse files Browse the repository at this point in the history
  • Loading branch information
BKadirkhodjaev committed Dec 20, 2024
1 parent a45584d commit e971d15
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 47 deletions.
14 changes: 2 additions & 12 deletions src/main/java/org/folio/service/pieces/PiecesClaimingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.folio.rest.jaxrs.model.Parameter;
import org.folio.rest.jaxrs.model.Piece;
import org.folio.rest.jaxrs.model.PieceBatchStatusCollection;
import org.folio.rest.tools.utils.TenantTool;
import org.folio.service.caches.ConfigurationEntriesCache;
import org.folio.service.orders.PurchaseOrderLineService;
import org.folio.service.orders.PurchaseOrderStorageService;
Expand All @@ -41,7 +40,6 @@
import static java.util.stream.Collectors.toList;
import static org.folio.models.claiming.IntegrationDetailField.CLAIM_PIECE_IDS;
import static org.folio.models.claiming.IntegrationDetailField.EXPORT_TYPE_SPECIFIC_PARAMETERS;
import static org.folio.models.claiming.IntegrationDetailField.TENANT;
import static org.folio.models.claiming.IntegrationDetailField.VENDOR_EDI_ORDERS_EXPORT_CONFIG;
import static org.folio.orders.utils.HelperUtils.DATA_EXPORT_SPRING_CONFIG_MODULE_NAME;
import static org.folio.orders.utils.HelperUtils.collectResultsOnSuccess;
Expand Down Expand Up @@ -104,7 +102,7 @@ public Future<ClaimingResults> sendClaims(ClaimingCollection claimingCollection,
}
pieceIdsByVendors.forEach((vendor, piecesByVendor) ->
log.info("createVendorPiecePair:: Using pieces by vendor map, vendorId: {}, piecesByVendor: {}", vendor.getId(), piecesByVendor));
var vendorWithoutIntegrationDetails = findFirstMissingVendorWithoutIntegrationDetail(config, pieceIdsByVendors, requestContext);
var vendorWithoutIntegrationDetails = findFirstMissingVendorWithoutIntegrationDetail(config, pieceIdsByVendors);
if (Objects.nonNull(vendorWithoutIntegrationDetails)) {
log.info("sendClaims:: Unable to generate claims because no claim integrations exist - No claims are sent");
throwHttpExceptionOnMissingVendorIntegrationDetails(claimingCollection, vendorWithoutIntegrationDetails);
Expand Down Expand Up @@ -165,13 +163,11 @@ private Future<Pair<Organization, String>> createVendorPiecePair(Pair<String, St
});
}

private Organization findFirstMissingVendorWithoutIntegrationDetail(JsonObject config, Map<Organization, List<String>> pieceIdsByVendors,
RequestContext requestContext) {
private Organization findFirstMissingVendorWithoutIntegrationDetail(JsonObject config, Map<Organization, List<String>> pieceIdsByVendors) {
return pieceIdsByVendors.keySet().stream()
.filter(vendor -> {
var vendorIntegrationDetails = config.stream()
.filter(configEntry -> isExportTypeClaimsAndCorrectVendorId(vendor.getId(), configEntry))
.filter(configEntry -> isCorrectTenant(TenantTool.tenantId(requestContext.getHeaders()), configEntry))
.toList();
log.info("checkVendorIntegrationDetails:: Found vendor integration details, vendorId: {}, integrationDetails: {}", vendor.getId(), vendorIntegrationDetails);
return vendorIntegrationDetails.isEmpty();
Expand Down Expand Up @@ -205,7 +201,6 @@ private List<Future<List<String>>> createUpdatePiecesAndJobFutures(ClaimingColle
var updatePiecesAndJobFutures = new ArrayList<Future<List<String>>>();
pieceIdsByVendor.forEach((vendor, pieceIds) -> config.stream()
.filter(configEntry -> isExportTypeClaimsAndCorrectVendorId(vendor.getId(), configEntry))
.filter(configEntry -> isCorrectTenant(TenantTool.tenantId(requestContext.getHeaders()), configEntry))
.forEach(configEntry -> {
log.info("createUpdatePiecesAndJobFutures:: Preparing job integration detail for vendor, vendor id: {}, pieces: {}, job key: {}",
vendor.getId(), pieceIds.size(), configEntry.getKey());
Expand Down Expand Up @@ -241,11 +236,6 @@ private boolean isExportTypeClaimsAndCorrectVendorId(String vendorId, Map.Entry<
return configEntry.getKey().startsWith(String.format("%s_%s", EXPORT_TYPE_CLAIMS, vendorId)) && Objects.nonNull(configEntry.getValue());
}

private boolean isCorrectTenant(String tenantId, Map.Entry<String, Object> configEntry) {
var integrationDetail = new JsonObject(String.valueOf(configEntry.getValue()));
return integrationDetail.getString(TENANT.getValue()).equals(tenantId);
}

private static Map<Organization, List<String>> transformAndGroupPieceIdsByVendor(List<Pair<Organization, String>> piecesByVendorList) {
return StreamEx.of(piecesByVendorList).distinct().filter(Objects::nonNull)
.groupingBy(Pair::getKey, mapping(Pair::getValue, toList()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.folio.service.pieces;

import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.junit5.VertxExtension;
import io.vertx.junit5.VertxTestContext;
Expand Down Expand Up @@ -33,7 +32,6 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.folio.models.claiming.IntegrationDetailField.CLAIM_PIECE_IDS;
Expand All @@ -42,7 +40,6 @@
import static org.folio.models.claiming.IntegrationDetailField.EXPORT_TYPE_SPECIFIC_PARAMETERS;
import static org.folio.orders.utils.ResourcePathResolver.DATA_EXPORT_SPRING_CREATE_JOB;
import static org.folio.orders.utils.ResourcePathResolver.resourcesPath;
import static org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT;
import static org.folio.rest.core.exceptions.ErrorCodes.CANNOT_FIND_PIECES_WITH_LATE_STATUS_TO_PROCESS;
import static org.folio.rest.core.exceptions.ErrorCodes.CANNOT_RETRIEVE_CONFIG_ENTRIES;
import static org.folio.rest.core.exceptions.ErrorCodes.CANNOT_SEND_CLAIMS_PIECE_IDS_ARE_EMPTY;
Expand Down Expand Up @@ -250,38 +247,6 @@ void testSendClaims_missingOrganizationIntegrationDetailsForThreeOrganizations(V
})));
}

@Test
void testSendClaims_incorrectRequestTenant(VertxTestContext testContext) {
var pieceId = UUID.randomUUID().toString();
var piece = new Piece().withId(pieceId).withPoLineId("poLineId").withReceivingStatus(Piece.ReceivingStatus.LATE);
var claimingCollection = new ClaimingCollection().withClaimingPieceIds(List.of(pieceId));
var requestContext = new RequestContext(Vertx.vertx().getOrCreateContext(), Map.of(OKAPI_HEADER_TENANT, "folio"));

when(configurationEntriesCache.loadConfiguration(any(), any())).thenReturn(Future.succeededFuture(new JsonObject()
.put("CLAIMS_vendorId", createIntegrationDetail())));
when(pieceStorageService.getPiecesByIds(any(), any())).thenReturn(Future.succeededFuture(List.of(piece)));
when(purchaseOrderLineService.getOrderLineById(any(), any())).thenReturn(Future.succeededFuture(new PoLine().withPurchaseOrderId("orderId")));
when(purchaseOrderStorageService.getPurchaseOrderById(any(), any())).thenReturn(Future.succeededFuture(new PurchaseOrder().withVendor("vendorId")));
when(organizationService.getVendorById(any(), any())).thenReturn(Future.succeededFuture(new Organization().withId("vendorId").withCode("VENDOR").withIsVendor(true)));

piecesClaimingService.sendClaims(claimingCollection, requestContext)
.onComplete(testContext.failing(throwable -> testContext.verify(() -> {
Assertions.assertInstanceOf(HttpException.class, throwable);
var httpException = (HttpException) throwable;
var error = httpException.getErrors().getErrors().get(0);
assertEquals(UNABLE_TO_GENERATE_CLAIMS_FOR_ORG_NO_INTEGRATION_DETAILS.getCode(), error.getCode());
assertEquals(String.format(UNABLE_TO_GENERATE_CLAIMS_FOR_ORG_NO_INTEGRATION_DETAILS.getDescription(), "VENDOR"), error.getMessage());
Assertions.assertEquals(2, error.getParameters().size());
var parameter1 = error.getParameters().get(0);
Assertions.assertEquals("pieceId", parameter1.getKey());
Assertions.assertEquals(pieceId, parameter1.getValue());
var parameter2 = error.getParameters().get(1);
Assertions.assertEquals("vendorCode", parameter2.getKey());
Assertions.assertEquals("VENDOR", parameter2.getValue());
testContext.completeNow();
})));
}

@Test
void testSendClaims_success(VertxTestContext testContext) {
var claimingCollection = new ClaimingCollection().withClaimingPieceIds(List.of("pieceId1")).withClaimingInterval(1);
Expand Down

0 comments on commit e971d15

Please sign in to comment.