Example usage for org.apache.commons.collections4 CollectionUtils isEmpty

List of usage examples for org.apache.commons.collections4 CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.collections4 CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(final Collection<?> coll) 

Source Link

Document

Null-safe check if the specified collection is empty.

Usage

From source file:org.craftercms.core.service.Item.java

/**
 * Queries multiple descriptor node text values. First looks in the properties, if not found it executes the XPath
 * query.//w w  w  . j av a  2 s .  c  o m
 */
@SuppressWarnings("unchecked")
public List<String> queryDescriptorValues(String xpathQuery) {
    if (descriptorDom != null) {
        List<String> value = (List<String>) getProperty(xpathQuery);
        if (CollectionUtils.isEmpty(value)) {
            value = XmlUtils.selectNodeValues(descriptorDom, xpathQuery);
        }

        return value;
    } else {
        return Collections.emptyList();
    }
}

From source file:org.craftercms.deployer.api.ChangeSet.java

/**
 * Returns true if there are not created, updated or deleted files.
 *//*  ww w.j a  v a  2s.c om*/
@JsonIgnore
public boolean isEmpty() {
    return CollectionUtils.isEmpty(createdFiles) && CollectionUtils.isEmpty(updatedFiles)
            && CollectionUtils.isEmpty(deletedFiles);
}

From source file:org.craftercms.deployer.impl.TargetServiceImpl.java

protected Collection<File> getTargetConfigFiles() throws TargetServiceException {
    if (targetConfigFolder.exists()) {
        Collection<File> yamlFiles = FileUtils.listFiles(targetConfigFolder, new CustomConfigFileFilter(),
                null);//  w  ww  . j av a 2s.c o  m

        if (CollectionUtils.isEmpty(yamlFiles)) {
            logger.warn("No YAML config files found under {}", targetConfigFolder.getAbsolutePath());
        }

        return yamlFiles;
    } else {
        logger.warn("Config folder {} doesn't exist. Trying to create it...",
                targetConfigFolder.getAbsolutePath());

        try {
            FileUtils.forceMkdir(targetConfigFolder);
        } catch (IOException e) {
            throw new TargetServiceException("Unable to create config folder " + targetConfigFolder, e);
        }

        return Collections.emptyList();
    }
}

From source file:org.craftercms.deployer.utils.ConfigurationUtils.java

@SuppressWarnings("unchecked")
public static List<HierarchicalConfiguration> getRequiredConfigurationsAt(HierarchicalConfiguration config,
        String key) throws DeploymentConfigurationException {
    List<HierarchicalConfiguration> configs = getConfigurationsAt(config, key);
    if (CollectionUtils.isEmpty(configs)) {
        throw new MissingConfigurationPropertyException("Missing required sub-configurations at '" + key + "'");
    } else {//w w  w . j  ava 2 s.c o  m
        return configs;
    }
}

From source file:org.craftercms.deployer.utils.ConfigUtils.java

/**
 * Returns the sub-configuration tree whose root is the specified key. If the tree is missing a
 * {@link MissingConfigurationPropertyException} is thrown
 *
 * @param config    the configuration//from  w w  w.java2s  .  c o m
 * @param key       the key of the configuration tree
 *
 * @return the sub-configuration tree, or null if not found
 *
 * @throws MissingConfigurationPropertyException if the property is missing from the configuration
 * @throws DeployerConfigurationException if an error occurs
 */
@SuppressWarnings("unchecked")
public static List<HierarchicalConfiguration> getRequiredConfigurationsAt(HierarchicalConfiguration config,
        String key) throws DeployerConfigurationException {
    List<HierarchicalConfiguration> configs = getConfigurationsAt(config, key);
    if (CollectionUtils.isEmpty(configs)) {
        throw new MissingConfigurationPropertyException(key);
    } else {
        return configs;
    }
}

From source file:org.craftercms.social.services.system.impl.SocialContextServiceImpl.java

@Override
@HasPermission(type = SocialPermission.class, action = SecurityActionNames.SYSTEM_ADD_PROFILE_CONTEXT)
public Profile addProfileToContext(final String profileId, final String contextId, final String[] roles)
        throws SocialException {
    try {//from  ww  w  .  j a  v  a2  s .co m
        Profile p = profileService.getProfile(profileId, SocialSecurityUtils.SOCIAL_CONTEXTS_ATTRIBUTE);
        if (p == null) {
            throw new ProfileConfigurationException("Given profile \"" + profileId + "\" does not exist");
        }
        final HashMap<String, Object> attributesToUpdate = new HashMap<>();
        List<Map<String, Object>> socialContexts = p
                .getAttribute(SocialSecurityUtils.SOCIAL_CONTEXTS_ATTRIBUTE);
        SocialContext ctx = socialContextRepository.findById(contextId);
        if (ctx == null) {
            throw new ProfileConfigurationException("Given context \"" + contextId + "\" does not exist");
        }
        if (CollectionUtils.isEmpty(socialContexts)) {
            Map<String, Object> socialContext = new HashMap<>();
            socialContext.put(SocialSecurityUtils.SOCIAL_CONTEXT_NAME, ctx.getContextName());
            socialContext.put(SocialSecurityUtils.SOCIAL_CONTEXT_ID, ctx.getId());
            socialContext.put(SocialSecurityUtils.SOCIAL_CONTEXT_ROLES, Arrays.asList(roles));
            socialContexts = Arrays.asList(socialContext);
        } else {
            boolean foundOne = false;
            for (Map<String, Object> socialContext : socialContexts) {
                if (socialContext.containsValue(ctx.getId())) {
                    socialContext.put(SocialSecurityUtils.SOCIAL_CONTEXT_ROLES, Arrays.asList(roles));
                    foundOne = true;
                    break;
                }
            }
            if (!foundOne) {
                Map<String, Object> newCtx = new HashMap<>();
                newCtx.put(SocialSecurityUtils.SOCIAL_CONTEXT_NAME, ctx.getContextName());
                newCtx.put(SocialSecurityUtils.SOCIAL_CONTEXT_ID, ctx.getId());
                newCtx.put(SocialSecurityUtils.SOCIAL_CONTEXT_ROLES, Arrays.asList(roles));
                socialContexts.add(newCtx);
            }
        }
        attributesToUpdate.put(SocialSecurityUtils.SOCIAL_CONTEXTS_ATTRIBUTE, socialContexts);
        return profileService.updateAttributes(profileId, attributesToUpdate, FIRST_NAME_ATTRIBUTE,
                LAST_NAME_ATTRIBUTE, DISPLAY_NAME_ATTRIBUTE, AVATAR_LINK_ATTRIBUTE,
                SocialSecurityUtils.SOCIAL_CONTEXTS_ATTRIBUTE);
    } catch (ProfileException e) {
        log.error("Unable to find profile with given id " + profileId, e);
        throw new SocialException("Unable to find profile ", e);
    } catch (MongoDataException e) {
        log.error("Unable to look for SocialContext", e);
        throw new SocialException("Unable to find Context by id", e);
    }
}

From source file:org.craftercms.studio.impl.v1.asset.processing.AssetProcessingConfigReaderImpl.java

@SuppressWarnings("unchecked")
private List<HierarchicalConfiguration> getRequiredConfigurationsAt(HierarchicalConfiguration config,
        String key) throws AssetProcessingConfigurationException {
    List<HierarchicalConfiguration> configs = config.configurationsAt(key);
    if (CollectionUtils.isEmpty(configs)) {
        throw new AssetProcessingConfigurationException("Missing required property '" + key + "'");
    } else {//from   ww w.ja  va 2 s .  com
        return configs;
    }
}

From source file:org.craftercms.studio.impl.v1.service.dependency.DependencyServiceImpl.java

private List<String> getItemSpecificDependenciesFromDB(String site, Set<String> paths) {
    if (CollectionUtils.isEmpty(paths)) {
        return new ArrayList<String>();
    }//from   w ww.  j  av  a 2  s .  co  m
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(SITE_PARAM, site);
    params.put(PATHS_PARAM, paths);
    params.put(REGEX_PARAM, getItemSpecificDependenciesPatterns());
    return dependencyMapper.getItemSpecificDependenciesForList(params);
}

From source file:org.craftercms.studio.impl.v1.service.dependency.DependencyServiceImpl.java

private List<String> getItemDependenciesFromDB(String site, Set<String> paths) {
    if (CollectionUtils.isEmpty(paths)) {
        return new ArrayList<String>();
    }/* w  w  w  .j  a  v  a  2s  .  c o m*/
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(SITE_PARAM, site);
    params.put(PATHS_PARAM, paths);
    return dependencyMapper.getDependenciesForList(params);
}

From source file:org.craftercms.studio.impl.v1.service.dependency.DependencyServiceImpl.java

private List<String> getItemsDependingOnFromDB(String site, Set<String> paths) {
    if (CollectionUtils.isEmpty(paths)) {
        return new ArrayList<String>();
    }//from   w w  w .j a  v  a2  s .  c o  m
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(SITE_PARAM, site);
    params.put(PATHS_PARAM, paths);
    return dependencyMapper.getItemsDependingOn(params);
}