This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MonetaryAmount dinars = Money.of(100.2473, "BHD"); | |
| assertEquals(3, dinars.getCurrency().getDefaultFractionDigits()); | |
| MonetaryAmount dinars = Money.of(100.2473, "BHD"); | |
| MonetaryAmount roundedDinars = dinars.with(Monetary.getDefaultRounding()); | |
| assertEquals("100.247", roundedDinars.getNumber().toString()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static BigDecimal extractAmount(MonetaryAmount monetaryAmount) { | |
| if (monetaryAmount == null) { | |
| return null; | |
| } | |
| return monetaryAmount.getNumber().numberValue(BigDecimal.class); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Test | |
| void testAdditionDifferentCurrencies() { | |
| MonetaryAmount us = Money.of(100.2473, "USD"); | |
| MonetaryAmount canada = Money.of(23.20, "CAD"); | |
| assertThrows(MonetaryException.class, () -> canada.add(us)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Entity | |
| public class Fee { | |
| @Id | |
| @GeneratedValue(strategy = GenerationType.AUTO) | |
| private UUID id; | |
| @NotNull(message = "Client ID is required") | |
| private String clientId; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CustomExchangeRateProvider extends AbstractRateProvider { | |
| public CustomExchangeRateProvider() { | |
| super(ProviderContext.of("GRAND")); | |
| } | |
| @Override | |
| public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) { | |
| CurrencyUnit baseCurrency = conversionQuery.getBaseCurrency(); | |
| CurrencyUnit currency = conversionQuery.getCurrency(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| @StepScope | |
| public class CashFlowProcessor implements ItemProcessor<BankTransaction, MonthlyCashFlow> { | |
| private LocalDate lastDate = null; | |
| private List<BankTransaction> monthlyGroup = new ArrayList<>(); | |
| @Override | |
| public MonthlyCashFlow process(BankTransaction transaction) { | |
| if (lastDate == null || isSameMonth(transaction.getDate())) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| @StepScope | |
| public class BankTransactionProcessor implements ItemProcessor<BankTransaction, BankTransaction> { | |
| @Override | |
| public BankTransaction process(BankTransaction transaction) throws IllegalArgumentException { | |
| if ("BOB".equals(transaction.getBank())) { | |
| return null; //Skip these transactions | |
| } | |
| if (transaction.getAmount().compareTo(BigDecimal.ZERO) < 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TransactionImportSkipListener implements SkipListener<BankTransaction, BankTransaction> { | |
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| @Override | |
| public void onSkipInRead(Throwable throwable) { | |
| logger.warn("Line skipped on read", throwable); | |
| } | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| Step importTransactionsStep(FlatFileItemReader<BankTransaction> transactionFileReader, | |
| JdbcBatchItemWriter<BankTransaction> transactionBatchWriter) { | |
| return stepBuilderFactory.get("importTransactionsStep") | |
| .<BankTransaction, BankTransaction>chunk(100) | |
| .reader(transactionFileReader) | |
| .processor(transactionProcessor) | |
| .writer(transactionBatchWriter) | |
| .faultTolerant() | |
| .skipLimit(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Map<Class<?>, PropertyEditor> getCustomEditors() { | |
| Map<Class<?>, PropertyEditor> editors = new HashMap<>(); | |
| editors.put(LocalDate.class, new PropertyEditorSupport() { | |
| @Override | |
| public void setAsText(String text) { | |
| super.setValue(LocalDate.parse(text)); | |
| } | |
| }); |