View Javadoc

1   package com.leonarduk.clearcheckbook.calls;
2   
3   import java.io.IOException;
4   import java.util.List;
5   
6   import org.apache.log4j.Logger;
7   
8   import com.leonarduk.clearcheckbook.ClearCheckBookConnection;
9   import com.leonarduk.clearcheckbook.ClearcheckbookException;
10  import com.leonarduk.clearcheckbook.dto.AbstractDataType;
11  import com.leonarduk.clearcheckbook.dto.AccountDataType;
12  import com.leonarduk.clearcheckbook.dto.ParsedNameValuePair;
13  import com.leonarduk.clearcheckbook.dto.TransactionDataType;
14  
15  public class TransactionCall extends AbstractCall<TransactionDataType> {
16  
17  	private static final Logger _logger = Logger
18  			.getLogger(TransactionCall.class);
19  
20  	public static final String TYPE = "transaction";
21  
22  	public TransactionCall(ClearCheckBookConnection connection) {
23  		super(connection, TransactionDataType.class);
24  	}
25  
26  	@Override
27  	public List<String> bulkProcess(List<TransactionDataType> dataTypeList)
28  			throws ClearcheckbookException {
29  		return super.bulkProcess(dataTypeList);
30  	}
31  
32  	@Override
33  	protected String getUrlSuffix() {
34  		return TYPE;
35  	}
36  
37  	/***
38  	 * Returns an array of transactions for the current user <br>
39  	 * Method: get <br>
40  	 * Call: transactions
41  	 * <p>
42  	 * Example: <br>
43  	 * https://username:password@www.clearcheckbook.com/api/transactions/
44  	 * <p>
45  	 * Parameters: <br>
46  	 * Parameter Required Description <br>
47  	 * account_id Optional Get transactions for a specific account <br>
48  	 * page Optional integer used for limiting the number of transactions. Used
49  	 * in conjunction with limit. (eg: page=2, limit=10) <br>
50  	 * limit Optional The number of transactions you want to receive. Must be
51  	 * used with the page variable.
52  	 * <p>
53  	 * Returned Values: <br>
54  	 * Value Description <br>
55  	 * id The id of the transaction <br>
56  	 * date The date for the transaction (formatted as yyyy-mm-dd) <br>
57  	 * amount Float value for the amount of the transaction. <br>
58  	 * transaction_type Whether this transaction is a deposit or withdrawal
59  	 * (0=withdrawal, 1=deposit) <br>
60  	 * description The description for this transaction <br>
61  	 * account_id The account associated with this transaction. 0 = No account <br>
62  	 * category_id The category associated with this transaction. 0 = No
63  	 * category <br>
64  	 * jive Whether or not this transaction is jived (0= Not jived, 1= Jived) <br>
65  	 * specialstatus Text that is empty or says Transfer or Split <br>
66  	 * parent If this is a split from a split transaction, this is the id of the
67  	 * parent transaction <br>
68  	 * related_transfer A unique integer corresponding to its related transfer.
69  	 * <br>
70  	 * check_num Text from the check number field <br>
71  	 * memo Text from the memo field <br>
72  	 * payee Text from the payee field <br>
73  	 * initial_balance Boolean for whether or not this was set up as an initial
74  	 * balance for an account
75  	 * 
76  	 * @Override {@link AbstractCall#getAll()}
77  	 * @throws ClearcheckbookException
78  	 * @return List of transactions
79  	 */
80  	public List<TransactionDataType> getAll() throws ClearcheckbookException {
81  		return super.getAll();
82  	}
83  
84  	public List<TransactionDataType> getAll(long accountId)
85  			throws ClearcheckbookException {
86  		return super.getAll(AccountDataType.getIdParameter(accountId));
87  	}
88  
89  	/***
90  	 * 
91  	 * @param account
92  	 * @return
93  	 * @throws ClearcheckbookException
94  	 */
95  	public List<TransactionDataType> getAll(AccountDataType account)
96  			throws ClearcheckbookException {
97  		return super.getAll(new ParsedNameValuePair("account_id", String
98  				.valueOf(account.getId())));
99  	}
100 
101 	public List<TransactionDataType> getAll(long accountId, int page, int limit)
102 			throws ClearcheckbookException {
103 		return super.getAll(AccountDataType.getIdParameter(accountId),
104 				TransactionDataType.getPageParameter(page),
105 				TransactionDataType.getLimitParameter(limit));
106 	}
107 
108 	public List<TransactionDataType> getAll(int page, int limit)
109 			throws ClearcheckbookException {
110 		return super.getAll(TransactionDataType.getPageParameter(page),
111 				TransactionDataType.getLimitParameter(limit));
112 	}
113 
114 	/***
115 	 * Returns information about a specific transaction. <br>
116 	 * Method: get <br>
117 	 * Call: transaction
118 	 * <p>
119 	 * Example: <br>
120 	 * https://username:password@www.clearcheckbook.com/api/transaction/
121 	 * <p>
122 	 * Parameters: <br>
123 	 * Parameter Required Description <br>
124 	 * id Required The id of the transaction you want
125 	 * <p>
126 	 * Returned Values: <br>
127 	 * Value Description <br>
128 	 * id The id of the transaction <br>
129 	 * date The date for the transaction (formatted as yyyy-mm-dd) <br>
130 	 * amount Float value for the amount of the transaction. <br>
131 	 * transaction_type Whether this transaction is a deposit or withdrawal
132 	 * (0=withdrawal, 1=deposit) <br>
133 	 * description The description for this transaction <br>
134 	 * account_id The account associated with this transaction. 0 = No account <br>
135 	 * category_id The category associated with this transaction. 0 = No
136 	 * category <br>
137 	 * jive Whether or not this transaction is jived (0= Not jived, 1= Jived) <br>
138 	 * specialstatus Text that is empty or says Transfer or Split <br>
139 	 * parent If this is a split from a split transaction, this is the id of the
140 	 * parent transaction <br>
141 	 * related_transfer A unique integer corresponding to its related transfer.
142 	 * <br>
143 	 * check_num Text from the check number field <br>
144 	 * memo Text from the memo field <br>
145 	 * payee Text from the payee field <br>
146 	 * initial_balance Boolean for whether or not this was set up as an initial
147 	 * balance for an account
148 	 * 
149 	 * @Override {@link AbstractCall#get(ParsedNameValuePair)}
150 	 * @return transaction
151 	 */
152 	public TransactionDataType get(ParsedNameValuePair id)
153 			throws ClearcheckbookException {
154 		TransactionDataType transactionDataType = super.get(id);
155 		_logger.debug("get: " + transactionDataType);
156 		return transactionDataType;
157 
158 	}
159 
160 	/***
161 	 * Inserts a transaction for the current user <br>
162 	 * Method: post <br>
163 	 * Call: transaction
164 	 * <p>
165 	 * Example: <br>
166 	 * https://username:password@www.clearcheckbook.com/api/transaction/
167 	 * <p>
168 	 * Parameters: <br>
169 	 * Parameter Required Description <br>
170 	 * date Required The date for the transaction (Formatted as yyyy-mm-dd) <br>
171 	 * amount Required Float value formatted as (xxxx.xx) <br>
172 	 * transaction_type Required Whether the transaction is a deposit or
173 	 * withdrawal (0= Withdrawal, 1= Deposit, 3= Transfer) <br>
174 	 * account_id Required* The id of the account for this transaction (0 if no
175 	 * account). * Not required if transaction_type=3 <br>
176 	 * category_id Required The id of the category for this transaction (0 if no
177 	 * category) <br>
178 	 * description Required Text for the description of this transaction <br>
179 	 * jive Optional If the transaction being added should be marked as jived.
180 	 * (0= un-jived, 1= jived) <br>
181 	 * from_account_id Optional If this transaction is a transfer, this is the
182 	 * id of the account you're transferring from. <br>
183 	 * to_account_id Optional If this transaction is a transfer, this is the id
184 	 * of the account you're transferring to. <br>
185 	 * check_num Optional If the user has a premium membership and has the
186 	 * check_num field enabled, the system will accept a check number <br>
187 	 * memo Optional If the user has a premium membership and has the memo field
188 	 * enabled, the system will accept a memo <br>
189 	 * payee Optional If the user has a premium membership and has the payee
190 	 * field enabled, the system will accept a payee
191 	 * <p>
192 	 * Returned Values: <br>
193 	 * Value Description <br>
194 	 * Multiple Responses* Returns the id of the newly created transaction, true
195 	 * (if the transaction is a transfer) or false/null on fail.
196 	 * 
197 	 * @Override {@link AbstractCall#insert(AbstractDataType)}
198 	 * @throws IOException
199 	 * @return transaction
200 	 */
201 	public String insert(TransactionDataType input)
202 			throws ClearcheckbookException {
203 		return super.insert(input);
204 	}
205 
206 	/***
207 	 * Edit a specific transaction for the current user. <br>
208 	 * Method: put <br>
209 	 * Call: transaction
210 	 * <p>
211 	 * Example: <br>
212 	 * https://username:password@www.clearcheckbook.com/api/transaction/
213 	 * <p>
214 	 * Parameters: <br>
215 	 * Parameter Required Description <br>
216 	 * id Required The id of the transaction being edited <br>
217 	 * date Required The date for the transaction (Formatted as yyyy-mm-dd) <br>
218 	 * amount Required Float value formatted as (xxxx.xx) <br>
219 	 * transaction_type Required Whether the transaction is a deposit or
220 	 * withdrawal (0= Withdrawal, 1= Deposit) <br>
221 	 * account_id Required The id of the account for this transaction (0 if no
222 	 * account) <br>
223 	 * category_id Required The id of the category for this transaction (0 if no
224 	 * category) <br>
225 	 * description Required Text for the description of this transaction <br>
226 	 * jive Optional Optional value to set whether or not the transaction is
227 	 * jived (0= Un-jived, 1= Jived). If you just want to jive a transaction,
228 	 * use editJive() instead. <br>
229 	 * check_num Optional If the user has a premium membership and has the
230 	 * check_num field enabled, the system will accept a check number <br>
231 	 * memo Optional If the user has a premium membership and has the memo field
232 	 * enabled, the system will accept a memo <br>
233 	 * payee Optional If the user has a premium membership and has the payee
234 	 * field enabled, the system will accept a payee
235 	 * <p>
236 	 * Returned Values: <br>
237 	 * Value Description <br>
238 	 * true / false Returns true on a successful edit or false/null on fail.
239 	 * 
240 	 * @Override {@link AbstractCall#edit(AbstractDataType)}
241 	 * @return transaction
242 	 * @throws ClearcheckbookException
243 	 */
244 	public boolean edit(TransactionDataType input)
245 			throws ClearcheckbookException {
246 		return super.edit(input);
247 	}
248 
249 	/***
250 	 * Delete a specific transaction for the current user. <br>
251 	 * Method: delete <br>
252 	 * Call: transaction
253 	 * <p>
254 	 * Example: <br>
255 	 * https://username:password@www.clearcheckbook.com/api/transaction/
256 	 * <p>
257 	 * Parameters: <br>
258 	 * Parameter Required Description <br>
259 	 * id Required The id of the transaction to delete
260 	 * <p>
261 	 * Returned Values: <br>
262 	 * Value Description <br>
263 	 * true / false Returns true on a successful delete or false/null on fail
264 	 * 
265 	 * @Override {@link AbstractCall#insert(AbstractDataType)}
266 	 * @throws IOException
267 	 * @return transaction
268 	 * @throws ClearcheckbookException
269 	 */
270 	@Override
271 	public boolean delete(ParsedNameValuePair input)
272 			throws ClearcheckbookException {
273 		return super.delete(input);
274 	}
275 
276 	/***
277 	 * Jive or Un-jive a specific transaction for the current user. <br>
278 	 * Method: put <br>
279 	 * Call: jive
280 	 * <p>
281 	 * Example: <br>
282 	 * https://username:password@www.clearcheckbook.com/api/jive/
283 	 * <p>
284 	 * Parameters: <br>
285 	 * Parameter Required Description <br>
286 	 * id Required The id of the transaction being updated <br>
287 	 * status Required The status of the jive (0= Un-jived, 1= Jived)
288 	 * <p>
289 	 * Returned Values: <br>
290 	 * Value Description <br>
291 	 * true / false Returns true on a successful jive update or false/null on
292 	 * fail
293 	 * 
294 	 * @param input
295 	 * @throws ClearcheckbookException
296 	 */
297 	public boolean editJive(ParsedNameValuePair id, boolean jiveStatus)
298 			throws ClearcheckbookException {
299 		String status = (jiveStatus) ? "1" : "0";
300 		ParsedNameValuePair statusParameter = new ParsedNameValuePair("status",
301 				status);
302 		try {
303 			String exitStatus = this.getConnection().putPage("jive",
304 					new ParsedNameValuePair[] { id, statusParameter });
305 			return Boolean.valueOf(exitStatus);
306 		} catch (IOException e) {
307 			throw new ClearcheckbookException(
308 					"failed to edit jive for transaction id: " + id.getValue(),
309 					e);
310 		}
311 	}
312 }