Skip to content

Commit

Permalink
- fix status check on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
psmagin committed Sep 5, 2024
1 parent 1233697 commit 6c94919
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/main/java/org/folio/search/service/reindex/ReindexService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.folio.search.service.reindex;

import static org.folio.search.model.types.ReindexStatus.MERGE_FAILED;
import static org.folio.search.model.types.ReindexStatus.MERGE_IN_PROGRESS;
import static org.folio.search.service.reindex.ReindexConstants.MERGE_RANGE_ENTITY_TYPES;

import java.util.ArrayList;
Expand Down Expand Up @@ -155,19 +157,20 @@ private void validateUploadReindex(String tenantId, List<ReindexEntityType> enti

var statusesByType = statusService.getStatusesByType();

var fullReindexNotComplete = statusesByType.keySet().stream()
.filter(MERGE_RANGE_ENTITY_TYPES::contains)
var mergeNotComplete = statusesByType.entrySet().stream()
.filter(status -> MERGE_RANGE_ENTITY_TYPES.contains(status.getKey()))
.filter(status -> status.getValue().equals(MERGE_IN_PROGRESS) || status.getValue().equals(MERGE_FAILED))
.findFirst();
if (fullReindexNotComplete.isPresent()) {
var mergeEntity = fullReindexNotComplete.get();
if (mergeNotComplete.isPresent()) {
var mergeEntityStatus = mergeNotComplete.get();
// full reindex is either in progress or failed
throw new RequestValidationException(
"Full Reindex Merge is either in progress or failed: %s".formatted(mergeEntity.getType()),
"reindexStatus", statusesByType.get(mergeEntity).getValue());
"Merge phase is in progress or failed for: %s".formatted(mergeEntityStatus.getKey()),
"reindexStatus", mergeEntityStatus.getValue().getValue());
}

var uploadInProgress = entityTypes.stream()
.filter(entityType -> statusesByType.keySet().contains(entityType))
.filter(statusesByType::containsKey)
.filter(entityType -> statusesByType.get(entityType) == ReindexStatus.UPLOAD_IN_PROGRESS)
.findAny();
if (uploadInProgress.isPresent()) {
Expand Down

0 comments on commit 6c94919

Please sign in to comment.