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:org.springsource.sinspctr.InspctrServer.java

public InspctrServer(ConfigurableWebApplicationContext webApplicationContext, int port) {
    Assert.notNull(webApplicationContext, "context must not be null");
    Assert.isTrue(!webApplicationContext.isActive(), "context must not have been started");
    this.webApplicationContext = webApplicationContext;
    this.port = port;
}

From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHandlerRegistration.java

@Override
protected ResourceHttpRequestHandler getRequestHandler() {
    Field locationsField = ReflectionUtils.findField(ResourceHandlerRegistration.class, "locations");
    ReflectionUtils.makeAccessible(locationsField);
    @SuppressWarnings("unchecked")
    List<Resource> locations = (List<Resource>) ReflectionUtils.getField(locationsField, this);

    Field cachePeriodField = ReflectionUtils.findField(ResourceHandlerRegistration.class, "cachePeriod");
    ReflectionUtils.makeAccessible(cachePeriodField);
    Integer cachePeriod = (Integer) ReflectionUtils.getField(cachePeriodField, this);

    // Initial code is replace by a new Vfs2ResourceHttpRequestHandler()
    Assert.isTrue(!CollectionUtils.isEmpty(locations),
            "At least one location is required for resource handling.");
    ResourceHttpRequestHandler requestHandler = new Vfs2ResourceHttpRequestHandler();
    requestHandler.setLocations(locations);
    if (cachePeriod != null) {
        requestHandler.setCacheSeconds(cachePeriod);
    }//from w  ww. j  ava  2  s  .  c  om
    return requestHandler;
}

From source file:cz.cvut.zuul.samples.provider.FileQuotesDao.java

private Quote parseLine(String line) {
    String[] cols = line.split("\t");
    Assert.isTrue(cols.length == 6, "Line must have 6 columns");

    return new Quote(cols[1], cols[2], cols[4], parseInt(cols[5]));
}

From source file:com.ewcms.common.query.cache.CacheResult.java

@Override
public List<Object> getResultList() {

    int fromIndex = getFromIndex();
    if (fromIndex >= count) {
        return Collections.emptyList();
    }/*from  w  w  w  .ja  va2s  .c  o m*/
    Assert.isTrue(isLoaded(), "load data incomplete");
    int toIndex = getToIndex();
    return resultList.subList(fromIndex, toIndex);
}

From source file:grails.plugin.springsecurity.web.authentication.AjaxAwareAuthenticationEntryPoint.java

/**
 * Dependency injection for the Ajax login form url, e.g. '/login/authAjax'.
 * @param url the url/*from  www.  ja va 2 s .c  o  m*/
 */
public void setAjaxLoginFormUrl(final String url) {
    Assert.isTrue(url == null || url.startsWith("/"), "ajaxLoginFormUrl must begin with '/'");
    ajaxLoginFormUrl = url;
}

From source file:com.springsource.html5expense.config.CloudDataSourceConfig.java

private <T extends AbstractServiceInfo> T requireOneService(String serviceName, Class<T> clazzOfT)
        throws Exception {
    String errMsg = "There must be only one %s service bound to this application. Currently, there are %s %s services.";
    List<T> serviceInfoList = cloudEnvironment.getServiceInfos(clazzOfT);
    Assert.isTrue(serviceInfoList.size() == 1,
            String.format(errMsg, serviceName, serviceInfoList.size(), serviceName));
    return serviceInfoList.iterator().next();
}

From source file:com.fns.grivet.controller.NamedQueryController.java

@PreAuthorize("hasAuthority('write:query')")
@PostMapping("/api/v1/query")
public ResponseEntity<?> createNamedQuery(@RequestBody NamedQuery query) {
    ResponseEntity<?> result = ResponseEntity.unprocessableEntity().build();
    Assert.isTrue(StringUtils.isNotBlank(query.getName()), "Query name must not be null, empty or blank.");
    Assert.notNull(query.getQuery(), "Query string must not be null!");
    Assert.isTrue(isSupportedQuery(query), "Query must start with either CALL or SELECT");
    // check for named parameters; but only if they exist
    if (!query.getParams().isEmpty()) {
        query.getParams().keySet()/*from   w  w  w .  j a  v  a2  s.com*/
                .forEach(k -> Assert.isTrue(query.getQuery().contains(String.format(":%s", k)),
                        String.format("Query must contain named parameter [%s]", k)));
    }
    namedQueryService.create(query);
    log.info("Named Query \n\n{}\n\n successfully registered!", query);
    UriComponentsBuilder ucb = UriComponentsBuilder.newInstance();
    if (query.getParams().isEmpty()) {
        result = ResponseEntity
                .created(ucb.path("/api/v1/query/{name}").buildAndExpand(query.getName()).toUri()).build();
    } else {
        result = ResponseEntity.noContent().build();
    }
    return result;
}

From source file:com.wavemaker.commons.io.store.StoredResource.java

@Override
public Resource rename(String name) throws ResourceExistsException {
    Assert.hasLength(name, "Name must not be empty");
    Assert.isTrue(!name.contains("/"), "Name must not contain path elements");
    ensureExists();/*from w w  w .  ja v  a  2s. c  o  m*/
    Assert.state(getPath().getPath().getParent() != null, "Root folders cannot be renamed");
    return getStore().rename(name);
}

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

@Override
public Object buildXmlFragment(final IInputDataContainer senderData, final IExtraProfileConfiguration config) {
    LOG.debug("Base64CharSequenceType aufbauen");
    final Base64CharSequenceType base64CharSequence = new Base64CharSequenceType();
    final IContentInputDataContainer fileInputdata = senderData.cast(IContentInputDataContainer.class);
    final List<ISingleContentInputData> inputDataList = fileInputdata.getInputData();
    // Es kann nicht in RequestTransport mehrere Datenstze bertragen
    // werden!!//from   w  ww  .  j  a  va  2s.com
    Assert.isTrue(inputDataList.size() == 1, "Unexpected InputData size.");
    final ISingleContentInputData singleInputData = inputDataList.get(0);

    final DataHandler dataHandler = new DataHandler(singleInputData.getInputDataAsDataSource());
    base64CharSequence.setValue(dataHandler);
    return base64CharSequence;
}

From source file:org.jasig.openregistry.core.repository.XmlSystemOfRecordRepository.java

/**
 * Creates a new repository using the supplied directory as the starting point.
 * //from   w ww .j  av  a2s  . com
 * @param resource
 * @throws Exception
 */
public XmlSystemOfRecordRepository(final Resource resource) throws Exception {
    this.file = resource.getFile();
    logger.info("Attempting to load Xml Repository from [" + this.file.getAbsolutePath() + "]");
    Assert.isTrue(this.file.isDirectory(), "Provided resource MUST be a directory.");
    reload();
}