Skip to content

Commit

Permalink
MODSOURCE-817: fix sonar quality gate issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mukhiddin-yusuf committed Nov 26, 2024
1 parent c04d831 commit 80c6847
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -956,14 +956,14 @@ private RecordsBatchResponse saveRecords(RecordCollection recordCollection, Stri
.commitAfter(1000)
.onErrorAbort()
.loadRecords(dbRecords.stream()
.map(record -> {
Integer generation = matchedGenerations.get(record.getMatchedId());
.map(recordDto -> {
Integer generation = matchedGenerations.get(recordDto.getMatchedId());
if (Objects.nonNull(generation)) {
record.setGeneration(generation + 1);
} else if (Objects.isNull(record.getGeneration())) {
record.setGeneration(0);
recordDto.setGeneration(generation + 1);
} else if (Objects.isNull(recordDto.getGeneration())) {
recordDto.setGeneration(0);
}
return record;
return recordDto;
})
.toList())
.fieldsCorresponding()
Expand Down Expand Up @@ -1025,14 +1025,14 @@ private RecordsBatchResponse saveRecords(RecordCollection recordCollection, Stri
}
}

private void validateRecordType(Record record, RecordType recordType) {
if (record.getRecordType() == null) {
var error = record.getErrorRecord() != null ? record.getErrorRecord().getDescription() : "";
private void validateRecordType(Record recordDto, RecordType recordType) {
if (recordDto.getRecordType() == null) {
var error = recordDto.getErrorRecord() != null ? recordDto.getErrorRecord().getDescription() : "";
throw new BadRequestException(
StringUtils.defaultIfEmpty(error, String.format("Record with id %s has not record type", record.getId())));
StringUtils.defaultIfEmpty(error, String.format("Record with id %s has not record type", recordDto.getId())));
}

if (RecordType.valueOf(record.getRecordType().name()) != recordType) {
if (RecordType.valueOf(recordDto.getRecordType().name()) != recordType) {
throw new BadRequestException("Batch record collection only supports single record type");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ public Future<RecordsBatchResponse> saveRecordsByExternalIds(List<String> extern
RecordsModifierOperator recordsModifier,
Map<String, String> okapiHeaders) {
if (CollectionUtils.isEmpty(externalIds)) {
LOG.warn("saveRecordsBlocking:: Skipping the records save, no external IDs are provided");
LOG.warn("saveRecordsByExternalIds:: Skipping the records save, no external IDs are provided");
return Future.succeededFuture(new RecordsBatchResponse().withTotalRecords(0));
}

if (recordsModifier == null) {
LOG.warn("saveRecordsBlocking:: Skipping the records save, no operator is provided to modify the existing records");
LOG.warn("saveRecordsByExternalIds:: Skipping the records save, no operator is provided to modify the existing records");
return Future.succeededFuture(new RecordsBatchResponse().withTotalRecords(0));
}

Expand All @@ -210,8 +210,12 @@ public Future<RecordsBatchResponse> saveRecordsByExternalIds(List<String> extern
.toCompletionStage().toCompletableFuture().get();
}
return recordCollection;
} catch (InterruptedException | ExecutionException ex) {
LOG.warn("saveRecordsBlocking:: Failed to set record matched id: {}", ex.getMessage());
} catch (InterruptedException ex) {
LOG.warn("saveRecordsByExternalIds:: Setting record matched id is interrupted: {}", ex.getMessage());
Thread.currentThread().interrupt();
throw new RecordUpdateException(ex.getMessage());
} catch (ExecutionException ex) {
LOG.warn("saveRecordsByExternalIds:: Failed to set record matched id: {}", ex.getMessage());
throw new RecordUpdateException(ex.getMessage());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import io.reactivex.Flowable;
import io.vertx.core.AsyncResult;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.json.JsonArray;
Expand Down Expand Up @@ -62,7 +61,6 @@
import org.folio.rest.jaxrs.model.RecordsBatchResponse;
import org.folio.rest.jaxrs.model.Snapshot;
import org.folio.rest.jaxrs.model.SourceRecord;
import org.folio.rest.jaxrs.model.SourceRecordCollection;
import org.folio.rest.jaxrs.model.StrippedParsedRecord;
import org.folio.rest.jooq.enums.RecordState;
import org.folio.services.domainevent.RecordDomainEventPublisher;
Expand Down

0 comments on commit 80c6847

Please sign in to comment.