Skip to content

Commit

Permalink
bug: [PagoPA-1935] - order error (#79)
Browse files Browse the repository at this point in the history
* [PAGOPA-1935] first impl

* [PAGOPA-1935] amount and fee fix

---------

Co-authored-by: pagopa-github-bot <github-bot@pagopa.it>
Co-authored-by: aacitelli <aacitelli@PDD-NB-0205.dgsgroup.it>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent 0862d0f commit adb939a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package it.gov.pagopa.bizeventsservice.entity.view;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.azure.spring.data.cosmos.core.mapping.Container;
import com.azure.spring.data.cosmos.core.mapping.GeneratedValue;
Expand Down Expand Up @@ -31,4 +33,9 @@ public class BizEventsViewUser implements Serializable {
private Boolean hidden;
private Boolean isPayer;
private Boolean isDebtor;

public LocalDateTime getTransactionDateAsLocalDateTime() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("[yyyy-MM-dd'T'HH:mm:ss'Z'][yyyy-MM-dd'T'HH:mm:ss.SSSSSS]");
return LocalDateTime.parse(this.getTransactionDate(), formatter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.math.RoundingMode;
import java.time.DateTimeException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -46,7 +46,7 @@ public static TransactionDetailResponse convertTransactionDetails(String taxCode
listOfCartItems.add(
CartItem.builder()
.subject(bizEventsViewCart.getSubject())
.amount(currencyFormat(String.valueOf(bizEventsViewCart.getAmount())))
.amount(new BigDecimal(bizEventsViewCart.getAmount()).setScale(2, RoundingMode.UNNECESSARY).toString())
.debtor(bizEventsViewCart.getDebtor())
.payee(bizEventsViewCart.getPayee())
.refNumberType(bizEventsViewCart.getRefNumberType())
Expand All @@ -69,8 +69,8 @@ public static TransactionDetailResponse convertTransactionDetails(String taxCode
.pspName(bizEventsViewGeneral.getPspName())
.walletInfo(isDebtor ? null:bizEventsViewGeneral.getWalletInfo())
.payer(isDebtor ? null:bizEventsViewGeneral.getPayer())
.amount(currencyFormat(totalAmount.get().toString()))
.fee(bizEventsViewGeneral.getFee())
.amount(totalAmount.get().setScale(2, RoundingMode.UNNECESSARY).toString())
.fee(StringUtils.isNotEmpty(bizEventsViewGeneral.getFee()) ? bizEventsViewGeneral.getFee().replace(',', '.') : bizEventsViewGeneral.getFee())
.paymentMethod(isDebtor ? null:bizEventsViewGeneral.getPaymentMethod())
.origin(bizEventsViewGeneral.getOrigin())
.build()
Expand All @@ -91,21 +91,13 @@ public static TransactionListItem convertTransactionListItem(BizEventsViewUser v
.payeeName(listOfCartViews.size() > 1 ? payeeCartName : listOfCartViews.get(0).getPayee().getName())
.payeeTaxCode(listOfCartViews.size() > 1 ? "" : listOfCartViews.get(0).getPayee().getTaxCode())
// PAGOPA-1763: the amount value must be returned only if it is not a cart type transaction
.amount(listOfCartViews.size() > 1 && BooleanUtils.isTrue(viewUser.getIsDebtor()) ? null : currencyFormat(totalAmount.get().toString()))
.amount(listOfCartViews.size() > 1 && BooleanUtils.isTrue(viewUser.getIsDebtor()) ? null : totalAmount.get().setScale(2, RoundingMode.UNNECESSARY).toString())
.transactionDate(dateFormatZoned(viewUser.getTransactionDate()))
.isCart(listOfCartViews.size() > 1)
.isPayer(BooleanUtils.isTrue(viewUser.getIsPayer()))
.isDebtor(BooleanUtils.isTrue(viewUser.getIsDebtor()))
.build();
}

private static String currencyFormat(String value) {
BigDecimal valueToFormat = new BigDecimal(value);
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ITALY);
numberFormat.setMaximumFractionDigits(2);
numberFormat.setMinimumFractionDigits(2);
return numberFormat.format(valueToFormat);
}

private static String dateFormatZoned(String date) {
String dateSub = StringUtils.substringBeforeLast(date, ".");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Repository
public interface BizEventsViewUserRepository extends CosmosRepository<BizEventsViewUser, String> {

@Query("SELECT * FROM c WHERE c.taxCode = @taxCode AND c.hidden = false AND (IS_NULL(@isPayer) = true OR c.isPayer = @isPayer) AND (IS_NULL(@isDebtor) = true OR c.isDebtor = @isDebtor)")
@Query("SELECT * FROM c WHERE c.taxCode = @taxCode AND c.hidden = false AND (IS_NULL(@isPayer) = true OR c.isPayer = @isPayer) AND (IS_NULL(@isDebtor) = true OR c.isDebtor = @isDebtor)")
Page<BizEventsViewUser> getBizEventsViewUserByTaxCode(@Param("taxCode") String taxCode, @Param("isPayer") Boolean isPayer, @Param("isDebtor") Boolean isDebtor, Pageable pageable);

@Query("select * from c where c.taxCode = @taxCode and c.hidden = false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class TransactionService implements ITransactionService {
Expand Down Expand Up @@ -83,9 +84,14 @@ public TransactionListResponse getTransactionList(String taxCode, Boolean isPaye
final CosmosPageRequest pageRequest = new CosmosPageRequest(0, size, continuationToken, sort);
final Page<BizEventsViewUser> page = this.bizEventsViewUserRepository.getBizEventsViewUserByTaxCode(taxCode, isPayer, isDebtor, pageRequest);
Set<String> set = new HashSet<>(page.getContent().size());

List<BizEventsViewUser> listOfViewUser = page.getContent().stream()
.sorted(Comparator.comparing(BizEventsViewUser::getIsDebtor,Comparator.reverseOrder()))
.filter(p -> set.add(p.getTransactionId())).toList();
.filter(p -> set.add(p.getTransactionId()))
.collect(Collectors.toList())
.stream()
.sorted(Comparator.comparing(BizEventsViewUser::getTransactionDate,Comparator.reverseOrder()))
.toList();

if(listOfViewUser.isEmpty()){
throw new AppException(AppError.VIEW_USER_NOT_FOUND_WITH_TAX_CODE_AND_FILTER, taxCode, isPayer, isDebtor);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/it/gov/pagopa/bizeventsservice/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ public static void getSortedList(List<BizEventsViewUser> listToSort, Transaction
if (TransactionListOrder.TRANSACTION_DATE.equals(order)) {
switch (direction) {
case ASC:
Collections.sort(listToSort, Comparator.comparing(BizEventsViewUser::getTransactionDate,
Collections.sort(listToSort, Comparator.comparing(BizEventsViewUser::getTransactionDateAsLocalDateTime,
Comparator.nullsLast(Comparator.naturalOrder())));
break;
case DESC:
default:
Collections.sort(listToSort, Comparator.comparing(BizEventsViewUser::getTransactionDate,
Collections.sort(listToSort, Comparator.comparing(BizEventsViewUser::getTransactionDateAsLocalDateTime,
Comparator.nullsLast(Comparator.naturalOrder())).reversed());
break;
}
} else {
// the default sorting is by transaction date and DESC direction
Collections.sort(listToSort, Comparator
.comparing(BizEventsViewUser::getTransactionDate, Comparator.nullsLast(Comparator.naturalOrder()))
.comparing(BizEventsViewUser::getTransactionDateAsLocalDateTime, Comparator.nullsLast(Comparator.naturalOrder()))
.reversed());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class ViewGenerator {
public static final String SUBJECT = "subject";
public static final String PAYEE_NAME = "payeeName";
public static final String AMOUNT = "100";
public static final String FORMATTED_AMOUNT = "100,00";
public static final String FORMATTED_GRAND_TOTAL = "500,00";
public static final String FORMATTED_AMOUNT = "100.00";
public static final String FORMATTED_GRAND_TOTAL = "500.00";
public static final String PAYEE_TAX_CODE = "payeeTaxCode";
public static final String DEBTOR_NAME = "debtorName";
public static final String REF_NUMBER_TYPE = "refNumberType";
Expand Down

0 comments on commit adb939a

Please sign in to comment.