}*/
}
private void addTransaction(HttpServletRequest request, HttpServletResponse response) throws IOException
{
NotificationBean notificationBean = new NotificationBean();
if(isPost){
// recive post data
String type = request.getParameter("type");
String dateStr = request.getParameter("date");
String amountStr = request.getParameter("amount");
String description = request.getParameter("description");
// valiadation
Date date = null;
float amount = 0;
type = "EARNING".equals(type) ? "EARNING" : "EXPENSE";
try {
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
date = formatter.parse(dateStr);
} catch (ParseException e) {
// do nothing
}
try
{
amount = Float.valueOf(amountStr).floatValue();
} catch (Exception e) {
// do nothing
}
// set notifications
if(date == null){
notificationBean.addError("Please enter a valid date");
}
if(amount == 0){
notificationBean.addError("Please enter an valid amount");
}
// store data
if(notificationBean.getErrorCount() == 0 ){
Key transactionKey = KeyFactory.createKey("UserTransactions", user.getUserId());
Entity t = new Entity("Transaction", transactionKey);
t.setProperty("type", type);