Example usage for javax.servlet ServletException printStackTrace

List of usage examples for javax.servlet ServletException printStackTrace

Introduction

In this page you can find the example usage for javax.servlet ServletException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:net.morphbank.mbsvc3.webservices.Uploader.java

/**
 * Shows the list of xml files generated
 * @param request// ww  w .j  av  a 2  s .co m
 * @param response
 */
private void htmlPresentation(HttpServletRequest request, HttpServletResponse response, String folderPath,
        boolean testPassed) {
    StringBuffer listOfFiles = new StringBuffer();
    ArrayList<String> filesToZip = new ArrayList<String>();
    Iterator<String> iter = listOfXmlFiles.iterator();
    while (iter.hasNext()) {
        String next = iter.next();
        if (next.contains("Size of file") || !next.endsWith(".xml")) {
            listOfFiles.append(next + "<br />");
        } else {
            String nameToDisplay = next.replaceFirst(folderPath, "");
            next = next.replaceFirst(folderPath, "");
            filesToZip.add(next);
            String link = "<a href=\"" + "xmlfiles/" + next + "\">" + nameToDisplay + "</a>";
            if (!sendToDB) {
                listOfFiles.append(this.createHtmlForm(link, next));
            } else {
                listOfFiles.append(link + "<br />");
            }
        }
    }
    if (testPassed) {
        String zipFile = this.createZipFile();
        listOfFiles.append("<br/><b>Download all xml files: </b>");
        listOfFiles.append("<a href=\"" + "xmlfiles/" + zipFile + "\">" + zipFile + "</a>");
    }
    if (listOfFiles.length() == 0) {
        listOfFiles.append("No file selected.");
    }
    request.setAttribute("listOfFiles", listOfFiles.toString());
    try {
        this.getServletContext().getRequestDispatcher("/showListOfFile.jsp").forward(request, response);
    } catch (ServletException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.emc.plants.web.servlets.AccountServlet.java

private void performTask(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    String action = null;/*from w ww.jav a 2s . c om*/

    action = req.getParameter(Util.ATTR_ACTION);
    Util.debug("action=" + action);

    if (action.equals(ACTION_LOGIN)) {
        try {
            HttpSession session = req.getSession(true);
            String userid = req.getParameter("userid");
            String passwd = req.getParameter("passwd");
            String updating = req.getParameter(Util.ATTR_UPDATING);

            String results = null;
            if (Util.validateString(userid)) {
                results = login.verifyUserAndPassword(userid, passwd);
            } else {
                //user id was invalid, and may contain XSS attack
                results = "\nEmail address was invalid.";
                Util.debug("User id or email address was invalid. id=" + userid);
            }

            // If results have an error msg, return it, otherwise continue.
            if (results != null) {
                // Proliferate UPDATING flag if user is trying to update his account.
                if (updating.equals("true"))
                    req.setAttribute(Util.ATTR_UPDATING, "true");

                req.setAttribute(Util.ATTR_RESULTS, results);
                requestDispatch(getServletConfig().getServletContext(), req, resp, Util.PAGE_LOGIN);
            } else {
                // If not logging in for the first time, then clear out the
                // session data for the old user.
                if (session.getAttribute(Util.ATTR_CUSTOMER) != null) {
                    session.removeAttribute(Util.ATTR_CART);
                    session.removeAttribute(Util.ATTR_CART_CONTENTS);
                    session.removeAttribute(Util.ATTR_CHECKOUT);
                    session.removeAttribute(Util.ATTR_ORDERKEY);
                }

                // Store customer userid in HttpSession.
                CustomerInfo customerInfo = login.getCustomerInfo(userid);
                session.setAttribute(Util.ATTR_CUSTOMER, customerInfo);
                Util.debug("updating=" + updating + "=");

                // Was customer trying to edit account information.
                if (updating.equals("true")) {
                    req.setAttribute(Util.ATTR_EDITACCOUNTINFO, customerInfo);

                    requestDispatch(getServletConfig().getServletContext(), req, resp, Util.PAGE_ACCOUNT);
                } else {
                    // See if user was in the middle of checking out.
                    Boolean checkingOut = (Boolean) session.getAttribute(Util.ATTR_CHECKOUT);
                    Util.debug("checkingOut=" + checkingOut + "=");
                    if ((checkingOut != null) && (checkingOut.booleanValue())) {
                        Util.debug("must be checking out");
                        requestDispatch(getServletConfig().getServletContext(), req, resp, Util.PAGE_ORDERINFO);
                    } else {
                        Util.debug("must NOT be checking out");
                        String url;
                        String category = (String) session.getAttribute(Util.ATTR_CATEGORY);

                        // Default to plants
                        Util.debug("category : " + category);
                        if ((category == null) || (category.equals("null"))) {
                            url = Util.PAGE_PROMO;
                        } else {
                            url = Util.PAGE_SHOPPING;
                            req.setAttribute(Util.ATTR_INVITEMS,
                                    catalog.getItemsByCategory(Integer.parseInt(category)));
                        }

                        requestDispatch(getServletConfig().getServletContext(), req, resp, url);
                    }
                }
            }
        } catch (ServletException e) {
            e.printStackTrace();
            req.setAttribute(Util.ATTR_RESULTS, "/nException occurred");
            throw e;
        } catch (Exception e) {
            req.setAttribute(Util.ATTR_RESULTS, "/nException occurred");
            e.printStackTrace();
            throw new ServletException(e.getMessage());
        }
    } else if (action.equals(ACTION_REGISTER)) {
        // Register a new user.
        //         try
        //         {
        String url;
        HttpSession session = req.getSession(true);

        String userid = req.getParameter("userid");
        String password = req.getParameter("passwd");
        String cpassword = req.getParameter("vpasswd");
        String firstName = req.getParameter("fname");
        String lastName = req.getParameter("lname");
        String addr1 = req.getParameter("addr1");
        String addr2 = req.getParameter("addr2");
        String addrCity = req.getParameter("city");
        String addrState = req.getParameter("state");
        String addrZip = req.getParameter("zip");
        String phone = req.getParameter("phone");

        //validate all user input
        //This could be done more eloquently using a framework such as Struts...
        if (!Util.validateString(userid)) {
            req.setAttribute(Util.ATTR_RESULTS, "Email address contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(firstName)) {
            req.setAttribute(Util.ATTR_RESULTS, "First Name contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(lastName)) {
            req.setAttribute(Util.ATTR_RESULTS, "Last Name contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(addr1)) {
            req.setAttribute(Util.ATTR_RESULTS, "Address Line 1 contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(addr2)) {
            req.setAttribute(Util.ATTR_RESULTS, "Address Line 2 contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(addrCity)) {
            req.setAttribute(Util.ATTR_RESULTS, "City contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(addrState)) {
            req.setAttribute(Util.ATTR_RESULTS, "State contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(addrZip)) {
            req.setAttribute(Util.ATTR_RESULTS, "Zip contains invalid characters.");
            url = Util.PAGE_REGISTER;
        } else if (!Util.validateString(phone)) {
            req.setAttribute(Util.ATTR_RESULTS, "Phone Number contains invalid characters.");
            url = Util.PAGE_REGISTER;
        }
        // Make sure passwords match.
        else if (!password.equals(cpassword)) {
            req.setAttribute(Util.ATTR_RESULTS, "Passwords do not match.");
            url = Util.PAGE_REGISTER;
        } else {
            // Create the new user.
            CustomerInfo customerInfo = login.createNewUser(userid, password, firstName, lastName, addr1, addr2,
                    addrCity, addrState, addrZip, phone);

            if (customerInfo != null) {
                // Store customer info in HttpSession.
                session.setAttribute(Util.ATTR_CUSTOMER, customerInfo);

                // See if user was in the middle of checking out.
                Boolean checkingOut = (Boolean) session.getAttribute(Util.ATTR_CHECKOUT);
                if ((checkingOut != null) && (checkingOut.booleanValue())) {
                    url = Util.PAGE_ORDERINFO;
                } else {
                    String category = (String) session.getAttribute(Util.ATTR_CATEGORY);

                    // Default to plants
                    if (category == null) {
                        url = Util.PAGE_PROMO;
                    } else {
                        url = Util.PAGE_SHOPPING;
                        req.setAttribute(Util.ATTR_INVITEMS,
                                catalog.getItemsByCategory(Integer.parseInt(category)));
                    }
                }
            } else {
                url = Util.PAGE_REGISTER;
                req.setAttribute(Util.ATTR_RESULTS, "New user NOT created!");
            }
        }
        requestDispatch(getServletConfig().getServletContext(), req, resp, url);
        //         }
        //         catch (CreateException e) { }
    } else if (action.equals(ACTION_ACCOUNT)) {
        String url;
        HttpSession session = req.getSession(true);
        CustomerInfo customerInfo = (CustomerInfo) session.getAttribute(Util.ATTR_CUSTOMER);
        if (customerInfo == null) {
            url = Util.PAGE_LOGIN;
            req.setAttribute(Util.ATTR_UPDATING, "true");
            req.setAttribute(Util.ATTR_RESULTS, "\nYou must login first.");
        } else {
            url = Util.PAGE_ACCOUNT;
            req.setAttribute(Util.ATTR_EDITACCOUNTINFO, customerInfo);
        }
        requestDispatch(getServletConfig().getServletContext(), req, resp, url);
    } else if (action.equals(ACTION_ACCOUNTUPDATE)) {
        //         try
        //         {
        String url;
        HttpSession session = req.getSession(true);
        CustomerInfo customerInfo = (CustomerInfo) session.getAttribute(Util.ATTR_CUSTOMER);

        String userid = customerInfo.getCustomerID();
        String firstName = req.getParameter("fname");
        String lastName = req.getParameter("lname");
        String addr1 = req.getParameter("addr1");
        String addr2 = req.getParameter("addr2");
        String addrCity = req.getParameter("city");
        String addrState = req.getParameter("state");
        String addrZip = req.getParameter("zip");
        String phone = req.getParameter("phone");

        // Create the new user.
        customerInfo = login.updateUser(userid, firstName, lastName, addr1, addr2, addrCity, addrState, addrZip,
                phone);
        // Store updated customer info in HttpSession.
        session.setAttribute(Util.ATTR_CUSTOMER, customerInfo);

        // See if user was in the middle of checking out.
        Boolean checkingOut = (Boolean) session.getAttribute(Util.ATTR_CHECKOUT);
        if ((checkingOut != null) && (checkingOut.booleanValue())) {
            url = Util.PAGE_ORDERINFO;
        } else {
            String category = (String) session.getAttribute(Util.ATTR_CATEGORY);

            // Default to plants
            if (category == null) {
                url = Util.PAGE_PROMO;
            } else {
                url = Util.PAGE_SHOPPING;
                req.setAttribute(Util.ATTR_INVITEMS, catalog.getItemsByCategory(Integer.parseInt(category)));
            }
        }

        requestDispatch(getServletConfig().getServletContext(), req, resp, url);
        //         }
        //         catch (CreateException e) { }
    } else if (action.equals(ACTION_SETLOGGING)) {
        String debugSetting = req.getParameter("logging");
        if ((debugSetting == null) || (!debugSetting.equals("debug")))
            Util.setDebug(false);
        else
            Util.setDebug(true);

        requestDispatch(getServletConfig().getServletContext(), req, resp, Util.PAGE_HELP);
    }
}

From source file:org.openbravo.erpCommon.ad_forms.DocCostAdjustment.java

/**
 * Get the account for Accounting Schema
 * //w w  w .  j  a  va 2 s .c  om
 * @param AcctType
 *          see ACCTTYPE_*
 * @param as
 *          accounting schema
 * @return Account
 */
public final Account getAccountByWarehouse(String AcctType, AcctSchema as, String WarehouseId,
        ConnectionProvider conn) {
    AcctServerData[] data = null;

    try {
        /** Account Type - Invoice */
        if (AcctType.equals(ACCTTYPE_InvDifferences)) {
            /** Inventory Accounts */
            data = AcctServerData.selectWDifferencesAcct(conn, WarehouseId, as.getC_AcctSchema_ID());
        } else {
            log4jDocCostAdjustment.warn("AcctServer - getAccount - Not found AcctType=" + AcctType);
            return null;
        }
    } catch (ServletException e) {
        log4jDocCostAdjustment.warn(e);
        e.printStackTrace();
    }
    // Get Acct
    String Account_ID = "";
    if (data != null && data.length != 0) {
        Account_ID = data[0].accountId;
    } else
        return null;
    // No account
    if (Account_ID.equals("")) {
        log4jDocCostAdjustment
                .warn("AcctServer - getAccount - NO account Type=" + AcctType + ", Record=" + Record_ID);
        return null;
    }
    Account acct = null;
    try {
        acct = Account.getAccount(conn, Account_ID);
    } catch (ServletException e) {
        log4jDocCostAdjustment.warn(e);
        e.printStackTrace();
    }
    return acct;
}

From source file:com.glaf.core.web.springmvc.MxSystemDbTableController.java

@ResponseBody
@RequestMapping("/genCreateScripts")
public void genCreateScripts(HttpServletRequest request, HttpServletResponse response) throws IOException {
    StringBuffer sb = new StringBuffer();
    String tableNames = request.getParameter("tables");
    String dbType = request.getParameter("dbType");
    if (StringUtils.isNotEmpty(dbType) && StringUtils.isNotEmpty(tableNames)) {
        List<String> list = StringTools.split(tableNames);
        for (String tableName : list) {
            List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tableName);
            TableDefinition tableDefinition = new TableDefinition();
            tableDefinition.setTableName(tableName);
            tableDefinition.setColumns(columns);
            for (ColumnDefinition column : columns) {
                if (column.isPrimaryKey()) {
                    tableDefinition.setIdColumn(column);
                    String sql = DBUtils.getCreateTableScript(dbType, tableDefinition);
                    sb.append(FileUtils.newline).append(sql).append(FileUtils.newline)
                            .append(FileUtils.newline);
                    break;
                }/*from w w w .j a v a2  s  . co  m*/
            }
        }
    }

    try {
        ResponseUtils.download(request, response, sb.toString().getBytes(),
                "createTable_" + DateUtils.getDate(new Date()) + "." + dbType + ".sql");
    } catch (ServletException ex) {
        ex.printStackTrace();
    }
}

From source file:com.glaf.core.web.springmvc.MxSystemDbTableController.java

@ResponseBody
@RequestMapping("/exportData")
public void exportData(HttpServletRequest request, HttpServletResponse response) throws IOException {
    StringBuffer sb = new StringBuffer();
    String tables = request.getParameter("exportTables");
    String dbType = request.getParameter("dbType");
    if (StringUtils.isNotEmpty(dbType) && StringUtils.isNotEmpty(tables)) {
        List<String> list = StringTools.split(tables);
        for (String tablename : list) {
            if (StringUtils.isNotEmpty(tablename)) {
                if (StringUtils.endsWithIgnoreCase(tablename, "log")) {
                    continue;
                }//from  w  w  w .j  av  a 2s .  c  o m
                logger.debug("process table:" + tablename);
                List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tablename);
                TablePageQuery query = new TablePageQuery();
                query.tableName(tablename);
                query.firstResult(0);
                query.maxResults(20000);
                int count = tablePageService.getTableCount(query);
                if (count <= 20000) {
                    List<Map<String, Object>> rows = tablePageService.getTableData(query);
                    if (rows != null && !rows.isEmpty()) {
                        for (Map<String, Object> dataMap : rows) {
                            Map<String, Object> lowerMap = QueryUtils.lowerKeyMap(dataMap);
                            sb.append(" insert into ").append(tablename).append(" (");
                            for (int i = 0, len = columns.size(); i < len; i++) {
                                ColumnDefinition column = columns.get(i);
                                sb.append(column.getColumnName().toLowerCase());
                                if (i < columns.size() - 1) {
                                    sb.append(", ");
                                }
                            }
                            sb.append(" ) values (");
                            for (int i = 0, len = columns.size(); i < len; i++) {
                                ColumnDefinition column = columns.get(i);
                                Object value = lowerMap.get(column.getColumnName().toLowerCase());
                                if (value != null) {
                                    if (value instanceof Short) {
                                        sb.append(value);
                                    } else if (value instanceof Integer) {
                                        sb.append(value);
                                    } else if (value instanceof Long) {
                                        sb.append(value);
                                    } else if (value instanceof Double) {
                                        sb.append(value);
                                    } else if (value instanceof String) {
                                        String str = (String) value;
                                        str = StringTools.replace(str, "'", "''");
                                        sb.append("'").append(str).append("'");
                                    } else if (value instanceof Date) {
                                        Date date = (Date) value;
                                        if (StringUtils.equalsIgnoreCase(dbType, "oracle")) {
                                            sb.append(" to_date('").append(DateUtils.getDateTime(date))
                                                    .append("', 'yyyy-mm-dd hh24:mi:ss')");
                                        } else if (StringUtils.equalsIgnoreCase(dbType, "db2")) {
                                            sb.append(" TO_DATE('").append(DateUtils.getDateTime(date))
                                                    .append("', ''YYY-MM-DD HH24:MI:SS')");
                                        } else {
                                            sb.append("'").append(DateUtils.getDateTime(date)).append("'");
                                        }
                                    } else {
                                        String str = value.toString();
                                        str = StringTools.replace(str, "'", "''");
                                        sb.append("'").append(str).append("'");
                                    }
                                } else {
                                    sb.append("null");
                                }
                                if (i < columns.size() - 1) {
                                    sb.append(", ");
                                }
                            }
                            sb.append(");");
                            sb.append(FileUtils.newline);
                        }
                    }
                }
                sb.append(FileUtils.newline);
                sb.append(FileUtils.newline);
            }
        }
    }

    try {
        ResponseUtils.download(request, response, sb.toString().getBytes(),
                "insert_" + DateUtils.getDate(new Date()) + "." + dbType + ".sql");
    } catch (ServletException ex) {
        ex.printStackTrace();
    }
}

From source file:com.glaf.core.web.springmvc.MxSystemDbTableController.java

@ResponseBody
@RequestMapping("/exportSysTables")
public void exportSysTables(HttpServletRequest request, HttpServletResponse response) throws IOException {
    StringBuffer sb = new StringBuffer();
    JSONArray result = null;/*from  ww  w.  j  a va  2s. c o  m*/
    SystemParam param = systemParamService.getSystemParam("sys_table");
    if (param != null && StringUtils.isNotEmpty(param.getTextVal())) {
        result = JSON.parseArray(param.getTextVal());
    }
    String dbType = request.getParameter("dbType");
    if (StringUtils.isNotEmpty(dbType) && result != null) {
        for (int index = 0, len = result.size(); index < len; index++) {
            JSONObject json = result.getJSONObject(index);
            String tablename = json.getString("tablename");
            if (StringUtils.isNotEmpty(tablename)) {
                logger.debug("process table:" + tablename);
                List<ColumnDefinition> columns = DBUtils.getColumnDefinitions(tablename);
                TablePageQuery query = new TablePageQuery();
                query.tableName(tablename);
                query.firstResult(0);
                query.maxResults(5000);
                int count = tablePageService.getTableCount(query);
                if (count <= 5000) {
                    List<Map<String, Object>> rows = tablePageService.getTableData(query);
                    if (rows != null && !rows.isEmpty()) {
                        for (Map<String, Object> dataMap : rows) {
                            Map<String, Object> lowerMap = QueryUtils.lowerKeyMap(dataMap);
                            sb.append(" insert into ").append(tablename).append(" (");
                            for (int i = 0, len2 = columns.size(); i < len2; i++) {
                                ColumnDefinition column = columns.get(i);
                                sb.append(column.getColumnName().toLowerCase());
                                if (i < columns.size() - 1) {
                                    sb.append(", ");
                                }
                            }
                            sb.append(" ) values (");
                            for (int i = 0, len2 = columns.size(); i < len2; i++) {
                                ColumnDefinition column = columns.get(i);
                                Object value = lowerMap.get(column.getColumnName().toLowerCase());
                                if (value != null) {
                                    if (value instanceof Short) {
                                        sb.append(value);
                                    } else if (value instanceof Integer) {
                                        sb.append(value);
                                    } else if (value instanceof Long) {
                                        sb.append(value);
                                    } else if (value instanceof Double) {
                                        sb.append(value);
                                    } else if (value instanceof String) {
                                        String str = (String) value;
                                        str = StringTools.replace(str, "'", "''");
                                        sb.append("'").append(str).append("'");
                                    } else if (value instanceof Date) {
                                        Date date = (Date) value;
                                        if (StringUtils.equalsIgnoreCase(dbType, "oracle")) {
                                            sb.append(" to_date('").append(DateUtils.getDateTime(date))
                                                    .append("', 'yyyy-mm-dd hh24:mi:ss')");
                                        } else if (StringUtils.equalsIgnoreCase(dbType, "db2")) {
                                            sb.append(" TO_DATE('").append(DateUtils.getDateTime(date))
                                                    .append("', ''YYY-MM-DD HH24:MI:SS')");
                                        } else {
                                            sb.append("'").append(DateUtils.getDateTime(date)).append("'");
                                        }
                                    } else {
                                        String str = value.toString();
                                        str = StringTools.replace(str, "'", "''");
                                        sb.append("'").append(str).append("'");
                                    }
                                } else {
                                    sb.append("null");
                                }
                                if (i < columns.size() - 1) {
                                    sb.append(", ");
                                }
                            }
                            sb.append(");");
                            sb.append(FileUtils.newline);
                        }
                    }
                }
                sb.append(FileUtils.newline);
                sb.append(FileUtils.newline);
            }
        }
    }

    try {
        ResponseUtils.download(request, response, sb.toString().getBytes(),
                "insert_sys_" + DateUtils.getDate(new Date()) + "." + dbType + ".sql");
    } catch (ServletException ex) {
        ex.printStackTrace();
    }
}

From source file:com.lrodriguez.SVNBrowser.java

public void init() throws ServletException {
    try {//from   w ww .j av a2  s .c o  m
        super.init();
    } catch (ServletException e) {
        e.printStackTrace();
    }
    webappRoot = (this.getServletContext().getRealPath("/") == null ? getInitParameter(WEBAPP_ROOT)
            : this.getServletContext().getRealPath("/")).replaceAll("[/\\\\]+", "\\" + File.separator);
    ;
    System.out.println("init() setting webappRoot to " + webappRoot);
    if (getServletContext().getAttribute("com.lrodriguez.model.SVNLogEntryDB") == null) {
        try {
            initSVNRepositoryFactories();
            //SVNLogEntryDB db = SVNLogEntryDB.getInstance();
            SVNRepository repository = SVNRepositoryFactory
                    .create(SVNURL.parseURIEncoded(getInitParameter(REPOSITORY_URL)));
            ISVNAuthenticationManager manager = SVNWCUtil.createDefaultAuthenticationManager(
                    getInitParameter(USER_NAME), getInitParameter("password"));
            repository.setAuthenticationManager(manager);

        } catch (SVNException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.openbravo.erpCommon.ad_forms.DocInvoice.java

private ArrayList<HashMap<String, String>> calculateAccDefPlan(Period startingPeriod, int periodNumber,
        BigDecimal amount, String strCurrencyId) {
    Period period = startingPeriod;
    Date date = period.getEndingDate();
    ArrayList<HashMap<String, String>> plan = new ArrayList<HashMap<String, String>>();
    int i = 1;/*w w  w  .  j a va  2 s .  c  o m*/
    BigDecimal total = BigDecimal.ZERO;
    int stdPrecision = 0;
    OBContext.setAdminMode(true);
    try {
        stdPrecision = OBDal.getInstance().get(Currency.class, this.C_Currency_ID).getStandardPrecision()
                .intValue();
    } finally {
        OBContext.restorePreviousMode();
    }
    BigDecimal periodAmount = amount
            .divide(new BigDecimal(periodNumber), new MathContext(32, RoundingMode.HALF_UP))
            .setScale(stdPrecision, BigDecimal.ROUND_HALF_UP);

    while (i <= periodNumber) {
        if (!OBDateUtils.formatDate(date).equals(DateAcct)) {
            HashMap<String, String> hm = new HashMap<String, String>();
            hm.put("date", OBDateUtils.formatDate(date));
            hm.put("amount", i == periodNumber ? amount.subtract(total).toString() : periodAmount.toString());
            plan.add(hm);
        }
        try {
            AcctServerData[] data = AcctServerData.periodOpen(connectionProvider, AD_Client_ID, DocumentType,
                    AD_Org_ID, OBDateUtils.formatDate(period.getEndingDate()));
            if ("".equals(data[0].period)) {
                setStatus(STATUS_PeriodClosed);
                throw new OBException("@PeriodNotAvailable@");
            }
        } catch (ServletException e) {
            log4j.warn("DocInvoice - Error checking period open.", e);
            e.printStackTrace();
        }
        if (i < periodNumber) {
            period = AccDefUtility.getNextPeriod(period);
            date = period.getEndingDate();
        }
        total = total.add(periodAmount);
        i++;
    }
    return plan;
}

From source file:org.openbravo.erpCommon.ad_forms.AcctServer.java

public static BigDecimal getConvertionRate(String CurFrom_ID, String CurTo_ID, String ConvDate, String RateType,
        String client, String org, ConnectionProvider conn) {
    if (CurFrom_ID.equals(CurTo_ID))
        return BigDecimal.ONE;
    AcctServerData[] data = null;/* www  . jav a 2s  .com*/
    try {
        if (ConvDate != null && ConvDate.equals(""))
            ConvDate = DateTimeData.today(conn);
        // ConvDate IN DATE
        if (RateType == null || RateType.equals(""))
            RateType = "S";
        data = AcctServerData.currencyConvertionRate(conn, CurFrom_ID, CurTo_ID, ConvDate, RateType, client,
                org);
    } catch (ServletException e) {
        log4j.warn(e);
        e.printStackTrace();
    }
    if (data == null || data.length == 0) {
        log4j.error("No conversion ratio");
        return BigDecimal.ZERO;
    } else {
        if (log4j.isDebugEnabled())
            log4j.debug("getConvertionRate - rate:" + data[0].converted);
        return new BigDecimal(data[0].converted);
    }
}

From source file:org.openbravo.erpCommon.ad_forms.AcctServer.java

public static String getConvertedAmt(String Amt, String CurFrom_ID, String CurTo_ID, String ConvDate,
        String RateType, String client, String org, ConnectionProvider conn) {
    if (log4j.isDebugEnabled())
        log4j.debug("AcctServer - getConvertedAmount - starting method - Amt : " + Amt + " - CurFrom_ID : "
                + CurFrom_ID + " - CurTo_ID : " + CurTo_ID + "- ConvDate: " + ConvDate + " - RateType:"
                + RateType + " - client:" + client + "- org:" + org);
    if (Amt.equals(""))
        throw new IllegalArgumentException("AcctServer - getConvertedAmt - required parameter missing - Amt");
    if (CurFrom_ID.equals(CurTo_ID) || Amt.equals("0"))
        return Amt;
    AcctServerData[] data = null;//from  w  w  w  .j av  a 2 s .  co m
    try {
        if (ConvDate != null && ConvDate.equals(""))
            ConvDate = DateTimeData.today(conn);
        // ConvDate IN DATE
        if (RateType == null || RateType.equals(""))
            RateType = "S";
        data = AcctServerData.currencyConvert(conn, Amt, CurFrom_ID, CurTo_ID, ConvDate, RateType, client, org);
    } catch (ServletException e) {
        log4j.warn(e);
        e.printStackTrace();
    }
    if (data == null || data.length == 0) {
        /*
         * log4j.error("No conversion ratio"); throw new
         * ServletException("No conversion ratio defined!");
         */
        return "";
    } else {
        if (log4j.isDebugEnabled())
            log4j.debug("getConvertedAmount - converted:" + data[0].converted);
        return data[0].converted;
    }
}