| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.plugin.api.model.impl; |
| 5 | |
|
| 6 | |
import java.util.Date; |
| 7 | |
import java.util.List; |
| 8 | |
|
| 9 | |
import org.homeunix.thecave.buddi.i18n.keys.BudgetCategoryTypes; |
| 10 | |
import org.homeunix.thecave.buddi.model.Account; |
| 11 | |
import org.homeunix.thecave.buddi.model.AccountType; |
| 12 | |
import org.homeunix.thecave.buddi.model.BudgetCategory; |
| 13 | |
import org.homeunix.thecave.buddi.model.BudgetCategoryType; |
| 14 | |
import org.homeunix.thecave.buddi.model.Document; |
| 15 | |
import org.homeunix.thecave.buddi.model.Source; |
| 16 | |
import org.homeunix.thecave.buddi.model.Transaction; |
| 17 | |
import org.homeunix.thecave.buddi.model.impl.ModelFactory; |
| 18 | |
import org.homeunix.thecave.buddi.model.impl.WrapperLists; |
| 19 | |
import org.homeunix.thecave.buddi.plugin.api.exception.ModelException; |
| 20 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableAccount; |
| 21 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableAccountType; |
| 22 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableBudgetCategory; |
| 23 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableBudgetCategoryType; |
| 24 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableDocument; |
| 25 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableSource; |
| 26 | |
import org.homeunix.thecave.buddi.plugin.api.model.ImmutableTransaction; |
| 27 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableAccount; |
| 28 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableAccountType; |
| 29 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableBudgetCategory; |
| 30 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableDocument; |
| 31 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableScheduledTransaction; |
| 32 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableSource; |
| 33 | |
import org.homeunix.thecave.buddi.plugin.api.model.MutableTransaction; |
| 34 | |
|
| 35 | 0 | public class MutableDocumentImpl extends MutableModelObjectImpl implements MutableDocument, ImmutableDocument { |
| 36 | |
|
| 37 | |
private final Document model; |
| 38 | |
|
| 39 | |
public MutableDocumentImpl(Document model) { |
| 40 | 0 | super(model); |
| 41 | |
|
| 42 | 0 | this.model = model; |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public void addAccount(MutableAccount account) throws ModelException{ |
| 46 | 0 | getModel().addAccount(account.getAccount()); |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
public void addBudgetCategory(MutableBudgetCategory budgetCategory) throws ModelException{ |
| 50 | 0 | getModel().addBudgetCategory(budgetCategory.getBudgetCategory()); |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
public void addScheduledTransaction(MutableScheduledTransaction scheduledTransaction) throws ModelException{ |
| 54 | 0 | getModel().addScheduledTransaction(scheduledTransaction.getScheduledTransaction()); |
| 55 | 0 | } |
| 56 | |
|
| 57 | |
public void addTransaction(MutableTransaction transaction) throws ModelException{ |
| 58 | 0 | getModel().addTransaction(transaction.getTransaction()); |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
public void addAccountType(MutableAccountType type) throws ModelException{ |
| 62 | 0 | getModel().addAccountType(type.getType()); |
| 63 | 0 | } |
| 64 | |
|
| 65 | |
public void removeAccount(MutableAccount account) throws ModelException{ |
| 66 | 0 | getModel().removeAccount(account.getAccount()); |
| 67 | 0 | } |
| 68 | |
|
| 69 | |
public void removeBudgetCategory(MutableBudgetCategory budgetCategory) throws ModelException{ |
| 70 | 0 | getModel().removeBudgetCategory(budgetCategory.getBudgetCategory()); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public void removeScheduledTransaction(MutableScheduledTransaction scheduledTransaction) throws ModelException{ |
| 74 | 0 | getModel().removeScheduledTransaction(scheduledTransaction.getScheduledTransaction()); |
| 75 | 0 | } |
| 76 | |
|
| 77 | |
public void removeTransaction(MutableTransaction transaction) throws ModelException{ |
| 78 | 0 | getModel().removeTransaction(transaction.getTransaction()); |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
public void removeType(MutableAccountType type) throws ModelException{ |
| 82 | 0 | getModel().removeAccountType(type.getType()); |
| 83 | 0 | } |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public MutableAccount getAccount(String name) { |
| 88 | 0 | if (getModel().getAccount(name) == null) |
| 89 | 0 | return null; |
| 90 | 0 | return new MutableAccountImpl(getModel().getAccount(name)); |
| 91 | |
} |
| 92 | |
|
| 93 | |
public List<MutableAccount> getMutableAccounts(){ |
| 94 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableAccount, Account>(getModel(), getModel().getAccounts()); |
| 95 | |
} |
| 96 | |
|
| 97 | |
public List<MutableBudgetCategory> getMutableBudgetCategories(){ |
| 98 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableBudgetCategory, BudgetCategory>(getModel(), getModel().getBudgetCategories()); |
| 99 | |
} |
| 100 | |
|
| 101 | |
public MutableBudgetCategory getBudgetCategory(String fullName) { |
| 102 | 0 | BudgetCategory bc = getModel().getBudgetCategory(fullName); |
| 103 | 0 | if (bc == null) |
| 104 | 0 | return null; |
| 105 | 0 | return new MutableBudgetCategoryImpl(bc); |
| 106 | |
} |
| 107 | |
|
| 108 | |
public Document getModel(){ |
| 109 | 0 | return model; |
| 110 | |
} |
| 111 | |
|
| 112 | |
public List<MutableTransaction> getMutableTransactions(){ |
| 113 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableTransaction, Transaction>(getModel(), getModel().getTransactions()); |
| 114 | |
} |
| 115 | |
|
| 116 | |
public List<MutableTransaction> getMutableTransactions(Date startDate, Date endDate){ |
| 117 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableTransaction, Transaction>(getModel(), getModel().getTransactions(startDate, endDate)); |
| 118 | |
} |
| 119 | |
|
| 120 | |
public List<MutableTransaction> getMutableTransactions(MutableSource source){ |
| 121 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableTransaction, Transaction>(getModel(), getModel().getTransactions((Source) source.getRaw())); |
| 122 | |
} |
| 123 | |
|
| 124 | |
public List<MutableTransaction> getMutableTransactions(MutableSource source, Date startDate, Date endDate){ |
| 125 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableTransaction, Transaction>(getModel(), getModel().getTransactions((Source) source.getRaw(), startDate, endDate)); |
| 126 | |
} |
| 127 | |
|
| 128 | |
public MutableAccountType getAccountType(String name) { |
| 129 | 0 | if (getModel().getAccountType(name) == null) |
| 130 | 0 | return null; |
| 131 | 0 | return new MutableAccountTypeImpl(getModel().getAccountType(name)); |
| 132 | |
} |
| 133 | |
|
| 134 | |
public List<MutableAccountType> getMutableAccountTypes(){ |
| 135 | 0 | return new WrapperLists.ImmutableObjectWrapperList<MutableAccountType, AccountType>(getModel(), getModel().getAccountTypes()); |
| 136 | |
} |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
public List<ImmutableAccount> getImmutableAccounts(){ |
| 142 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableAccount, Account>(getModel(), getModel().getAccounts()); |
| 143 | |
} |
| 144 | |
|
| 145 | |
public List<ImmutableBudgetCategory> getImmutableBudgetCategories(){ |
| 146 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableBudgetCategory, BudgetCategory>(getModel(), getModel().getBudgetCategories()); |
| 147 | |
} |
| 148 | |
|
| 149 | |
public List<ImmutableTransaction> getImmutableTransactions(){ |
| 150 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions()); |
| 151 | |
} |
| 152 | |
|
| 153 | |
public List<ImmutableTransaction> getImmutableTransactions(Date startDate, Date endDate){ |
| 154 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions(startDate, endDate)); |
| 155 | |
} |
| 156 | |
|
| 157 | |
public List<ImmutableTransaction> getImmutableTransactions(ImmutableSource source){ |
| 158 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions((Source) source.getRaw())); |
| 159 | |
} |
| 160 | |
|
| 161 | |
public List<ImmutableTransaction> getImmutableTransactions(ImmutableSource source, Date startDate, Date endDate){ |
| 162 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableTransaction, Transaction>(getModel(), getModel().getTransactions((Source) source.getRaw(), startDate, endDate)); |
| 163 | |
} |
| 164 | |
|
| 165 | |
public List<ImmutableAccountType> getImmutableAccountTypes(){ |
| 166 | 0 | return new WrapperLists.ImmutableObjectWrapperList<ImmutableAccountType, AccountType>(getModel(), getModel().getAccountTypes()); |
| 167 | |
} |
| 168 | |
|
| 169 | |
public ImmutableBudgetCategoryType getBudgetCategoryType(BudgetCategoryTypes name){ |
| 170 | 0 | return getBudgetCategoryType(name.toString()); |
| 171 | |
} |
| 172 | |
|
| 173 | |
public ImmutableBudgetCategoryType getBudgetCategoryType(String name) { |
| 174 | 0 | BudgetCategoryType type = ModelFactory.getBudgetCategoryType(name); |
| 175 | 0 | if (type == null) |
| 176 | 0 | return null; |
| 177 | 0 | return new ImmutableBudgetCategoryTypeImpl(type); |
| 178 | |
} |
| 179 | |
public long getNetWorth(Date date) { |
| 180 | 0 | return getModel().getNetWorth(date); |
| 181 | |
} |
| 182 | |
} |