Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

In this page you can find the example usage for java.lang NumberFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

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

Usage

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "List_Online_User", cmd = "2020")
@RequestMapping("/list_online_user.json")
public void listOnlineUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String organId = request.getParameter("organId");
    if (StringUtils.isBlank(organId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [organId]");
    }//from w w w .j  a va  2 s.c o  m

    Integer startIndex = 0;
    String startIndexSatring = request.getParameter("startIndex");
    if (StringUtils.isNotBlank(startIndexSatring)) {
        try {
            startIndex = Integer.parseInt(startIndexSatring);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter startIndex[" + startIndexSatring + "] invalid !");
        }
    }
    Integer limit = 1000;
    String limitString = request.getParameter("limit");
    if (StringUtils.isNotBlank(limitString)) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter limit[" + limitString + "] invalid !");
        }
    }

    String logonName = request.getParameter("logonName");

    String name = request.getParameter("name");

    int totalCount = userManager.countOnlineUser(organId, logonName, name);

    // omc?????
    if (startIndex != 0 && totalCount != 0) {
        if (startIndex.intValue() >= totalCount) {
            startIndex -= ((startIndex.intValue() - totalCount) / limit + 1) * limit;
        }
    }

    List<ListOnlineUsersVO> list = userManager.listOnlineUser(organId, logonName, name, startIndex, limit);

    ListOnlineUsersDTO dto = new ListOnlineUsersDTO();
    dto.setUserList(list);
    dto.setTotalCount(totalCount + "");

    dto.setCmd("2020");
    dto.setMethod("List_Online_User");
    writePage(response, dto);
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "List_User_Operation_Log", cmd = "1318")
@RequestMapping("/list_user_operation_log.xml")
public void listUserOperationLog(HttpServletRequest request, HttpServletResponse response) throws Exception {
    SimpleRequestReader reader = new SimpleRequestReader(request);

    String operationType = reader.getString("operationType", true);

    Long beginTime = reader.getLong("beginTime", true);

    Long endTime = reader.getLong("endTime", true);

    Integer startIndex = 0;/*from  ww  w .  j  a  v  a2  s  .  co m*/
    String startIndexString = request.getParameter("startIndex");
    if (StringUtils.isNotBlank(startIndexString)) {
        try {
            startIndex = Integer.parseInt(startIndexString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter startIndex[" + startIndexString + "] invalid !");
        }
    }
    Integer limit = 1000;
    String limitString = request.getParameter("limit");
    if (StringUtils.isNotBlank(limitString)) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter limit[" + limitString + "] invalid !");
        }
    }

    Integer totalCount = userManager.findTotalCount(operationType, beginTime, endTime);
    // ?
    // Boolean isAdmin = false;
    // isAdmin = userManager.isAdmin(resource.get().getId());
    // if (isAdmin) {
    // listLog = userManager.listSysLogByAdmin(resourceName, startTime,
    // endTime, startIndex, limit, targetName, operationCode,
    // operationType, resourceType);
    // } else {
    Element list = userManager.listUserOperationLog(operationType, beginTime, endTime, startIndex, limit);

    BaseDTO dto = new BaseDTO();
    Document doc = new Document();
    dto.setMethod("List_User_Operation_Log");
    dto.setCmd("1318");
    dto.setMessage(totalCount + "");
    Element root = ElementUtil.createElement("Response", dto, null, null);
    root.addContent(list);
    doc.setRootElement(root);
    writePageWithContentLength(response, doc);
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "List_User_Session", cmd = "2024")
@RequestMapping("/list_user_session.json")
public void listUserSession(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String userId = request.getParameter("userId");
    String userName = request.getParameter("userName");
    String organId = request.getParameter("organId");

    Long startTime = null;/*from  w  w  w .  ja va  2  s  .c  o  m*/
    String startTimeString = request.getParameter("startTime");
    if (StringUtils.isNotBlank(startTimeString)) {
        try {
            startTime = Long.parseLong(startTimeString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + startTimeString + "] invalid !");
        }
    }
    Long endTime = null;
    String endTimeString = request.getParameter("endTime");
    if (StringUtils.isNotBlank(endTimeString)) {
        try {
            endTime = Long.parseLong(endTimeString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + endTimeString + "] invalid !");
        }
    }
    Integer startIndex = 0;
    String startIndexSatring = request.getParameter("startIndex");
    if (StringUtils.isNotBlank(startIndexSatring)) {
        try {
            startIndex = Integer.parseInt(startIndexSatring);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + startIndexSatring + "] invalid !");
        }
    }
    Integer limit = 1000;
    String limitString = request.getParameter("limit");
    if (StringUtils.isNotBlank(limitString)) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + limitString + "] invalid !");
        }
    }
    String logonUserId = resource.get().getId();

    Integer totalCount = userManager.selectTotalCount(userId, userName, organId, startTime, endTime,
            logonUserId);
    // omc?????
    if (startIndex != 0 && totalCount.intValue() != 0) {
        if (startIndex.intValue() >= totalCount.intValue()) {
            startIndex -= ((startIndex.intValue() - totalCount.intValue()) / limit + 1) * limit;
        }
    }

    List<ListUserSessionHistoryVO> listVO = userManager.listUserSessionHistory(userId, userName, organId,
            startTime, endTime, startIndex, limit, logonUserId);

    ListUserSessionHistoryDTO dto = new ListUserSessionHistoryDTO();
    dto.setUserSessionList(listVO);
    dto.setTotalCount(totalCount.toString());
    dto.setCmd("2024");
    dto.setMethod("List_User_Session");
    writePage(response, dto);
}

From source file:eu.prestoprime.plugin.p4.legacy.FFProbeTaskExtended.java

@Override
public void execute(Map<String, String> sParams, Map<String, String> dParamsString,
        Map<String, File> dParamFile) throws TaskExecutionFailedException {

    // get sipID/*from  w  w  w .  ja v  a2 s  .  c om*/
    String sipID = dParamsString.get("sipID");

    SIP sip = null;
    try {
        // get sip
        sip = P4DataManager.getInstance().getSIPByID(sipID);

        // get MQ file
        String videoFile = null;
        String[] MQformats = sParams.get("MQformats").split(",");
        logger.debug("Checking for MQ formats: " + Arrays.toString(MQformats));
        for (String format : MQformats) {
            List<String> videoFileList = sip.getAVMaterial(format, "FILE");
            if (videoFileList.size() > 0) {
                videoFile = videoFileList.get(0);
                break;
            }
        }
        if (videoFile == null) {
            throw new TaskExecutionFailedException("Unable to find supported MQ format...");
        }

        // run FFprobe
        FFprobe ffprobe = new FFprobe();

        ToolOutput<FFprobe.AttributeType> output = ffprobe.extract(videoFile);
        String ffprobeOutput = output.getAttribute(FFprobe.AttributeType.json);

        Section section = new Section();
        section.setId("ffprobe");

        // get JSON Object
        JSONObject jsonOutput = new JSONObject(ffprobeOutput);

        // FFprobe show format
        JSONObject jsonFormat = jsonOutput.getJSONObject("format");

        Iterator<String> itFormat = jsonFormat.keys();

        while (itFormat.hasNext()) {

            String key = itFormat.next();
            String value = jsonFormat.getString(key);
            Record record = getDnxKvRecord(key, value);
            section.getRecord().add(record);
        }

        // prepare videoMd map
        Map<String, String> vidMd = new HashMap<>();

        // set format
        String formatN = jsonFormat.getString("format_name");
        String formatLN = jsonFormat.getString("format_long_name");

        vidMd.put("format_name", formatN);
        vidMd.put("format_long_name", formatLN);

        // size
        String size = jsonFormat.getString("size");
        vidMd.put("size", size);

        dParamsString.put("isMXF", "false");
        if (formatN != null) {
            synchronized (sip) {
                List<String> formats = sip.getDCField(DCField.format);
                formats.add(formatLN + "(" + formatN.toUpperCase() + ")");
                sip.setDCField(DCField.format, formats);
            }

            if (formatN.equalsIgnoreCase("MXF")) {
                dParamsString.put("isMXF", "true");
            }
        }

        // FFprobe show streams
        JSONArray jsonStreams = jsonOutput.getJSONArray("streams");

        int numOfStreams = jsonStreams.length();

        vidMd.put("nb_streams", "" + numOfStreams);

        for (int i = 0; i < numOfStreams; i++) {

            JSONObject jsonStream = jsonStreams.getJSONObject(i);
            String index = jsonStream.getString("index");

            Iterator<String> itStream = jsonStream.keys();

            while (itStream.hasNext()) {
                String key = itStream.next();
                String value = jsonStream.getString(key);
                Record record = getDnxKvRecord(key, value, index);
                section.getRecord().add(record);
            }

            if (jsonStream.getString("codec_type").equals("video")) {
                vidMd.put("duration", jsonStream.getString("duration"));
                vidMd.put("framerate", jsonStream.getString("r_frame_rate"));
                vidMd.put("aspect_ratio", jsonStream.getString("display_aspect_ratio"));
                vidMd.put("video_codec", jsonStream.getString("codec_name"));
                vidMd.put("width", jsonStream.getString("width"));
                vidMd.put("height", jsonStream.getString("height"));
            }

            if (jsonStream.getString("codec_type").equals("audio")) {
                vidMd.put("audio_codec", jsonStream.getString("codec_name"));
            }

        }

        try {
            dParamsString.put("duration", "" + (int) Double.parseDouble(vidMd.get("duration")));
        } catch (NumberFormatException e) {
            dParamsString.put("duration", "0");
        }

        String frameRate = vidMd.get("framerate");
        if (frameRate != null) {
            String fpsString = frameRate.split("/")[0];

            try {
                dParamsString.put("fps", "" + Integer.parseInt(fpsString));
            } catch (NumberFormatException e) {
                dParamsString.put("fps", "25");
            }
        }

        // set new DNX section
        Dnx dnx = new Dnx();
        dnx.getSection().add(section);
        sip.addDNX(dnx, "ffprobe", true);

        // add DNX section with video information
        Record videoRecord = new Record();
        Key key = null;
        for (Entry<String, String> e : vidMd.entrySet()) {
            key = getDnxKey(e.getKey(), e.getValue());
            videoRecord.getKey().add(key);
        }

        Section videoSec = new Section();
        videoSec.setId("videoMD");
        videoSec.getRecord().add(videoRecord);

        Dnx videoDnx = new Dnx();
        videoDnx.getSection().add(videoSec);

        sip.addDNX(videoDnx, "videoMD", false);

    } catch (JSONException e) {
        throw new TaskExecutionFailedException("Unable to parse JSON output from ffprobe...");
    } catch (DataException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to retrieve the SIP...");
    } catch (IPException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to work with SIP...");
    } catch (ToolException e) {
        e.printStackTrace();
        throw new TaskExecutionFailedException("Unable to run FFProbe...");
    } finally {
        // release SIP
        P4DataManager.getInstance().releaseIP(sip);
    }
}

From source file:com.safi.workshop.util.SafletPersistenceManager.java

public Map<String, ServerResource> getLocalProjectCopies(final boolean safletsOnly) {
    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IProject[] projects = ws.getRoot().getProjects();
    List<IProject> plist = new ArrayList<IProject>(Arrays.asList(projects));
    final Map<String, ServerResource> localResources = new HashMap<String, ServerResource>();
    for (final IProject p : plist) {
        try {//from   ww w  . ja v a  2s .  c  o m
            final SafletProject[] projResult = new SafletProject[1];
            if (!safletsOnly) {
                final SafletProject sp = ConfigFactory.eINSTANCE.createSafletProject();
                String id = p.getPersistentProperty(SafletPersistenceManager.RES_ID_KEY);
                if (StringUtils.isNotBlank(id)) {
                    try {
                        sp.setId(Integer.valueOf(id));
                    } catch (NumberFormatException e) {
                        e.printStackTrace();
                    }
                }
                sp.setLastModified(SafletPersistenceManager.getInstance().getLastModified(p));
                sp.setLastUpdated(SafletPersistenceManager.getInstance().getLastUpdated(p));
                sp.setName(p.getName());
                localResources.put(sp.getName(), sp);
                projResult[0] = sp;
            }
            p.accept(new IResourceVisitor() {

                @Override
                public boolean visit(IResource resource) throws CoreException {
                    if (resource.getType() == IResource.FILE && "saflet".equals(resource.getFileExtension())) {
                        int pid = SafletPersistenceManager.getInstance().getResourceId(resource);
                        Saflet saflet = ConfigFactory.eINSTANCE.createSaflet();
                        saflet.setId(pid);
                        saflet.setLastModified(
                                SafletPersistenceManager.getInstance().getLastModified(resource));
                        saflet.setLastUpdated(SafletPersistenceManager.getInstance().getLastUpdated(resource));
                        saflet.setName(SafletPersistenceManager.getInstance().getSafletName(resource));
                        // saflet.setName(resource.getName().substring(0,
                        // resource.getName().length() - (resource.getFileExtension().length() +
                        // 1)));

                        localResources.put(p.getName() + "/" + saflet.getName(), saflet);
                        if (!safletsOnly)
                            projResult[0].getSaflets().add(saflet);
                    }
                    return true;
                }

            });
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    return localResources;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectCMFListener.java

public boolean checkFormat(File file) {
    boolean isSubjectIdSet = false;
    try {/*from   w  ww  .  j  a  v  a  2s  .c  o  m*/
        BufferedReader br = new BufferedReader(new FileReader(file));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
            if (line.compareTo("") != 0) {
                String[] fields = line.split("\t", -1);
                //check columns number
                if (fields.length != 6) {
                    this.selectCMFUI.displayMessage("Error:\nLines have not the right number of columns");
                    br.close();
                    return false;
                }
                //check raw file names
                if (!((ClinicalData) this.dataType).getRawFilesNames().contains(fields[0])) {
                    this.selectCMFUI.displayMessage("Error:\nData file '" + fields[0] + "' does not exist");
                    br.close();
                    return false;
                }
                //check that subject identifier is set
                if (fields[3].compareTo("SUBJ_ID") == 0) {
                    isSubjectIdSet = true;
                }
                //check that column number is set and is a number
                if (fields[2].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nColumns numbers have to be set");
                    br.close();
                    return false;
                }
                try {
                    Integer.parseInt(fields[2]);
                } catch (NumberFormatException e) {
                    this.selectCMFUI.displayMessage("Error:\nColumns numbers have to be numbers");
                    br.close();
                    return false;
                }
                //check that datalabel is set
                if (fields[3].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nData labels have to be set");
                    br.close();
                    return false;
                }
                //check that category code is set, except for reserved words
                if (!(fields[3].compareTo("SUBJ_ID") == 0 || fields[3].compareTo("OMIT") == 0
                        || fields[3].compareTo("SITE_ID") == 0 || fields[3].compareTo("VISIT_NAME") == 0)
                        && fields[1].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nCategory codes have to be set");
                    br.close();
                    return false;
                }
                //check that data label source is set if the data label is '\'
                if (fields[3].compareTo("\\") == 0 && fields[4].compareTo("") == 0) {
                    this.selectCMFUI.displayMessage("Error:\nData label sources have to be set");
                    br.close();
                    return false;
                }
            }
        }
        br.close();
    } catch (Exception e) {
        this.selectCMFUI.displayMessage("File error: " + e.getLocalizedMessage());
        e.printStackTrace();
        return false;
    }
    if (!isSubjectIdSet) {
        this.selectCMFUI.displayMessage("Error:\nSubject identifiers have to be set");
        return false;
    }
    return true;
}

From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java

@Override
public List<ProductStaVO> getProductStaListByConfigureData(Long businessId, String productName, String barcode,
        String startDate, String endDate, int page, int pageSize) {
    String sqlString = "";
    if (startDate != null && !"".equals(startDate)) {
        sqlString += " AND tr.publishDate >= '" + startDate + "' ";
    }//www  .j av a2 s. c  o m
    if (endDate != null && !"".equals(endDate)) {
        sqlString += " AND tr.publishDate < DATE_ADD('" + endDate + "', INTERVAL 1 DAY) ";
    }
    String sql = " SELECT  ";
    //???
    sql += " (SELECT COUNT(*) FROM product_instance pri,test_result tr WHERE p.id=pri.product_id AND  tr.sample_id=pri.id AND tr.publish_flag=1 ";
    sql += " AND tr.organization = bu.organization ";
    sql += sqlString;
    sql += " ) publishReportQuantity ,";
    //???
    sql += "(SELECT COUNT(*) FROM product_instance pri,test_result tr WHERE p.id=pri.product_id AND  tr.sample_id=pri.id AND tr.publish_flag=0 ";
    sql += " AND tr.organization = bu.organization) notPublishReportQuantity ,";
    //???
    sql += " (SELECT MAX(tr.publishDate) FROM product_instance pri,test_result tr WHERE p.id=pri.product_id AND  tr.sample_id=pri.id AND tr.publish_flag=1";
    sql += " AND tr.organization = bu.organization AND tr.publishDate is not null ";
    sql += sqlString;
    sql += " ) publishDate,";
    sql += "bu.name buName,p.name productName,p.barcode,bu.organization ";
    sql += " FROM  product p ";
    sql += " LEFT JOIN business_unit bu ON  p.organization = bu.organization ";
    sql += " WHERE bu.id=:buId ";
    if (productName != null && !"".equals(productName)) {
        sql += " AND p.name LIKE '%" + productName + "%' ";
    }
    if (barcode != null && !"".equals(barcode)) {
        sql += " AND p.barcode LIKE '%" + barcode + "%'";
    }
    Query query = entityManager.createNativeQuery(sql);
    query.setParameter("buId", businessId);
    if (page > 0 && pageSize > 0) {
        query.setFirstResult((page - 1) * pageSize);
        query.setMaxResults(pageSize);
    }
    @SuppressWarnings("unchecked")
    List<Object[]> objs = query.getResultList();
    List<ProductStaVO> proList = new ArrayList<ProductStaVO>();
    try {
        for (Object[] obj : objs) {
            ProductStaVO proSta = new ProductStaVO();
            //???
            proSta.setReportQuantity(obj[0] == null ? null : Long.parseLong(obj[0].toString()));
            //???
            proSta.setNotPublishReportQuantity(obj[1] == null ? null : Long.parseLong(obj[1].toString()));
            //???
            proSta.setLastPubDate(obj[2] == null ? null : formatter.parse(obj[2].toString()));
            proSta.setBusinessName(obj[3] == null ? null : obj[3].toString());
            proSta.setProductName(obj[4] == null ? null : obj[4].toString());
            proSta.setBarcode(obj[5] == null ? null : obj[5].toString());
            proList.add(proSta);
        }
    } catch (NumberFormatException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return proList;
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "Update_User", cmd = "2003")
@RequestMapping("/update_user.json")
public void updateUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String id = request.getParameter("id");
    if (StringUtils.isBlank(id)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [id]");
    }/*from  w w w.j  a  v  a 2  s.co m*/

    String standardNumber = request.getParameter("standardNumber");

    String ccsId = request.getParameter("ccsId");

    String name = request.getParameter("name");
    if (null != name && StringUtils.isBlank(name)) {
        throw new BusinessException(ErrorCode.PARAMETER_INVALID, "Can not modify name to empty !");
    }

    String password = request.getParameter("password");

    Short sex = null;
    String sexString = request.getParameter("sex");
    if (StringUtils.isNotBlank(sexString)) {
        try {
            sex = Short.parseShort(sexString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter sex[" + sexString + "] invalid !");
        }
    }

    String email = request.getParameter("email");

    String phone = request.getParameter("phone");

    String address = request.getParameter("address");

    String organId = request.getParameter("organId");

    Short priority = null;
    String priorityString = request.getParameter("priority");
    if (StringUtils.isNotBlank(priorityString)) {
        try {
            priority = Short.parseShort(priorityString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + priorityString + "] invalid !");
        }
    }

    String note = request.getParameter("note");

    Short status = null;
    String statusString = request.getParameter("status");
    if (StringUtils.isNotBlank(statusString)) {
        try {
            status = Short.parseShort(statusString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter status[" + statusString + "] invalid !");
        }
    }

    Integer maxConnect = null;
    String maxConnectString = request.getParameter("maxConnect");
    if (StringUtils.isNotBlank(maxConnectString)) {
        try {
            maxConnect = Integer.parseInt(maxConnectString);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter maxConnect[" + maxConnectString + "] invalid !");
        }
    }

    userManager.updateUser(id, name, standardNumber, ccsId, password, sex, email, phone, address, organId,
            priority, note, status, maxConnect);

    BaseDTO dto = new BaseDTO();
    dto.setCmd("2003");
    dto.setMethod("Update_User");

    writePage(response, dto);
}

From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java

@Override
public Long getProductStaCountByConfigureData(Long businessId, String productName, String barcode) {

    String sql = " SELECT  count(*) ";
    sql += " FROM  product p ";
    sql += " LEFT JOIN business_unit bu ON  p.organization = bu.organization ";
    sql += " WHERE bu.id=:buId ";
    if (productName != null && !"".equals(productName)) {
        sql += " AND p.name LIKE '%" + productName + "%' ";
    }//ww w .  j a  va  2s .co  m
    if (barcode != null && !"".equals(barcode)) {
        sql += " AND p.barcode LIKE '%" + barcode + "%'";
    }
    Long counts = 0l;
    try {
        Query query = entityManager.createNativeQuery(sql);
        query.setParameter("buId", businessId);
        Object rtn = query.getSingleResult();
        counts = rtn == null ? 0 : Long.parseLong(rtn.toString());
    } catch (NumberFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return counts;
}

From source file:com.znsx.cms.web.controller.UserController.java

@InterfaceDescription(logon = true, method = "List_Sys_Log", cmd = "2121")
@RequestMapping("/list_sys_log.json")
public void listSysLog(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String resourceName = request.getParameter("resourceName");
    String organId = request.getParameter("organId");
    if (StringUtils.isBlank(organId)) {
        throw new BusinessException(ErrorCode.PARAMETER_NOT_FOUND, "missing [organId]");
    }/*from   www . j  a v  a2s .c o m*/
    Long startTime = null;
    String startTimeString = request.getParameter("startTime");
    if (StringUtils.isNotBlank(startTimeString)) {
        try {
            startTime = Long.parseLong(startTimeString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + startTimeString + "] invalid !");
        }
    }
    Long endTime = null;
    String endTimeString = request.getParameter("endTime");
    if (StringUtils.isNotBlank(endTimeString)) {
        try {
            endTime = Long.parseLong(endTimeString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + endTimeString + "] invalid !");
        }
    }
    Integer startIndex = 0;
    String startIndexString = request.getParameter("startIndex");
    if (StringUtils.isNotBlank(startIndexString)) {
        try {
            startIndex = Integer.parseInt(startIndexString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + startIndexString + "] invalid !");
        }
    }
    Integer limit = 1000;
    String limitString = request.getParameter("limit");
    if (StringUtils.isNotBlank(limitString)) {
        try {
            limit = Integer.parseInt(limitString);
        } catch (NumberFormatException be) {
            be.printStackTrace();
            throw new BusinessException(ErrorCode.PARAMETER_INVALID,
                    "Parameter priority[" + limitString + "] invalid !");
        }
    }
    String targetName = request.getParameter("targetName");

    String operationCode = request.getParameter("operationCode");

    String operationType = request.getParameter("operationType");

    String resourceType = request.getParameter("resourceType");

    String logonUserId = resource.get().getId();

    String type = request.getParameter("type");

    List<SysLog> listLog = new ArrayList<SysLog>();

    Integer totalCount = userManager.findTotalCount(organId, resourceName, startTime, endTime, targetName,
            operationCode, operationType, resourceType, type);
    // omc?????
    if (startIndex != 0 && totalCount.intValue() != 0) {
        if (startIndex.intValue() >= totalCount.intValue()) {
            startIndex -= ((startIndex.intValue() - totalCount.intValue()) / limit + 1) * limit;
        }
    }
    // ?
    // Boolean isAdmin = false;
    // isAdmin = userManager.isAdmin(resource.get().getId());
    // if (isAdmin) {
    // listLog = userManager.listSysLogByAdmin(resourceName, startTime,
    // endTime, startIndex, limit, targetName, operationCode,
    // operationType, resourceType);
    // } else {
    listLog = userManager.listSysLog(organId, resourceName, startTime, endTime, startIndex, limit, targetName,
            operationCode, logonUserId, operationType, resourceType, type);
    // }

    ListSysLogDTO dto = new ListSysLogDTO();
    dto.setCmd("2121");
    dto.setMethod("List_Sys_Log");
    dto.setTotalCount(totalCount.toString());
    dto.setListSysLog(listLog);
    writePage(response, dto);
}