Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.reactive.function.client.WebClient;
import org.torpedoquery.jakarta.jpa.OnGoingLogicalCondition;
import org.torpedoquery.jakarta.jpa.Torpedo;
Expand All @@ -29,6 +31,7 @@
@Service
public class CurrencyTypeService extends BaseService {

private static final Logger logger = LoggerFactory.getLogger(CurrencyTypeService.class);
private static final String CURRENCY = "currency";

@Value("${INAtrace.exchangerate.apiKey}")
Expand Down Expand Up @@ -69,7 +72,7 @@ public void updateCurrencies() {
.get()
.accept(MediaType.APPLICATION_JSON)
.retrieve().bodyToMono(ApiCurrencySymbolsResponse.class)
.doOnError(Throwable::printStackTrace)
.doOnError(e -> logger.error("Failed to fetch exchange rate data: {}", e.getMessage()))
.onErrorReturn(new ApiCurrencySymbolsResponse())
.block();
if (apiCurrencySymbolsResponse != null && apiCurrencySymbolsResponse.isSuccess()) {
Expand All @@ -90,7 +93,7 @@ public void updateCurrencies() {
.get()
.accept(MediaType.APPLICATION_JSON)
.retrieve().bodyToMono(ApiCurrencyRatesResponse.class)
.doOnError(Throwable::printStackTrace)
.doOnError(e -> logger.error("Failed to fetch exchange rate data: {}", e.getMessage()))
.onErrorReturn(new ApiCurrencyRatesResponse())
.block();
if (apiCurrencyResponse != null && apiCurrencyResponse.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.abelium.inatrace.components.currencies.api.ApiCurrencyRatesResponse;
import com.abelium.inatrace.db.entities.codebook.CurrencyType;
import com.abelium.inatrace.db.entities.currencies.CurrencyPair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
Expand All @@ -24,6 +26,7 @@
@Service
public class CurrencyService extends BaseService {

private static final Logger logger = LoggerFactory.getLogger(CurrencyService.class);
private static final String CURRENCY = "currency";

@Autowired
Expand Down Expand Up @@ -103,7 +106,7 @@ public void fetchRates(Date date) {
.get()
.accept(MediaType.APPLICATION_JSON)
.retrieve().bodyToMono(ApiCurrencyRatesResponse.class)
.doOnError(Throwable::printStackTrace)
.doOnError(e -> logger.error("Failed to fetch exchange rate data: {}", e.getMessage()))
.onErrorReturn(new ApiCurrencyRatesResponse())
.block();
if (apiCurrencyRatesResponse != null && apiCurrencyRatesResponse.isSuccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public ApiResponse<ApiBaseEntity> createProductType(ApiProductType apiProductTyp
productType.setCode(apiProductType.getCode());
em.persist(productType);

if (apiProductType.getTranslations() == null || apiProductType.getTranslations().isEmpty()) {
throw new ApiException(ApiStatus.INVALID_REQUEST, "English translation is required!");
}

apiProductType.getTranslations().stream().filter(productTypeTranslation -> productTypeTranslation != null &&
Language.EN.equals(productTypeTranslation.getLanguage()) &&
productTypeTranslation.getName() != null &&
Expand Down Expand Up @@ -91,6 +95,10 @@ public ApiResponse<ApiBaseEntity> updateProductType(ApiProductType apiProductTyp

productType.setCode(apiProductType.getCode());

if (apiProductType.getTranslations() == null || apiProductType.getTranslations().isEmpty()) {
throw new ApiException(ApiStatus.INVALID_REQUEST, "English translation is required!");
}

apiProductType.getTranslations().stream().filter(productTypeTranslation -> productTypeTranslation != null &&
Language.EN.equals(productTypeTranslation.getLanguage()) &&
productTypeTranslation.getName() != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.support.MissingServletRequestPartException;
import org.springframework.web.servlet.NoHandlerFoundException;
import org.springframework.web.servlet.resource.NoResourceFoundException;

import java.io.IOException;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -156,6 +157,12 @@ public ResponseEntity<?> handleNotFoundException(NoHandlerFoundException exc, Ht
logger.error(exc.getMessage());
return exceptionResponseBuilder.getAcceptableResponse(HttpStatus.NOT_FOUND, ApiStatus.ERROR, exc.getMessage(), request);
}

@ExceptionHandler
public ResponseEntity<?> handleNoResourceFoundException(NoResourceFoundException exc, HttpServletRequest request) {
logger.warn("No resource found: {}", exc.getMessage());
return exceptionResponseBuilder.getAcceptableResponse(HttpStatus.NOT_FOUND, ApiStatus.ERROR, exc.getMessage(), request);
}

@ExceptionHandler
public ResponseEntity<?> handleValidationException(MethodArgumentNotValidException exc, HttpServletRequest request) {
Expand Down