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:ru.anr.base.facade.ejb.mdb.AbstractMessageDrivenHandler.java

/**
 * {@inheritDoc}//from   w w  w  .  j  av a 2 s. c o  m
 */
@Override
public void onMessage(Message message) {

    Assert.isTrue(message instanceof TextMessage, "TextMessage only");
    MessageConverter converter = new MessagingMessageConverter();

    try {

        @SuppressWarnings("unchecked")
        org.springframework.messaging.Message<String> msg = (org.springframework.messaging.Message<String>) converter
                .fromMessage(message);

        logger.debug("Received a JMS message: {}", msg);
        onMessage(msg);

    } catch (JMSException ex) {
        throw new ApplicationException(ex);
    }
}

From source file:biz.c24.io.spring.integration.config.XPathSelectorParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    String evaluationType = element.getAttribute("evaluation-result-type");

    String expression = element.getAttribute("xpath-statement");
    String expressionRef = element.getAttribute("xpath-statement-ref");

    boolean hasRef = StringUtils.hasText(expressionRef);
    Assert.isTrue(hasRef ^ StringUtils.hasText(expression),
            "Exactly one of the 'xpath-statement' or 'xpath-statement-ref' attributes is required.");
    if (hasRef) {
        builder.addConstructorArgReference(expressionRef);
    } else {//from  w ww  .j a  v  a 2 s .  c  om
        builder.addConstructorArgValue(expression);
    }

    String stringTestValue = element.getAttribute("string-test-value");

    if (evaluationType.equals("boolean")) {
        builder.getBeanDefinition()
                .setBeanClass(biz.c24.io.spring.integration.selector.C24BooleanTestXPathMessageSelector.class);
        Assert.state(!StringUtils.hasText(stringTestValue),
                "'string-test-value' should not be specified when 'evaluation-result-type' is boolean");
    } else if (evaluationType.equals("string")) {
        Assert.hasText(stringTestValue,
                "'string-test-value' must be specified when 'evaluation-result-type' is string");
        builder.addPropertyValue("valueToTestFor", stringTestValue);
        builder.getBeanDefinition().setBeanClass(
                biz.c24.io.spring.integration.selector.C24StringValueTestXPathMessageSelector.class);
    } else {
        throw new IllegalArgumentException("Unsupported value [" + evaluationType
                + "] for 'evaluation-result-type', expected boolean or string.");
    }
}

From source file:cn.bjfu.springdao.jpa.domain.order.LineItem.java

/**
 * Creates a new {@link LineItem} for the given {@link Product} and amount.
 * /* w  ww  .j  a  v  a  2 s.  c om*/
 * @param product must not be {@literal null}.
 * @param amount
 */
public LineItem(Product product, int amount) {

    Assert.notNull(product, "The given Product must not be null!");
    Assert.isTrue(amount > 0, "The amount of Products to be bought must be greater than 0!");

    this.product = product;
    this.amount = amount;
    this.price = product.getPrice();
}

From source file:com.azaptree.services.http.impl.ExecutorThreadPoolWithGracefulShutdown.java

public ExecutorThreadPoolWithGracefulShutdown(final ExecutorService executor, final int shutdownTimeoutSecs) {
    super(executor);
    Assert.notNull(executor);/*ww w.  j av  a2s . co m*/
    Assert.isTrue(shutdownTimeoutSecs > 0, "constraint failed: shutdownTimeoutSecs > 0");
    this.executor = executor;
    this.shutdownTimeoutSecs = shutdownTimeoutSecs;
}

From source file:org.sharetask.security.WorkspaceMemberOrOwnerPermission.java

@Override
public boolean isAllowed(final Authentication authentication, final Object targetDomainObject) {
    boolean result;
    Assert.isTrue(isAuthenticated(authentication), "UserAuthentication is not authenticated!");
    Assert.isTrue(targetDomainObject instanceof Long);
    final Long workspaceId = (Long) targetDomainObject;
    final String userName = authentication.getName();
    final Workspace workspace = workspaceRepository.read(workspaceId);
    if (isWorkspaceOwner(workspace, userName)) {
        result = true;//from   w  w  w  .j a  v  a  2s. c o m
    } else if (isWorkspaceMember(workspace, userName)) {
        result = true;
    } else {
        result = false;
    }
    return result;
}

From source file:com.gemstone.gemfire.rest.internal.web.swagger.config.RestApiPathProvider.java

public RestApiPathProvider(final String docsLocation) {
    Assert.isTrue(!StringUtils.isBlank(docsLocation), "The docs location must be specified!");

    DistributionConfig config = InternalDistributedSystem.getAnyInstance().getConfig();
    String scheme = config.getHttpServiceSSLEnabled() ? "https" : "http";

    this.docsLocation = scheme + "://" + getBindAddressForHttpService() + ":" + config.getHttpServicePort();
}

From source file:org.cleverbus.core.throttling.ThrottleProcessorImpl.java

@Override
public void throttle(ThrottleScope throttleScope) {
    if (!configuration.isThrottlingDisabled()) {
        Assert.notNull(throttleScope, "throttleScope must not be null");

        Assert.isTrue(
                !throttleScope.getSourceSystem().equals(ThrottleScope.ANY_SOURCE_SYSTEM)
                        || !throttleScope.getServiceName().equals(ThrottleScope.ANY_SERVICE),
                "throttle scope must define source system or service name (one of them at least)");

        ThrottleProps throttleProps = configuration.getThrottleProps(throttleScope);
        if (throttleProps == null) {
            Log.warn("no throttling for input request: " + throttleScope);
            return;
        }//from  w  w  w .  ja  v  a2  s  .co m

        int reqCount = counter.count(throttleScope, throttleProps.getInterval());

        if (reqCount > throttleProps.getLimit()) {
            String errMsg = "Actual count of requests for source system '" + throttleScope.getSourceSystem()
                    + "' and service '" + throttleScope.getServiceName() + "' exceeded limit (interval="
                    + throttleProps.getInterval() + "sec, limit=" + throttleProps.getLimit() + ", actual count="
                    + reqCount + ")";

            Log.warn(errMsg);

            throw new ThrottlingExceededException(errMsg);
        }
    }
}

From source file:org.geowebcache.grid.GridSetFactory.java

/**
 * Note that you should provide EITHER resolutions or scales. Providing both will cause a
 * precondition violation exception./* w  ww . j a  va2 s.  com*/
 * 
 * @param name
 * @param srs
 * @param extent
 * @param resolutions
 * @param scales
 * @param tileWidth
 * @param tileHeight
 * @param pixelSize
 * @param yCoordinateFirst
 * @return
 */
public static GridSet createGridSet(final String name, final SRS srs, final BoundingBox extent,
        boolean alignTopLeft, double[] resolutions, double[] scaleDenoms, Double metersPerUnit,
        double pixelSize, String[] scaleNames, int tileWidth, int tileHeight, boolean yCoordinateFirst) {

    Assert.notNull(name, "name is null");
    Assert.notNull(srs, "srs is null");
    Assert.notNull(extent, "extent is null");
    Assert.isTrue(!extent.isNull() && extent.isSane(), "Extent is invalid: " + extent);
    Assert.isTrue(resolutions != null || scaleDenoms != null);
    Assert.isTrue(resolutions == null || scaleDenoms == null,
            "Only one of resolutions or scaleDenoms should be provided, not both");

    for (int i = 1; resolutions != null && i < resolutions.length; i++) {
        if (resolutions[i] >= resolutions[i - 1]) {
            throw new IllegalArgumentException("Each resolution should be lower than it's prior one. Res[" + i
                    + "] == " + resolutions[i] + ", Res[" + (i - 1) + "] == " + resolutions[i - 1] + ".");
        }
    }

    for (int i = 1; scaleDenoms != null && i < scaleDenoms.length; i++) {
        if (scaleDenoms[i] >= scaleDenoms[i - 1]) {
            throw new IllegalArgumentException(
                    "Each scale denominator should be lower than it's prior one. Scale[" + i + "] == "
                            + scaleDenoms[i] + ", Scale[" + (i - 1) + "] == " + scaleDenoms[i - 1] + ".");
        }
    }

    GridSet gridSet = baseGridSet(name, srs, tileWidth, tileHeight);

    gridSet.setResolutionsPreserved(resolutions != null);

    gridSet.setPixelSize(pixelSize);

    gridSet.setOriginalExtent(extent);
    gridSet.yBaseToggle = alignTopLeft;

    gridSet.setyCoordinateFirst(yCoordinateFirst);

    if (metersPerUnit == null) {
        if (srs.equals(SRS.getEPSG4326())) {
            gridSet.setMetersPerUnit(EPSG4326_TO_METERS);
        } else if (srs.equals(SRS.getEPSG3857())) {
            gridSet.setMetersPerUnit(EPSG3857_TO_METERS);
        } else {
            if (resolutions == null) {
                log.warn("GridSet " + name + " was defined without metersPerUnit, assuming 1m/unit."
                        + " All scales will be off if this is incorrect.");
            } else {
                log.warn("GridSet " + name + " was defined without metersPerUnit. "
                        + "Assuming 1m per SRS unit for WMTS scale output.");

                gridSet.setScaleWarning(true);
            }
            gridSet.setMetersPerUnit(1.0);
        }
    } else {
        gridSet.setMetersPerUnit(metersPerUnit);
    }

    if (resolutions == null) {
        gridSet.setGridLevels(new Grid[scaleDenoms.length]);
    } else {
        gridSet.setGridLevels(new Grid[resolutions.length]);
    }

    for (int i = 0; i < gridSet.getGridLevels().length; i++) {
        Grid curGrid = new Grid();

        if (scaleDenoms != null) {
            curGrid.setScaleDenominator(scaleDenoms[i]);
            curGrid.setResolution(pixelSize * (scaleDenoms[i] / gridSet.getMetersPerUnit()));
        } else {
            curGrid.setResolution(resolutions[i]);
            curGrid.setScaleDenominator(
                    (resolutions[i] * gridSet.getMetersPerUnit()) / DEFAULT_PIXEL_SIZE_METER);
        }

        final double mapUnitWidth = tileWidth * curGrid.getResolution();
        final double mapUnitHeight = tileHeight * curGrid.getResolution();

        final long tilesWide = (long) Math.ceil((extent.getWidth() - mapUnitWidth * 0.01) / mapUnitWidth);
        final long tilesHigh = (long) Math.ceil((extent.getHeight() - mapUnitHeight * 0.01) / mapUnitHeight);

        curGrid.setNumTilesWide(tilesWide);
        curGrid.setNumTilesHigh(tilesHigh);

        if (scaleNames == null || scaleNames[i] == null) {
            curGrid.setName(gridSet.getName() + ":" + i);
        } else {
            curGrid.setName(scaleNames[i]);
        }

        gridSet.getGridLevels()[i] = curGrid;
    }

    return gridSet;
}

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

@Override
public CacheResult setRow(int row) {
    Assert.isTrue(row > 0, "row is not <= 0");
    this.row = row;
    return this;
}

From source file:org.jasig.cas.web.flow.SelectiveFlowHandlerAdapter.java

@Override
public void afterPropertiesSet() throws Exception {
    super.afterPropertiesSet();
    Assert.isTrue(!supportedFlowIds.isEmpty(), "Must specify at least one supported flow ID");
}