Skip to content

Commit

Permalink
MODBULKOPS-331 - Optimisation of FQM query invocation (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
siarhei-charniak authored Aug 16, 2024
1 parent 08603bc commit 0a43c13
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/swagger.api/schemas/query-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -20,7 +25,7 @@
}
},
"required": [
"fqlQuery",
"queryId",
"entityTypeId"
],
"additionalProperties": false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0a43c13

Please sign in to comment.