Example usage for org.apache.commons.lang Validate notEmpty

List of usage examples for org.apache.commons.lang Validate notEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang Validate notEmpty.

Prototype

public static void notEmpty(String string, String message) 

Source Link

Document

Validate an argument, throwing IllegalArgumentException if the argument String is empty (null or zero length).

 Validate.notEmpty(myString, "The string must not be empty"); 

Usage

From source file:ch.algotrader.dao.PositionDaoImpl.java

@Override
public List<Position> findOpenPositionsByStrategyAndSecurityFamily(String strategyName, long securityFamilyId) {

    Validate.notEmpty(strategyName, "Strategy name is empty");

    return findCaching("Position.findOpenPositionsByStrategyAndSecurityFamily", QueryType.BY_NAME,
            new NamedParam("strategyName", strategyName), new NamedParam("securityFamilyId", securityFamilyId));
}

From source file:fr.Axeldu18.PterodactylAPI.Users.java

/**
 * @param email Mail of the new user./*from   www. java2s. c o  m*/
 * @param username Username of the new user.
 * @param first_name First name of the new user.
 * @param last_name Last name of the new user.
 * @param password Password of the new user OPTIONAL. (Leave blank will be generated by the panel randomly)
 * @param root_admin Set the root admin role of the new user.
 * @return if success it return the USER class with ATTRIBUTES of the new user.
 */
public User createUser(String email, String username, String first_name, String last_name, String password,
        boolean root_admin) {
    Validate.notEmpty(email, "The MAIL is required");
    Validate.notEmpty(username, "The USERNAME is required");
    Validate.notEmpty(first_name, "The FIRST_NAME is required");
    Validate.notEmpty(last_name, "The LAST_NAME is required");
    Validate.notNull(root_admin, "The ROOT_ADMIN Boolean is required");
    int admin = (root_admin) ? 1 : 0;
    JSONObject jsonUserPost = new JSONObject();
    jsonUserPost.put("email", email);
    jsonUserPost.put("username", email);
    jsonUserPost.put("name_first", email);
    jsonUserPost.put("name_last", email);
    jsonUserPost.put("password", email);
    jsonUserPost.put("root_admin", email);
    JSONObject jsonObject = new JSONObject(main.getPostMethods()
            .call(main.getMainURL() + POSTMethods.Methods.USERS_CREATE_USER.getURL(), jsonUserPost.toString()));
    if (!jsonObject.has("data")) {
        main.log(Level.SEVERE, jsonObject.toString());
        return new User();
    }
    JSONObject userJSON = jsonObject.getJSONObject("data");
    User user = getUser(userJSON.getInt("id"));
    return user;
}

From source file:ch.algotrader.service.LookupServiceImpl.java

/**
 * {@inheritDoc}// w w  w  .j  ava 2  s.c om
 */
@Override
public Security getSecurityByBbgid(final String bbgid) {

    Validate.notEmpty(bbgid, "bbgid is empty");

    return this.cacheManager.findUnique(Security.class, "Security.findByBbgid", QueryType.BY_NAME,
            new NamedParam("bbgid", bbgid));

}

From source file:com.firstdata.globalgatewaye4.CheckRequest.java

/**
 * @param transaction_tag {@link #String} value of the transaction tag.
 * <p>Required for the following {@link #TransactionType}s:</p>
 * <ul>//w  w w .  j a  v a  2s.  c  o m
 * <li>{@link TransactionType#TaggedRefund}</li>
 * <li>{@link TransactionType#TaggedVoid}</li>
 * <li>{@link TransactionType#TaggedPreAuthorizationCompletion}</li>
 * </ul>
 * @return {@link #CheckRequest}
 */
public CheckRequest transaction_tag(String transaction_tag) {
    Validate.notEmpty(transaction_tag, "transaction_tag cannot be empty.");
    this.transaction_tag = transaction_tag;
    return this;
}

From source file:ch.algotrader.service.ib.IBFixAllocationServiceImpl.java

/**
 * {@inheritDoc}//from w  w  w  .ja v  a 2  s.c  om
 */
@Override
@ManagedOperation(description = "Removes an Account Group from the specified Account.")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "account", description = "account"),
        @ManagedOperationParameter(name = "group", description = "group") })
public void removeGroup(final String account, final String group) {

    Validate.notEmpty(account, "Account is empty");
    Validate.notEmpty(group, "Group is empty");

    try {
        requestGroups(account);
    } catch (InterruptedException ex) {
        Thread.currentThread().interrupt();
        throw new ServiceException(ex);
    } catch (SessionNotFound ex) {
        throw new ExternalServiceException(ex);
    }

    this.groups.remove(group);

    try {
        postGroups(account);
    } catch (SessionNotFound ex) {
        throw new ExternalServiceException(ex);
    }

}

From source file:edu.snu.leader.hidden.ResultsReporter.java

/**
 * Initialize this reporter/*  w  ww .j a v a 2 s .c  o m*/
 *
 * @param simState
 */
public void initialize(SimulationState simState) {
    _LOG.trace("Entering initialize( simState )");

    // Save the simulation state
    _simState = simState;

    // Grab the properties
    Properties props = simState.getProps();

    // Build some variables
    int individualCount = _simState.getIndividualCount();
    _movementCounts = new int[individualCount + 1];
    _finalInitiatorCounts = new int[individualCount + 1];
    _finalSuccessfulInitiatorCounts = new int[individualCount + 1];
    _finalFailedInitiatorCounts = new int[individualCount + 1];
    _maxInitiatorCounts = new int[individualCount + 1];
    _maxSuccessfulInitiatorCounts = new int[individualCount + 1];
    _maxFailedInitiatorCounts = new int[individualCount + 1];

    // Load the results filename
    String resultsFile = props.getProperty(_RESULTS_FILE_KEY);
    Validate.notEmpty(resultsFile, "Results file may not be empty");

    // Create the statistics writer
    try {
        _writer = new PrintWriter(new BufferedWriter(new FileWriter(resultsFile)));
    } catch (IOException ioe) {
        _LOG.error("Unable to open results file [" + resultsFile + "]", ioe);
        throw new RuntimeException("Unable to open results file [" + resultsFile + "]", ioe);
    }

    // Log the system properties to the stats file for future reference
    _writer.println("# Started: " + (new Date()));
    _writer.println(_SPACER);
    _writer.println("# Simulation properties");
    _writer.println(_SPACER);
    List<String> keyList = new ArrayList<String>(props.stringPropertyNames());
    Collections.sort(keyList);
    Iterator<String> iter = keyList.iterator();
    while (iter.hasNext()) {
        String key = iter.next();
        String value = props.getProperty(key);

        _writer.println("# " + key + " = " + value);
    }
    _writer.println(_SPACER);
    _writer.println();
    _writer.flush();

    // Do we log simulations?
    String useSimLogFileStr = props.getProperty(_USE_SIM_LOG_FILE_FLAG_KEY);
    if (null != useSimLogFileStr) {
        _useSimLogFile = Boolean.parseBoolean(useSimLogFileStr);
        _LOG.info("Using _useSimLogFile=[" + _useSimLogFile + "]");
    }

    if (_useSimLogFile) {
        // Build the compressed simulation log file
        int lastDotIdx = resultsFile.lastIndexOf('.');
        String simLogFile = resultsFile.substring(0, lastDotIdx) + ".log.gz";
        _LOG.warn("Sending simulation log to [" + simLogFile + "]");

        // Build the log writer
        try {
            _logWriter = new PrintWriter(new BufferedWriter(
                    new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(simLogFile)))));
        } catch (IOException ioe) {
            _LOG.error("Unable to open simulation log file [" + simLogFile + "]", ioe);
            throw new RuntimeException("Unable to open simulation log file [" + simLogFile + "]", ioe);
        }
    }

    // Do we log locations?
    String useLocationLogFileStr = props.getProperty(_USE_LOCATION_LOG_FILE_FLAG_KEY);
    if (null != useLocationLogFileStr) {
        _useLocationLogFile = Boolean.parseBoolean(useLocationLogFileStr);
        _LOG.info("Using _useLocationLogFile=[" + _useLocationLogFile + "]");
    }

    if (_useLocationLogFile) {
        // Build the compressed location log file
        int lastDotIdx = resultsFile.lastIndexOf('.');
        String simLocationFile = resultsFile.substring(0, lastDotIdx) + ".locations";
        //                    + ".locations.gz";
        _LOG.warn("Sending location log to [" + simLocationFile + "]");

        // Build the location log writer
        try {
            _locationWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                    //                                new GZIPOutputStream(
                    new FileOutputStream(simLocationFile))));
            // );
        } catch (IOException ioe) {
            _LOG.error("Unable to open location log file [" + simLocationFile + "]", ioe);
            throw new RuntimeException("Unable to open location log file [" + simLocationFile + "]", ioe);
        }
    }

    _LOG.trace("Leaving initialize( simState )");
}

From source file:com.evolveum.midpoint.web.component.data.TablePanel.java

public void setStyle(String value) {
    Validate.notEmpty(value, "Value must not be null or empty.");

    DataTable table = getDataTable();//from   w  ww  .  j  a  va  2 s.c om
    table.add(new AttributeModifier("style", new Model(value)));
}

From source file:ch.algotrader.service.LookupServiceImpl.java

/**
 * {@inheritDoc}//from   w w  w  .  j  a v a 2s  .  c  om
 */
@Override
public Security getSecurityByRic(final String ric) {

    Validate.notEmpty(ric, "ric is empty");

    return this.cacheManager.findUnique(Security.class, "Security.findByRic", QueryType.BY_NAME,
            new NamedParam("ric", ric));

}

From source file:com.evolveum.midpoint.repo.sql.SqlRepositoryServiceImpl.java

@Override
public <T extends ObjectType> PrismObject<T> getObject(Class<T> type, String oid,
        Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result)
        throws ObjectNotFoundException, SchemaException {
    Validate.notNull(type, "Object type must not be null.");
    Validate.notEmpty(oid, "Oid must not be null or empty.");
    Validate.notNull(result, "Operation result must not be null.");

    LOGGER.debug("Getting object '{}' with oid '{}'.", new Object[] { type.getSimpleName(), oid });

    final String operation = "getting";
    int attempt = 1;

    OperationResult subResult = result.createMinorSubresult(GET_OBJECT);
    subResult.addParam("type", type.getName());
    subResult.addParam("oid", oid);

    SqlPerformanceMonitor pm = getPerformanceMonitor();
    long opHandle = pm.registerOperationStart("getObject");

    try {// ww w.j av a2  s . c  o  m
        while (true) {
            try {
                return objectRetriever.getObjectAttempt(type, oid, options, subResult);
            } catch (RuntimeException ex) {
                attempt = logOperationAttempt(oid, operation, attempt, ex, subResult);
                pm.registerOperationNewTrial(opHandle, attempt);
            }
        }
    } finally {
        pm.registerOperationFinish(opHandle, attempt);
    }
}

From source file:com.mxhero.plugin.cloudstorage.onedrive.api.OneDrive.java

/**
 * Redeem daemon./*w  w  w.  j  ava  2 s  . c om*/
 *
 * @param redeemDaemonRequest the redeem daemon request
 * @return the Access Token redeemed it
 * @throws AuthenticationException the authentication exception
 */
public static String redeemDaemon(RedeemDaemonRequest redeemDaemonRequest) throws AuthenticationException {
    ExecutorService service = Executors.newCachedThreadPool();
    AuthenticationResult authenticationResult = null;
    String authority = String.format(ApiEnviroment.tokenDaemonBaseUrl.getValue(),
            redeemDaemonRequest.getTenantId());
    logger.debug("Trying to get App Only token for {}", redeemDaemonRequest);
    try {
        AuthenticationContext authenticationContext = new AuthenticationContext(authority, false, service);
        String filePkcs12 = ApiEnviroment.fileUrlPkcs12Certificate.getValue();
        if (StringUtils.isNotEmpty(redeemDaemonRequest.getFileUrlPkcs12Certificate())) {
            filePkcs12 = redeemDaemonRequest.getFileUrlPkcs12Certificate();
        }

        String filePkcs12Secret = ApiEnviroment.pkcs12CertificateSecret.getValue();
        if (StringUtils.isNotEmpty(redeemDaemonRequest.getCertificateSecret())) {
            filePkcs12Secret = redeemDaemonRequest.getCertificateSecret();
        }

        Validate.notEmpty(filePkcs12,
                "Pkcs12 Key file path must be provided or configured. You can set it on environment var 'ONEDRIVE_DAEMON_PKCS12_FILE_URL' or through Java System Property 'onedrive.daemon.pkcs12.file.url'");
        Validate.notEmpty(filePkcs12Secret,
                "Pkcs12 Secret Key file must be provided or configured. You can set it on environment var 'ONEDRIVE_DAEMON_PKCS12_FILE_SECRET' or through Java System Property 'onedrive.daemon.pkcs12.file.secret'");

        InputStream pkcs12Certificate = new FileInputStream(filePkcs12);
        AsymmetricKeyCredential credential = AsymmetricKeyCredential.create(redeemDaemonRequest.getClientId(),
                pkcs12Certificate, filePkcs12Secret);

        Future<AuthenticationResult> future = authenticationContext
                .acquireToken(redeemDaemonRequest.getResourceSharepointId(), credential, null);
        authenticationResult = future.get(10, TimeUnit.SECONDS);
        logger.debug("Token retrieved {}",
                ToStringBuilder.reflectionToString(authenticationResult, ToStringStyle.SHORT_PREFIX_STYLE));
        return authenticationResult.getAccessToken();
    } catch (Exception e) {
        logger.error("Error trying to get new App Only Token", e);
        throw new AuthenticationException(
                String.format("Error trying to get new App Only Token for tenantId %s and sharepointUri %s",
                        redeemDaemonRequest.getTenantId(), redeemDaemonRequest.getResourceSharepointId()));
    } finally {
        service.shutdown();
    }

}