Example usage for org.springframework.util Assert isTrue

List of usage examples for org.springframework.util Assert isTrue

Introduction

In this page you can find the example usage for org.springframework.util Assert isTrue.

Prototype

public static void isTrue(boolean expression, Supplier<String> messageSupplier) 

Source Link

Document

Assert a boolean expression, throwing an IllegalArgumentException if the expression evaluates to false .

Usage

From source file:com.skymobi.monitor.action.AdminAction.java

@RequestMapping(value = "/admin/views/save")
public @ResponseBody WebResult createView(HttpEntity<View> entity, ModelMap map) {
    WebResult result = new WebResult();
    try {//from  w w w  .j a v  a2 s .  c o  m
        View view = entity.getBody();
        Assert.isTrue(view.getName().length() > 0, "name should not be null");
        logger.debug("save view ={}", view);
        viewService.saveView(view);
    } catch (Exception e) {
        result.setSuccess(false);
        result.setMessage(e.getMessage());
    }

    return result;
}

From source file:com.athena.peacock.engine.action.ConfigurationAction.java

@Override
public void perform() {
    Assert.notNull(fileName, "filename cannot be null.");
    Assert.notNull(properties, "properties cannot be null.");

    File file = new File(fileName);

    Assert.isTrue(file.exists(), fileName + " does not exist.");
    Assert.isTrue(file.isFile(), fileName + " is not a file.");

    logger.debug("[{}] file's configuration will be changed.", fileName);

    try {//w ww.  j a  va  2s . co m
        String fileContents = IOUtils.toString(file.toURI());

        for (Property property : properties) {
            logger.debug("\"${{}}\" will be changed to \"{}\".", property.getKey(),
                    property.getValue().replaceAll("\\\\", ""));
            fileContents = fileContents.replaceAll("\\$\\{" + property.getKey() + "\\}", property.getValue());
        }

        FileOutputStream fos = new FileOutputStream(file);
        IOUtils.write(fileContents, fos);
        IOUtils.closeQuietly(fos);
    } catch (IOException e) {
        logger.error("IOException has occurred.", e);
    }
}

From source file:com.aeg.ims.ftp.SftpOutboundTransferSample.java

@Test
public void testOutbound() throws Exception {

    final String sourceFileName = "README.md";
    final String destinationFileName = sourceFileName + "_foo";

    final ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
            "/META-INF/spring/integration/SftpOutboundTransferSample-context.xml",
            SftpOutboundTransferSample.class);
    @SuppressWarnings("unchecked")
    SessionFactory<LsEntry> sessionFactory = ac.getBean(CachingSessionFactory.class);
    RemoteFileTemplate<LsEntry> template = new RemoteFileTemplate<LsEntry>(sessionFactory);
    //SftpTestUtils.createTestFiles(template); // Just the directory

    try {/*from www. ja  v  a2s . c  om*/
        final File file = new File(sourceFileName);

        Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName));

        final Message<File> message = MessageBuilder.withPayload(file).build();
        final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);

        inputChannel.send(message);
        Thread.sleep(2000);

        Assert.isTrue(SftpTestUtils.fileExists(template, destinationFileName));

        System.out.println(String.format(
                "Successfully transferred '%s' file to a " + "remote location under the name '%s'",
                sourceFileName, destinationFileName));
    } finally {
        //SftpTestUtils.cleanUp(template, destinationFileName);
        ac.close();
    }
}

From source file:com.berwickheights.spring.svc.SendEmailSvcImpl.java

/**
 * Check that properties have been set correctly in bean definition
 *//*from w  ww .  j  av  a2 s.c  o  m*/
public void afterPropertiesSet() throws Exception {
    Assert.notNull(emailSender, "emailSender must be set");
    Assert.notNull(from, "from must be set");
    Assert.isTrue(numWorkerThreads > 0, "numWorkerThreads must be greater than 0");

    // Set up thread pool to send email messages asynchronously
    threadPool = Executors.newFixedThreadPool(numWorkerThreads);
}

From source file:org.twinkql.context.JenaHttpQueryExecutionProvider.java

public void afterPropertiesSet() throws Exception {
    Assert.isTrue(this.sparqlEndpointUrl != null, "A SPARQL Endpoint URL is required.");
}

From source file:com.nortal.petit.orm.statement.InsertStatement.java

public InsertStatement(JdbcOperations jdbcTemplate, StatementBuilder statementBuilder, Class<B> beanClass) {
    Assert.isTrue(beanClass != null, "InsertStatement.construct: beanClass is mandatory");
    init(jdbcTemplate, statementBuilder, beanClass);
}

From source file:com.cxplonka.feature.service.controller.CustomerController.java

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void delete(@PathVariable long id) {
    Assert.isTrue(id > 0, "No valid primary key.");

    repository.delete(id);/*ww  w.  j  a v a 2s .co m*/
}

From source file:com.vladmihalcea.concurrent.aop.OptimisticConcurrencyControlAspect.java

private Object proceed(ProceedingJoinPoint pjp, Retry retryAnnotation) throws Throwable {
    int times = retryAnnotation.times();
    Class<? extends Throwable>[] retryOn = retryAnnotation.on();
    Assert.isTrue(times > 0, "@Retry{times} should be greater than 0!");
    Assert.isTrue(retryOn.length > 0, "@Retry{on} should have at least one Throwable!");
    if (retryAnnotation.failInTransaction() && TransactionSynchronizationManager.isActualTransactionActive()) {
        throw new IllegalTransactionStateException(
                "You shouldn't retry an operation from withing an existing Transaction."
                        + "This is because we can't retry if the current Transaction was already rollbacked!");
    }//from  w ww.ja va2  s.c  om
    LOGGER.info("Proceed with {} retries on {}", times, Arrays.toString(retryOn));
    return tryProceeding(pjp, times, retryOn);
}

From source file:de.extra.client.core.builder.impl.components.TransportBodyCharSequenceBuilder.java

@Override
public Object buildXmlFragment(final IInputDataContainer senderData, final IExtraProfileConfiguration config) {
    logger.debug("CharSequenceType aufbauen");
    final CharSequenceType charSequence = new CharSequenceType();
    final IContentInputDataContainer fileInputdata = senderData.cast(IContentInputDataContainer.class);
    final List<ISingleContentInputData> inputDataList = fileInputdata.getInputData();
    // Es kann nicht in RequestTransport mehrere Datenstze bertragen werden!!
    Assert.isTrue(inputDataList.size() != 1, "Unexpected InputData size.");
    final ISingleContentInputData singleFileInputData = inputDataList.get(0);
    final String inpurDataString = singleFileInputData.getInputDataAsString();

    charSequence.setValue(inpurDataString);

    return charSequence;
}

From source file:net.abhinavsarkar.spelhelper.ExtensionFunctions.java

/**
 * Creates an unmodifiable {@link Map} using the {@link List} of keys
 * provided as the first argument and the {@link List} of values provided
 * as the second argument./*ww  w  .j  av a  2  s .co  m*/
 *
 * Example use: `"#map(#list('one', 'two', 'three'), #list(1, 2, 3))"`
 * @param <K>   Type of the keys of the map.
 * @param <V>   Type of the values of map.
 * @param keys  List of the keys.
 * @param values    List of the values.
 * @return  A unmodifiable map created from the key and value lists.
 * @throws  IllegalArgumentException if the number of keys and the number of
 * values is not equal.
 */
public static <K, V> Map<K, V> map(final List<? extends K> keys, final List<? extends V> values) {
    Assert.isTrue(keys.size() == values.size(), "There should be equal number of keys and values");
    Map<K, V> map = new HashMap<K, V>();
    int length = keys.size();
    for (int i = 0; i < length; i++) {
        map.put(keys.get(i), values.get(i));
    }
    return unmodifiableMap(map);
}