diff --git a/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java b/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java index a947419c3fe2e43697b577c7998f5e413cbb704e..58a75b6941e0f1c912ebbae80db4460c24e21676 100644 --- a/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java +++ b/src/main/java/de/deadlocker8/budgetmaster/accounts/AccountService.java @@ -2,6 +2,8 @@ package de.deadlocker8.budgetmaster.accounts; import de.deadlocker8.budgetmaster.authentication.User; import de.deadlocker8.budgetmaster.authentication.UserRepository; +import de.deadlocker8.budgetmaster.icon.Icon; +import de.deadlocker8.budgetmaster.icon.IconService; import de.deadlocker8.budgetmaster.services.AccessAllEntities; import de.deadlocker8.budgetmaster.services.AccessEntityByID; import de.deadlocker8.budgetmaster.services.Resettable; @@ -25,16 +27,20 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A { private static final Logger LOGGER = LoggerFactory.getLogger(AccountService.class); + private static final String PLACEHOLDER_ICON = "fas fa-landmark"; + private final AccountRepository accountRepository; private final TransactionService transactionService; private final UserRepository userRepository; + private final IconService iconService; @Autowired - public AccountService(AccountRepository accountRepository, TransactionService transactionService, UserRepository userRepository) + public AccountService(AccountRepository accountRepository, TransactionService transactionService, UserRepository userRepository, IconService iconService) { this.accountRepository = accountRepository; this.transactionService = transactionService; this.userRepository = userRepository; + this.iconService = iconService; createDefaults(); } @@ -121,6 +127,7 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A if(accountRepository.findAll().isEmpty()) { Account placeholder = new Account("Placeholder", AccountType.ALL); + placeholder.updateIcon(iconService, null, PLACEHOLDER_ICON, null, this); accountRepository.save(placeholder); LOGGER.debug("Created placeholder account"); @@ -148,6 +155,14 @@ public class AccountService implements Resettable, AccessAllEntities<Account>, A handleNullValuesForAccountState(account); accountRepository.save(account); } + + final Account placeholderAccount = accountRepository.findAllByType(AccountType.ALL).get(0); + final Icon icon = placeholderAccount.getIconReference(); + if(icon.getBuiltinIdentifier() == null) + { + placeholderAccount.updateIcon(iconService, null, PLACEHOLDER_ICON, null, this); + LOGGER.debug(MessageFormat.format("Updated placeholder account: Set missing icon to \"{0}\"", PLACEHOLDER_ICON)); + } } private void handleNullValuesForAccountState(Account account) diff --git a/src/test/java/de/deadlocker8/budgetmaster/unit/AccountServiceTest.java b/src/test/java/de/deadlocker8/budgetmaster/unit/AccountServiceTest.java index 3d5a4c55da456ff89ccb8a8e6f12def7da17ce41..0b811ebb95c93a85648a42b6002361ffc9160ba5 100644 --- a/src/test/java/de/deadlocker8/budgetmaster/unit/AccountServiceTest.java +++ b/src/test/java/de/deadlocker8/budgetmaster/unit/AccountServiceTest.java @@ -3,6 +3,7 @@ package de.deadlocker8.budgetmaster.unit; import de.deadlocker8.budgetmaster.accounts.*; import de.deadlocker8.budgetmaster.authentication.UserRepository; import de.deadlocker8.budgetmaster.icon.Icon; +import de.deadlocker8.budgetmaster.icon.IconService; import de.deadlocker8.budgetmaster.transactions.TransactionService; import de.deadlocker8.budgetmaster.unit.helpers.LocalizedTest; import de.deadlocker8.budgetmaster.utils.Strings; @@ -33,6 +34,9 @@ class AccountServiceTest @Mock private UserRepository userRepository; + @Mock + private IconService iconService; + private AccountService accountService; private Account ACCOUNT_DEFAULT; @@ -67,7 +71,7 @@ class AccountServiceTest Mockito.when(accountRepository.findById(1)).thenReturn(Optional.of(ACCOUNT_PLACEHOLDER)); Mockito.when(accountRepository.findById(3)).thenReturn(Optional.of(ACCOUNT_NORMAL)); - accountService = new AccountService(accountRepository, transactionService, userRepository); + accountService = new AccountService(accountRepository, transactionService, userRepository, iconService); } @Test