From 0a43c138d2e5d919cb5aa14490d803311edbe8cf Mon Sep 17 00:00:00 2001 From: siarhei-charniak Date: Fri, 16 Aug 2024 12:37:07 +0300 Subject: [PATCH] MODBULKOPS-331 - Optimisation of FQM query invocation (#253) --- .../bulkops/service/BulkOperationService.java | 12 ++---- .../swagger.api/schemas/query-request.json | 7 +++- .../service/BulkOperationServiceTest.java | 37 ------------------- 3 files changed, 9 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/folio/bulkops/service/BulkOperationService.java b/src/main/java/org/folio/bulkops/service/BulkOperationService.java index 71c2afb7..28ceec81 100644 --- a/src/main/java/org/folio/bulkops/service/BulkOperationService.java +++ b/src/main/java/org/folio/bulkops/service/BulkOperationService.java @@ -78,7 +78,6 @@ import org.folio.bulkops.repository.BulkOperationExecutionRepository; import org.folio.bulkops.repository.BulkOperationRepository; import org.folio.bulkops.util.Utils; -import org.folio.querytool.domain.dto.SubmitQuery; import org.folio.spring.FolioExecutionContext; import org.folio.spring.FolioModuleMetadata; import org.folio.spring.scope.FolioExecutionContextSetter; @@ -196,21 +195,16 @@ public BulkOperation uploadCsvFile(EntityType entityType, IdentifierType identif } public BulkOperation triggerByQuery(UUID userId, QueryRequest queryRequest) { - var submitQuery = new SubmitQuery() - .fqlQuery(queryRequest.getFqlQuery()) - .entityTypeId(queryRequest.getEntityTypeId()); - var queryId = queryService.executeQuery(submitQuery); - var entityType = entityTypeService.getEntityTypeById(submitQuery.getEntityTypeId()); return bulkOperationRepository.save(BulkOperation.builder() .id(UUID.randomUUID()) - .entityType(entityType) + .entityType(entityTypeService.getEntityTypeById(queryRequest.getEntityTypeId())) .approach(QUERY) .identifierType(IdentifierType.ID) .status(EXECUTING_QUERY) .startTime(LocalDateTime.now()) .userId(userId) - .fqlQuery(submitQuery.getFqlQuery()) - .fqlQueryId(queryId) + .fqlQuery(queryRequest.getFqlQuery()) + .fqlQueryId(queryRequest.getQueryId()) .userFriendlyQuery(queryRequest.getUserFriendlyQuery()) .build()); } diff --git a/src/main/resources/swagger.api/schemas/query-request.json b/src/main/resources/swagger.api/schemas/query-request.json index 1b852920..ff570fe3 100644 --- a/src/main/resources/swagger.api/schemas/query-request.json +++ b/src/main/resources/swagger.api/schemas/query-request.json @@ -5,6 +5,11 @@ "description": "Query request body", "type": "object", "properties": { + "queryId": { + "description": "FQL query identifier", + "type": "string", + "format": "uuid" + }, "fqlQuery": { "description": "FQL string", "type": "string" @@ -20,7 +25,7 @@ } }, "required": [ - "fqlQuery", + "queryId", "entityTypeId" ], "additionalProperties": false diff --git a/src/test/java/org/folio/bulkops/service/BulkOperationServiceTest.java b/src/test/java/org/folio/bulkops/service/BulkOperationServiceTest.java index 1f41841f..ec82489d 100644 --- a/src/test/java/org/folio/bulkops/service/BulkOperationServiceTest.java +++ b/src/test/java/org/folio/bulkops/service/BulkOperationServiceTest.java @@ -51,7 +51,6 @@ import java.util.UUID; import lombok.SneakyThrows; import org.apache.commons.lang3.StringUtils; -import org.assertj.core.api.Assertions; import org.awaitility.Awaitility; import org.folio.bulkops.BaseTest; import org.folio.bulkops.client.BulkEditClient; @@ -84,7 +83,6 @@ import org.folio.bulkops.domain.dto.MarcAction; import org.folio.bulkops.domain.dto.OperationStatusType; import org.folio.bulkops.domain.dto.Parameter; -import org.folio.bulkops.domain.dto.QueryRequest; import org.folio.bulkops.domain.dto.UpdateActionType; import org.folio.bulkops.domain.dto.UpdateOptionType; import org.folio.bulkops.domain.entity.BulkOperation; @@ -100,7 +98,6 @@ import org.folio.bulkops.repository.BulkOperationExecutionRepository; import org.folio.bulkops.repository.BulkOperationRepository; import org.folio.bulkops.util.ErrorCode; -import org.folio.querytool.domain.dto.SubmitQuery; import org.folio.s3.client.FolioS3Client; import org.folio.s3.client.RemoteStorageWriter; import org.folio.s3.exception.S3ClientException; @@ -153,15 +150,9 @@ class BulkOperationServiceTest extends BaseTest { @MockBean private ItemReferenceService itemReferenceService; - @MockBean - private NoteTableUpdater noteTableUpdater; - @MockBean private QueryService queryService; - @MockBean - private EntityTypeService entityTypeService; - @MockBean private ConsortiaService consortiaService; @@ -1370,34 +1361,6 @@ void shouldUpdateItemsWhenCommittingHoldingsRecordDiscoverySuppressed(DiscoveryS } } - @Test - void testQueryExecution() { - var fqlQueryId = UUID.randomUUID(); - var entityTypeId = UUID.randomUUID(); - var query = "query"; - var queryRequest = new QueryRequest() - .fqlQuery(query) - .userFriendlyQuery(query) - .entityTypeId(entityTypeId); - var submitQuery = new SubmitQuery() - .fqlQuery(query) - .entityTypeId(entityTypeId); - when(queryService.executeQuery(submitQuery)).thenReturn(fqlQueryId); - when(entityTypeService.getEntityTypeById(entityTypeId)).thenReturn(ITEM); - - bulkOperationService.triggerByQuery(UUID.randomUUID(), queryRequest); - - verify(queryService).executeQuery(submitQuery); - var operationCaptor = ArgumentCaptor.forClass(BulkOperation.class); - verify(bulkOperationRepository).save(operationCaptor.capture()); - var operation = operationCaptor.getValue(); - Assertions.assertThat(operation.getEntityType()).isEqualTo(ITEM); - Assertions.assertThat(operation.getIdentifierType()).isEqualTo(IdentifierType.ID); - Assertions.assertThat(operation.getStatus()).isEqualTo(EXECUTING_QUERY); - Assertions.assertThat(operation.getFqlQueryId()).isEqualTo(fqlQueryId); - Assertions.assertThat(operation.getFqlQuery()).isEqualTo(query); - } - @Test void shouldCheckQueryExecution() { var operationId = UUID.randomUUID();