Example usage for org.apache.commons.lang StringUtils isNumeric

List of usage examples for org.apache.commons.lang StringUtils isNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils isNumeric.

Prototype

public static boolean isNumeric(String str) 

Source Link

Document

Checks if the String contains only unicode digits.

Usage

From source file:com.thoughtworks.go.server.controller.PropertiesController.java

@RequestMapping("/repository/restful/properties/jobs/search")
public ModelAndView jobsSearch(@RequestParam("pipelineName") String pipelineName,
        @RequestParam("stageName") String stageName, @RequestParam("jobName") String jobName,
        @RequestParam(value = "limitPipeline", required = false) String limitPipeline,
        @RequestParam(value = "limitCount", required = false) Integer limitCount, HttpServletResponse response)
        throws Exception {

    Long limitPipelineId = null;/* w w  w.ja  va2s.com*/
    int pipelineCounter = 0;
    if (limitPipeline != null) {
        if (JobIdentifier.LATEST.equalsIgnoreCase(limitPipeline)) {
            PipelineIdentifier pipelineIdentifier = pipelineService.mostRecentPipelineIdentifier(pipelineName);
            pipelineCounter = pipelineIdentifier.getCounter();
        } else if (StringUtils.isNumeric(limitPipeline)) {
            pipelineCounter = Integer.parseInt(limitPipeline);
        } else {
            return notFound(String.format(
                    "Expected a numeric value for query parameter 'limitPipeline', but received [%s]",
                    limitPipeline)).respond(response);

        }
        Pipeline pipeline = pipelineService.findPipelineByNameAndCounter(pipelineName, pipelineCounter);
        if (pipeline != null) {
            limitPipelineId = pipeline.getId();
        } else {
            return notFound(String.format(
                    "The value [%s] of query parameter 'limitPipeline' is not a valid pipeline counter for pipeline '%s'",
                    limitPipeline, pipelineName)).respond(response);
        }
    }

    limitCount = limitCount == null ? 100 : limitCount;
    try {
        List<Properties> result = propertyService.loadHistory(pipelineName, stageName, jobName, limitPipelineId,
                limitCount);
        PropertiesService.PropertyLister propertyLister = PropertiesService.asCsv(jobName);
        return propertyLister.listPropertiesHistory(result).respond(response);
    } catch (Exception e) {
        String message = String.format(
                "Error on listing properties history for job %s/%s/%s with limitPipeline=%s and limitCount=%s",
                pipelineName, stageName, jobName, limitPipeline, limitCount);
        LOGGER.error(message, e);
        return notFound(message + "\n" + e.getMessage()).respond(response);
    }
}

From source file:gov.nih.nci.cabig.caaers.web.admin.CreateINDController.java

public void validate(INDCommand command, BindException errors) {
    BeanWrapper commandBean = new BeanWrapperImpl(command);
    for (InputFieldGroup fieldGroup : fieldMap.values()) {
        for (InputField field : fieldGroup.getFields()) {
            field.validate(commandBean, errors);
        }/*from ww w  .ja v a  2 s  .  c  om*/
    }
    // check if the strINDNumber is a numeric value
    if (!StringUtils.isNumeric((String) commandBean.getPropertyValue("strINDNumber"))) {
        errors.rejectValue("strINDNumber", "ADM_IND_001", "IND# must be numeric");
    }
}

From source file:fr.paris.lutece.plugins.mydashboard.modules.myaccount.web.DemandMyAccountApp.java

@View(value = VIEW_NOTIFICATIONS, defaultView = true)
public XPage getViewNotificationCrm(HttpServletRequest request) {
    LuteceUser user = SecurityService.getInstance().getRegisteredUser(request);
    Map<String, Object> model = getModel();

    if (user != null) {
        CRMUser crmUser = CRMUserService.getService().findByUserGuid(user.getName());
        String strIdDemand = request.getParameter(CRMConstants.PARAMETER_ID_DEMAND);

        if ((crmUser != null) && StringUtils.isNotBlank(strIdDemand) && StringUtils.isNumeric(strIdDemand)) {
            int nIdDemand = Integer.parseInt(strIdDemand);
            model.put(MARK_ID_DEMAND, nIdDemand);
            Demand demand = DemandService.getService().findByPrimaryKey(nIdDemand);

            if ((demand != null) && (crmUser.getIdCRMUser() == demand.getIdCRMUser())) {
                NotificationFilter nFilter = new NotificationFilter();
                nFilter.setIdDemand(nIdDemand);
                List<Notification> listNotification = NotificationService.getService().findByFilter(nFilter);
                DemandType demandType = DemandTypeService.getService()
                        .findByPrimaryKey(demand.getIdDemandType());
                model.put(CRMConstants.MARK_NOTIFICATIONS_LIST, listNotification);
                model.put(CRMConstants.MARK_DEMAND_TYPE, demandType);
                //update unread Flag
                if (!CollectionUtils.isEmpty(listNotification)) {
                    for (Notification notification : listNotification) {
                        if (!notification.isRead()) {
                            Notification notificationSave = NotificationService.getService()
                                    .findByPrimaryKey(notification.getIdNotification());
                            notificationSave.setIsRead(true);
                            NotificationService.getService().update(notificationSave);
                        }/*from  www  .java 2 s. co  m*/
                    }

                }

            }
        }
    }

    XPage xpage = getXPage(TEMPLATE_NOTIFICATION_CRM, getLocale(request), model);
    xpage.setStandalone(true);

    return xpage;
}

From source file:fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeSelectSQL.java

/**
 * {@inheritDoc}//from  w  ww .  j a  va 2  s  .  c  o  m
 */
@Override
public GenericAttributeError getResponseData(Entry entry, HttpServletRequest request,
        List<Response> listResponse, Locale locale) {
    String strIdField = request.getParameter(PREFIX_ATTRIBUTE + entry.getIdEntry());
    int nIdField = -1;
    Field field = null;
    Response response = new Response();
    response.setEntry(entry);

    if (StringUtils.isNotEmpty(strIdField) && StringUtils.isNumeric(strIdField)) {
        nIdField = Integer.parseInt(strIdField);
    }

    if (nIdField != -1) {
        field = GenericAttributesUtils.findFieldByIdInTheList(nIdField, getSqlQueryFields(entry));
    }

    if (field != null) {
        response.setResponseValue(field.getValue());
        response.setField(field);
    }

    listResponse.add(response);

    if (entry.isMandatory()) {
        if ((field == null) || StringUtils.isBlank(field.getValue())) {
            return new MandatoryError(entry, locale);
        }
    }

    return null;
}

From source file:com.impetus.kundera.property.accessor.DateAccessor.java

/**
 * Get Date from given below formats.//from www  .j  a va2 s  . co  m
 * 
 * @param date
 *            Date pattern
 * @return date instance
 * @throws PropertyAccessException
 *             throws only if invalid format is supplied.
 */
public static Date getDateByPattern(String date) {
    if (StringUtils.isNumeric(date)) {
        return new Date(Long.parseLong(date));
    }

    for (String p : patterns) {
        try {
            DateFormat formatter = new SimpleDateFormat(p);
            Date dt = formatter.parse(date);
            return dt;
        } catch (IllegalArgumentException iae) {
            // Do nothing.
            // move to next pattern.
        } catch (ParseException e) {
            // Do nothing.
            // move to next pattern.
        }

    }
    log.error("Required Date format is not supported!" + date);
    throw new PropertyAccessException("Required Date format is not supported!" + date);
}

From source file:azkaban.server.HttpRequestUtils.java

/**
 * parse a string as number and throws exception if parsed value is not a
 * valid integer/* w w  w  . j av  a  2s  . c o  m*/
 * @param params
 * @param paramName
 * @throws ExecutorManagerException if paramName is not a valid integer
 */
public static boolean validateIntegerParam(Map<String, String> params, String paramName)
        throws ExecutorManagerException {
    if (params != null && params.containsKey(paramName) && !StringUtils.isNumeric(params.get(paramName))) {
        throw new ExecutorManagerException(paramName + " should be an integer");
    }
    return true;
}

From source file:fr.paris.lutece.plugins.directory.web.action.MassChangeStatesRecordDirectoryAction.java

/**
 * Redirects to {@link #JSP_DIRECTORY_MASS_CHANGE_STATES_RECORD}
 *//*from w  w w .j  a  v  a2  s  .  co  m*/
public IPluginActionResult process(HttpServletRequest request, HttpServletResponse response,
        AdminUser adminUser, DirectoryAdminSearchFields sessionFields) throws AccessDeniedException {
    IPluginActionResult result = new DefaultPluginActionResult();

    String strRedirect = StringUtils.EMPTY;

    if ((sessionFields.getSelectedRecords() != null) && !sessionFields.getSelectedRecords().isEmpty()) {
        String strIdDirectory = request.getParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY);
        UrlItem url = new UrlItem(AppPathService.getBaseUrl(request) + JSP_DIRECTORY_MASS_CHANGE_STATES_RECORD);
        url.addParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY, strIdDirectory);

        for (String strIdRecord : sessionFields.getSelectedRecords()) {
            if (StringUtils.isNotBlank(strIdRecord) && StringUtils.isNumeric(strIdRecord)) {
                url.addParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY_RECORD, strIdRecord);
            }
        }

        strRedirect = url.getUrl();
    } else {
        strRedirect = AdminMessageService.getMessageUrl(request, DirectoryUtils.MESSAGE_SELECT_RECORDS,
                AdminMessage.TYPE_INFO);
    }

    result.setRedirect(strRedirect);

    return result;
}

From source file:br.gov.jfrj.siga.libs.webwork.SigaAnonimoActionSupport.java

public Integer paramInteger(final String parameterName) {
    final String s = param(parameterName);
    if (s == null || s.equals("") || !StringUtils.isNumeric(s))
        return null;
    return Integer.parseInt(s);
}

From source file:edu.ku.brc.af.ui.ESTermParser.java

@Override
public boolean parse(final String searchTermArg, final boolean parseAsSingleTerm) {
    instance.fields.clear();//  w  w  w. j  a  v a 2 s  .  c  o m

    //DateWrapper scrDateFormat = AppPrefsCache.getDateWrapper("ui", "formatting", "scrdateformat");
    int currentYear = Calendar.getInstance().get(Calendar.YEAR);
    String searchTerm = searchTermArg;
    DateParser dd = new DateParser(instance.scrDateFormat.getSimpleDateFormat().toPattern());

    //----------------------------------------------------------------------------------------------
    // NOTE: If a full date was type in and it was parsed as such
    // and it couldn't be something else, then it only searches date fields.
    //----------------------------------------------------------------------------------------------

    int cnt = 0;

    if (searchTerm.length() > 0) {
        if (StringUtils.contains(searchTerm, '\\')) {
            return false;
        }

        String[] terms;

        boolean startWith = searchTerm.startsWith("*");
        boolean endsWith = searchTerm.endsWith("*");

        searchTerm = StringUtils.remove(searchTerm, '*');

        if (searchTerm.startsWith("\"") || searchTerm.startsWith("'") || searchTerm.startsWith("`")) {
            searchTerm = StringUtils.stripStart(searchTerm, "\"'`");
            searchTerm = StringUtils.stripEnd(searchTerm, "\"'`");
            terms = new String[] { searchTerm };

        } else if (parseAsSingleTerm) {
            terms = new String[] { searchTerm };

        } else {
            terms = StringUtils.split(searchTerm, ' ');
        }

        if (terms.length == 1) {
            terms[0] = (startWith ? "*" : "") + terms[0] + (endsWith ? "*" : "");
        } else {

            terms[0] = (startWith ? "*" : "") + terms[0];
            terms[terms.length - 1] = terms[terms.length - 1] + (endsWith ? "*" : "");
        }

        for (String term : terms) {
            if (StringUtils.isEmpty(term)) {
                continue;
            }

            SearchTermField stf = new SearchTermField(term);

            if (stf.isSingleChar()) {
                return false;
            }
            instance.fields.add(stf);

            cnt += !stf.isSingleChar() ? 1 : 0;

            //log.debug(term);
            String termStr = term;

            if (termStr.startsWith("*")) {
                stf.setOption(SearchTermField.STARTS_WILDCARD);
                termStr = termStr.substring(1);
                stf.setTerm(termStr);
            }

            if (termStr.endsWith("*")) {
                stf.setOption(SearchTermField.ENDS_WILDCARD);
                termStr = termStr.substring(0, termStr.length() - 1);
                stf.setTerm(termStr);
            }

            // First check to see if it is all numeric.
            if (StringUtils.isNumeric(termStr)) {
                stf.setOption(SearchTermField.IS_NUMERIC);
                if (StringUtils.contains(termStr, '.')) {
                    stf.setOption(SearchTermField.HAS_DEC_POINT);
                }

                if (!stf.isOn(SearchTermField.HAS_DEC_POINT) && termStr.length() == 4) {
                    int year = Integer.parseInt(termStr);
                    if (year > 1000 && year <= currentYear) {
                        stf.setOption(SearchTermField.IS_YEAR_OF_DATE);
                    }
                }
            } else {
                // Check to see if it is date
                Date searchDate = dd.parseDate(searchTermArg);
                if (searchDate != null) {
                    try {
                        termStr = dbDateFormat.format(searchDate);
                        stf.setTerm(termStr);
                        stf.setOption(SearchTermField.IS_DATE);

                    } catch (Exception ex) {
                        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ESTermParser.class, ex);
                        // should never get here
                    }
                }
            }
        }
    }

    return instance.fields.size() > 0 && cnt > 0;
}

From source file:hydrograph.ui.engine.converter.Converter.java

/**
 * Converts the String to {@link BigInteger}
 * /*from www  .j av  a2 s.  co m*/
 * @param propertyName
 * @return {@link BigInteger}
 */
protected BigInteger getBigInteger(String propertyName) {
    logger.debug("Getting boolean Value for {}={}",
            new Object[] { propertyName, properties.get(propertyName) });
    BigInteger bigInteger = null;
    String propertyValue = (String) properties.get(propertyName);
    if (StringUtils.isNotBlank(propertyValue) && StringUtils.isNumeric(propertyValue)) {
        bigInteger = new BigInteger(String.valueOf(propertyValue));
    } else if (ParameterUtil.isParameter(propertyValue)) {
        ComponentXpath.INSTANCE.getXpathMap()
                .put((ComponentXpathConstants.COMPONENT_XPATH_BOOLEAN.value().replace(ID, componentId))
                        .replace(Constants.PARAM_PROPERTY_NAME, propertyName),
                        new ComponentsAttributeAndValue(null, properties.get(propertyName).toString()));
        bigInteger = new BigInteger(String.valueOf(0));
    }
    return bigInteger;

}