Example usage for org.springframework.util Assert notEmpty

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

Introduction

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

Prototype

public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSupplier) 

Source Link

Document

Assert that a Map contains entries; that is, it must not be null and must contain at least one entry.

Usage

From source file:org.finra.herd.service.impl.BusinessObjectFormatServiceImpl.java

/**
 * Retrieves the DDL to initialize the specified type of the database system (e.g. Hive) by creating a table for the requested business object format.
 *
 * @param request the business object format DDL request
 * @param skipRequestValidation specifies whether to skip the request validation and trimming
 *
 * @return the business object format DDL information
 *///w w w  .  ja  va 2s  . co m
protected BusinessObjectFormatDdl generateBusinessObjectFormatDdlImpl(BusinessObjectFormatDdlRequest request,
        boolean skipRequestValidation) {
    // Perform the validation.
    if (!skipRequestValidation) {
        validateBusinessObjectFormatDdlRequest(request);
    }

    // Get the business object format entity for the specified parameters and make sure it exists.
    // Please note that when format version is not specified, we should get back the latest format version.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper
            .getBusinessObjectFormatEntity(new BusinessObjectFormatKey(request.getNamespace(),
                    request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(),
                    request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()));

    // Get business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = businessObjectFormatHelper
            .getBusinessObjectFormatKey(businessObjectFormatEntity);

    // Validate that format has schema information.
    Assert.notEmpty(businessObjectFormatEntity.getSchemaColumns(), String.format(
            "Business object format with namespace \"%s\", business object definition name \"%s\", format usage \"%s\", format file type \"%s\","
                    + " and format version \"%s\" doesn't have schema information.",
            businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName(),
            businessObjectFormatKey.getBusinessObjectFormatUsage(),
            businessObjectFormatKey.getBusinessObjectFormatFileType(),
            businessObjectFormatKey.getBusinessObjectFormatVersion()));

    // If it was specified, retrieve the custom DDL and ensure it exists.
    CustomDdlEntity customDdlEntity = null;
    if (StringUtils.isNotBlank(request.getCustomDdlName())) {
        customDdlEntity = customDdlDaoHelper
                .getCustomDdlEntity(new CustomDdlKey(businessObjectFormatKey.getNamespace(),
                        businessObjectFormatKey.getBusinessObjectDefinitionName(),
                        businessObjectFormatKey.getBusinessObjectFormatUsage(),
                        businessObjectFormatKey.getBusinessObjectFormatFileType(),
                        businessObjectFormatKey.getBusinessObjectFormatVersion(), request.getCustomDdlName()));
    }

    // Create business object format DDL object instance.
    BusinessObjectFormatDdl businessObjectFormatDdl = new BusinessObjectFormatDdl();
    businessObjectFormatDdl.setNamespace(businessObjectFormatKey.getNamespace());
    businessObjectFormatDdl
            .setBusinessObjectDefinitionName(businessObjectFormatKey.getBusinessObjectDefinitionName());
    businessObjectFormatDdl
            .setBusinessObjectFormatUsage(businessObjectFormatKey.getBusinessObjectFormatUsage());
    businessObjectFormatDdl
            .setBusinessObjectFormatFileType(businessObjectFormatKey.getBusinessObjectFormatFileType());
    businessObjectFormatDdl
            .setBusinessObjectFormatVersion(businessObjectFormatKey.getBusinessObjectFormatVersion());
    businessObjectFormatDdl.setOutputFormat(request.getOutputFormat());
    businessObjectFormatDdl.setTableName(request.getTableName());
    businessObjectFormatDdl.setCustomDdlName(
            customDdlEntity != null ? customDdlEntity.getCustomDdlName() : request.getCustomDdlName());
    DdlGenerator ddlGenerator = ddlGeneratorFactory.getDdlGenerator(request.getOutputFormat());
    String ddl;
    if (Boolean.TRUE.equals(request.isReplaceColumns())) {
        ddl = ddlGenerator.generateReplaceColumnsStatement(request, businessObjectFormatEntity);
    } else {
        ddl = ddlGenerator.generateCreateTableDdl(request, businessObjectFormatEntity, customDdlEntity);
    }
    businessObjectFormatDdl.setDdl(ddl);

    // Return business object format DDL.
    return businessObjectFormatDdl;
}

From source file:org.finra.herd.service.impl.EmrServiceImpl.java

/**
 * Validates the add groups to EMR cluster master create request. This method also trims request parameters.
 *
 * @param request the request.//from w w  w  . j av  a 2  s .co m
 *
 * @throws IllegalArgumentException if any validation errors were found.
 */
private void validateAddSecurityGroupsToClusterMasterRequest(EmrMasterSecurityGroupAddRequest request)
        throws IllegalArgumentException {
    // Validate required elements
    Assert.hasText(request.getNamespace(), "A namespace must be specified.");
    Assert.hasText(request.getEmrClusterDefinitionName(), "An EMR cluster definition name must be specified.");
    Assert.hasText(request.getEmrClusterName(), "An EMR cluster name must be specified.");

    Assert.notEmpty(request.getSecurityGroupIds(), "At least one security group must be specified.");
    for (String securityGroup : request.getSecurityGroupIds()) {
        Assert.hasText(securityGroup, "A security group value must be specified.");
    }

    // Remove leading and trailing spaces.
    request.setNamespace(request.getNamespace().trim());
    request.setEmrClusterDefinitionName(request.getEmrClusterDefinitionName().trim());
    request.setEmrClusterName(request.getEmrClusterName().trim());
    for (int i = 0; i < request.getSecurityGroupIds().size(); i++) {
        String element = request.getSecurityGroupIds().get(i);
        request.getSecurityGroupIds().set(i, element.trim());
    }
}

From source file:org.finra.herd.service.impl.ExpectedPartitionValueServiceImpl.java

/**
 * Validate a list of expected partition values. This method also trims the expected partition values.
 *
 * @param expectedPartitionValues the list of expected partition values
 *
 * @return the validated and sorted list of expected partition values
 * @throws IllegalArgumentException if any validation errors were found
 *///from w w  w.  j  a v  a2  s. c  om
private List<String> validateExpectedPartitionValues(List<String> expectedPartitionValues) {
    Assert.notEmpty(expectedPartitionValues, "At least one expected partition value must be specified.");

    // Ensure the expected partition value isn't a duplicate by using a hash set.
    Set<String> validatedExpectedPartitionValuesSet = new LinkedHashSet<>();
    for (String expectedPartitionValue : expectedPartitionValues) {
        String trimmedExpectedPartitionValue = alternateKeyHelper.validateStringParameter("An",
                "expected partition value", expectedPartitionValue);

        if (validatedExpectedPartitionValuesSet.contains(trimmedExpectedPartitionValue)) {
            throw new IllegalArgumentException(String.format("Duplicate expected partition value \"%s\" found.",
                    trimmedExpectedPartitionValue));
        }

        validatedExpectedPartitionValuesSet.add(trimmedExpectedPartitionValue);
    }

    List<String> validatedExpectedPartitionValues = new ArrayList<>(validatedExpectedPartitionValuesSet);

    // Sort the expected partition values list.
    Collections.sort(validatedExpectedPartitionValues);

    // Return the updated expected partition value list.
    return validatedExpectedPartitionValues;
}

From source file:org.finra.herd.service.impl.IndexSearchServiceImpl.java

/**
 * Validates the specified index search filters.
 *
 * @param indexSearchFilters the index search filters
 *//*w  w  w.j  ava  2s.  com*/
private void validateIndexSearchFilters(List<IndexSearchFilter> indexSearchFilters) {
    // Validate that the search filters list is not empty
    Assert.notEmpty(indexSearchFilters, "At least one index search filter must be specified.");

    for (IndexSearchFilter searchFilter : indexSearchFilters) {
        // Silently skip a search filter which is null
        if (searchFilter != null) {
            // Validate that each search filter has at least one index search key
            Assert.notEmpty(searchFilter.getIndexSearchKeys(),
                    "At least one index search key must be specified.");

            // Guard against a single null element in the index search keys list
            if (searchFilter.getIndexSearchKeys().get(0) != null) {
                // Get the instance type of the key in the search filter, match all other keys with this
                Class<?> expectedInstanceType = searchFilter.getIndexSearchKeys().get(0)
                        .getIndexSearchResultTypeKey() != null ? IndexSearchResultTypeKey.class : TagKey.class;

                searchFilter.getIndexSearchKeys().forEach(indexSearchKey -> {
                    // Validate that each search key has either an index search result type key or a tag key
                    Assert.isTrue(
                            (indexSearchKey.getIndexSearchResultTypeKey() != null)
                                    ^ (indexSearchKey.getTagKey() != null),
                            "Exactly one instance of index search result type key or tag key must be specified.");

                    Class<?> actualInstanceType = indexSearchKey.getIndexSearchResultTypeKey() != null
                            ? IndexSearchResultTypeKey.class
                            : TagKey.class;

                    // Validate that search keys within the same filter have either index search result type keys or tag keys
                    Assert.isTrue(expectedInstanceType.equals(actualInstanceType),
                            "Index search keys should be a homogeneous list of either index search result type keys or tag keys.");

                    // Validate tag key if present
                    if (indexSearchKey.getTagKey() != null) {
                        tagHelper.validateTagKey(indexSearchKey.getTagKey());

                        // Validates that a tag entity exists for the specified tag key and gets the actual key from the database
                        // We then modify the index search filter key to use the actual values because it eventually becomes a filter query and it will not
                        // automatically be case-sensitivity and whitespace resilient.
                        TagEntity actualTagEntity = tagDaoHelper.getTagEntity(indexSearchKey.getTagKey());
                        TagKey tagKey = new TagKey(actualTagEntity.getTagType().getCode(),
                                actualTagEntity.getTagCode());

                        indexSearchKey.setTagKey(tagKey);
                    }

                    // Validate search result type key if present
                    if (indexSearchKey.getIndexSearchResultTypeKey() != null) {
                        validateIndexSearchResultTypeKey(indexSearchKey.getIndexSearchResultTypeKey());

                        // Ensure that specified search index type exists.
                        searchIndexTypeDaoHelper.getSearchIndexTypeEntity(
                                indexSearchKey.getIndexSearchResultTypeKey().getIndexSearchResultType());
                    }
                });
            }
        }
    }
}

From source file:org.finra.herd.service.impl.UploadDownloadHelperServiceImpl.java

/**
 * Gets a unique storage from the given business object data. The given business object data must have one and only one storage unit with a storage,
 * otherwise this method throws an exception.
 *
 * @param businessObjectDataEntity the business object data entity
 *
 * @return the unique storage entity//from w  w  w  .  j a  va  2 s.  c o m
 */
private StorageEntity getUniqueStorage(BusinessObjectDataEntity businessObjectDataEntity) {
    Collection<StorageUnitEntity> targetStorageUnits = businessObjectDataEntity.getStorageUnits();
    Assert.notEmpty(targetStorageUnits,
            "No storage units found for business object data ID \"" + businessObjectDataEntity.getId() + "\".");
    Assert.isTrue(targetStorageUnits.size() == 1,
            "More than 1 storage units found for business object data ID \"" + businessObjectDataEntity.getId()
                    + "\".");
    return IterableUtils.get(targetStorageUnits, 0).getStorage();
}

From source file:org.finra.herd.service.impl.UploadDownloadHelperServiceImpl.java

/**
 * Gets the target business object data entity with the given source business object data entity. The target is a business object data which has the same
 * partition value as the source, and is not the source itself. Throws an error if no target is found, or more than 1 business object data other than the
 * source is found with the partition value.
 *
 * @param sourceBusinessObjectDataEntity the source business object data entity
 *
 * @return the target business object data entity
 *///  w w w  . j av  a 2 s.c om
private BusinessObjectDataEntity getTargetBusinessObjectDataEntity(
        BusinessObjectDataEntity sourceBusinessObjectDataEntity) {
    String uuidPartitionValue = sourceBusinessObjectDataEntity.getPartitionValue();
    List<BusinessObjectDataEntity> targetBusinessObjectDataEntities = businessObjectDataDao
            .getBusinessObjectDataEntitiesByPartitionValue(uuidPartitionValue);

    Assert.notEmpty(targetBusinessObjectDataEntities,
            "No target business object data found with partition value \"" + uuidPartitionValue + "\".");

    // we check for size 2 because one is the source bdata, the other is the target
    Assert.isTrue(targetBusinessObjectDataEntities.size() == 2,
            "More than 1 target business object data found with partition value \"" + uuidPartitionValue
                    + "\".");

    // Find the bdata which is NOT the source bdata. It should be the target bdata.
    BusinessObjectDataEntity targetBusinessObjectDataEntity = null;
    for (BusinessObjectDataEntity businessObjectDataEntity : targetBusinessObjectDataEntities) {
        if (!Objects.equals(businessObjectDataEntity.getId(), sourceBusinessObjectDataEntity.getId())) {
            targetBusinessObjectDataEntity = businessObjectDataEntity;
        }
    }

    Assert.notNull(targetBusinessObjectDataEntity,
            "No target business object data found with partition value \"" + uuidPartitionValue + "\".");

    return targetBusinessObjectDataEntity;
}

From source file:org.geoserver.backuprestore.reader.CatalogFileReader.java

/**
 * Ensure that all required dependencies for the ItemReader to run are provided after all properties have been set.
 * /*from   www  . j  a v  a2  s  .c om*/
 * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
 * @throws IllegalArgumentException if the Resource, FragmentDeserializer or FragmentRootElementName is null, or if the root element is empty.
 * @throws IllegalStateException if the Resource does not exist.
 */
@Override
public void afterPropertiesSet() throws Exception {
    Assert.notEmpty(fragmentRootElementNames, "The FragmentRootElementNames must not be empty");
    for (QName fragmentRootElementName : fragmentRootElementNames) {
        Assert.hasText(fragmentRootElementName.getLocalPart(),
                "The FragmentRootElementNames must not contain empty elements");
    }
}

From source file:org.impalaframework.service.registry.internal.ServiceEntryRegistryDelegate.java

/**
 * Returns named service, which has to implement all of implementation types specified
 *//*from w w  w  . j a  va  2  s .co  m*/
@SuppressWarnings("unchecked")
private List<ServiceRegistryEntry> getServicesInternal(String beanName, Class<?>[] exportTypes) {

    final boolean useBeanLookup;
    final boolean exportTypesSet;

    if (ArrayUtils.isNullOrEmpty(exportTypes)) {
        Assert.notNull(beanName, "Either bean name must be not null, or export types must be non-empty");
        useBeanLookup = true;
        exportTypesSet = false;
    } else {
        exportTypesSet = true;

        if (beanName == null) {
            Assert.notEmpty(exportTypes,
                    "Either bean name must be not null, or export types must be non-empty");
            useBeanLookup = false;
        } else {
            //bean lookup and export types are available - use bean lookup
            useBeanLookup = true;
        }
    }

    List<ServiceRegistryEntry> references;

    //use read lock protected section to get services
    try {
        registryReadLock.lock();

        final List<ServiceRegistryEntry> list;

        if (useBeanLookup) {
            list = beanNameToService.get(beanName);

            //if we have explicit types and list is not empty, we get the exported list use this to filter the 
            //list to be returned
            if (exportTypesSet && list != null && !list.isEmpty()) {

                final List<ServiceRegistryEntry> exportList = classNameToServices.get(exportTypes[0].getName());
                if (exportList == null) {
                    return Collections.EMPTY_LIST;
                } else {
                    list.retainAll(exportList);
                }
            }
        } else {
            //get list from export types
            list = classNameToServices.get(exportTypes[0].getName());
        }
        references = (list == null ? Collections.EMPTY_LIST : new ArrayList<ServiceRegistryEntry>(list));

    } finally {
        registryReadLock.unlock();
    }

    //no need to sort here, as it is already sorted
    return references;
}

From source file:org.impalaframework.service.registry.internal.ServiceEntryRegistryDelegate.java

/**
 * Returns filtered services, which has to implement all of implemenation types specified.
 * @param filter the filter which is used to match service references. Can be null. If so, {@link IdentityServiceReferenceFilter} is used,
 * which always returns true. See {@link IdentityServiceReferenceFilter#matches(ServiceRegistryEntry)}.
 * @param types the types with which returned references should be compatible
 * @param if true only matches against explicit export types
 *//*from   w  w  w . ja v  a2s .co m*/
public List<ServiceRegistryEntry> getServices(ServiceReferenceFilter filter, Class<?>[] types,
        boolean exportTypesOnly) {

    if (filter == null) {
        filter = IDENTIFY_FILTER;
    }

    if (exportTypesOnly) {

        Assert.notNull(types, "exportTypesOnly is true but types is null");
        Assert.notEmpty(types, "exportTypesOnly is true but types is empty");

        final List<ServiceRegistryEntry> values;

        //build a copy of values within read lock protected block
        try {
            registryReadLock.lock();

            final List<ServiceRegistryEntry> tempValues = classNameToServices.get(types[0].getName());

            if (tempValues == null) {
                return Collections.emptyList();
            } else {
                values = new ArrayList<ServiceRegistryEntry>(tempValues);
            }
        } finally {
            registryReadLock.unlock();
        }

        //filter only export types
        filterReferenceByExportTypes(values, types);

        //check each entry against filter
        for (Iterator<ServiceRegistryEntry> iterator = values.iterator(); iterator.hasNext();) {
            ServiceRegistryEntry serviceReference = iterator.next();

            if (!filter.matches(serviceReference)) {
                iterator.remove();
            }
        }

        return serviceReferenceSorter.sort(values, true);
    } else {

        //Create new list of services for concurrency protection
        final List<ServiceRegistryEntry> values;

        try {
            registryReadLock.lock();
            values = new LinkedList<ServiceRegistryEntry>(this.services);
        } finally {
            registryReadLock.unlock();
        }

        for (Iterator<ServiceRegistryEntry> iterator = values.iterator(); iterator.hasNext();) {
            ServiceRegistryEntry serviceReference = iterator.next();

            if (!(classChecker.matchesTypes(serviceReference, types) && filter.matches(serviceReference))) {
                iterator.remove();
            }
        }
        //sort, reusing existing list
        return serviceReferenceSorter.sort(values, true);
    }

}

From source file:org.jasig.cas.authentication.ImmutableAuthentication.java

/**
 * Creates a new instance with the given data.
 *
 * @param date Non-null authentication date.
 * @param credentials Non-null list of credential metadata containing at least one entry.
 * @param principal Non-null authenticated principal.
 * @param attributes Nullable map of authentication metadata.
 * @param successes Non-null map of authentication successes containing at least one entry.
 * @param failures Nullable map of authentication failures.
 *//*from  w ww.j  a  va  2s.  c  om*/
public ImmutableAuthentication(final DateTime date, final List<CredentialMetaData> credentials,
        final Principal principal, final Map<String, Object> attributes,
        final Map<String, HandlerResult> successes, final Map<String, Class<? extends Exception>> failures) {

    Assert.notNull(date, "Date cannot be null");
    Assert.notNull(credentials, "Credential cannot be null");
    Assert.notNull(principal, "Principal cannot be null");
    Assert.notNull(successes, "Successes cannot be null");
    Assert.notEmpty(credentials, "Credential cannot be empty");
    Assert.notEmpty(successes, "Successes cannot be empty");

    this.authenticationDate = date.toDate().getTime();
    this.credentials = credentials;
    this.principal = principal;
    this.attributes = attributes.isEmpty() ? null : attributes;
    this.successes = successes;
    this.failures = failures.isEmpty() ? null : failures;
}