19 package org.turro.warnings;
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.stream.Stream;
25 import org.turro.annotation.ElephantWarning;
26 import org.turro.elephant.context.Application;
27 import org.turro.financials.db.FinancialsPU;
28 import org.turro.financials.entity.Account;
29 import org.turro.financials.entity.MajorAccount;
30 import org.turro.i18n.I_;
31 import org.turro.jpa.Dao;
50 return Collections.EMPTY_LIST;
53 private List<IWarning> createModel() {
55 List<IWarning> warnings =
new ArrayList<>();
56 try(Stream<MajorAccount> majors = dao.stream(
MajorAccount.class,
"select m from MajorAccount m")) {
57 majors.forEach((major) -> {
58 checkMajor(warnings, major);
61 try(Stream<Account> accounts = dao.stream(Account.class,
"select a from Account a")) {
62 accounts.forEach((account) -> {
63 checkAccount(warnings, account);
69 private void checkMajor(List<IWarning> warnings, MajorAccount major) {
70 Warning warning =
new Warning();
71 warning.setEntity(major);
72 if(major.getAccount().length() > 1 && major.getParent() ==
null) {
73 warning.addMessage(I_.format(
"%s has no parent",
74 major.getAccount() +
" - " + major.getDescription()));
76 if(!warning.getMessages().isEmpty()) {
77 warnings.add(warning);
81 private void checkAccount(List<IWarning> warnings, Account account) {
82 Warning warning =
new Warning();
83 warning.setEntity(account);
84 MajorAccount ma = account.getParent();
86 warning.addMessage(I_.format(
"%s has no parent",
87 account.getId()+
" - " + account.getDescription()));
88 }
else if(ma.getAccount().length() < 3) {
89 warning.addMessage(I_.format(
"%s has a wrong parent",
90 account.getId()+
" - " + account.getDescription()));
92 if(!warning.getMessages().isEmpty()) {
93 warnings.add(warning);
boolean isInRole(String role)
static Application getApplication()
List< IWarning > getWarnings()