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.cloudbyexample.dc.web.service.docker.ApplicationController.java

@Override
@RequestMapping(value = UPDATE_REQUEST, method = RequestMethod.PUT)
public ApplicationResponse update(@RequestBody Application request) {
    Assert.isTrue(isPrimaryKeyValid(request), "Update should have a valid primary key.");

    logger.info("Update application.  id={}", request.getId());

    return service.update(request);
}

From source file:org.springmodules.validation.bean.conf.loader.annotation.handler.LengthValidationAnnotationHandler.java

protected void validateMax(int max, Class clazz, String propertyName) {
    Assert.isTrue(max >= 0, "@Length annotation on property '" + clazz.getName() + "." + propertyName
            + "' is mal-configured - 'max' attribute cannot hold a negative value");
}

From source file:grails.plugin.searchable.internal.compass.config.mapping.CompassAnnotationSearchableGrailsDomainClassMappingConfigurator.java

/**
 * Configure the Mapping in the CompassConfiguration for the given domain class
 *
 * @param compassConfiguration          the CompassConfiguration instance
 * @param configurationContext          a configuration context, for flexible parameter passing
 * @param searchableGrailsDomainClasses searchable domain classes to map
 * @param allSearchableGrailsDomainClasses all searchable domain classes, whether configured here or elsewhere
 *///from  w ww  . j  ava 2s .c o  m
public void configureMappings(CompassConfiguration compassConfiguration, Map configurationContext,
        Collection searchableGrailsDomainClasses, Collection allSearchableGrailsDomainClasses) {
    Assert.isTrue(annotationsAvailable, "Annotations must be available");
    Assert.notNull(compassConfiguration, "compassConfiguration cannot be null");
    Assert.notNull(configurationContext, "configurationContext cannot be null");

    if (configurationContext.containsKey(CompassXmlConfigurationSearchableCompassConfigurator.CONFIGURED)) {
        return;
    }

    for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext();) {
        GrailsDomainClass gdc = (GrailsDomainClass) iter.next();
        compassConfiguration.addClass(gdc.getClazz());
    }
}

From source file:org.codehaus.groovy.grails.plugins.searchable.compass.config.mapping.CompassAnnotationSearchableGrailsDomainClassMappingConfigurator.java

/**
 * Configure the Mapping in the CompassConfiguration for the given domain class
 *
 * @param compassConfiguration          the CompassConfiguration instance
 * @param configurationContext          a configuration context, for flexible parameter passing
 * @param searchableGrailsDomainClasses searchable domain classes to map
 *//*from   w  ww .  ja  v  a 2s  .  co m*/
public void configureMappings(CompassConfiguration compassConfiguration, Map configurationContext,
        Collection searchableGrailsDomainClasses) {
    Assert.isTrue(annotationsAvailable, "Annotations must be available");
    Assert.notNull(compassConfiguration, "compassConfiguration cannot be null");
    Assert.notNull(configurationContext, "configurationContext cannot be null");

    if (configurationContext.containsKey(CompassXmlConfigurationSearchableCompassConfigurator.CONFIGURED)) {
        return;
    }

    Class compassAnnotationsConfigurationClass = getCompassAnnotationConfigurationClass();
    Assert.isTrue(compassAnnotationsConfigurationClass.isAssignableFrom(compassConfiguration.getClass()),
            "compassConfiguration must be an instance of CompassAnnotationsConfiguration");
    for (Iterator iter = searchableGrailsDomainClasses.iterator(); iter.hasNext();) {
        compassConfiguration.addClass(((GrailsDomainClass) iter.next()).getClazz());
    }
}

From source file:org.surfnet.oaaas.model.AccessToken.java

private void invariant() {
    Assert.notNull(token, "Token may not be null");
    Assert.notNull(client, "Client may not be null");
    Assert.notNull(principal, "AuthenticatedPrincipal may not be null");
    Assert.isTrue(StringUtils.isNotBlank(principal.getName()), "AuthenticatedPrincipal#name may not be null");
}

From source file:example.app.model.Person.java

public void setBirthDateFor(int age) {
    Assert.isTrue(age >= 0, "Age must be greater than equal to 0");
    setBirthDate(LocalDate.now().minusYears(age));
}

From source file:org.broadleafcommerce.payment.service.gateway.AuthorizeNetTransactionServiceImpl.java

@Override
public PaymentResponseDTO refund(PaymentRequestDTO paymentRequestDTO) throws PaymentException {
    Assert.isTrue(paymentRequestDTO.getAdditionalFields().containsKey(AuthNetField.X_TRANS_ID.getFieldName()),
            "Must pass 'x_trans_id' value on the additionalFields of the Payment Request DTO");
    Assert.isTrue(paymentRequestDTO.getTransactionTotal() != null,
            "The Transaction Total must not be null on the Payment Request DTO");
    Boolean cardNumOrLastFourPopulated = paymentRequestDTO.creditCardPopulated()
            && (paymentRequestDTO.getCreditCard().getCreditCardLastFour() != null
                    || paymentRequestDTO.getCreditCard().getCreditCardNum() != null);
    Assert.isTrue(cardNumOrLastFourPopulated
            || (paymentRequestDTO.getAdditionalFields().get(AuthNetField.X_CARD_NUM.getFieldName()) != null),
            "Must pass the Last four card number digits on the credit card of the Payment Request DTO");
    return common(paymentRequestDTO, TransactionType.CREDIT);
}

From source file:net.kamhon.ieagle.datagrid.DefaultDatagridModel.java

public void setSorterDirection(int index, String direction) {
    Assert.isTrue(sorters.size() >= index, "sorters.size() must equals or greater than index");

    if (sorters.size() >= index + 1) {
        Sorter sorter = sorters.get(index);
        sorter.setDirection(direction);/* w  w w .  j a v a 2  s.c  o  m*/
    } else if (sorters.size() == index) {
        Sorter sorter = new DefaultSorter();
        sorter.setDirection(direction);
        sorters.add(index, sorter);
    }
}

From source file:com.autentia.wuija.security.impl.hibernate.HibernateSecurityGroup.java

/**
 * @see SecurityGroup#addUser(SecurityUser)
 *//*from  www .j  a  v a  2s. co m*/
public void addUser(SecurityUser user) {
    Assert.isTrue(!users.contains(user), "Group " + groupname + " already contains user " + user.getUsername());
    final HibernateSecurityUser hibernateUser = (HibernateSecurityUser) user;
    hibernateUser.addGroup(this);
    users.add(user);
}

From source file:org.broadleafcommerce.payment.service.module.PayPalPaymentModule.java

@Override
public PaymentResponseItem reverseAuthorize(PaymentContext paymentContext) throws PaymentException {
    //void authorization from DoVoid
    PayPalPaymentRequest request = buildBasicRequest(paymentContext, PayPalTransactionType.REVERSEAUTHORIZE);
    request.setMethodType(PayPalMethodType.VOID);
    request.setCurrency(paymentContext.getPaymentInfo().getAmount().getCurrency().getCurrencyCode());

    Assert.isTrue(
            paymentContext.getPaymentInfo().getAdditionalFields().get(MessageConstants.TRANSACTIONID) != null,
            "The TRANSACTIONID value must be defined as an additional field in the PaymentInfo instance passed in.");
    request.setTransactionID(// w ww  .j av a2 s . c  o m
            paymentContext.getPaymentInfo().getAdditionalFields().get(MessageConstants.TRANSACTIONID));

    PayPalPaymentResponse response;
    try {
        response = (PayPalPaymentResponse) payPalPaymentService.process(request);
    } catch (org.broadleafcommerce.common.vendor.service.exception.PaymentException e) {
        throw new PaymentException(e);
    }

    PaymentResponseItem responseItem = buildBasicResponse(response);
    setDecisionInformation(response, responseItem);
    responseItem.setAmountPaid(paymentContext.getPaymentInfo().getAmount());

    return responseItem;
}