Example usage for org.apache.commons.lang RandomStringUtils randomNumeric

List of usage examples for org.apache.commons.lang RandomStringUtils randomNumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang RandomStringUtils randomNumeric.

Prototype

public static String randomNumeric(int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of numeric characters.

Usage

From source file:com.ozpathway.sw.erms.webapp.action.schedule.ScheduleBean.java

public void addSampleEntries(ActionEvent event) {
    if (model == null)
        return;//from   ww  w  .  j a v a 2  s .  c o m
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(model.getSelectedDate());
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
    calendar.set(Calendar.HOUR_OF_DAY, 14);
    DefaultScheduleEntry entry1 = new DefaultScheduleEntry();
    // every entry in a schedule must have a unique id
    entry1.setId(RandomStringUtils.randomNumeric(32));
    entry1.setStartTime(calendar.getTime());
    calendar.add(Calendar.MINUTE, 45);
    entry1.setEndTime(calendar.getTime());
    entry1.setTitle("Test MyFaces schedule component");
    entry1.setSubtitle("my office");
    entry1.setDescription("We need to get this thing out of the sandbox ASAP");
    model.addEntry(entry1);
    DefaultScheduleEntry entry2 = new DefaultScheduleEntry();
    entry2.setId(RandomStringUtils.randomNumeric(32));
    // entry2 overlaps entry1
    calendar.add(Calendar.MINUTE, -20);
    entry2.setStartTime(calendar.getTime());
    calendar.add(Calendar.HOUR, 2);
    entry2.setEndTime(calendar.getTime());
    entry2.setTitle("Show schedule component to boss");
    entry2.setSubtitle("my office");
    entry2.setDescription("Convince him to get time to thoroughly test it");
    model.addEntry(entry2);
    DefaultScheduleEntry entry3 = new DefaultScheduleEntry();
    entry3.setId(RandomStringUtils.randomNumeric(32));
    calendar.add(Calendar.DATE, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 9);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    entry3.setStartTime(calendar.getTime());
    calendar.set(Calendar.HOUR_OF_DAY, 17);
    entry3.setEndTime(calendar.getTime());
    entry3.setTitle("Thoroughly test schedule component");
    model.addEntry(entry3);
    DefaultScheduleEntry entry4 = new DefaultScheduleEntry();
    entry4.setId(RandomStringUtils.randomNumeric(32));
    calendar.add(Calendar.MONTH, -1);
    calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
    calendar.set(Calendar.HOUR_OF_DAY, 11);
    entry4.setStartTime(calendar.getTime());
    calendar.set(Calendar.HOUR_OF_DAY, 14);
    entry4.setEndTime(calendar.getTime());
    entry4.setTitle("Long lunch");
    model.addEntry(entry4);
    DefaultScheduleEntry entry5 = new DefaultScheduleEntry();
    entry5.setId(RandomStringUtils.randomNumeric(32));
    calendar.add(Calendar.MONTH, 2);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 1);
    entry5.setStartTime(calendar.getTime());
    calendar.set(Calendar.HOUR_OF_DAY, 5);
    entry5.setEndTime(calendar.getTime());
    entry5.setTitle("Fishing trip");
    model.addEntry(entry5);
    // Let's add a zero length entry...
    DefaultScheduleEntry entry6 = new DefaultScheduleEntry();
    calendar.setTime(model.getSelectedDate());
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
    calendar.set(Calendar.HOUR_OF_DAY, 16);
    entry6.setId(RandomStringUtils.randomNumeric(32));
    entry6.setStartTime(calendar.getTime());
    entry6.setEndTime(calendar.getTime());
    entry6.setTitle("Zero length entry");
    entry6.setDescription("Is only rendered when the 'renderZeroLengthEntries' attribute is 'true'");
    model.addEntry(entry6);
    // And also an allday event
    DefaultScheduleEntry entry7 = new DefaultScheduleEntry();
    entry7.setId(RandomStringUtils.randomNumeric(32));
    entry7.setTitle("All day event");
    entry7.setSubtitle("This event renders as an all-day event");
    entry7.setAllDay(true);
    model.addEntry(entry7);
    model.refresh();
}

From source file:net.nelz.simplesm.aop.ReadThroughMultiCacheTest.java

@Test
public void testInitialKey2Result() {
    final AnnotationData annotation = new AnnotationData();
    annotation.setNamespace(RandomStringUtils.randomAlphanumeric(6));
    final Map<String, Object> expectedString2Object = new HashMap<String, Object>();
    final Map<String, Object> key2Result = new HashMap<String, Object>();
    final Set<Object> missObjects = new HashSet<Object>();
    final int length = 15;
    for (int ix = 0; ix < length; ix++) {

        final String object = RandomStringUtils.randomAlphanumeric(2 + ix);
        final String key = cut.buildCacheKey(object, annotation);
        expectedString2Object.put(key, object);

        // There are 3 possible outcomes when fetching by key from memcached:
        // 0) You hit, and the key & result are in the map
        // 1) You hit, but the result is null, which counts as a miss.
        // 2) You miss, and the key doesn't even get into the result map.
        final int option = RandomUtils.nextInt(3);
        if (option == 0) {
            key2Result.put(key, key + RandomStringUtils.randomNumeric(5));
        }//w  w  w  . ja  v  a 2  s  . c om
        if (option == 1) {
            key2Result.put(key, null);
            missObjects.add(object);
        }
        if (option == 2) {
            missObjects.add(object);
        }
    }

    try {
        coord.setInitialKey2Result(null);
        fail("Expected Exception.");
    } catch (RuntimeException ex) {
    }

    coord.getKey2Obj().putAll(expectedString2Object);

    coord.setInitialKey2Result(key2Result);

    assertTrue(coord.getMissObjects().containsAll(missObjects));
    assertTrue(missObjects.containsAll(coord.getMissObjects()));

}

From source file:com.greenline.guahao.biz.manager.partners.unicom.impl.UnicomManagerImpl.java

@Override
public String orderMessage(String productid, String backurl) {
    try {// ww w.ja v  a  2s .c o m
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("spid", spID));
        params.add(new BasicNameValuePair("productid", productid));
        String gettime = String.valueOf((new Date().getTime()) / 1000);
        params.add(new BasicNameValuePair("gettime", gettime));
        String rand = RandomStringUtils.randomNumeric(5);
        params.add(new BasicNameValuePair("rand", rand));
        String key = MD5Util.getMD5Format(spID + productid + gettime + spPassWord + rand);
        params.add(new BasicNameValuePair("key", key));
        params.add(new BasicNameValuePair("backurl", backurl));

        log.info("______________orderMessageurl:" + orderurl + "?spid=" + spID + "&productid=" + productid
                + "&gettime=" + gettime + "&rand=" + rand + "&key=" + key + "&backurl=" + backurl
                + "______________");

        HttpClient client = httpClientManager.getHttpClient();
        LocalResponseDO<Object> lrd = new LocalResponseDO<Object>();
        // ??
        String res = HttpClientUtil.httpSendByPost(lrd, orderurl, params, "??", client, "GBK");

        log.info("______________??:" + res + "______________");

        if (StringUtils.isBlank(res)) {
            return null;
        }

        @SuppressWarnings("unchecked")
        Map<String, String> map = jackjson.read(res, Map.class);
        // ? 1-? 0- 2-
        return map.get("pay");
    } catch (Exception e) {
        log.error("??" + "", e);
        return null;
    }
}

From source file:edu.sampleu.admin.CampusActionListAftBase.java

private void reattemptPrimaryKey() throws InterruptedException {
    int attempts = 0;
    while (isTextPresent("a record with the same primary key already exists.") && ++attempts <= 10) {
        jGrowl("record with the same primary key already exists trying another, attempt: " + attempts);
        clearTextByName("document.newMaintainableObject.code"); // primary key
        String randomNumbeForCode = RandomStringUtils.randomNumeric(1);
        String randomAlphabeticForCode = RandomStringUtils.randomAlphabetic(1);
        jiraAwareTypeByName("document.newMaintainableObject.code",
                randomNumbeForCode + randomAlphabeticForCode);
        waitAndClickByName("methodToCall.route");
        waitForProgress("Submitting...");
    }//from   w  w  w  .  j  a v  a 2s . co  m
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.api.tags.MMXDeviceTagsResourceTest.java

private static DeviceEntity createRandomDeviceEntity(AppEntity appEntity, int index) {
    DeviceEntity deviceEntity = new DeviceEntity();
    deviceEntity.setAppId(appEntity.getAppId());
    deviceEntity.setName(RandomStringUtils.randomAlphabetic(5) + " " + RandomStringUtils.randomAlphabetic(5));
    deviceEntity.setOsType(OSType.ANDROID);
    deviceEntity.setCreated(new Date());
    deviceEntity.setOwnerId(appEntity.getOwnerId());
    deviceEntity.setStatus(DeviceStatus.ACTIVE);
    deviceEntity.setDeviceId("mmxdevicetagsresourcetestdevice" + "_" + index);
    deviceEntity.setPhoneNumber("+213" + RandomStringUtils.randomNumeric(7));
    deviceEntity.setPhoneNumberRev(StringUtils.reverse(deviceEntity.getPhoneNumber()));
    DBTestUtil.getDeviceDAO().persist(deviceEntity);
    return deviceEntity;
}

From source file:com.google.code.ssm.aop.ReadThroughMultiCacheTest.java

@Test
public void testInitialKey2Result() {
    final AnnotationData annotation = new AnnotationData();
    annotation.setNamespace(RandomStringUtils.randomAlphanumeric(6));
    final Map<String, Object> expectedString2Object = new HashMap<String, Object>();
    final Map<String, Object> key2Result = new HashMap<String, Object>();
    final Set<Object> missObjects = new HashSet<Object>();
    final int length = 15;
    for (int ix = 0; ix < length; ix++) {

        final String object = RandomStringUtils.randomAlphanumeric(2 + ix);
        final String key = cut.getCacheBase().getCacheKeyBuilder().getCacheKey(object,
                annotation.getNamespace());
        expectedString2Object.put(key, object);

        // There are 3 possible outcomes when fetching by key from memcached:
        // 0) You hit, and the key & result are in the map
        // 1) You hit, but the result is null, which counts as a miss.
        // 2) You miss, and the key doesn't even get into the result map.
        final int option = RandomUtils.nextInt(3);
        if (option == 0) {
            key2Result.put(key, key + RandomStringUtils.randomNumeric(5));
        }/*ww  w  . j  av  a2  s . c o  m*/
        if (option == 1) {
            key2Result.put(key, null);
            missObjects.add(object);
        }
        if (option == 2) {
            missObjects.add(object);
        }
    }

    try {
        coord.setInitialKey2Result(null);
        fail("Expected Exception.");
    } catch (RuntimeException ex) {
    }

    coord.getKey2Obj().putAll(expectedString2Object);
    coord.setInitialKey2Result(key2Result);

    assertTrue(coord.getMissedObjects().containsAll(missObjects));
    assertTrue(missObjects.containsAll(coord.getMissedObjects()));

}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRforeignFileConversionServiceImpl.java

public DvnRforeignFileConversionServiceImpl() {
    dbgLog.fine("***** DvnRforeignFileConversionServiceImpl: within the constructor starts here *****");
    // initialization
    PID = RandomStringUtils.randomNumeric(6);

    requestdir = "Zlg_" + PID;

    wrkdir = DSB_TMP_DIR + "/" + requestdir;

    tempFileName = DSB_TMP_DIR + "/" + TMP_DATA_FILE_NAME + "." + PID + TMP_DATA_FILE_EXT;

    tempFileNameNew = wrkdir + "/" + TMP_DATA_FILE_NAME + "." + PID + TMP_DATA_FILE_EXT;

    dbgLog.fine("requestdir=" + requestdir);
    dbgLog.fine("wrkdir=" + wrkdir);
    dbgLog.fine("tempFileName=" + tempFileName);
    dbgLog.fine("tempFileNameNew=" + tempFileNameNew);

}

From source file:fr.univlorraine.ecandidat.controllers.DemoController.java

/**
 * @return une liste de peopleLdap anonyme pour la recherche Ldap
 *///from   w ww.j  a  va  2s.c  o  m
public List<PeopleLdap> findListIndividuLdapDemo() {
    List<PeopleLdap> liste = new ArrayList<PeopleLdap>();
    for (int i = 0; i < 6; i++) {
        String login = RandomStringUtils.randomAlphabetic(8).toLowerCase() + RandomStringUtils.randomNumeric(1);
        PeopleLdap people = new PeopleLdap(login, "displayName-" + login, "sn-" + login, "cn-" + login,
                "mail-" + login, null, "M.", "givenName-" + login);
        liste.add(people);
    }
    return liste;
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRGraphServiceImpl.java

public DvnRGraphServiceImpl() {

    // initialization
    IdSuffix = RandomStringUtils.randomNumeric(6);

    requestdir = "Grph_" + IdSuffix;

    wrkdir = DSB_TMP_DIR + "/" + requestdir;

    RDataFileName = DSB_TMP_DIR + "/" + RDATA_FILE_NAME + "." + IdSuffix + RDATA_FILE_EXT;

    GraphMLfileNameRemote = DSB_TMP_DIR + "/" + GRAPHML_FILE_NAME + "." + IdSuffix + GRAPHML_FILE_EXT;

    if (RConnectionPool == null) {
        dbgLog.info("number of RServe connections: " + RSERVE_CONNECTION_POOLSIZE);
        RConnectionPool = new DvnRConnectionPool(RSERVE_CONNECTION_POOLSIZE);
    }/*from w w  w .j  av a2s. c  om*/

}

From source file:io.kamax.mxisd.session.SessionMananger.java

public String create(String server, ThreePid tpid, String secret, int attempt, String nextLink) {
    PolicyTemplate policy = cfg.getPolicy().getValidation();
    if (!policy.isEnabled()) {
        throw new NotAllowedException("Validating 3PID is disabled globally");
    }/*  www  .j  a v a 2  s.  c  om*/

    synchronized (this) {
        log.info("Server {} is asking to create session for {} (Attempt #{}) - Next link: {}", server, tpid,
                attempt, nextLink);
        Optional<IThreePidSessionDao> dao = storage.findThreePidSession(tpid, secret);
        if (dao.isPresent()) {
            ThreePidSession session = new ThreePidSession(dao.get());
            log.info("We already have a session for {}: {}", tpid, session.getId());
            if (session.getAttempt() < attempt) {
                log.info(
                        "Received attempt {} is greater than stored attempt {}, sending validation communication",
                        attempt, session.getAttempt());
                notifMgr.sendForValidation(session);
                log.info("Sent validation notification to {}", tpid);
                session.increaseAttempt();
                storage.updateThreePidSession(session.getDao());
            }

            return session.getId();
        } else {
            log.info("No existing session for {}", tpid);

            boolean isLocal = isLocal(tpid);
            log.info("Is 3PID bound to local domain? {}", isLocal);

            // This might need a configuration by medium type?
            PolicySource policySource = policy.forIf(isLocal);
            if (!policySource.isEnabled() || (!policySource.toLocal() && !policySource.toRemote())) {
                log.info("Session for {}: cancelled due to policy", tpid);
                throw new NotAllowedException(
                        "Validating " + (isLocal ? "local" : "remote") + " 3PID is not allowed");
            }

            String sessionId;
            do {
                sessionId = Long.toString(System.currentTimeMillis());
            } while (storage.getThreePidSession(sessionId).isPresent());

            String token = RandomStringUtils.randomNumeric(6);
            ThreePidSession session = new ThreePidSession(sessionId, server, tpid, secret, attempt, nextLink,
                    token);
            log.info("Generated new session {} to validate {} from server {}", sessionId, tpid, server);

            // This might need a configuration by medium type?
            if (policySource.toLocal()) {
                log.info("Session {} for {}: sending local validation notification", sessionId, tpid);
                notifMgr.sendForValidation(session);
            } else {
                log.info("Session {} for {}: sending remote-only validation notification", sessionId, tpid);
                notifMgr.sendforRemoteValidation(session);
            }

            storage.insertThreePidSession(session.getDao());
            log.info("Stored session {}", sessionId, tpid, server);

            return sessionId;
        }
    }
}