Skip to content

Commit

Permalink
fix(pub-period-migration) fix Sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
SvitlanaKovalova1 committed Oct 23, 2024
1 parent a7831b4 commit 9322a53
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
10 changes: 7 additions & 3 deletions src/main/java/org/folio/persist/AbstractRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public <V> Future<Map<String, T>> getById(Collection<V> records, Function<V, Str
public Future<RowSet<Row>> update(AsyncResult<SQLConnection> connection, String id, T entity) {
final Promise<RowSet<Row>> promise = promise();

postgresClient.update(connection, tableName, entity, "jsonb",
postgresClient.update(connection, tableName, entity, JSON_COLUMN,
format("WHERE id = '%s'", id), false, promise);

return promise.future();
Expand Down Expand Up @@ -138,6 +138,8 @@ public Future<RowSet<Row>> deleteById(String id) {
return postgresClientFuturized.deleteById(tableName, id);
}

@SuppressWarnings("java:S107")
// suppress "Methods should not have too many parameters"
public <S, R> void streamGet(String table, Class<S> clazz,
String cql, int offset, int limit, List<String> facets,
String element, int queryTimeout, RoutingContext routingContext,
Expand All @@ -156,6 +158,8 @@ public <S, R> void streamGet(String table, Class<S> clazz,
}
}

@SuppressWarnings("java:S107")
// suppress "Methods should not have too many parameters"
private <S, R> void streamGetInstances(String table, Class<S> clazz,
CQLWrapper filter, List<FacetField> facetList,
String element, int queryTimeout,
Expand Down Expand Up @@ -203,9 +207,9 @@ private <S> void handleFailure(CQLWrapper filter,
private void streamTrailer(HttpServerResponse response, ResultInfo resultInfo) {
response.write("],\n");
if (resultInfo.getTotalRecords() != null) {
response.write(String.format(" \"totalRecords\": %d,\n", resultInfo.getTotalRecords()));
response.write(String.format(" \"totalRecords\": %d,%n", resultInfo.getTotalRecords()));
}
response.end(String.format(" \"resultInfo\": %s\n}", Json.encode(resultInfo)));
response.end(String.format(" \"resultInfo\": %s%n}", Json.encode(resultInfo)));
}

private <S> void handleException(PostgresClientStreamResult<S> result, HttpServerResponse response, Throwable res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,17 @@ public Future<Void> publishReindexInstanceRecords(String rangeId, String fromId,
.compose(instances -> domainEventPublisher.publishReindexInstances(rangeId, instances));
}

@SuppressWarnings("java:S107")
// suppress "Methods should not have too many parameters"
public void streamGetInstances(String table, String cql, int offset, int limit, List<String> facets,
String element, int queryTimeout, RoutingContext routingContext) {
instanceRepository.streamGet(
table, Instance.class, cql, offset, limit, facets, element,
queryTimeout, routingContext, InstanceWithoutPubPeriod.class);
}

@SuppressWarnings("java:S107")
// suppress "Methods should not have too many parameters"
public void streamGetInventoryViewInstances(String table, String cql, int offset, int limit, List<String> facets,
String element, int queryTimeout, RoutingContext routingContext) {
instanceRepository.streamGet(
Expand Down
34 changes: 5 additions & 29 deletions src/test/java/org/folio/rest/api/InstanceStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
import static java.net.HttpURLConnection.HTTP_OK;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.awaitility.Awaitility.await;
import static org.folio.rest.support.HttpResponseMatchers.errorMessageContains;
import static org.folio.rest.support.HttpResponseMatchers.errorParametersValueIs;
import static org.folio.rest.support.HttpResponseMatchers.statusCodeIs;
Expand Down Expand Up @@ -822,8 +823,11 @@ public void canSearchUsingMetadataDateUpdatedIndex()
UUID secondInstanceId = UUID.randomUUID();

JsonObject secondInstanceToCreate = nod(secondInstanceId);
// wait 2 seconds before creating the second instance to have a different "updatedDate" field
// than the first instance.
await().pollDelay(2, SECONDS).until(() -> true);

IndividualResource ir = createInstanceWithDelay(secondInstanceToCreate);
IndividualResource ir = createInstance(secondInstanceToCreate);

CompletableFuture<Response> getCompleted = new CompletableFuture<>();

Expand Down Expand Up @@ -3041,34 +3045,6 @@ private IndividualResource createInstance(JsonObject instanceToCreate)
return new IndividualResource(response);
}

private IndividualResource createInstanceWithDelay(JsonObject instanceToCreate)
throws InterruptedException, ExecutionException, TimeoutException {
// delay before creating the instance
CompletableFuture<Void> delayFuture = CompletableFuture.runAsync(() -> {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
// create the instance
CompletableFuture<Response> createCompleted = delayFuture.thenCompose(v -> {
CompletableFuture<Response> responseFuture = new CompletableFuture<>();

getClient().post(instancesStorageUrl(""), instanceToCreate,
TENANT_ID, json(responseFuture));

return responseFuture;
});
// get the response
Response response = createCompleted.get(2, TimeUnit.SECONDS);

assertThat(format("Create instance failed: %s", response.getBody()),
response.getStatusCode(), is(201));

return new IndividualResource(response);
}

private Response update(JsonObject instance) {
final UUID id = UUID.fromString(instance.getString("id"));
CompletableFuture<Response> replaceCompleted = new CompletableFuture<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void shouldConvertToInstance() {

@Test
@SneakyThrows
void shouldThrowIllegalArgumentExceptionWhenCannotConvertToInstance() {
assertThrows(IllegalArgumentException.class, () -> ObjectConverterUtils.convertObject(new Object(), String.class));
void shouldThrowExceptionWhenCannotConvertToInstance() {
assertThrows(Exception.class, () -> ObjectConverterUtils.convertObject(new Object(), String.class));
}
}

0 comments on commit 9322a53

Please sign in to comment.