com.ba.forms.serviceBillForm.BAServiceBillAction.java Source code

Java tutorial

Introduction

Here is the source code for com.ba.forms.serviceBillForm.BAServiceBillAction.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ba.forms.serviceBillForm;

import com.ba.masters.room.BARoomFactory;
import com.ba.util.BAHandleAllException;
import com.ba.util.BAUtil;
import com.fins.gt.server.GridServerHandler;
import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.json.simple.JSONObject;

/**
 *
 * @author RAPID
 */
public class BAServiceBillAction extends DispatchAction {

    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    private int objPageCount = 0;
    private static Logger logger = Logger.getLogger(BAServiceBillAction.class);

    /**
     * This is the Struts action method called on
     * http://.../actionPath?method=myAction1, where "method" is the value
     * specified in <action> element : ( <action parameter="method" .../> )
     */

    public ActionForward loadServiceBill(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        try {
            logger.info(" loadServiceBill method starts here");
            request.setAttribute("lstRooms", BARoomFactory.getInstanceOfBARoomFactory().getRoomDetails());
        } catch (Exception ex) {
            if (ex.toString().contains("com.mysql.jdbc.MysqlDataTruncation")) {
                request.setAttribute("ErrorMessage",
                        "Data is not correctly inserted into Database.Insertion Failed");
            } else if (ex.toString().contains("MySQLIntegrityConstraintViolationException")) {
                request.setAttribute("ErrorMessage", "Record already Exists");
            } else {
                String errorMessage = BAHandleAllException.exceptionHandler(ex);
                request.setAttribute("ErrorMessage", errorMessage);
            }
        }
        return mapping.findForward(SUCCESS);

    }

    public ActionForward baSave(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        logger.info(" save method starts here");
        GridServerHandler objGridServerHandler = new GridServerHandler(request, response);
        try {
            //      BAServiceBillActionForm formBean = (BAServiceBillActionForm)form;
            BAServiceBillDTO dto = new BAServiceBillDTO();

            //      BeanUtils.copyProperties(dto,formBean);

            dto.setRoomId(request.getParameter("roomId"));
            dto.setDateField(request.getParameter("date"));
            dto.setCustomerName(request.getParameter("customerName"));
            dto.setOrderType(request.getParameter("orderType"));
            dto.setAmount(request.getParameter("amount"));
            dto.setServiceCharge(request.getParameter("serviceCharge"));
            dto.setDiscount(request.getParameter("discount"));
            dto.setServiceTax(request.getParameter("serviceTax"));
            dto.setVat(request.getParameter("vat"));
            dto.setNetAmount(request.getParameter("netAmount"));
            dto.setPaymentMode(request.getParameter("paymentMode"));
            dto.setBookingId(request.getParameter("bookingId"));
            dto.setLstInsertedRecords(objGridServerHandler.getInsertedRecords());
            dto.setLstUpdatedRecords(objGridServerHandler.getUpdatedRecords());
            dto.setLstDeletedRecords(objGridServerHandler.getDeletedRecords());
            int userId = (Integer) request.getSession().getAttribute("UserId");
            int result = BAServiceBillFactory.getInstanceOfBAServiceBillFactory().insertServiceBillData(dto,
                    userId);
            if (result == 0) {
                objGridServerHandler.printResponseText("Record Insertion Failed . Try again");

            }
            if (result > 0) {
                objGridServerHandler.printResponseText("Record Inserted Successfully.");

            }
            if (result < 0) {
                objGridServerHandler.printResponseText("Database Connection  Problem Please check");

            }
        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            if (ex.toString().contains("com.mysql.jdbc.MysqlDataTruncation")) {
                objGridServerHandler
                        .printResponseText("Data is not correctly inserted into Database.Insertion Failed");
            } else if (ex.toString().contains("MySQLIntegrityConstraintViolationException")) {
                objGridServerHandler.printResponseText("Record already Exists");
            } else {
                String errorMessage = BAHandleAllException.exceptionHandler(ex);
                objGridServerHandler.printResponseText(errorMessage);
            }

        }

        return null;
    }

    public ActionForward baUpdate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        logger.info("update method starts here");
        GridServerHandler objGridServerHandler = new GridServerHandler(request, response);
        try {
            logger.info("hello h");
            BAServiceBillActionForm formBean = (BAServiceBillActionForm) form;
            BAServiceBillDTO dto = new BAServiceBillDTO();
            BeanUtils.copyProperties(dto, formBean);
            dto.setLstInsertedRecords(objGridServerHandler.getInsertedRecords());
            dto.setLstUpdatedRecords(objGridServerHandler.getUpdatedRecords());
            dto.setLstDeletedRecords(objGridServerHandler.getDeletedRecords());
            /**    request.setAttribute("lstRooms", BaIRoomFactory.getInstanceOfBaIRoomFactory().getRoomDtls()); */
            int userId = (Integer) request.getSession().getAttribute("UserId");
            int result = BAServiceBillFactory.getInstanceOfBAServiceBillFactory().UpdateServiceBillData(dto,
                    userId);

            if (result == 0) {
                objGridServerHandler.printResponseText("Record Updation Failed . Try again");

            }
            if (result > 0) {
                objGridServerHandler.printResponseText("Record Updated Successfully.");

            }
            if (result < 0) {
                objGridServerHandler.printResponseText("Database Connection  Problem Please check");

            }
        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            if (ex.toString().contains("com.mysql.jdbc.MysqlDataTruncation")) {
                objGridServerHandler
                        .printResponseText("Data is not correctly inserted into Database.Insertion Failed");
            } else if (ex.toString().contains("MySQLIntegrityConstraintViolationException")) {
                objGridServerHandler.printResponseText("Record already Exists");
            } else {
                String errorMessage = BAHandleAllException.exceptionHandler(ex);
                objGridServerHandler.printResponseText(errorMessage);
            }

        }

        return null;

    }

    public ActionForward baDelete(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        logger.info(" delete method starts here");
        try {
            logger.info("hello h");
            BAServiceBillActionForm formBean = (BAServiceBillActionForm) form;
            BAServiceBillDTO dto = new BAServiceBillDTO();
            BeanUtils.copyProperties(dto, formBean);
            /**    request.setAttribute("lstRooms", BaIRoomFactory.getInstanceOfBaIRoomFactory().getRoomDtls()); */
            int result1 = BAServiceBillFactory.getInstanceOfBAServiceBillFactory().deleteServiceBillData(dto);

            if (result1 == 0) {
                request.setAttribute("response", "Record Deletion Failed . Try again");

            }
            if (result1 > 0) {
                request.setAttribute("response", "Record Deleted Successfully.");

            }
            if (result1 < 0) {
                request.setAttribute("response", "Database Connection  Problem Please check");

            }
        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            if (ex.toString().contains("com.mysql.jdbc.MysqlDataTruncation")) {
                request.setAttribute("ErrorMessage",
                        "Data is not correctly inserted into Database.Insertion Failed");
            } else if (ex.toString().contains("MySQLIntegrityConstraintViolationException")) {
                request.setAttribute("ErrorMessage", "Record already Exists");
            } else {
                String errorMessage = BAHandleAllException.exceptionHandler(ex);
                request.setAttribute("ErrorMessage", errorMessage);
            }
        }

        return mapping.findForward(SUCCESS);

    }

    public ActionForward baView(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        JSONObject json = new JSONObject();
        BAServiceBillDTO vo = new BAServiceBillDTO();
        try {
            logger.info(" view method starts here");
            vo.setServiceId((request.getParameter("serviceId")));
            vo.setDateField(request.getParameter("dateField"));
            vo.setRoomId(request.getParameter("roomId"));
            vo.setCustomerName(request.getParameter("customerName"));
            vo.setOrderType((request.getParameter("orderType")));
            vo.setAmount((request.getParameter("amount")));
            vo.setServiceCharge((request.getParameter("serviceCharge")));
            vo.setDiscount((request.getParameter("discount")));
            vo.setServiceTax((request.getParameter("serviceTax")));
            vo.setVat((request.getParameter("vat")));
            vo.setNetAmount((request.getParameter("netAmount")));
            vo.setPaymentMode((request.getParameter("paymentMode")));
            vo.setBookingId((request.getParameter("bookingId")));

            List hashMpServiceBillItemDet = BAServiceBillFactory.getInstanceOfBAServiceBillFactory()
                    .getServiceBillDtls(1, vo);

            objPageCount = BAServiceBillFactory.getInstanceOfBAServiceBillFactory().getPageCount(vo);
            json.put("exception", "");
            json.put("ServiceBillDets", hashMpServiceBillItemDet);
            json.put("ServiceBillExit", hashMpServiceBillItemDet.size());
            json.put("objPageCount", objPageCount);
            //                 logger.warn("strCurrent PageNo ------------->"+objPageCount);

        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            ex.printStackTrace();
            json.put("exception", BAHandleAllException.exceptionHandler(ex));
        }
        response.getWriter().write(json.toString());
        return null;

    }

    public ActionForward baGet(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        logger.info(" get method starts here");
        JSONObject json = new JSONObject();
        BAServiceBillDTO vo = new BAServiceBillDTO();
        try {
            logger.info(" get method starts here");
            String serviceId = request.getParameter("search");
            HashMap hashMpServiceBillfItemDet = BAServiceBillFactory.getInstanceOfBAServiceBillFactory()
                    .getServiceBillItemDtls(serviceId);
            json.put("exception", "");
            json.put("ServiceBillDets", hashMpServiceBillfItemDet);
            json.put("ServiceBillExit", hashMpServiceBillfItemDet.size());

            //                 logger.warn("strCurrent PageNo ------------->"+objPageCount);

        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            ex.printStackTrace();
            json.put("exception", BAHandleAllException.exceptionHandler(ex));
        }
        response.getWriter().write(json.toString());
        return null;

    }

    public ActionForward getPageRecords(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        logger.info(" getPageRecords method starts here");
        JSONObject json = new JSONObject();
        BAServiceBillDTO vo = new BAServiceBillDTO();
        try {
            //            logger.info("======In GcsStockItemAction Action cmsGet method======");
            vo.setServiceId((request.getParameter("serviceId")));
            vo.setDateField(request.getParameter("dateField"));
            vo.setRoomId(request.getParameter("roomId"));
            vo.setCustomerName(request.getParameter("customerName"));
            vo.setOrderType((request.getParameter("orderType")));
            vo.setAmount((request.getParameter("amount")));
            vo.setServiceCharge((request.getParameter("serviceCharge")));
            vo.setDiscount((request.getParameter("discount")));
            vo.setServiceTax((request.getParameter("serviceTax")));
            vo.setVat((request.getParameter("vat")));
            vo.setNetAmount((request.getParameter("netAmount")));
            vo.setPaymentMode((request.getParameter("paymentMode")));
            vo.setBookingId((request.getParameter("bookingId")));

            String strNavigation = request.getParameter("navigation");
            int strCurrentPageNo = Integer.parseInt(request.getParameter("currentPageNo"));
            if (strNavigation != null && !strNavigation.equals("")) {
                if (strNavigation.equals("pre")) {
                    strCurrentPageNo = strCurrentPageNo - 1;
                    if (strCurrentPageNo <= 0)
                        strCurrentPageNo = 1;

                } else if (strNavigation.equals("next")) {
                    strCurrentPageNo = strCurrentPageNo + 1;
                    if (strCurrentPageNo > objPageCount)
                        strCurrentPageNo = objPageCount;
                }
            }
            logger.info("strCurrent PageNo ------------->" + strCurrentPageNo);
            List hashMpServiceBillItemDet = BAServiceBillFactory.getInstanceOfBAServiceBillFactory()
                    .getServiceBillDtls(strCurrentPageNo, vo);

            json.put("exception", "");
            json.put("ServiceBillDets", hashMpServiceBillItemDet);
            json.put("ServiceBillExit", hashMpServiceBillItemDet.size());
        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            ex.printStackTrace();
            json.put("exception", BAHandleAllException.exceptionHandler(ex));
        }
        response.getWriter().write(json.toString());
        return null;
    }

    public ActionForward baGetServiceGridData(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        logger.info(" baGetServiceGridData method starts here");
        GridServerHandler objGridServerHandler = new GridServerHandler(request, response);
        try {
            logger.info(" save method starts here");
            String serviceId = request.getParameter("serviceId");

            List<HashMap<String, String>> lstSalesInvoiceGriddDets = BAServiceBillFactory
                    .getInstanceOfBAServiceBillFactory().getServiceBillGridDtls(BAUtil.getIntValue(serviceId));
            objGridServerHandler.setTotalRowNum(lstSalesInvoiceGriddDets.size());
            objGridServerHandler.setPageSize(lstSalesInvoiceGriddDets.size());
            objGridServerHandler.setData(lstSalesInvoiceGriddDets);

            response.getWriter().write(objGridServerHandler.getLoadResponseText());
        } catch (Exception ex) {
            logger.error("The Exception is  :" + ex);
            objGridServerHandler.printResponseText(BAHandleAllException.exceptionHandler(ex));
        }
        return null;
    }
}