Example usage for java.lang NumberFormatException getMessage

List of usage examples for java.lang NumberFormatException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Load a long property from the file./*from   w ww  .j  a  v a2s .  co m*/
 *
 * @param key The name of the property
 * @param defaultValue The default value for this property
 * @return The value loaded from the file or the default value, if it is not
 * specified in the file.
 * @throws NumberFormatException The loaded value can not be converted to
 * long
 * @throws NullPointerException The parameter file was not initialized
 * @throws MissingOptionException The parameter is mandatory and it was not
 * found in the parameter file.
 */
private long getLongProperty(ParameterList key, long defaultValue)
        throws NumberFormatException, NullPointerException, MissingOptionException {
    try {
        boolean keyPresent = fileParameters.containsKey(key.name);
        String strValue = keyPresent ? fileParameters.getProperty(key.name).replaceAll("\\s", "") : null;
        if (!keyPresent && key.mandatory) {
            throw new MissingOptionException("The input parameter (" + key.name + ") was not found");
        } else if (!keyPresent || strValue.equals("")) {
            loadedParametersLog.append(key.name).append("=").append(defaultValue).append(" (DEFAULT)\n");
            return defaultValue;
        }
        loadedParametersLog.append(key.name).append("=").append(strValue).append("\n");
        return Integer.parseInt(strValue);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                e.getMessage() + "\nThe input parameter (" + key.name + ") could not be converted to long.");
    } catch (NullPointerException e) {
        throw new NullPointerException(e.getMessage() + "\nThe parameter file was not initialized.");
    }
}

From source file:edu.gsgp.experiment.config.PropertiesManager.java

/**
 * Load a double property from the file.
 *
 * @param key The name of the property//www .j a  va2s. c  om
 * @param defaultValue The default value for this property
 * @return The value loaded from the file or the default value, if it is not
 * specified in the file.
 * @throws NumberFormatException The loaded value can not be converted to
 * double
 * @throws NullPointerException The parameter file was not initialized
 * @throws MissingOptionException The parameter is mandatory and it was not
 * found in the parameter file.
 */
private double getDoubleProperty(ParameterList key, double defaultValue)
        throws NumberFormatException, NullPointerException, MissingOptionException {
    try {
        boolean keyPresent = fileParameters.containsKey(key.name);
        String strValue = keyPresent ? fileParameters.getProperty(key.name).replaceAll("\\s", "") : null;
        if (!keyPresent && key.mandatory) {
            throw new MissingOptionException("The input parameter (" + key.name + ") was not found");
        } else if (!keyPresent || strValue.equals("")) {
            loadedParametersLog.append(key.name).append("=").append(defaultValue).append(" (DEFAULT)\n");
            return defaultValue;
        }
        loadedParametersLog.append(key.name).append("=").append(strValue).append("\n");
        return Double.parseDouble(strValue);
    } catch (NumberFormatException e) {
        throw new NumberFormatException(
                e.getMessage() + "\nThe input parameter (" + key.name + ") could not be converted to double.");
    } catch (NullPointerException e) {
        throw new NullPointerException(e.getMessage() + "\nThe parameter file was not initialized.");
    }
}

From source file:fr.paris.lutece.plugins.rss.web.RssJspBean.java

/**
 * Creates the push RSS file corresponding to the given portlet
 *
 * @return The Jsp URL of the process result
 * @param request requete Http/*from w w  w  .  j  a va 2s .c  o m*/
 */
public String doCreateRssFilePortlet(HttpServletRequest request) {
    if (request.getParameter(PARAMETER_CANCEL) != null) {
        return getHomeUrl(request);
    }

    String strPortletId = request.getParameter(PARAMETER_PUSH_RSS_PORTLET_ID);
    String strRssFileName = request.getParameter(PARAMETER_PUSH_RSS_NAME);
    String strRssFileDescription = request.getParameter(PARAMETER_PUSH_RSS_DESCRIPTION);
    String strWorkgroup = request.getParameter(PARAMETER_WORKGROUP_KEY);
    String strRssMaxItems = request.getParameter(PARAMETER_PUSH_RSS_MAX_ITEMS);
    String strFeedType = request.getParameter(PARAMETER_PUSH_RSS_FEED_TYPE);
    String strEncoding = request.getParameter(PARAMETER_PUSH_RSS_ENCODING);

    if ((strPortletId == null) || !strPortletId.matches(REGEX_ID)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_DOCUMENT_PORTLET, AdminMessage.TYPE_STOP);
    }

    int nPortletId = Integer.parseInt(strPortletId);

    //Mandatory fields
    if (request.getParameter(PARAMETER_PUSH_RSS_NAME).equals("")
            || request.getParameter(PARAMETER_PUSH_RSS_DESCRIPTION).equals("")) {
        return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
    }

    // Check the file name length
    String strNameMaxLength = AppPropertiesService.getProperty(PROPERTY_NAME_MAX_LENGTH);

    if (strRssFileName.length() > Integer.parseInt(strNameMaxLength)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_FILENAME_TOO_LONG, AdminMessage.TYPE_STOP);
    }

    // Format the new file name
    strRssFileName = UploadUtil.cleanFileName(strRssFileName);

    // Check the type of the name
    String strFileType = AppPropertiesService.getProperty(PROPERTY_FILE_TYPE);

    if (!strRssFileName.toLowerCase().endsWith(strFileType)) {
        strRssFileName = strRssFileName + strFileType;
    }

    // Verifies whether the file's name exists
    if (RssGeneratedFileHome.checkRssFileFileName(strRssFileName)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_FILENAME_ALREADY_EXISTS,
                AdminMessage.TYPE_STOP);
    }

    if (StringUtils.isBlank(strFeedType)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_FEED_TYPE, AdminMessage.TYPE_STOP);
    }

    if (!getFeedTypes().contains(strFeedType)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_FEED_TYPE, AdminMessage.TYPE_STOP);
    }

    if (StringUtils.isBlank(strEncoding)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_ENCODING, AdminMessage.TYPE_STOP);
    }

    int nMaxItems;

    if (StringUtils.isBlank(strRssMaxItems)) {
        // set to 0 -- no limit
        nMaxItems = 0;
    } else {
        try {
            nMaxItems = Integer.parseInt(strRssMaxItems);
        } catch (NumberFormatException nfe) {
            AppLogService.error(nfe.getMessage(), nfe);

            return AdminMessageService.getMessageUrl(request, MESSAGE_MAX_ITEMS, AdminMessage.TYPE_STOP);
        }
    }

    // Check if a RSS file exists for this portlet
    String strRssDocument = RssGeneratorService.createRssDocument(nPortletId, strRssFileDescription,
            strEncoding, strFeedType, nMaxItems, request);

    // Call the create file method
    RssGeneratorService.createFileRss(strRssFileName, strRssDocument);

    // Update the database with the new push RSS file
    RssGeneratedFile rssFile = new RssGeneratedFile();
    rssFile.setPortletId(nPortletId);
    rssFile.setName(strRssFileName);
    rssFile.setState(STATE_OK);
    rssFile.setDescription(strRssFileDescription);
    rssFile.setWorkgroup(strWorkgroup);
    rssFile.setMaxItems(nMaxItems);
    rssFile.setFeedType(strFeedType);
    rssFile.setEncoding(strEncoding);

    RssGeneratedFileHome.create(rssFile);

    return getHomeUrl(request);
}

From source file:com.sfs.whichdoctor.search.http.PersonInputHandler.java

/**
 * Process the RACP Fellowship search parameters.
 *
 * @param request the request//from   w w w . j  a va 2s.c om
 *
 * @return the membership bean[]
 */
private MembershipBean[] processRACPFellowship(final HttpServletRequest request) {

    MembershipBean criteria = membershipDAO.getInstance("RACP", "Fellowship Details");
    MembershipBean constraints = membershipDAO.getInstance("RACP", "Fellowship Details");

    String strFRACPA = DataFilter.getHtml(request.getParameter("fracpA"));
    String strFRACPB = DataFilter.getHtml(request.getParameter("fracpB"));
    String strFellowshipDateA = DataFilter.getHtml(request.getParameter("fellowshipDateA"));
    String strFellowshipDateB = DataFilter.getHtml(request.getParameter("fellowshipDateB"));
    String strAdmittingSAC = DataFilter.getHtml(request.getParameter("admittingSAC"));
    String strAdmittingCountry = DataFilter.getHtml(request.getParameter("admittingCountry"));

    // Add FRACP number to criteria if successfully parsed to int
    try {
        int criteriaFRACP = Integer.parseInt(strFRACPA);
        criteria.setField("FRACP", new Integer(criteriaFRACP));
    } catch (NumberFormatException nfe) {
        dataLogger.debug("Error parsing FRACP A: " + nfe.getMessage());
    }

    if (strFRACPB != null) {
        int constraintFRACP = 0;
        try {
            constraintFRACP = Integer.parseInt(strFRACPB);
        } catch (NumberFormatException nfe) {
            dataLogger.debug("Error parsing FRACP B: " + nfe.getMessage());
        }
        if (strFRACPB.compareTo("+") == 0) {
            constraintFRACP = MAX_ID;
        }
        if (strFRACPB.compareTo("-") == 0) {
            constraintFRACP = -1;
        }
        constraints.setField("FRACP", new Integer(constraintFRACP));
    }

    if (strFellowshipDateA != null) {
        if (strFellowshipDateA.compareTo("") != 0) {
            criteria.setField("Fellowship Date", DataFilter.parseDate(strFellowshipDateA, false));
        }
    }
    if (strFellowshipDateB != null) {
        if (strFellowshipDateB.compareTo("") != 0) {

            constraints.setField("Fellowship Date", DataFilter.parseDate(strFellowshipDateB, false));

            if (strFellowshipDateB.compareTo("+") == 0) {
                // All dates above Date A requested
                constraints.setField("Fellowship Date", getMaximumDate());
            }
            if (strFellowshipDateB.compareTo("-") == 0) {
                // Add dates below Date A requested
                constraints.setField("Fellowship Date", getMinimumDate());
            }
        }
    }
    if (StringUtils.isNotBlank(strAdmittingSAC) && !StringUtils.equalsIgnoreCase(strAdmittingSAC, "Null")) {
        ObjectTypeBean object = new ObjectTypeBean();
        object.setClassName(strAdmittingSAC);
        criteria.setField("Admitting SAC", object);
    }
    if (StringUtils.isNotBlank(strAdmittingCountry)
            && !StringUtils.equalsIgnoreCase(strAdmittingCountry, "Null")) {
        criteria.setField("Admitting Country", strAdmittingCountry);
    }

    return new MembershipBean[] { criteria, constraints };
}

From source file:fr.paris.lutece.plugins.rss.web.RssJspBean.java

/**
 * Returns the creation form of a rss file
 *
 * @param request The Http request//www.j  a  v  a 2 s  . c o  m
 * @return Html form
 */
public String doCreateRssFileResource(HttpServletRequest request) {
    if (request.getParameter(PARAMETER_CANCEL) != null) {
        return getHomeUrl(request);
    }

    String strWorkgroup = request.getParameter(PARAMETER_WORKGROUP_KEY);
    String strRssFileName = request.getParameter(PARAMETER_PUSH_RSS_NAME);
    String strRssMaxItems = request.getParameter(PARAMETER_PUSH_RSS_MAX_ITEMS);
    String strEncoding = request.getParameter(PARAMETER_PUSH_RSS_ENCODING);
    String strFeedType = request.getParameter(PARAMETER_PUSH_RSS_FEED_TYPE);

    String strResourceRssKey = request.getParameter(PARAMETER_RSS_RESOURCE_KEY);
    IResourceRss resourceRss = RssService.getInstance().getResourceRssInstance(strResourceRssKey, getLocale());

    if (request.getParameter(PARAMETER_APPLY) != null) {
        return getJspCreateRssResource(request, request.getParameter(PARAMETER_PUSH_RSS_NAME),
                request.getParameter(PARAMETER_WORKGROUP_KEY), request.getParameter(PARAMETER_RSS_TYPE),
                request.getParameter(PARAMETER_RSS_RESOURCE_KEY), resourceRss.getParameterToApply(request));
    }

    if (strRssFileName.equals("")) {
        return AdminMessageService.getMessageUrl(request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP);
    }

    String strNameMaxLength = AppPropertiesService.getProperty(PROPERTY_NAME_MAX_LENGTH);

    if (strRssFileName.length() > Integer.parseInt(strNameMaxLength)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_FILENAME_TOO_LONG, AdminMessage.TYPE_STOP);
    }

    // Format the new file name
    strRssFileName = UploadUtil.cleanFileName(strRssFileName);

    // Check the type of the name
    String strFileType = AppPropertiesService.getProperty(PROPERTY_FILE_TYPE);

    if (!strRssFileName.toLowerCase().endsWith(strFileType)) {
        strRssFileName = strRssFileName + strFileType;
    }

    // Verifies whether the file's name exists
    if (RssGeneratedFileHome.checkRssFileFileName(strRssFileName)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_FILENAME_ALREADY_EXISTS,
                AdminMessage.TYPE_STOP);
    }

    if ((resourceRss != null) && (request.getParameter(PARAMETER_CANCEL) == null)) {
        String strError = resourceRss.doValidateConfigForm(request, getLocale());

        if (strError != null) {
            return strError;
        }
    }

    if (StringUtils.isBlank(strFeedType)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_FEED_TYPE, AdminMessage.TYPE_STOP);
    }

    if (!getFeedTypes().contains(strFeedType)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_FEED_TYPE, AdminMessage.TYPE_STOP);
    }

    if (StringUtils.isBlank(strEncoding)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_ENCODING, AdminMessage.TYPE_STOP);
    }

    int nMaxItems;

    if (StringUtils.isBlank(strRssMaxItems)) {
        // set to 0 -- no limit
        nMaxItems = 0;
    } else {
        try {
            nMaxItems = Integer.parseInt(strRssMaxItems);
        } catch (NumberFormatException nfe) {
            AppLogService.error(nfe.getMessage(), nfe);

            return AdminMessageService.getMessageUrl(request, MESSAGE_MAX_ITEMS, AdminMessage.TYPE_STOP);
        }
    }

    RssGeneratedFile rssFile = new RssGeneratedFile();
    rssFile.setName(strRssFileName);
    rssFile.setState(STATE_OK);
    rssFile.setDescription(resourceRss.getDescription());
    rssFile.setWorkgroup(strWorkgroup);
    rssFile.setTypeResourceRss(resourceRss.getResourceRssType().getKey());
    rssFile.setMaxItems(nMaxItems);
    rssFile.setFeedType(strFeedType);
    rssFile.setEncoding(strEncoding);
    RssGeneratedFileHome.create(rssFile);

    resourceRss.setEncoding(strEncoding);
    resourceRss.setFeedType(strFeedType);
    resourceRss.setId(rssFile.getId());

    //sauvegarde du cot directory
    resourceRss.doSaveConfig(request, getLocale());

    String strRss = FeedUtil.getFeed(resourceRss);

    // Call the create file method
    RssGeneratorService.createFileRss(strRssFileName, strRss);

    return getJspManageRssFile(request);
}

From source file:com.sfs.whichdoctor.isb.publisher.PersonIsbXmlWriter.java

/**
 * Builds the relationship id./*from  ww w  .  j av a  2  s .  c om*/
 *
 * @param relationship the relationship
 *
 * @return the int
 */
private int buildRelationshipId(final RelationshipBean relationship) {
    int guid = 0;
    final String strGuid = String.valueOf(relationship.getHierarchy()) + "00" + relationship.getReferenceGUID();
    try {
        guid = Integer.parseInt(strGuid);
    } catch (NumberFormatException nfe) {
        isbLogger.debug("Error parsing GUID: " + nfe.getMessage());
    }
    return guid;
}

From source file:fr.paris.lutece.plugins.rss.web.RssJspBean.java

/**
 * Modification of a push RSS file/*from www.j a v  a  2  s .  com*/
 *
 * @return The Jsp URL of the process result
 * @param request requete Http
 */
public String doModifyRssFileResource(HttpServletRequest request) {
    if (request.getParameter(PARAMETER_CANCEL) != null) {
        return getHomeUrl(request);
    }

    // Recovery of parameters processing
    String strRssFileId = request.getParameter(PARAMETER_PUSH_RSS_ID);

    //String strWorkgroup = request.getParameter( PARAMETER_WORKGROUP_KEY );
    int nRssFileId = Integer.parseInt(strRssFileId);

    String strWorkgroup = request.getParameter(PARAMETER_WORKGROUP_KEY);
    String strRssFileName = request.getParameter(PARAMETER_PUSH_RSS_NAME);
    String strMaxItems = request.getParameter(PARAMETER_PUSH_RSS_MAX_ITEMS);
    String strEncoding = request.getParameter(PARAMETER_PUSH_RSS_ENCODING);
    String strFeedType = request.getParameter(PARAMETER_PUSH_RSS_FEED_TYPE);

    String strResourceRssKey = request.getParameter(PARAMETER_RSS_RESOURCE_KEY);
    IResourceRss resourceRss = RssService.getInstance().getResourceRssInstance(strResourceRssKey, getLocale());

    if (request.getParameter(PARAMETER_APPLY) != null) {
        return getJspModifyRssResource(request, strRssFileId, request.getParameter(PARAMETER_PUSH_RSS_NAME),
                request.getParameter(PARAMETER_WORKGROUP_KEY), request.getParameter(PARAMETER_RSS_TYPE),
                request.getParameter(PARAMETER_RSS_RESOURCE_KEY), resourceRss.getParameterToApply(request));
    }

    String strNameMaxLength = AppPropertiesService.getProperty(PROPERTY_NAME_MAX_LENGTH);

    if (strRssFileName.length() > Integer.parseInt(strNameMaxLength)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_FILENAME_TOO_LONG, AdminMessage.TYPE_STOP);
    }

    // Format the new file name
    strRssFileName = UploadUtil.cleanFileName(strRssFileName);

    // Check the type of the name
    String strFileType = AppPropertiesService.getProperty(PROPERTY_FILE_TYPE);

    if (!strRssFileName.toLowerCase().endsWith(strFileType)) {
        strRssFileName = strRssFileName + strFileType;
    }

    if ((resourceRss != null) && (request.getParameter(PARAMETER_CANCEL) == null)) {
        String strError = resourceRss.doValidateConfigForm(request, getLocale());

        if (strError != null) {
            return strError;
        }
    }

    if (StringUtils.isBlank(strFeedType)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_FEED_TYPE, AdminMessage.TYPE_STOP);
    }

    if (!getFeedTypes().contains(strFeedType)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_FEED_TYPE, AdminMessage.TYPE_STOP);
    }

    if (StringUtils.isBlank(strEncoding)) {
        return AdminMessageService.getMessageUrl(request, MESSAGE_NO_ENCODING, AdminMessage.TYPE_STOP);
    }

    int nMaxItems;

    if (StringUtils.isBlank(strMaxItems)) {
        // set to 0 -- no limit
        nMaxItems = 0;
    } else {
        try {
            nMaxItems = Integer.parseInt(strMaxItems);
        } catch (NumberFormatException nfe) {
            AppLogService.error(nfe.getMessage(), nfe);

            return AdminMessageService.getMessageUrl(request, MESSAGE_MAX_ITEMS, AdminMessage.TYPE_STOP);
        }
    }

    // String strRssFileDescription = request.getParameter( PARAMETER_PUSH_RSS_DESCRIPTION );
    RssGeneratedFile rssFile = new RssGeneratedFile();
    rssFile.setId(nRssFileId);
    rssFile.setName(strRssFileName);
    rssFile.setState(STATE_OK);
    rssFile.setWorkgroup(strWorkgroup);
    rssFile.setDescription(resourceRss.getDescription());
    rssFile.setTypeResourceRss(resourceRss.getResourceRssType().getKey());
    rssFile.setMaxItems(nMaxItems);
    rssFile.setFeedType(strFeedType);
    rssFile.setEncoding(strEncoding);

    resourceRss.setId(rssFile.getId());
    resourceRss.setEncoding(strEncoding);
    resourceRss.setFeedType(strFeedType);

    // Check if the resource does exist
    if (!resourceRss.checkResource()) {
        rssFile.setState(STATE_PORTLET_MISSING);
    }

    // Update the database with the new push RSS file
    RssGeneratedFileHome.update(rssFile);

    //sauvegarde du cot directory
    resourceRss.doUpdateConfig(request, getLocale());

    // Check if a RSS file exists for this portlet
    //String strRssDocument = RssGeneratorService.createRssDocument( nPortletId, strRssFileDescription );
    String strRss = FeedUtil.getFeed(resourceRss);

    // Call the create file method
    RssGeneratorService.createFileRss(strRssFileName, strRss);

    // Display the page of publishing
    return getHomeUrl(request);
}

From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java

private Provincia findProvincia(String provId, String provincia) {
    if (!StringUtils.hasLength(provId))
        return null;

    try {/*from  ww  w . j  a  va  2  s.c o m*/
        return provinciaService.findProvincia(satelite, provincia, Integer.parseInt(provId));
    } catch (NumberFormatException e) {
        logger.error(e.getMessage());
    } catch (ServiceException e) {
        logger.error(e.getMessage());
    }
    return null;
}

From source file:com.sfs.whichdoctor.search.sql.ReceiptSqlHandler.java

/**
 * Construct the SQL string, description and parameters.
 *
 * @param objCriteria Object containing search criteria values
 * @param objConstraints Object containing search constraint values
 *
 * @return Map containing a String[] { sql, description } =>
 *         Collection< Object > parameters
 *
 * @throws IllegalArgumentException the illegal argument exception
 *///from  ww  w.ja  v a  2s.  c om
public final Map<String[], Collection<Object>> construct(final Object objCriteria, final Object objConstraints)
        throws IllegalArgumentException {

    ReceiptBean searchCriteria = null;
    ReceiptBean searchConstraints = null;

    if (objCriteria instanceof ReceiptBean) {
        searchCriteria = (ReceiptBean) objCriteria;
    }
    if (objConstraints instanceof ReceiptBean) {
        searchConstraints = (ReceiptBean) objConstraints;
    }

    if (searchCriteria == null) {
        throw new IllegalArgumentException("The search criteria must be " + "a valid ReceiptBean");
    }
    if (searchConstraints == null) {
        throw new IllegalArgumentException("The search constraints must be " + "a valid ReceiptBean");
    }

    StringBuffer sqlWHERE = new StringBuffer();
    StringBuffer description = new StringBuffer();
    Collection<Object> parameters = new ArrayList<Object>();

    if (searchCriteria.getTags() != null) {
        try {
            for (TagBean tag : searchCriteria.getTags()) {
                Map<String[], Collection<Object>> results = this.tagSearchDAO.construct(tag, new TagBean());

                for (String[] index : results.keySet()) {
                    String tagWHERE = index[0];
                    String tagDescription = index[1];
                    Collection<Object> tagParameters = results.get(index);

                    if (tagWHERE.compareTo("") != 0) {
                        /*
                         * A WHERE condition is defined, add to the SQL
                         * WHERE clause
                         */
                        sqlWHERE.append(" " + this.getSQL().getValue("receipt/searchTags") + " WHERE "
                                + tagWHERE + ")");
                        /* Add to the description and process the arrays */
                        description.append(tagDescription);
                        if (tagParameters != null) {
                            parameters.addAll(tagParameters);
                        }
                    }
                }
            }
        } catch (Exception e) {
            dataLogger.error("Error setting tag search options: " + e.getMessage());
        }
    }

    if (searchCriteria.getBasicSearch() != null) {
        if (searchCriteria.getBasicSearch().compareTo("") != 0) {
            String searchString = searchCriteria.getBasicSearch().trim();

            int basicSearch = 0;
            try {
                basicSearch = Integer.parseInt(searchCriteria.getBasicSearch());
            } catch (NumberFormatException nfe) {
                dataLogger.debug("Error parsing BasicSearch: " + nfe.getMessage());
            }
            if (basicSearch == 0) {
                // If the search string has : in the first ten
                // characters the financial abbreviation is probably
                // included - strip it out for search purposes
                if (searchString.indexOf(": ") > 3 && searchString.indexOf(": ") < 10) {
                    searchString = searchString.substring(3, searchString.length());
                }
                dataLogger.debug("Basic search string: " + searchString);

                String field = "%" + searchString + "%";
                sqlWHERE.append(" AND (concat(receipt.ReceiptNo, ': ', " + "receipt.Description) LIKE ?)");
                description.append(" and a receipt description like '" + searchCriteria.getBasicSearch() + "'");
                parameters.add(field);
            } else {
                sqlWHERE.append(" AND (receipt.ReceiptNo LIKE ?)");
                description.append(" and a receipt number of '"
                        + DataFilter.getHtml(searchCriteria.getBasicSearch()) + "'");
                parameters.add("%" + searchCriteria.getBasicSearch());
            }
        }
    }

    if (searchCriteria.getNumber() != null) {
        boolean SearchConstraints = false;
        if (searchCriteria.getNumber().compareTo("") != 0) {
            if (searchConstraints.getNumber() != null) {
                if (searchConstraints.getNumber().compareTo("") != 0) {
                    SearchConstraints = true;
                }
            }

            if (SearchConstraints) {
                if (searchConstraints.getNumber().compareTo("-") == 0) {
                    // Less than Receipt specified
                    sqlWHERE.append(" AND receipt.ReceiptNo <= ?");
                    description.append(" and a receipt number less than '" + searchCriteria.getNumber() + "'");
                    parameters.add(searchCriteria.getNumber());
                } else if (searchConstraints.getNumber().compareTo("+") == 0) {
                    // Greater then Receipt specified
                    sqlWHERE.append(" AND receipt.ReceiptNo >= ?");
                    description
                            .append(" and a receipt number greater than '" + searchCriteria.getNumber() + "'");
                    parameters.add(searchCriteria.getNumber());
                } else {
                    // Range between a and b - find whether greater than or
                    // less than...
                    int intA = 0;
                    int intB = 0;
                    try {
                        intA = Integer.parseInt(searchCriteria.getNumber());
                    } catch (NumberFormatException nfe) {
                        dataLogger.debug("Error parsing ReceiptNo: " + nfe.getMessage());
                    }
                    try {
                        intB = Integer.parseInt(searchConstraints.getNumber());
                    } catch (NumberFormatException nfe) {
                        dataLogger.debug("Error parsing ReceiptNo: " + nfe.getMessage());
                    }
                    if (intA == intB) {
                        // criteria A and B are the same
                        sqlWHERE.append(" AND receipt.ReceiptNo LIKE ?");
                        description.append(" and a receipt number of '" + searchCriteria.getNumber() + "'");
                        parameters.add("%" + searchCriteria.getNumber());
                    }
                    if (intA < intB) {
                        // criteria A is less than B
                        sqlWHERE.append(" AND receipt.ReceiptNo BETWEEN ? AND ?");
                        description.append(" and a receipt number between '" + searchCriteria.getNumber()
                                + "' and '" + searchConstraints.getNumber() + "'");
                        parameters.add(searchCriteria.getNumber());
                        parameters.add(searchConstraints.getNumber());
                    }
                    if (intA > intB) {
                        // Criteria A is greater than B
                        sqlWHERE.append(" AND receipt.ReceipttNo BETWEEN ? AND ?");
                        description.append(" and a receipt number between '" + searchConstraints.getNumber()
                                + "' and '" + searchCriteria.getNumber() + "'");
                        parameters.add(searchConstraints.getNumber());
                        parameters.add(searchCriteria.getNumber());
                    }
                }
            } else {
                sqlWHERE.append(" AND receipt.ReceiptNo LIKE ?");
                description.append(" and a receipt number of '" + searchCriteria.getNumber() + "'");
                parameters.add("%" + searchCriteria.getNumber());
            }
        }
    }

    if (searchCriteria.getGUIDList() != null) {
        final StringBuffer guidWHERE = new StringBuffer();

        for (String guid : searchCriteria.getGUIDList()) {
            if (StringUtils.isNotBlank(guid)) {
                guidWHERE.append(" OR receipt.GUID = ?");
                parameters.add(guid);
            }
        }
        if (guidWHERE.length() > 0) {
            // Append the guidWHERE buffer to the sqlWHERE buffer
            sqlWHERE.append(" AND (");
            // Append the guidWHERE but strip the first OR statement
            sqlWHERE.append(guidWHERE.toString().substring(4));
            sqlWHERE.append(")");
            description.append(" and has a GUID in the supplied list");
        }
    }

    if (searchCriteria.getIdentifierList() != null) {
        final StringBuffer identifierWHERE = new StringBuffer();

        for (String identifier : searchCriteria.getIdentifierList()) {
            if (StringUtils.isNotBlank(identifier)) {
                identifierWHERE.append(" OR receipt.ReceiptNo LIKE ?");
                parameters.add("%" + identifier);
            }
        }
        if (identifierWHERE.length() > 0) {
            // Append the identifierWHERE buffer to the sqlWHERE buffer
            sqlWHERE.append(" AND (");
            // Append the identifierWHERE but strip the first OR statement
            sqlWHERE.append(identifierWHERE.toString().substring(4));
            sqlWHERE.append(")");
            description.append(" and has a receipt number in the supplied list");
        }
    }

    if (searchCriteria.getBatchReferenceInt() > 0) {
        boolean SearchConstraints = false;
        if (searchConstraints.getBatchReferenceLimiter() != null) {
            if (searchConstraints.getBatchReferenceLimiter().compareTo("+") == 0) {
                // Greater then Receipt specified
                sqlWHERE.append(" AND receipt.BatchReference >= ?");
                description.append(
                        " and a batch number greater than '" + searchCriteria.getBatchReference() + "'");
                parameters.add(searchCriteria.getBatchReference());
                SearchConstraints = true;
            }
            if (searchConstraints.getBatchReferenceLimiter().compareTo("-") == 0) {
                // Less than Receipt specified
                sqlWHERE.append(" AND receipt.BatchReference <= ?");
                description
                        .append(" and a batch number less than '" + searchCriteria.getBatchReference() + "'");
                parameters.add(searchCriteria.getBatchReference());
                SearchConstraints = true;
            }
        }
        if (searchConstraints.getBatchReferenceInt() > 0) {
            // Range between a and b - find whether greater than or less
            // than.

            if (searchCriteria.getBatchReferenceInt() == searchConstraints.getBatchReferenceInt()) {
                // criteria A and B are the same
                sqlWHERE.append(" AND receipt.BatchReference = ?");
                description
                        .append(" and a batch number equal to '" + searchCriteria.getBatchReferenceInt() + "'");
                parameters.add(searchCriteria.getBatchReferenceInt());
                SearchConstraints = true;
            }
            if (searchCriteria.getBatchReferenceInt() < searchConstraints.getBatchReferenceInt()) {
                // criteria A is less than B
                sqlWHERE.append(" AND receipt.BatchReference BETWEEN ? AND ?");
                description.append(" and a batch number between '" + searchCriteria.getBatchReferenceInt()
                        + "' and '" + searchConstraints.getBatchReferenceInt() + "'");
                parameters.add(searchCriteria.getBatchReferenceInt());
                parameters.add(searchConstraints.getBatchReferenceInt());
                SearchConstraints = true;
            }
            if (searchCriteria.getBatchReferenceInt() > searchConstraints.getBatchReferenceInt()) {
                // Criteria A is greater than B
                sqlWHERE.append(" AND receipt.BatchReference BETWEEN ? AND ?");
                description.append(" and a batch number between '" + searchConstraints.getBatchReferenceInt()
                        + "' and '" + searchCriteria.getBatchReferenceInt() + "'");
                parameters.add(searchConstraints.getBatchReferenceInt());
                parameters.add(searchCriteria.getBatchReferenceInt());
                SearchConstraints = true;
            }
        }

        if (!SearchConstraints) {
            sqlWHERE.append(" AND receipt.BatchReference = ?");
            description.append(" and a batch number equal to '" + searchCriteria.getBatchReferenceInt() + "'");
            parameters.add(searchCriteria.getBatchReferenceInt());
        }
    }

    if (searchCriteria.getProcessType() != null) {
        if (searchCriteria.getProcessType().compareTo("") != 0) {
            sqlWHERE.append(" AND processtype.Class LIKE ?");
            description.append(" and a process type like '" + searchCriteria.getProcessType() + "'");
            parameters.add(searchCriteria.getProcessType());
        }
    }

    if (searchCriteria.getPerson() != null) {
        if (searchCriteria.getPerson().getId() != 0) {
            sqlWHERE.append(" AND receipt.PersonId = ?");
            description.append(" and a person GUID equal to '" + searchCriteria.getPerson() + "'");
            parameters.add(searchCriteria.getPerson());
        }
    }

    if (searchCriteria.getOrganisation() != null) {
        if (searchCriteria.getOrganisation().getId() != 0) {
            sqlWHERE.append(" AND receipt.OrganisationId = ?");
            description.append(" and an organisation GUID equal to '" + searchCriteria.getOrganisation() + "'");
            parameters.add(searchCriteria.getOrganisation());
        }
    }

    if (searchCriteria.getCancelled()) {
        if (searchConstraints.getCancelled()) {
            // Only cancelled receipts
            sqlWHERE.append(" AND receipt.Cancelled = true");
            description.append(" and the receipt is cancelled");
        }
    } else {
        if (!searchConstraints.getCancelled()) {
            // Only non-cancelled receipts
            sqlWHERE.append(" AND receipt.Cancelled = false");
            description.append(" and the receipt is not cancelled");
        }
    }

    if (searchCriteria.getDescription() != null) {
        if (searchCriteria.getDescription().compareTo("") != 0) {
            if (searchCriteria.getDescription().indexOf("\"") > -1) {
                // Description contains "" so treat as a specific search
                sqlWHERE.append(" AND receipt.Description LIKE ?");
                description.append(" and a receipt description like '" + searchCriteria.getDescription() + "'");
                parameters.add(StringUtils.replace(searchCriteria.getDescription(), "\"", ""));
            } else {
                sqlWHERE.append(" AND receipt.Description LIKE ?");
                description.append(" and a receipt description like '" + searchCriteria.getDescription() + "'");
                parameters.add("%" + searchCriteria.getDescription() + "%");
            }
        }
    }

    if (searchCriteria.getTypeName() != null) {
        if (searchCriteria.getTypeName().compareTo("") != 0) {
            sqlWHERE.append(" AND financialtype.Name LIKE ?");
            description.append(" and a receipt type like '" + searchCriteria.getTypeName() + "'");
            parameters.add(searchCriteria.getTypeName());
        }
    }

    if (searchCriteria.getClassName() != null) {
        if (searchCriteria.getClassName().compareTo("") != 0) {
            sqlWHERE.append(" AND financialtype.Class LIKE ?");
            description.append(" and a receipt class like '" + searchCriteria.getClassName() + "'");
            parameters.add(searchCriteria.getClassName());
        }
    }

    if (searchCriteria.getSecurity() != null) {
        if (searchCriteria.getSecurity().compareTo("") != 0) {
            sqlWHERE.append(" AND financialtype.Security = ?");
            description.append(" and a security setting of '" + searchCriteria.getSecurity() + "'");
            parameters.add(searchCriteria.getSecurity());
        }
    }

    if (searchCriteria.getPayments() != null) {
        for (PaymentBean payment : searchCriteria.getPayments()) {
            StringBuffer paymentSearch = new StringBuffer();

            if (payment.getDebit() != null) {
                final DebitBean debit = payment.getDebit();

                if (debit.getGUID() > 0) {
                    paymentSearch.append(" AND payment.InvoiceId = ?");
                    description
                            .append(" and has a payment associated with " + "debit guid: " + debit.getGUID());
                    parameters.add(debit.getGUID());
                }
            }
            if (paymentSearch.length() > 0) {
                sqlWHERE.append(
                        " " + getSQL().getValue("receipt/searchPayment") + paymentSearch.toString() + ")");
            }
        }
    }

    // Other searches: cancelled, date issued.....
    if (searchCriteria.getIssued() != null) {
        if (searchConstraints.getIssued() != null) {
            int larger = searchCriteria.getIssued().compareTo(searchConstraints.getIssued());
            if (larger > 0) {
                // SearchCriteria date after SearchConstraint date
                String fieldA = this.getDf().format(searchCriteria.getIssued());
                String fieldB = this.getDf().format(searchConstraints.getIssued());
                sqlWHERE.append(" AND receipt.Issued BETWEEN ? AND ?");
                description.append(" and issued between '" + fieldB + "' and '" + fieldA + "'");
                parameters.add(fieldB);
                parameters.add(fieldA);
            }
            if (larger < 0) {
                // SearchCriteria date before SearchConstraint date
                String fieldA = this.getDf().format(searchCriteria.getIssued());
                String fieldB = this.getDf().format(searchConstraints.getIssued());
                sqlWHERE.append(" AND receipt.Issued BETWEEN ? AND ?");
                description.append(" and issued between '" + fieldA + "' and '" + fieldB + "'");
                parameters.add(fieldA);
                parameters.add(fieldB);

            }
            if (larger == 0) {
                // SearchCritier and SearchConstraint are equal
                String field = this.getDf().format(searchCriteria.getIssued());
                sqlWHERE.append(" AND receipt.Issued = ?");
                description.append(" and issued on '" + field + "'");
                parameters.add(field);
            }
        } else {
            String field = this.getDf().format(searchCriteria.getIssued());
            sqlWHERE.append(" AND receipt.Issued = ?");
            description.append(" and issued on '" + field + "'");
            parameters.add(field);
        }
    }

    if (searchCriteria.getCreatedDate() != null) {
        if (searchConstraints.getCreatedDate() != null) {
            int larger = searchCriteria.getCreatedDate().compareTo(searchConstraints.getCreatedDate());
            if (larger > 0) {
                // SearchCriteria date after SearchConstraint date
                String fieldA = this.getDf().format(searchCriteria.getCreatedDate());
                String fieldB = this.getDf().format(searchConstraints.getCreatedDate());
                sqlWHERE.append(" AND guid.CreatedDate BETWEEN ? AND ?");
                description.append(" and created between '" + fieldB + "' and '" + fieldA + "'");
                parameters.add(fieldB);
                parameters.add(fieldA);
            }
            if (larger < 0) {
                // SearchCriteria date before SearchConstraint date
                String fieldA = this.getDf().format(searchCriteria.getCreatedDate());
                String fieldB = this.getDf().format(searchConstraints.getCreatedDate());
                sqlWHERE.append(" AND guid.CreatedDate BETWEEN ? AND ?");
                description.append(" and created between '" + fieldA + "' and '" + fieldB + "'");
                parameters.add(fieldA);
                parameters.add(fieldB);

            }
            if (larger == 0) {
                // SearchCritier and SearchConstraint are equal
                String field = this.getDf().format(searchCriteria.getCreatedDate());
                sqlWHERE.append(" AND guid.CreatedDate = ?");
                description.append(" and created on '" + field + "'");
                parameters.add(field);
            }
        } else {
            String field = this.getDf().format(searchCriteria.getCreatedDate());
            sqlWHERE.append(" AND guid.CreatedDate = ?");
            description.append(" and created on '" + field + "'");
            parameters.add(field);
        }
    }

    if (searchCriteria.getModifiedDate() != null) {
        if (searchConstraints.getModifiedDate() != null) {
            int larger = searchCriteria.getModifiedDate().compareTo(searchConstraints.getModifiedDate());
            if (larger > 0) {
                // SearchCriteria date after SearchConstraint date
                String fieldA = this.getDf().format(searchCriteria.getModifiedDate());
                String fieldB = this.getDf().format(searchConstraints.getModifiedDate());
                sqlWHERE.append(" AND guid.ModifiedDate BETWEEN ? AND ?");
                description.append(" and modified between '" + fieldB + "' and '" + fieldA + "'");
                parameters.add(fieldB);
                parameters.add(fieldA);
            }
            if (larger < 0) {
                // SearchCriteria date before SearchConstraint date
                String fieldA = this.getDf().format(searchCriteria.getModifiedDate());
                String fieldB = this.getDf().format(searchConstraints.getModifiedDate());
                sqlWHERE.append(" AND guid.ModifiedDate BETWEEN ? AND ?");
                description.append(" and modified between '" + fieldA + "' and '" + fieldB + "'");
                parameters.add(fieldA);
                parameters.add(fieldB);

            }
            if (larger == 0) {
                // SearchCritier and SearchConstraint are equal
                String field = this.getDf().format(searchCriteria.getModifiedDate());
                sqlWHERE.append(" AND guid.ModifiedDate = ?");
                description.append(" and modified on '" + field + "'");
                parameters.add(field);
            }
        } else {
            String field = this.getDf().format(searchCriteria.getModifiedDate());
            sqlWHERE.append(" AND guid.ModifiedDate = ?");
            description.append(" and modified on '" + field + "'");
            parameters.add(field);
        }
    }

    if (searchCriteria.getIncludeGUIDList() != null) {
        final StringBuffer guidWHERE = new StringBuffer();

        for (String guid : searchCriteria.getIncludeGUIDList()) {
            if (StringUtils.isNotBlank(guid)) {
                guidWHERE.append(" OR receipt.GUID = ?");
                parameters.add(guid);
            }
        }
        if (guidWHERE.length() > 0) {
            // Append the guidWHERE buffer to the sqlWHERE buffer
            sqlWHERE.append(" OR (");
            // Append the guidWHERE but strip the first OR statement
            sqlWHERE.append(guidWHERE.toString().substring(4));
            sqlWHERE.append(")");
            description.append(" and has a GUID in the supplied list");
        }
    }

    String[] index = new String[] { sqlWHERE.toString(), DataFilter.getHtml(description.toString()) };

    Map<String[], Collection<Object>> results = new HashMap<String[], Collection<Object>>();

    results.put(index, parameters);

    return results;
}

From source file:io.lqd.sdk.model.LQDevice.java

public JSONObject toJSON() {
    // Updating to avoid callbacks
    mInternetConnectivity = LQDevice.getInternetConnectivity(mContext);

    HashMap<String, Object> attrs = new HashMap<String, Object>();
    if (mAttributes != null) {
        attrs.putAll(mAttributes);// w  ww. j a  v  a  2s  .co m
    }
    attrs.put("vendor", mVendor);
    attrs.put("platform", "Android");
    attrs.put("model", mDeviceModel);
    try {
        attrs.put("system_version", Integer.parseInt(mSystemVersion));
    } catch (NumberFormatException e) {
        attrs.put("system_version", mSystemVersion);
    }
    attrs.put("screen_size", mScreenSize);
    attrs.put("carrier", mCarrier);
    attrs.put("internet_connectivity", mInternetConnectivity);
    attrs.put("unique_id", mUid);
    attrs.put("app_bundle", mAppBundle);
    attrs.put("app_name", mAppName);
    attrs.put("app_version", mAppVersion);
    attrs.put("release_version", mReleaseVersion);
    attrs.put("liquid_version", mLiquidVersion);
    attrs.put("locale", mLocale);
    attrs.put("system_language", mSystemLanguage);

    JSONObject json = new JSONObject();
    try {
        if (attrs != null) {
            for (String key : attrs.keySet()) {
                json.put(key, attrs.get(key));
            }
        }
        return json;
    } catch (JSONException e) {
        LQLog.error("LQDevice toJSON: " + e.getMessage());
    }
    return null;
}