Example usage for java.lang Byte parseByte

List of usage examples for java.lang Byte parseByte

Introduction

In this page you can find the example usage for java.lang Byte parseByte.

Prototype

public static byte parseByte(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal byte .

Usage

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.RealWorkflowPortlet.java

/**
 * Workflow exportalas az ETICS rendszerbe (singlenode & multinode tipusu WF)
public void doExportEtics(ActionRequest request, ActionResponse response) throws PortletException {
String msg = new String("");/* w  w  w .j a va 2 s.co m*/
String retString = "";
try {
    String portalID = new String("http://hostURL:8080/portal30");
    String wfsServiceURL = new String("http://hostURL:8080/wfs");
    String wfsServiceID = new String("/services/urn:wfswfiservice");
    String clientObject = new String("hu.sztaki.lpds.wfs.net.wsaxis13.WfiWfsClientImpl");
    //
        
    WorkflowData wData=PortalCacheService.getInstance().getUser(request.getRemoteUser()).getWorkflow(request.getParameter("workflow"));
    //
        
    Hashtable hsh = new Hashtable();
    hsh.put("url", wData.getWfsID());// PortalCacheService.getInstance().getUser(req.getRemoteUser()).getWorkflow(wfID).getWfsID()
    ServiceType st = InformationBase.getI().getService("wfs", "wfi", hsh, new Vector());
        
        
    WfiWfsClient client = (WfiWfsClient) Class.forName(st.getClientObject()).newInstance();
    client.setServiceURL(st.getServiceUrl());
    client.setServiceID(st.getServiceID());
    //
    ComDataBean comBean = new ComDataBean();
    comBean.setPortalID(PropertyLoader.getInstance().getProperty("service.url"));//portalID
    comBean.setWorkflowtype(wData.getWorkflowType());//"workflowType"
    comBean.setWorkflowID(wData.getWorkflowID());//"workflowID"
    comBean.setGraf(wData.getGraf());//"grafID"
    comBean.setUserID(request.getRemoteUser());//"userID"
    //
    retString = client.getWfiXML(comBean);
    msg=EticsCacheService.getInstance().processWorkflowXml(retString, request.getRemoteUser());
            
    //
} catch (Exception e) {
    e.printStackTrace();
    msg = e.getLocalizedMessage();
}
setRequestAttribute(request.getPortletSession(),"msg",msg);
}
 */

@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    String key;
    if ("editgraphURL".equals(request.getResourceID()) && request.getParameter("wfId") != null) {
        GraphEditorUtil.jnpl(request, response);
        return;
    }

    if ("refreshConfigURL".equals(request.getResourceID())) {
        List<String> graphs = new ArrayList<String>();
        Enumeration<String> enm = PortalCacheService.getInstance().getUser(request.getRemoteUser())
                .getAbstactWorkflows().keys();
        while (enm.hasMoreElements())
            graphs.add(enm.nextElement());

        request.setAttribute("graphs", graphs);
        request.setAttribute("workflow", request.getPortletSession().getAttribute("cworkflow"));
        getPortletContext().getRequestDispatcher("/jsp/workflow/accepteditedgraph.jsp").include(request,
                response);
        return;
    }

    // ajax help
    if (request.getParameter("helptext") != null) {
        super.serveResource(request, response);
        return;
    }
    //output download
    if (request.getParameter("downloadType") != null) {
        response.setContentType("application/zip");
        response.setProperty("Content-Disposition", "inline; filename=\"" + request.getParameter("workflowID")
                + "_" + request.getParameter("jobID") + "_" + request.getParameter("pidID") + "_outputs.zip\"");
        try {
            HttpDownload.fileDownload(request.getParameter("downloadType"), request, response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PortletException("com error");
        }
        return;
    }
    // logs download  
    if (request.getParameter("fileID") != null) {
        response.setContentType("application/text");
        response.setProperty("Content-Disposition",
                "inline; filename=\"" + request.getParameter("workflowID") + "_" + request.getParameter("jobID")
                        + "_" + request.getParameter("pidID") + "_" + request.getParameter("fileID")
                        + ".txt\"");
        try {
            HttpDownload.fileView(request, response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PortletException("com error");
        }
        return;
    }

    // file upload status
    if (request.getParameter("uploadStatus") != null) {
        PortletSession ps = request.getPortletSession();
        // end of download
        if (ps.getAttribute("finaluploads") != null) {
            ps.removeAttribute("finaluploads");
            ps.removeAttribute("uploaded");
            ps.removeAttribute("upload");
            ps.removeAttribute("uploading");
            response.getWriter().write("Upload");

        } else {
            try {
                Vector<String> tmp = (Vector<String>) ps.getAttribute("uploaded");
                response.getWriter().write("&nbsp;<br/>");
                for (String t : tmp)
                    response.getWriter().write("uploaded:" + t + "<br/>");
                FileUploadProgressListener lisener = (FileUploadProgressListener) ((PortletFileUpload) ps
                        .getAttribute("upload")).getProgressListener();
                byte uplStatus = Byte.parseByte(lisener.getFileuploadstatus());
                response.getWriter()
                        .write("uploading:" + ps.getAttribute("uploading") + "->" + "<div style=\"width:"
                                + uplStatus + "px;background-color:blue; \" >" + uplStatus + "%<br/>");
            } catch (Exception ee) {
                System.out.println("file upload has not yet begun " + ps.getId());
                ee.printStackTrace();
            }
        }
        return;
    }
    // configuration
    Hashtable reqhash = new Hashtable();
    Enumeration enm0 = request.getParameterNames();
    while (enm0.hasMoreElements()) {
        key = "" + enm0.nextElement();
        reqhash.put(key, request.getParameter(key));
    }
    reqhash.put("sid", request.getPortletSession().getId());
    try {
        ActionHandler t = null;
        try {
            String sid = request.getPortletSession().getId();
            String workflowName = "" + request.getPortletSession().getAttribute("cworkflow");
            String username = request.getRemoteUser();
            String wftype;
            PortletSession ps = request.getPortletSession();
            if (request.getPortletSession().getAttribute("cworkflow") == null) {
                System.out.println(
                        "RealWFPortlet-serveresource- request.getPortletSession().getAttribute(cworkflow)==null !!!!!!!! try cworkflow1");
                System.out.println("cworkflow1:" + ps.getAttribute("cworkflow1", ps.APPLICATION_SCOPE));
                workflowName = "" + ps.getAttribute("cworkflow1", ps.APPLICATION_SCOPE);
                if (ps.getAttribute("cworkflow1", ps.APPLICATION_SCOPE) != null) {
                    request.getPortletSession().setAttribute("cworkflow", workflowName);
                }
            }
            wftype = PortalCacheService.getInstance().getUser(username).getWorkflow(workflowName)
                    .getWorkflowType();
            reqhash.put("ws-pgrade.wftype", wftype);
            t = (ActionHandler) Class.forName(
                    "hu.sztaki.lpds.pgportal.servlet.ajaxactions." + wftype + "." + request.getParameter("m"))
                    .newInstance();
            //                System.out.println("***SERVE-RESOURCE:"+t.getClass().getName());

        } catch (Exception e) {
            try {
                t = (ActionHandler) Class
                        .forName("hu.sztaki.lpds.pgportal.servlet.ajaxactions." + request.getParameter("m"))
                        .newInstance();
                //                    System.out.println("***SERVE-RESOURCE:"+t.getClass().getName());
            } catch (ClassNotFoundException e0) {
                System.out.println("classnotfound");
                e0.printStackTrace();
            } catch (InstantiationException e0) {
                e0.printStackTrace();
                System.out.println("---Init error:hu.sztaki.lpds.pgportal.servlet.ajaxactions."
                        + request.getParameter("m"));
                e0.printStackTrace();
            } catch (IllegalAccessException e0) {
                e0.printStackTrace();
                System.out.println("---Illegal Access:hu.sztaki.lpds.pgportal.servlet.ajaxactions."
                        + request.getParameter("m"));
                e0.printStackTrace();
            }
        }
        try {
            // Session transfer
            t.setSessionVariables(request.getPortletSession());
            // Parameter setting 
            reqhash.put("user", request.getRemoteUser());
            if (request.getPortletSession().getAttribute("cworkflow") != null)
                reqhash.put("workflow", request.getPortletSession().getAttribute("cworkflow"));
            if (request.getPortletSession().getAttribute("detailsruntime") != null)
                reqhash.put("detailsruntime", request.getPortletSession().getAttribute("detailsruntime"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Content transfer
        if (t.getDispacher(reqhash) == null) {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                out.print(t.getOutput(reqhash));
            } catch (Exception e) {
                e.printStackTrace();
            }
            out.close();
        }
        // Transfer of controlling 
        else {
            Hashtable res = t.getParameters(reqhash);
            Enumeration enm = res.keys();
            while (enm.hasMoreElements()) {
                key = "" + enm.nextElement();
                request.setAttribute(key, res.get(key));
            }
            PortletRequestDispatcher dispatcher = getPortletContext()
                    .getRequestDispatcher(t.getDispacher(reqhash));
            dispatcher.include(request, response);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("-----------------------Can not be initialized:" + request.getParameter("m"));
    }

}

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static byte toByte(Object o) {
    return o instanceof Byte ? (Byte) o
            : o instanceof Number ? toByte((Number) o) : Byte.parseByte(o.toString());
}

From source file:forseti.JUtil.java

public static synchronized String FormatearRep(String strval, String formato, String tipocol,
        HttpServletRequest request) {/*from   w ww  .j  av a  2  s.co  m*/
    if (strval == null)
        return "Valor-NULO";

    if (tipocol.equals("BYTE") || tipocol.equals("INT")) {
        String separador = formato.substring(0, 1);
        boolean si_o_ret_nada = formato.substring(2, 3).equals("1") ? true : false;
        return Converts(strval, separador, si_o_ret_nada);
    } else if (tipocol.equals("STRING")) {
        if (formato.equals("cuenta"))
            return obtCuentaFormato(new StringBuffer(strval), request);
        else if (!formato.equals("general")) {
            if (strval.length() > Integer.parseInt(formato))
                return strval.substring(0, Integer.parseInt(formato));
            else
                return strval;
        } else
            return strval;
    } else if (tipocol.equals("DECIMAL") || tipocol.equals("MONEY")) {
        if (formato.equals("LETRA")) {
            return CantEnLetra(Float.parseFloat(strval), null, null);
        } else {
            String separador = formato.substring(0, 1);
            String punto = formato.substring(2, 3);
            byte dec = Byte.parseByte(formato.substring(4, 5));
            boolean si_o_ret_nada = formato.substring(6, 7).equals("1") ? true : false;
            return Converts(strval, separador, punto, dec, si_o_ret_nada);
        }
    } else if (tipocol.equals("TIME")) {
        //System.out.println(strval + " " + formato);
        return obtFechaIMP(strval, formato);
    } else if (tipocol.equals("BOOL")) {
        return ConvertsBool(strval, formato);
    } else {
        return strval;
    }

}

From source file:configuration.Util.java

private static void uspBoxSpinVal(workflow_properties properties, HashMap<JCheckBox, JSpinner> BoxSpin) {
    for (JCheckBox cb : BoxSpin.keySet()) {
        boolean b = false;
        String k_s = cb.getName();
        if (properties.isSet(k_s)) {
            b = true;//from w  w  w .  java  2 s .co  m
        }
        if (BoxSpin.get(cb) != null) {
            String v_s = BoxSpin.get(cb).getName();
            if (properties.isSet(v_s)) {
                String s_bk = properties.get(v_s);
                if (valIsInt(v_s)) {
                    BoxSpin.get(cb).setValue(Integer.parseInt(s_bk));
                } else if (valIsDouble(v_s)) {
                    BoxSpin.get(cb).setValue(Double.parseDouble(s_bk));
                } else if (valIsFloat(v_s)) {
                    BoxSpin.get(cb).setValue(Float.parseFloat(s_bk));
                } else if (valIsByte(v_s)) {
                    BoxSpin.get(cb).setValue(Byte.parseByte(s_bk));
                } else if (valIsShort(v_s)) {
                    BoxSpin.get(cb).setValue(Short.parseShort(s_bk));
                } else if (valIsLong(v_s)) {
                    BoxSpin.get(cb).setValue(Long.parseLong(s_bk));
                }
                BoxSpin.get(cb).setEnabled(false);
                if (b) {
                    properties.put(cb.getName(), s_bk);
                }
            }
        }
    }
}

From source file:forseti.JUtil.java

public static synchronized String FormatearImp(String strval, String formato, String tipocol,
        HttpServletRequest request, String id_moneda, String moneda) {

    if (tipocol.equals("int") || tipocol.equals("int2") || tipocol.equals("int4")) {
        String separador = formato.substring(0, 1);
        boolean si_o_ret_nada = formato.substring(2, 3).equals("1") ? true : false;
        return Converts(strval, separador, si_o_ret_nada);
    } else if (tipocol.equals("bit") || tipocol.equals("boolean")) {
        return ConvertsBool(strval, formato);
    } else if (tipocol.equals("varchar") || tipocol.equals("bpchar") || tipocol.equals("text")
            || tipocol.equals("char")) //if(tipocol.equals("varchar") || tipocol.equals("char") || tipocol.equals("text") || tipocol.equals("nvarchar") || tipocol.equals("nchar") || tipocol.equals("ntext"))
    {/*  ww  w .j a va  2  s.c  o  m*/
        if (formato.equals("cuenta"))
            return obtCuentaFormato(new StringBuffer(strval), request);
        else if (!formato.equals("general")) {
            if (strval.length() > Integer.parseInt(formato))
                return strval.substring(0, Integer.parseInt(formato));
            else
                return strval;
        } else
            return strval;
    } else if (tipocol.equals("numeric") || tipocol.equals("decimal")) {
        if (formato.equals("LETRA")) {
            String LETRA = CantEnLetra(Float.parseFloat(strval), id_moneda, moneda);
            return LETRA.toUpperCase();
        }
        if (formato.equals("letra")) {
            String letra = CantEnLetra(Float.parseFloat(strval), id_moneda, moneda);
            return letra.toLowerCase();

        } else {
            String separador = formato.substring(0, 1);
            String punto = formato.substring(2, 3);
            byte dec = Byte.parseByte(formato.substring(4, 5));
            boolean si_o_ret_nada = formato.substring(6, 7).equals("1") ? true : false;
            return Converts(strval, separador, punto, dec, si_o_ret_nada);
        }
    } else if (tipocol.equals("timestamp")) {
        //System.out.println(strval + " " + formato);
        return obtFechaIMP(strval, formato);
    } else {
        return strval;
    }

}

From source file:com.haines.ml.rce.io.protostuff.ProtostuffEventMarshalBufferUnitTest.java

private Iterable<ByteBuffer> loadByteBuffersFromFile(String splitFileName) throws IOException {

    InputStream stream = ProtostuffEventMarshalBufferUnitTest.class
            .getResourceAsStream("/testBufferSplits/" + splitFileName);

    Iterable<String> bufferStrings = IOUtils.readLines(stream, Charset.defaultCharset());

    return Iterables.transform(bufferStrings, new Function<String, ByteBuffer>() {

        @Override//  ww  w  .  j  a v a  2 s .c  o m
        public ByteBuffer apply(String input) {

            Matcher matcher = BYTE_ARRAY_EXTRACTOR.matcher(input); // strip out everything except the bytes

            matcher.find();
            input = matcher.group(1);

            String[] byteStrs = input.split(",");

            byte[] bytes = new byte[byteStrs.length];

            for (int i = 0; i < byteStrs.length; i++) {
                bytes[i] = Byte.parseByte(byteStrs[i].trim());
            }
            return ByteBuffer.wrap(bytes);
        }

    });
}

From source file:configuration.Util.java

private static void uspRButSpinVal(workflow_properties properties, HashMap<JRadioButton, JSpinner> RButSpin) {
    for (JRadioButton cb : RButSpin.keySet()) {
        boolean b = false;
        String k_s = cb.getName();
        if (properties.isSet(k_s)) {
            b = true;/*from ww  w  . j  a va  2s .co m*/
        }
        if (RButSpin.get(cb) != null) {
            String v_s = RButSpin.get(cb).getName();
            if (properties.isSet(v_s)) {
                String s_bk = properties.get(v_s);
                if (valIsInt(v_s)) {
                    RButSpin.get(cb).setValue(Integer.parseInt(s_bk));
                } else if (valIsDouble(v_s)) {
                    RButSpin.get(cb).setValue(Double.parseDouble(s_bk));
                } else if (valIsFloat(v_s)) {
                    RButSpin.get(cb).setValue(Float.parseFloat(s_bk));
                } else if (valIsByte(v_s)) {
                    RButSpin.get(cb).setValue(Byte.parseByte(s_bk));
                } else if (valIsShort(v_s)) {
                    RButSpin.get(cb).setValue(Short.parseShort(s_bk));
                } else if (valIsLong(v_s)) {
                    RButSpin.get(cb).setValue(Long.parseLong(s_bk));
                }
                RButSpin.get(cb).setEnabled(false);
                if (b) {
                    properties.put(cb.getName(), s_bk);
                }
            }
        }
    }
}

From source file:hu.sztaki.lpds.pgportal.portlets.workflow.EasyWorkflowPortlet.java

@Override
public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {
    String key;//w w w  .  j  av a 2  s .c  o  m
    if ("editgraphURL".equals(request.getResourceID()) && request.getParameter("wfId") != null) {
        GraphEditorUtil.jnpl(request, response);
        return;
    }

    if ("refreshConfigURL".equals(request.getResourceID())) {
        List<String> graphs = new ArrayList<String>();
        Enumeration<String> enm = PortalCacheService.getInstance().getUser(request.getRemoteUser())
                .getAbstactWorkflows().keys();
        while (enm.hasMoreElements())
            graphs.add(enm.nextElement());

        request.setAttribute("graphs", graphs);
        request.setAttribute("workflow", request.getPortletSession().getAttribute("cworkflow"));
        getPortletContext().getRequestDispatcher("/jsp/workflow/accepteditedgraph.jsp").include(request,
                response);
        return;
    }

    // ajax help
    if (request.getParameter("helptext") != null) {
        super.serveResource(request, response);
        return;
    }
    //output download
    if (request.getParameter("downloadType") != null) {
        response.setContentType("application/zip");
        response.setProperty("Content-Disposition", "inline; filename=\"" + request.getParameter("workflowID")
                + "_" + request.getParameter("jobID") + "_" + request.getParameter("pidID") + "_outputs.zip\"");
        try {
            HttpDownload.fileDownload(request.getParameter("downloadType"), request, response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PortletException("com error");
        }
        return;
    }
    // logs download
    if (request.getParameter("fileID") != null) {
        response.setContentType("application/text");
        response.setProperty("Content-Disposition",
                "inline; filename=\"" + request.getParameter("workflowID") + "_" + request.getParameter("jobID")
                        + "_" + request.getParameter("pidID") + "_" + request.getParameter("fileID")
                        + ".txt\"");
        try {
            HttpDownload.fileView(request, response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new PortletException("com error");
        }
        return;
    }

    // file upload status
    if (request.getParameter("uploadStatus") != null) {
        PortletSession ps = request.getPortletSession();
        // end of download
        if (ps.getAttribute("finaluploads") != null) {
            ps.removeAttribute("finaluploads");
            ps.removeAttribute("uploaded");
            ps.removeAttribute("upload");
            ps.removeAttribute("uploading");
            response.getWriter().write("Upload");

        } else {
            try {
                Vector<String> tmp = (Vector<String>) ps.getAttribute("uploaded");
                response.getWriter().write("&nbsp;<br/>");
                for (String t : tmp)
                    response.getWriter().write("uploaded:" + t + "<br/>");
                FileUploadProgressListener lisener = (FileUploadProgressListener) ((PortletFileUpload) ps
                        .getAttribute("upload")).getProgressListener();
                byte uplStatus = Byte.parseByte(lisener.getFileuploadstatus());
                response.getWriter()
                        .write("uploading:" + ps.getAttribute("uploading") + "->" + "<div style=\"width:"
                                + uplStatus + "px;background-color:blue; \" >" + uplStatus + "%<br/>");
            } catch (Exception ee) {
                System.out.println("file upload has not yet begun " + ps.getId());
                ee.printStackTrace();
            }
        }
        return;
    }
    // configuration
    Hashtable reqhash = new Hashtable();
    Enumeration enm0 = request.getParameterNames();
    while (enm0.hasMoreElements()) {
        key = "" + enm0.nextElement();
        reqhash.put(key, request.getParameter(key));
    }
    reqhash.put("sid", request.getPortletSession().getId());
    try {
        ActionHandler t = null;
        try {
            String sid = request.getPortletSession().getId();
            String workflowName = "" + request.getPortletSession().getAttribute("cworkflow");
            String username = request.getRemoteUser();
            String wftype = PortalCacheService.getInstance().getUser(username).getWorkflow(workflowName)
                    .getWorkflowType();
            reqhash.put("ws-pgrade.wftype", wftype);
            t = (ActionHandler) Class.forName(
                    "hu.sztaki.lpds.pgportal.servlet.ajaxactions." + wftype + "." + request.getParameter("m"))
                    .newInstance();
            //                System.out.println("***SERVE-RESOURCE:"+t.getClass().getName());

        } catch (Exception e) {
            try {
                t = (ActionHandler) Class
                        .forName("hu.sztaki.lpds.pgportal.servlet.ajaxactions." + request.getParameter("m"))
                        .newInstance();
                //                    System.out.println("***SERVE-RESOURCE:"+t.getClass().getName());
            } catch (ClassNotFoundException e0) {
                System.out.println("classnotfound");
                e0.printStackTrace();
            } catch (InstantiationException e0) {
                e0.printStackTrace();
                System.out.println("---Init error:hu.sztaki.lpds.pgportal.servlet.ajaxactions."
                        + request.getParameter("m"));
                e0.printStackTrace();
            } catch (IllegalAccessException e0) {
                e0.printStackTrace();
                System.out.println("---Illegal Access:hu.sztaki.lpds.pgportal.servlet.ajaxactions."
                        + request.getParameter("m"));
                e0.printStackTrace();
            }
        }
        try {
            // Session transfer
            t.setSessionVariables(request.getPortletSession());
            // Parameter setting
            reqhash.put("user", request.getRemoteUser());
            if (request.getPortletSession().getAttribute("cworkflow") != null)
                reqhash.put("workflow", request.getPortletSession().getAttribute("cworkflow"));
            if (request.getPortletSession().getAttribute("detailsruntime") != null)
                reqhash.put("detailsruntime", request.getPortletSession().getAttribute("detailsruntime"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Content transfer
        if (t.getDispacher(reqhash) == null) {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                out.print(t.getOutput(reqhash));
            } catch (Exception e) {
                e.printStackTrace();
            }
            out.close();
        }
        // Transfer of controlling
        else {
            Hashtable res = t.getParameters(reqhash);
            Enumeration enm = res.keys();
            while (enm.hasMoreElements()) {
                key = "" + enm.nextElement();
                request.setAttribute(key, res.get(key));
            }
            PortletRequestDispatcher dispatcher = getPortletContext()
                    .getRequestDispatcher(t.getDispacher(reqhash));
            dispatcher.include(request, response);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("-----------------------Can not be initialized:" + request.getParameter("m"));
    }

}

From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java

/**
 * @param oldSQL//from w  w  w.  j  a v  a  2 s  . co m
 * @param newSQL
 * @return
 * @throws SQLException
 */
private StatusType compareRecords(final String desc, final String oldCatNumArg, final String newCatNumArg,
        final String oldSQLArg, final String newSQLArg, final boolean nullsAreOK, final boolean notRetarded)
        throws SQLException {
    boolean dbg = false;
    if (dbg) {
        System.out.println(oldSQLArg);
        System.out.println(newSQLArg);
    }
    if (dbg) {
        System.out.println("\n" + desc);
        dump(desc, oldDBConn, compareTo6DBs ? newSQLArg : oldSQLArg);
        dump(desc, newDBConn, newSQLArg);
    }

    String oldCatNum = oldCatNumArg;
    String newCatNum = newCatNumArg;
    if (compareTo6DBs) {
        oldCatNum = newCatNumArg;
    }

    if (notRetarded) {
        getResultSetsNotRetarded(oldSQLArg, newSQLArg, oldCatNum, newCatNum);
    } else {
        getResultSets(oldSQLArg, newSQLArg);
    }

    try {

        boolean hasOldRec = oldDBRS.next();
        boolean hasNewRec = newDBRS.next();

        if (!hasOldRec && !hasNewRec) {
            return StatusType.COMPARE_OK;
        }

        if (!hasOldRec) {
            if (nullsAreOK) {
                log.error(desc + " - No Old Record for [" + oldCatNum + "]");
                tblWriter.logErrors(oldCatNum, "No Old Record");
                return StatusType.NO_OLD_REC;
            }
            return StatusType.COMPARE_OK;
        }
        if (!hasNewRec) {
            log.error(desc + " - No New Record for [" + newCatNum + "]");
            tblWriter.logErrors(newCatNum, "No New Record");
            return StatusType.NO_NEW_REC;
        }

        //check number of rows, if not equal don't try to compare
        oldDBRS.last();
        newDBRS.last();
        if (oldDBRS.getRow() != newDBRS.getRow()) {
            String msg = desc + " Cat Num [" + oldCatNum + "]: Sp5 DB has " + oldDBRS.getRow()
                    + " related records. Sp6 DB has " + newDBRS.getRow();
            log.error(msg);
            tblWriter.logErrors(newCatNum, msg);
            return oldDBRS.getRow() < newDBRS.getRow() ? StatusType.NO_NEW_REC : StatusType.NO_OLD_REC;
        }
        oldDBRS.first();
        newDBRS.first();

        String oldNewIdStr = oldCatNum + " / " + newCatNum;

        boolean checkForAgent = newSQL.indexOf("a.LastName") > -1;

        ResultSetMetaData oldRsmd = oldDBRS.getMetaData();
        ResultSetMetaData newRsmd = newDBRS.getMetaData();

        PartialDateConv datePair = new PartialDateConv();
        Calendar cal = Calendar.getInstance();
        StringBuilder errSB = new StringBuilder();

        while (hasNewRec && hasOldRec) {
            errSB.setLength(0);

            int oldColInx = 0;
            int newColInx = 0;
            String idMsgStr = "";

            int numCols = newRsmd.getColumnCount();

            for (int col = 0; col < numCols; col++) {
                newColInx++;
                oldColInx++;

                if (dbg) {
                    System.out.println("\ncol       " + col + " / " + oldRsmd.getColumnCount());
                    System.out.println("newColInx " + newColInx);
                    System.out.println("oldColInx " + oldColInx);
                    System.out.println(oldRsmd.getColumnName(oldColInx));
                    System.out.println(newRsmd.getColumnName(newColInx));
                }

                Object newObj = newDBRS.getObject(newColInx);
                Object oldObj = oldDBRS.getObject(oldColInx);

                if (oldObj == null && newObj == null) {
                    String colName = newRsmd.getColumnName(newColInx);

                    if (StringUtils.contains(colName, "Date")
                            && StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
                        newColInx++;
                        numCols--;
                        if (compareTo6DBs)
                            oldColInx++;
                    }
                    continue;
                }

                if (col == 0) {
                    idMsgStr = String.format(" - Rec Ids[%s / %s] ", (oldObj != null ? oldObj : -1),
                            (newObj != null ? newObj : -1));
                    continue;
                }

                String oldColName = oldRsmd.getColumnName(oldColInx);
                if (oldColName.equals("PreparationMethod") && newObj != null) {
                    String newObjStr = newObj.toString();
                    if ((oldObj == null && !newObjStr.equalsIgnoreCase("Misc"))
                            || (oldObj != null && !newObjStr.equalsIgnoreCase(oldObj.toString()))) {
                        String msg = idMsgStr + "Old Value was null and shouldn't have been for Old CatNum ["
                                + oldCatNum + "] Field [" + oldColName + "] oldObj[" + oldObj + "] newObj ["
                                + newObj + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldCatNum, msg);
                        return StatusType.OLD_VAL_NULL;
                    }
                    continue;
                }

                if (oldObj == null && !StringUtils.contains(oldColName, "LastName")) {
                    if (!oldColName.equals("PreparationMethod") || !newObj.equals("Misc")) {
                        String msg = idMsgStr + "Old Value was null and shouldn't have been for Old CatNum ["
                                + oldCatNum + "] Field [" + oldColName + "]  New Val[" + newObj + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldCatNum, msg);
                        return StatusType.OLD_VAL_NULL;
                    }
                }

                if (newObj == null) {
                    String clsName = newRsmd.getColumnClassName(newColInx);
                    String colName = newRsmd.getColumnName(newColInx);

                    if (compareTo6DBs) {
                        if (!clsName.equals("java.sql.Date") || oldObj != null) {
                            String msg = "New Value was null and shouldn't have been for Key Value New CatNo["
                                    + newCatNum + "] Field [" + colName + "] [" + oldObj + "]";
                            log.error(desc + " - " + msg);
                            tblWriter.logErrors(newCatNum, msg);
                            return StatusType.NEW_VAL_NULL;
                        }

                    } else {
                        if (!clsName.equals("java.sql.Date")
                                || (!(oldObj instanceof String) && ((Number) oldObj).intValue() != 0)) {
                            String msg = "New Value was null and shouldn't have been for Key Value New CatNo["
                                    + newCatNum + "] Field [" + colName + "] [" + oldObj + "]";
                            log.error(desc + " - " + msg);
                            if (tblWriter != null && newCatNum != null && msg != null)
                                tblWriter.logErrors(newCatNum, msg);
                            dbg = true;
                            return StatusType.NEW_VAL_NULL;
                        }
                    }

                    if (StringUtils.contains(colName, "Date")
                            && StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
                        newColInx++;
                        numCols--;
                        if (compareTo6DBs)
                            oldColInx++;
                    }
                    continue;
                }

                //String colName = newRsmd.getColumnName(col);
                //System.out.println(newObj.getClass().getName()+"  "+oldObj.getClass().getName());

                if (newObj instanceof java.sql.Date) {
                    boolean isPartialDate = false;
                    Byte partialDateType = null;
                    if (StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) {
                        newColInx++;
                        numCols--;
                        partialDateType = newDBRS.getByte(newColInx);
                        isPartialDate = true;
                    }

                    if (compareTo6DBs) {
                        Object dateObj = oldDBRS.getObject(oldColInx);

                        boolean isPartialDate2 = false;
                        Byte partialDateType2 = null;
                        if (StringUtils.contains(oldRsmd.getColumnName(oldColInx + 1), "DatePrecision")) {
                            oldColInx++;
                            partialDateType2 = newDBRS.getByte(oldColInx);
                            isPartialDate2 = true;

                        } else {
                            log.error("Next isn't DatePrecision and can't be!");
                            tblWriter.logErrors(oldNewIdStr, errSB.toString());
                        }

                        if (!newObj.equals(dateObj)
                                || (isPartialDate2 && !partialDateType2.equals(partialDateType))) {
                            errSB.insert(0, oldColName + "  ");
                            errSB.append("[");
                            errSB.append(datePair);
                            errSB.append("][");
                            errSB.append(dateFormatter.format((Date) newObj));
                            errSB.append("] oldDate[");
                            errSB.append(dateFormatter.format((Date) dateObj));
                            errSB.append("]");
                            log.error(errSB.toString());
                            tblWriter.logErrors(oldNewIdStr, errSB.toString());
                            return StatusType.BAD_DATE;
                        }

                    } else {
                        int oldIntDate = oldDBRS.getInt(oldColInx);
                        if (oldIntDate == 0) {
                            continue;
                        }

                        BasicSQLUtils.getPartialDate(oldIntDate, datePair, false);

                        if (partialDateType != null) {
                            boolean ok = StringUtils.isNotEmpty(datePair.getPartial())
                                    && StringUtils.isNumeric(datePair.getPartial());
                            if (!ok || (Byte.parseByte(datePair.getPartial()) != partialDateType.byteValue())) {
                                errSB.append("Partial Dates Type do not match. Old[" + datePair.getPartial()
                                        + "]  New [" + partialDateType.byteValue() + "]");
                                // error partial dates don't match
                            }
                        }

                        cal.setTime((Date) newObj);

                        if (StringUtils.isNotEmpty(datePair.getDateStr())
                                && !datePair.getDateStr().equalsIgnoreCase("null")) {
                            int year = Integer.parseInt(datePair.getDateStr().substring(0, 4));
                            int mon = Integer.parseInt(datePair.getDateStr().substring(5, 7));
                            int day = Integer.parseInt(datePair.getDateStr().substring(8, 10));

                            if (mon > 0)
                                mon--;

                            boolean isYearOK = true;

                            int yr = cal.get(Calendar.YEAR);
                            if (year != yr) {
                                errSB.append("Year mismatch Old[" + year + "]  New [" + yr + "] ");
                                isYearOK = false;
                            }

                            if (mon != cal.get(Calendar.MONTH)) {
                                errSB.append("Month mismatch Old[" + mon + "]  New [" + cal.get(Calendar.MONTH)
                                        + "] ");
                            }

                            if (day != cal.get(Calendar.DAY_OF_MONTH)) {
                                errSB.append("Day mismatch Old[" + day + "]  New ["
                                        + cal.get(Calendar.DAY_OF_MONTH) + "] ");
                            }

                            if (errSB.length() > 0 && (!isYearOK || !isPartialDate)) {
                                errSB.insert(0, oldColName + "  ");
                                errSB.append("[");
                                errSB.append(datePair);
                                errSB.append("][");
                                errSB.append(dateFormatter.format((Date) newObj));
                                errSB.append("]");
                                log.error(errSB.toString());
                                tblWriter.logErrors(oldNewIdStr, errSB.toString());
                                return StatusType.BAD_DATE;
                            }
                        } else {
                            //String msg = "Date contains the string 'NULL'";
                            //log.error(msg);
                            //tblWriter.logErrors(oldNewIdStr, msg);
                            //return StatusType.BAD_DATE;
                        }
                    }
                } else if (newObj instanceof Float || newObj instanceof Double) {
                    String s1 = String.format("%10.5f",
                            newObj instanceof Float ? (Float) newObj : (Double) newObj);
                    String s2 = String.format("%10.5f",
                            oldObj instanceof Float ? (Float) oldObj : (Double) oldObj);
                    if (!s1.equals(s2)) {
                        String msg = idMsgStr + "Columns don't compare[" + s1 + "][" + s2 + "]  ["
                                + newRsmd.getColumnName(col) + "][" + oldRsmd.getColumnName(oldColInx) + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldNewIdStr, msg);
                        return StatusType.NO_COMPARE;
                    }

                } else {
                    String newColName = newRsmd.getColumnName(newColInx);
                    if (checkForAgent && StringUtils.contains(newColName, "LastName")) {
                        String lastName = oldDBRS.getString(oldColInx);
                        String agentName = oldDBRS.getString(oldColInx + 1); // The 'Name' Column
                        String newLastName = newDBRS.getString(newColInx);
                        if (!newLastName.equals(lastName) && !newLastName.equals(agentName)) {
                            String msg = idMsgStr + "Name Columns don't compare[" + newObj + "][" + oldObj
                                    + "]  [" + newColName + "][" + oldColName + "]";
                            log.error(desc + " - " + msg);
                            tblWriter.logErrors(oldNewIdStr, msg);
                            log.error(oldSQLArg + "\n" + newSQLArg);
                            return StatusType.NO_COMPARE;
                        }

                    } else if (StringUtils.contains(newColName, "YesNo")) {
                        boolean yesNoNew = newDBRS.getBoolean(newColInx);
                        boolean yesNoOld = oldDBRS.getInt(oldColInx) != 0;

                        if (yesNoNew != yesNoOld) {
                            String msg = idMsgStr + "Columns don't Cat Num[" + oldCatNum + "] compare["
                                    + yesNoNew + "][" + yesNoOld + "]  [" + newColName + "][" + oldColName
                                    + "]";
                            log.error(desc + " - " + msg);
                            tblWriter.logErrors(oldNewIdStr, msg);
                            return StatusType.NO_COMPARE;
                        }

                    } else if (!newObj.equals(oldObj)) {
                        String msg = idMsgStr + "Columns don't Cat Num[" + oldCatNum + "] compare[" + newObj
                                + "][" + oldObj + "]  [" + newColName + "][" + oldColName + "]";
                        log.error(desc + " - " + msg);
                        tblWriter.logErrors(oldNewIdStr, msg);
                        return StatusType.NO_COMPARE;

                        /*boolean isOK = false;
                        if (oldObj instanceof String)
                        {
                        String oldStr = (String)oldObj;
                        String newStr = (String)newObj;
                        String lof    = "\\r\\n";
                        int    inx    = newStr.indexOf(lof);
                        if (inx > -1)
                        {
                            String tok = oldStr.substring(0, inx);
                            if (newStr.equals(tok))
                            {
                                isOK = true;
                            }
                        }
                        }
                        if (!isOK)
                        {
                        log.error(desc+ " - Columns don't compare["+newObj+"]["+oldObj+"]  ["+newRsmd.getColumnName(newColInx)+"]["+oldRsmd.getColumnName(oldColInx)+"]");
                        return false;
                        }*/
                    }
                }
            }

            hasOldRec = oldDBRS.next();
            hasNewRec = newDBRS.next();

            if (!hasOldRec && !hasNewRec) {
                return StatusType.COMPARE_OK;
            }

            if (!hasOldRec) {
                log.error(desc + idMsgStr + " - No Old Record for [" + oldCatNum + "]");
                tblWriter.logErrors(oldNewIdStr, "No Old Record for [" + oldCatNum + "]");
                return StatusType.NO_OLD_REC;
            }
            if (!hasNewRec) {
                log.error(desc + idMsgStr + " No New Record for [" + newCatNum + "]");
                tblWriter.logErrors(oldNewIdStr, "No New Record for [" + newCatNum + "]");
                return StatusType.NO_NEW_REC;
            }
        }
    } finally {
        doneWithRS();
    }

    return StatusType.COMPARE_OK;
}

From source file:forseti.contabilidad.JContaPolizasDlg.java

public void AgregarPartida(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    short idmensaje = -1;
    StringBuffer mensaje = new StringBuffer(254);

    HttpSession ses = request.getSession(true);
    JContaPolizasSes pol = (JContaPolizasSes) ses.getAttribute("conta_polizas_dlg");

    double debe = (request.getParameter("debe") != null && !request.getParameter("debe").equals(""))
            ? Float.parseFloat(request.getParameter("debe"))
            : 0F;//w  ww. j  av a2  s . co  m
    double haber = (request.getParameter("haber") != null && !request.getParameter("haber").equals(""))
            ? Float.parseFloat(request.getParameter("haber"))
            : 0F;
    double tc = Float.parseFloat(request.getParameter("tc"));
    byte idmoneda = Byte.parseByte(request.getParameter("idmoneda"));

    idmensaje = pol.agregaPartida(request, JUtil.obtCuentas(request.getParameter("cuenta"), (byte) 19),
            pt(request.getParameter("concepto_part")), idmoneda, tc, debe, haber, mensaje);

    getSesion(request).setID_Mensaje(idmensaje, mensaje.toString());

}