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:fr.paris.lutece.plugins.workflow.modules.editrecord.service.TaskEditRecord.java

/**
 * {@inheritDoc}// w  w w  .  ja v  a 2 s .co  m
 */
@Override
public void processTask(int nIdResourceHistory, HttpServletRequest request, Locale locale) {
    String strMessage = request
            .getParameter(EditRecordConstants.PARAMETER_MESSAGE + EditRecordConstants.UNDERSCORE + getId());
    String[] listIdsEntry = request.getParameterValues(
            EditRecordConstants.PARAMETER_IDS_ENTRY + EditRecordConstants.UNDERSCORE + getId());

    boolean bCreate = false;
    List<EditRecordValue> listEditRecordValues = new ArrayList<EditRecordValue>();

    EditRecord editRecord = _editRecordService.find(nIdResourceHistory, getId());

    if (editRecord == null) {
        editRecord = new EditRecord();
        editRecord.setIdHistory(nIdResourceHistory);
        editRecord.setIdTask(getId());
        bCreate = true;
    }

    if (listIdsEntry != null) {
        for (String strIdEntry : listIdsEntry) {
            if (StringUtils.isNotBlank(strIdEntry) && StringUtils.isNumeric(strIdEntry)) {
                int nIdEntry = Integer.parseInt(strIdEntry);
                EditRecordValue editRecordValue = new EditRecordValue();
                editRecordValue.setIdEntry(nIdEntry);

                listEditRecordValues.add(editRecordValue);
            }
        }
    }

    editRecord.setMessage(StringUtils.isNotBlank(strMessage) ? strMessage : StringUtils.EMPTY);
    editRecord.setListEditRecordValues(listEditRecordValues);
    editRecord.setIsComplete(false);

    if (bCreate) {
        _editRecordService.create(editRecord);
    } else {
        _editRecordService.update(editRecord);
    }
}

From source file:com.streamsets.pipeline.lib.parser.net.netflow.NetflowDataParserFactory.java

@Override
public DataParser getParser(String id, InputStream is, String offset) throws DataParserException {
    return new NetflowDataParser(getSettings().getContext(), id, is,
            StringUtils.isNumeric(offset) ? Long.parseLong(offset) : null, getSettings().getMaxRecordLen(),
            getSettings().getCharset(), (OutputValuesMode) CONFIGS.get(OUTPUT_VALUES_MODE_KEY),
            (int) CONFIGS.get(MAX_TEMPLATE_CACHE_SIZE_KEY), (int) CONFIGS.get(TEMPLATE_CACHE_TIMEOUT_MS_KEY));
}

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

/**
 * {@inheritDoc}//from   ww  w . j  av  a 2 s .  c om
 */
public void fillModel(HttpServletRequest request, AdminUser adminUser, Map<String, Object> model) {
    ReferenceList refMassActions = null;
    String strIdDirectory = request.getParameter(DirectoryUtils.PARAMETER_ID_DIRECTORY);

    if (StringUtils.isNotBlank(strIdDirectory) && StringUtils.isNumeric(strIdDirectory)) {
        int nIdDirectory = DirectoryUtils.convertStringToInt(strIdDirectory);
        Plugin plugin = PluginService.getPlugin(DirectoryPlugin.PLUGIN_NAME);
        Directory directory = DirectoryHome.findByPrimaryKey(nIdDirectory, plugin);

        if ((directory != null) && (directory.getIdWorkflow() != DirectoryUtils.CONSTANT_ID_NULL)) {
            List<Action> listMassActions = WorkflowService.getInstance()
                    .getMassActions(directory.getIdWorkflow());

            if ((listMassActions != null) && !listMassActions.isEmpty()) {
                refMassActions = new ReferenceList();
                refMassActions.addAll(ReferenceList.convert(listMassActions, DirectoryUtils.CONSTANT_ID,
                        DirectoryUtils.CONSTANT_NAME, true));
            }
        }
    }

    model.put(MARK_LIST_MASS_WORKFLOW_ACTIONS, refMassActions);
}

From source file:edu.ku.brc.specify.toycode.RegAdder.java

/**
 * @param trackId/*w  w  w  .ja  va2s.  com*/
 * @param mv
 * @param pStmt
 * @throws SQLException
 */
private void doTrackInserts(final int trackId, final HashMap<String, String> mv, final PreparedStatement pStmt)
        throws SQLException {
    for (String key : mv.keySet()) {
        String value = mv.get(key);
        pStmt.setString(1, key);
        if (!StringUtils.contains(value, ".") && StringUtils.isNumeric(value) && value.length() < 10) {
            pStmt.setInt(2, Integer.parseInt(value));
            pStmt.setNull(3, java.sql.Types.VARCHAR);

        } else if (value.length() < STR_SIZE + 1) {
            pStmt.setNull(2, java.sql.Types.INTEGER);
            pStmt.setString(3, value);

        } else {
            String v = value.substring(0, STR_SIZE);
            System.err.println(
                    "Error - On line " + lineNo + " Value[" + value + "] too big trunccating to[" + v + "]");

            pStmt.setNull(2, java.sql.Types.INTEGER);
            pStmt.setString(3, v);
        }
        pStmt.setInt(4, trackId);

        //System.out.println(pStmt2.toString());

        int rv = pStmt.executeUpdate();
        if (rv != 1) {
            for (String k : mv.keySet()) {
                System.out.println("[" + k + "][" + mv.get(k) + "]");
            }
            System.err.println("------------------------ Line No: " + lineNo);
            throw new RuntimeException("Error insert trackitem for Id: " + trackId);
        }
    }
}

From source file:com.neusoft.mid.clwapi.service.photo.PhotoServiceImpl.java

/**
 * ??API//w  w  w .j  av a  2s. c  o  m
 * 
 * @param token
 *            token
 * @param body
 *            ?
 * @return
 */
@Override
public Object getPhotoList(String token, String body) {
    logger.info("???");

    String organizationId = context.getHttpHeaders().getHeaderString(UserInfoKey.ORGANIZATION_ID);

    // ??
    PhotoRequ iPhotoRequ = JacksonUtils.fromJsonRuntimeException(body, PhotoRequ.class);
    // ??
    iPhotoRequ.setEndTime(StringUtils.strip(iPhotoRequ.getEndTime()));
    iPhotoRequ.setStartTime(StringUtils.strip(iPhotoRequ.getStartTime()));
    iPhotoRequ.setNum(StringUtils.strip(iPhotoRequ.getNum()));
    iPhotoRequ.setType(StringUtils.strip(iPhotoRequ.getType()));
    iPhotoRequ.setPage(StringUtils.strip(iPhotoRequ.getPage()));
    iPhotoRequ.setOrganizationId(organizationId);

    // ??
    logger.info("??");
    if (StringUtils.isEmpty(iPhotoRequ.getType()) || StringUtils.isEmpty(iPhotoRequ.getNum())
            || StringUtils.isEmpty(iPhotoRequ.getPage())) {
        logger.error("??");
        throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
    } else if (StringUtils.isEmpty(iPhotoRequ.getStartTime()) || StringUtils.isEmpty(iPhotoRequ.getEndTime())) {
        logger.error("????");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    } else if (!iPhotoRequ.getType().equals(HttpConstant.PHOTOPORT_TYPE_ORDER)
            && !iPhotoRequ.getType().equals(HttpConstant.PHOTOPORT_TYPE_ALL)) {
        logger.error("??type?1?2");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    } else if (!StringUtils.isNumeric(iPhotoRequ.getNum())) {
        logger.error("??num?");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    } else if (!StringUtils.isNumeric(iPhotoRequ.getPage())) {
        logger.error("??page?");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    // ???
    if (!HttpConstant.TIME_ZERO.equals(iPhotoRequ.getStartTime())) {
        try {
            TimeUtil.parseStringToDate(iPhotoRequ.getStartTime(), HttpConstant.TIME_FORMAT);
        } catch (ParseException e) {
            logger.error("???????", e);
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }
    } else {
        iPhotoRequ.setStartTime(null);
    }
    if (!HttpConstant.TIME_ZERO.equals(iPhotoRequ.getEndTime())) {
        try {
            TimeUtil.parseStringToDate(iPhotoRequ.getEndTime(), HttpConstant.TIME_FORMAT);
        } catch (ParseException e) {
            logger.error("????????", e);
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }
    } else {
        iPhotoRequ.setEndTime(null);
    }

    // ?????
    int page = Integer.valueOf(iPhotoRequ.getPage());
    int num = Integer.valueOf(iPhotoRequ.getNum());

    // ????
    if (page <= 0) {
        logger.error("??page?0");
        throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
    }

    logger.info("???");

    // ?
    iPhotoRequ.setVin(StringUtils.isEmpty(iPhotoRequ.getVin()) ? null : iPhotoRequ.getVin());
    iPhotoRequ.setOrgaId(StringUtils.isEmpty(iPhotoRequ.getOrgaId()) ? null : iPhotoRequ.getOrgaId());

    // ??
    // IDEN_ID
    iPhotoRequ.setUsrId(context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID));
    iPhotoRequ.setEnId(context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID));

    // ?
    iPhotoRequ.setStartRow(String.valueOf(page * num - num));
    iPhotoRequ.setEndRow(String.valueOf(page * num));
    // 2type??sql
    iPhotoRequ.setType(
            iPhotoRequ.getType().equals(HttpConstant.PHOTOPORT_TYPE_ALL) ? null : iPhotoRequ.getType());

    logger.info("?");
    logger.debug("?");
    logger.debug(iPhotoRequ.toString());

    // ?
    List<PhotoInfo> imgs = iPhotoMapper.getPhotoList(iPhotoRequ);
    logger.info("??");
    logger.debug("imgs=" + (imgs == null ? "NULL" : imgs.size()));

    if (imgs == null || imgs.size() == 0) {
        logger.info("?");
        return Response.noContent().build();
    }

    logger.debug("?");
    if (logger.isDebugEnabled()) {
        Iterator<PhotoInfo> it = imgs.iterator();
        while (it.hasNext()) {
            PhotoInfo temp = it.next();
            logger.debug(temp.toString());
        }
    }

    // 
    PhotoResp iPhotoResp = new PhotoResp();
    iPhotoResp.setImgs(imgs);
    logger.info("???");

    return JacksonUtils.toJsonRuntimeException(iPhotoResp);
}

From source file:edu.usu.sdl.openstorefront.web.rest.service.NotificationService.java

@POST
@APIDescription("Sends recent change email to all user that are flag to be notified or an email via the query param")
@RequireAdmin/*www . j  a  v  a 2s. co m*/
@Path("/recent-changes")
public Response recentChanges(
        @QueryParam("lastRunDts") @APIDescription("MM/dd/yyyy or Unix Epoch - (Defaults to the beginning of the current day in server time)") String lastRunDtsValue,
        @QueryParam("emailAddress") @APIDescription("Set to send a preview email just to that address") String emailAddress) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy");

    Date lastRunDts;
    if (StringUtils.isBlank(lastRunDtsValue)) {
        lastRunDts = TimeUtil.beginningOfDay(TimeUtil.currentDate());
    } else {
        lastRunDts = simpleDateFormat.parse(lastRunDtsValue, new ParsePosition(0));
        if (lastRunDts == null) {
            if (StringUtils.isNumeric(lastRunDtsValue)) {
                lastRunDts = new Date(Convert.toLong(lastRunDtsValue));
            }
        }
    }

    if (lastRunDts != null) {
        TaskRequest taskRequest = new TaskRequest();
        taskRequest.setAllowMultiple(true);
        taskRequest.setName("Send Recent Change Email");
        String email = "";
        if (StringUtils.isNotBlank(emailAddress)) {
            email = " Email: " + emailAddress;
        }
        taskRequest.setDetails("Start Date: " + lastRunDts + email);
        service.getAsyncProxy(service.getUserService(), taskRequest).sendRecentChangeEmail(lastRunDts,
                emailAddress);
    } else {
        throw new OpenStorefrontRuntimeException("Unable to parse last run dts",
                "Check last run dts param format (MM/dd/yyyy) ");
    }
    return Response.ok().build();
}

From source file:com.intellectualcrafters.plot.commands.Condense.java

@Override
public boolean execute(final PlotPlayer plr, final String... args) {
    if (plr != null) {
        MainUtil.sendMessage(plr, (C.NOT_CONSOLE));
        return false;
    }//from   w  w w .j  a v a  2  s  .  c  o m
    if ((args.length != 2) && (args.length != 3)) {
        MainUtil.sendMessage(plr, "/plot condense <world> <start|stop|info> [radius]");
        return false;
    }
    final String worldname = args[0];
    if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) {
        MainUtil.sendMessage(plr, "INVALID WORLD");
        return false;
    }
    switch (args[1].toLowerCase()) {
    case "start": {
        if (args.length == 2) {
            MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
            return false;
        }
        if (TASK) {
            MainUtil.sendMessage(plr, "TASK ALREADY STARTED");
            return false;
        }
        if (args.length == 2) {
            MainUtil.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
            return false;
        }
        if (!StringUtils.isNumeric(args[2])) {
            MainUtil.sendMessage(plr, "INVALID RADIUS");
            return false;
        }
        final int radius = Integer.parseInt(args[2]);
        final Collection<Plot> plots = PS.get().getPlots(worldname).values();
        final int size = plots.size();
        final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
        if (radius < minimum_radius) {
            MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
            return false;
        }
        final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
        final List<PlotId> free = new ArrayList<>();
        PlotId start = new PlotId(0, 0);
        while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
            final Plot plot = MainUtil.getPlot(worldname, start);
            if (!plot.hasOwner()) {
                free.add(plot.id);
            }
            start = Auto.getNextPlot(start, 1);
        }
        if (free.size() == 0 || to_move.size() == 0) {
            MainUtil.sendMessage(plr, "NO PLOTS FOUND");
            return false;
        }
        MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)),
                new Runnable() {
                    @Override
                    public void run() {
                        if (!TASK) {
                            sendMessage("CONDENSE TASK CANCELLED");
                            return;
                        }
                        to_move.remove(0);
                        free.remove(0);
                        int index = 0;
                        for (final PlotId id : to_move) {
                            final Plot plot = MainUtil.getPlot(worldname, id);
                            if (plot.hasOwner()) {
                                break;
                            }
                            index++;
                        }
                        for (int i = 0; i < index; i++) {
                            to_move.remove(0);
                        }
                        index = 0;
                        for (final PlotId id : free) {
                            final Plot plot = MainUtil.getPlot(worldname, id);
                            if (!plot.hasOwner()) {
                                break;
                            }
                            index++;
                        }
                        for (int i = 0; i < index; i++) {
                            free.remove(0);
                        }
                        if (to_move.size() == 0) {
                            sendMessage(
                                    "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
                            TASK = false;
                            return;
                        }
                        if (free.size() == 0) {
                            sendMessage("TASK FAILED. NO FREE PLOTS FOUND!");
                            TASK = false;
                            return;
                        }
                        sendMessage("MOVING " + to_move.get(0) + " to " + free.get(0));
                        MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)),
                                MainUtil.getPlot(worldname, free.get(0)), this);
                    }
                });
        TASK = true;
        MainUtil.sendMessage(plr, "TASK STARTED...");
        return true;
    }
    case "stop": {
        if (!TASK) {
            MainUtil.sendMessage(plr, "TASK ALREADY STOPPED");
            return false;
        }
        TASK = false;
        MainUtil.sendMessage(plr, "TASK STOPPED");
        return true;
    }
    case "info": {
        if (args.length == 2) {
            MainUtil.sendMessage(plr, "/plot condense " + worldname + " info <radius>");
            return false;
        }
        if (!StringUtils.isNumeric(args[2])) {
            MainUtil.sendMessage(plr, "INVALID RADIUS");
            return false;
        }
        final int radius = Integer.parseInt(args[2]);
        final Collection<Plot> plots = PS.get().getPlots(worldname).values();
        final int size = plots.size();
        final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
        if (radius < minimum_radius) {
            MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
            return false;
        }
        final int max_move = getPlots(plots, minimum_radius).size();
        final int user_move = getPlots(plots, radius).size();
        MainUtil.sendMessage(plr, "=== DEFAULT EVAL ===");
        MainUtil.sendMessage(plr, "MINIMUM RADIUS: " + minimum_radius);
        MainUtil.sendMessage(plr, "MAXIMUM MOVES: " + max_move);
        MainUtil.sendMessage(plr, "=== INPUT EVAL ===");
        MainUtil.sendMessage(plr, "INPUT RADIUS: " + radius);
        MainUtil.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
        MainUtil.sendMessage(plr, "ESTIMATED TIME: "
                + "No idea, times will drastically change based on the system performance and load");
        MainUtil.sendMessage(plr, "&e - Radius is measured in plot width");
        return true;
    }
    }
    MainUtil.sendMessage(plr, "/plot condense " + worldname + " <start|stop|info> [radius]");
    return false;
}

From source file:fr.paris.lutece.plugins.mydashboard.web.portlet.MyDashboardPortletJspBean.java

/**
 * {@inheritDoc}/*from w ww  .ja  v  a  2 s .  c om*/
 */
@Override
public String doModify(HttpServletRequest request) {
    // recovers portlet attributes
    String strPortletId = request.getParameter(PARAMETER_PORTLET_ID);

    int nPortletId = (StringUtils.isNotEmpty(strPortletId) && StringUtils.isNumeric(strPortletId))
            ? Integer.parseInt(strPortletId)
            : 1;

    MyDashboardPortlet portlet = (MyDashboardPortlet) PortletHome.findByPrimaryKey(nPortletId);

    // retrieve portlet common attributes
    String strErrorUrl = setPortletCommonData(request, portlet);

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

    MyDashboardPortletHome.getInstance().update(portlet);

    // displays the page withe the potlet updated
    return getPageUrl(portlet.getPageId());
}

From source file:fr.paris.lutece.plugins.workflow.modules.editrecord.web.EditRecordApp.java

/**
 * {@inheritDoc}/* w w  w.  j a va 2s. co m*/
 */
public XPage getPage(HttpServletRequest request, int nMode, Plugin plugin)
        throws UserNotSignedException, SiteMessageException {
    XPage page = null;

    if (_editRecordService.isRequestAuthenticated(request)) {
        String strIdHistory = request.getParameter(EditRecordConstants.PARAMETER_ID_HISTORY);
        String strIdTask = request.getParameter(EditRecordConstants.PARAMETER_ID_TASK);

        if (StringUtils.isNotBlank(strIdHistory) && StringUtils.isNumeric(strIdHistory)
                && StringUtils.isNotBlank(strIdTask) && StringUtils.isNumeric(strIdTask)) {
            int nIdHistory = Integer.parseInt(strIdHistory);
            int nIdTask = Integer.parseInt(strIdTask);
            EditRecord editRecord = _editRecordService.find(nIdHistory, nIdTask);

            if ((editRecord != null) && !editRecord.isComplete()) {
                if (_editRecordService.isRecordStateValid(editRecord, request.getLocale())) {
                    doAction(request, editRecord);
                    page = getEditRecordPage(request, editRecord);
                } else {
                    _editRecordService.setSiteMessage(request, Messages.USER_ACCESS_DENIED,
                            SiteMessage.TYPE_STOP,
                            request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
                }
            } else {
                _editRecordService.setSiteMessage(request, EditRecordConstants.MESSAGE_RECORD_ALREADY_COMPLETED,
                        SiteMessage.TYPE_INFO, request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
            }
        } else {
            _editRecordService.setSiteMessage(request, Messages.MANDATORY_FIELDS, SiteMessage.TYPE_STOP,
                    request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
        }
    } else {
        _editRecordService.setSiteMessage(request, Messages.USER_ACCESS_DENIED, SiteMessage.TYPE_STOP,
                request.getParameter(EditRecordConstants.PARAMETER_URL_RETURN));
    }

    return page;
}

From source file:com.hmsinc.epicenter.integrator.service.event.AbstractHL7EventHandler.java

protected Integer extractAge(HL7Message message, PatientDetail detail) throws HL7Exception {

    Integer age = null;//w w w .  j  a  va 2s.c om

    // Set the age using PID-7-2 if necessary
    if (detail.getDateOfBirth() == null) {

        // Check PID-7-2 for Age
        final String ageStr = StringUtils.trimToNull(message.getTerser().get("/PID-7-2"));

        if (ageStr == null) {
            logger.error("No date of birth or age set in message");
        } else if (StringUtils.isNumeric(ageStr)) {
            Integer ageAtInteraction = Integer.valueOf(ageStr);
            if (ageAtInteraction < 200) {
                age = ageAtInteraction;
            } else {
                logger.error("Age out of range: {}", ageAtInteraction);
            }
            logger.debug("Using age from PID-7-2: {}", ageAtInteraction);
        } else {
            logger.error("Non-numeric age specified in message");
        }
    }
    return age;
}