Skip to content
Snippets Groups Projects
Commit 0e83b22b authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#528 - added new field "isReadOnly"

parent 52c800dc
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ public class Account
private Boolean isSelected = false;
private Boolean isDefault = false;
private Boolean isReadOnly = false;
@Expose
private AccountType type;
......@@ -39,6 +40,7 @@ public class Account
this.type = type;
this.isSelected = false;
this.isDefault = false;
this.isReadOnly = false;
}
public Account()
......@@ -95,6 +97,16 @@ public class Account
isDefault = aDefault;
}
public Boolean isReadOnly()
{
return isReadOnly;
}
public void setReadOnly(Boolean readOnly)
{
isReadOnly = readOnly;
}
public AccountType getType()
{
return type;
......@@ -114,6 +126,7 @@ public class Account
", referringTransactions=" + referringTransactions +
", isSelected=" + isSelected +
", isDefault=" + isDefault +
", isReadOnly=" + isReadOnly +
", type=" + type +
'}';
}
......@@ -126,6 +139,7 @@ public class Account
Account account = (Account) o;
return isSelected == account.isSelected &&
isDefault == account.isDefault &&
isReadOnly == account.isReadOnly &&
Objects.equals(ID, account.ID) &&
Objects.equals(name, account.name) &&
type == account.type;
......@@ -134,6 +148,6 @@ public class Account
@Override
public int hashCode()
{
return Objects.hash(ID, name, isSelected, isDefault, type);
return Objects.hash(ID, name, isSelected, isDefault, isReadOnly, type);
}
}
\ No newline at end of file
......@@ -19,9 +19,9 @@ import java.util.Optional;
public class AccountService implements Resetable
{
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
private AccountRepository accountRepository;
private TransactionService transactionService;
private UserRepository userRepository;
private final AccountRepository accountRepository;
private final TransactionService transactionService;
private final UserRepository userRepository;
@Autowired
public AccountService(AccountRepository accountRepository, TransactionService transactionService, UserRepository userRepository)
......@@ -48,7 +48,7 @@ public class AccountService implements Resetable
public void deleteAccount(int ID)
{
Optional<Account> accountToDeleteOptional = accountRepository.findById(ID);
if(!accountToDeleteOptional.isPresent())
if(accountToDeleteOptional.isEmpty())
{
return;
}
......@@ -97,6 +97,15 @@ public class AccountService implements Resetable
LOGGER.debug("Created default account");
}
for(Account account : accountRepository.findAll())
{
if(account.isReadOnly() == null)
{
account.setReadOnly(false);
}
accountRepository.save(account);
}
Account defaultAccount = accountRepository.findByIsDefault(true);
if(defaultAccount == null)
{
......@@ -121,7 +130,7 @@ public class AccountService implements Resetable
deselectAllAccounts();
Optional<Account> accountToSelectOptional = accountRepository.findById(ID);
if(!accountToSelectOptional.isPresent())
if(accountToSelectOptional.isEmpty())
{
return;
}
......@@ -143,7 +152,7 @@ public class AccountService implements Resetable
unsetDefaultForAllAccounts();
Optional<Account> accountToSelectOptional = accountRepository.findById(ID);
if(!accountToSelectOptional.isPresent())
if(accountToSelectOptional.isEmpty())
{
return;
}
......
......@@ -35,7 +35,7 @@ public class SettingsService
@Transactional
public void createDefaultSettingsIfNotExists()
{
if(!settingsRepository.findById(0).isPresent())
if(settingsRepository.findById(0).isEmpty())
{
settingsRepository.save(Settings.getDefault());
LOGGER.debug("Created default settings");
......@@ -43,7 +43,7 @@ public class SettingsService
Settings defaultSettings = Settings.getDefault();
Optional<Settings> settingsOptional = settingsRepository.findById(0);
if(!settingsOptional.isPresent())
if(settingsOptional.isEmpty())
{
throw new RuntimeException("Missing Settings in database");
}
......
......@@ -22,6 +22,7 @@
<input type="hidden" name="ID" value="<#if account.getID()??>${account.getID()?c}</#if>">
<input type="hidden" name="isSelected" value="<#if account.isSelected()??>${account.isSelected()?c}</#if>">
<input type="hidden" name="isDefault" value="<#if account.isDefault()??>${account.isDefault()?c}</#if>">
<input type="hidden" name="isReadOnly" value="<#if account.isReadOnly()??>${account.isReadOnly()?c}</#if>">
<#-- name -->
<div class="row">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment