FINERACT-1724: Sonar fixes
Fineract Docker build - MariaDB / build (push) Canceled after 0s
Fineract Docker build - PostgreSQL / build (push) Canceled after 0s
Fineract Kafka Smoke / build (push) Canceled after 0s
Fineract Documentation build / build (push) Canceled after 0s
Fineract Build & Test - MariaDB / build (push) Canceled after 0s
Fineract Build & Test - MySQL / build (push) Canceled after 0s
Fineract Build & Test - PostgreSQL / build (push) Canceled after 0s
Fineract ActiveMQ Smoke / build (push) Canceled after 0s

This commit is contained in:
abraham.menyhart
2023-08-10 12:56:45 +02:00
committed by Adam Saghy
parent 33c1aa7874
commit d6c10e8303
31 changed files with 113 additions and 276 deletions
@@ -19,6 +19,7 @@
package org.apache.fineract.client.util;
import java.io.IOException;
import lombok.extern.slf4j.Slf4j;
import retrofit2.Call;
import retrofit2.Response;
@@ -27,6 +28,7 @@ import retrofit2.Response;
*
* @author Michael Vorburger.ch
*/
@Slf4j
public class CallFailedRuntimeException extends RuntimeException {
private final Call<?> call;
@@ -46,17 +48,17 @@ public class CallFailedRuntimeException extends RuntimeException {
private static String message(Call<?> call, Response<?> response) {
StringBuilder sb = new StringBuilder("HTTP failed: " + call.request() + "; " + response);
if (response.message() != null && !response.message().isEmpty()) {
sb.append("; message: " + response.message());
if (null != response.message() && !response.message().isEmpty()) {
sb.append("; message: ").append(response.message());
}
String errorBody;
try {
errorBody = response.errorBody().string();
errorBody = response.errorBody() != null ? response.errorBody().string() : null;
if (errorBody != null) {
sb.append("; errorBody: " + errorBody);
sb.append("; errorBody: ").append(errorBody);
}
} catch (IOException e) {
// Ignore.
log.error("Exception during creating the {} message:", CallFailedRuntimeException.class.getSimpleName(), e);
}
return sb.toString();
}
@@ -23,6 +23,7 @@ import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.internal.bind.util.ISO8601Utils;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import io.gsonfire.GsonFireBuilder;
import java.io.IOException;
@@ -35,10 +36,12 @@ import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.apache.fineract.client.models.ExternalId;
import org.apache.fineract.client.util.adapter.ExternalIdAdapter;
import org.jetbrains.annotations.NotNull;
import retrofit2.Converter;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
@@ -212,25 +215,28 @@ public class JSON {
@Override
public Date read(JsonReader in) throws IOException {
try {
switch (in.peek()) {
case NULL:
in.nextNull();
return null;
default:
String date = in.nextString();
try {
if (dateFormat != null) {
return dateFormat.parse(date);
}
return ISO8601Utils.parse(date, new ParsePosition(0));
} catch (ParseException e) {
throw new JsonParseException(e);
}
if (Objects.requireNonNull(in.peek()) == JsonToken.NULL) {
in.nextNull();
return null;
}
String date = in.nextString();
return parseDate(date);
} catch (IllegalArgumentException e) {
throw new JsonParseException(e);
}
}
@NotNull
private Date parseDate(String date) {
try {
if (null != dateFormat) {
return dateFormat.parse(date);
}
return ISO8601Utils.parse(date, new ParsePosition(0));
} catch (ParseException e) {
throw new JsonParseException(e);
}
}
}
// The following is not from the generated JSON class, but from the original generated ApiClient.
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test;
public class FineractClientTechnicalTest {
@Test
@Disabled // TODO remove Ignore once https://issues.apache.org/jira/browse/FINERACT-1221 is fixed
@Disabled("remove Ignore once https://issues.apache.org/jira/browse/FINERACT-1221 is fixed")
void testInvalidOperations() {
FineractClient.Builder builder = FineractClient.builder().baseURL("http://test/").tenant("default").basicAuth("mifos", "password");
builder.getRetrofitBuilder().validateEagerly(true); // see FINERACT-1221