Coverage Report - org.homeunix.thecave.buddi.plugin.api.model.MutableModelFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
MutableModelFactory
0%
0/17
N/A
1
 
 1  
 /*
 2  
  * Created on Aug 26, 2007 by wyatt
 3  
  */
 4  
 package org.homeunix.thecave.buddi.plugin.api.model;
 5  
 
 6  
 import java.io.File;
 7  
 import java.util.Date;
 8  
 
 9  
 import org.homeunix.thecave.buddi.model.Account;
 10  
 import org.homeunix.thecave.buddi.model.AccountType;
 11  
 import org.homeunix.thecave.buddi.model.BudgetCategory;
 12  
 import org.homeunix.thecave.buddi.model.ScheduledTransaction;
 13  
 import org.homeunix.thecave.buddi.model.Transaction;
 14  
 import org.homeunix.thecave.buddi.model.TransactionSplit;
 15  
 import org.homeunix.thecave.buddi.model.impl.ModelFactory;
 16  
 import org.homeunix.thecave.buddi.plugin.api.exception.ModelException;
 17  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.ImmutableSplitImpl;
 18  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableAccountImpl;
 19  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableAccountTypeImpl;
 20  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableBudgetCategoryImpl;
 21  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableDocumentImpl;
 22  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableScheduledTransactionImpl;
 23  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableTransactionImpl;
 24  
 import org.homeunix.thecave.buddi.plugin.api.model.impl.MutableTransactionSplitImpl;
 25  
 import org.homeunix.thecave.buddi.util.OperationCancelledException;
 26  
 
 27  
 import ca.digitalcave.moss.application.document.exception.DocumentLoadException;
 28  
 
 29  0
 public class MutableModelFactory {
 30  
         /**
 31  
          * Creates a new MutableModel, with the default budget categories, types, etc.
 32  
          * @return
 33  
          * @throws ModelException
 34  
          */
 35  
         public static MutableDocument createDocument() throws ModelException {
 36  0
                 return new MutableDocumentImpl(ModelFactory.createDocument());
 37  
         }
 38  
         
 39  
         /**
 40  
          * Loads an existing MutableModel from the specified file.
 41  
          * @param file
 42  
          * @return
 43  
          * @throws DocumentLoadException
 44  
          * @throws OperationCancelledException
 45  
          */
 46  
         public static MutableDocument createDocument(File file) throws DocumentLoadException, OperationCancelledException {
 47  0
                 return new MutableDocumentImpl(ModelFactory.createDocument(file));
 48  
         }
 49  
         
 50  
         /**
 51  
          * Creates a new MutableAccount with the given details.
 52  
          * @param name
 53  
          * @param startingBalance
 54  
          * @param type
 55  
          * @return
 56  
          * @throws ModelException
 57  
          */
 58  
         public static MutableAccount createMutableAccount(String name, long startingBalance, MutableAccountType type)  throws ModelException {
 59  0
                 Account a = ModelFactory.createAccount(name, type.getType());
 60  0
                 a.setStartingBalance(startingBalance);
 61  
                 
 62  0
                 return new MutableAccountImpl(a);
 63  
         }
 64  
         
 65  
         /**
 66  
          * Creates a new Split object.  Split objects are used for exactly one purpose: to 
 67  
          * signal that instead of having a single source for the to / from of a transaction,
 68  
          * we instead will use the toSplits / fromSplits.  Thus, there is no need to set any
 69  
          * fields in this Split object, and thus we will just use an immutable one.
 70  
          * 
 71  
          * In fact, since there is no necessary information contained within a split object 
 72  
          * other than the fact that it is of type Split, the ModelFactory will reuse a
 73  
          * single Split object each time you call the method.
 74  
          * @return
 75  
          * @throws ModelException
 76  
          */
 77  
         public static ImmutableSplit createImmutableSplit() throws ModelException {
 78  0
                 return new ImmutableSplitImpl(ModelFactory.createSplit());
 79  
         }
 80  
         
 81  
         /**
 82  
          * Creates a new MutableAccountType with the given details.
 83  
          * @param name
 84  
          * @param credit
 85  
          * @return
 86  
          * @throws ModelException
 87  
          */
 88  
         public static MutableAccountType createMutableAccountType(String name, boolean credit) throws ModelException {
 89  0
                 AccountType t = ModelFactory.createAccountType(name, credit);
 90  
                 
 91  0
                 return new MutableAccountTypeImpl(t);
 92  
         }
 93  
         
 94  
         /**
 95  
          * Creates a new MutableBudgetCategory with the given details.
 96  
          * @param name
 97  
          * @param periodType
 98  
          * @param isIncome
 99  
          * @return
 100  
          * @throws ModelException
 101  
          */
 102  
         public static MutableBudgetCategory createMutableBudgetCategory(String name, ImmutableBudgetCategoryType periodType, boolean isIncome) throws ModelException {
 103  0
                 BudgetCategory bc = ModelFactory.createBudgetCategory(name, periodType.getBudgetCategoryType(), isIncome);
 104  
                 
 105  0
                 return new MutableBudgetCategoryImpl(bc);
 106  
         }
 107  
         
 108  
         /**
 109  
          * Creates a new MutableScheduledTransaction
 110  
          * @return
 111  
          * @throws ModelException
 112  
          */
 113  
         public static MutableScheduledTransaction createMutableScheduledTransaction(String name, String message, Date startDate, Date endDate, String frequencyType, int scheduleDay, int scheduleWeek, int scheduleMonth, Date date, String description, long amount, MutableSource from, MutableSource to) throws ModelException{
 114  0
                 ScheduledTransaction st = ModelFactory.createScheduledTransaction(name, message, startDate, endDate, frequencyType, scheduleDay, scheduleWeek, scheduleMonth, description, amount, from.getSource(), to.getSource());
 115  
                 
 116  0
                 return new MutableScheduledTransactionImpl(st);
 117  
         }
 118  
         
 119  
         /**
 120  
          * Creates a new MutableTransaction with the given details.
 121  
          * @param date
 122  
          * @param description
 123  
          * @param amount
 124  
          * @param from
 125  
          * @param to
 126  
          * @return
 127  
          * @throws ModelException
 128  
          */
 129  
         public static MutableTransaction createMutableTransaction(Date date, String description, long amount, MutableSource from, MutableSource to) throws ModelException {
 130  0
                 Transaction t = ModelFactory.createTransaction(date, description, amount, from.getSource(), to.getSource());
 131  
                 
 132  0
                 return new MutableTransactionImpl(t);
 133  
         }
 134  
         
 135  
         public static MutableTransactionSplit createMutableTransactionSplit(MutableSource source, long amount) throws ModelException {
 136  0
                 TransactionSplit t = ModelFactory.createTransactionSplit(source.getSource(), amount);
 137  0
                 return new MutableTransactionSplitImpl(t);
 138  
         }
 139  
 }