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

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

Introduction

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

Prototype

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

Source Link

Document

Null-safe check if the specified collection is not empty.

Usage

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

@Override
public Collection<Deployment> getAllDeployments() {
    Collection<Deployment> deployments = new ArrayList<>();
    Deployment currentDeployment = getCurrentDeployment();
    Collection<Deployment> pendingDeployments = getPendingDeployments();

    if (currentDeployment != null) {
        deployments.add(currentDeployment);
    }//  w w  w .  j av  a2 s . co m
    if (CollectionUtils.isNotEmpty(pendingDeployments)) {
        deployments.addAll(pendingDeployments);
    }

    return deployments;
}

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

@PreDestroy
public void destroy() {
    logger.info("Closing all targets...");

    if (CollectionUtils.isNotEmpty(loadedTargets)) {
        loadedTargets.forEach(Target::close);
    }/*from   w  w w.  j  a v  a  2s .c om*/
}

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

@Override
public synchronized List<Target> resolveTargets() throws TargetServiceException {
    Collection<File> configFiles = getTargetConfigFiles();
    List<Target> targets = new ArrayList<>();

    if (CollectionUtils.isNotEmpty(configFiles)) {
        closeTargetsWithNoConfigFile(configFiles);

        for (File file : configFiles) {
            Target target = resolveTargetFromConfigFile(file);
            targets.add(target);//  w w w.  j av a 2s . c  o  m
        }
    }

    return targets;
}

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

protected void closeTargetsWithNoConfigFile(Collection<File> configFiles) {
    if (CollectionUtils.isNotEmpty(loadedTargets)) {
        loadedTargets.removeIf(target -> {
            File configFile = target.getConfigurationFile();
            if (!configFiles.contains(configFile)) {
                logger.info("Config file {} doesn't exist anymore for target '{}'. Closing target...",
                        configFile);/*from w  w w.j  a  va  2 s . c om*/

                target.close();

                return true;
            } else {
                return false;
            }
        });
    }
}

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

protected Target findLoadedTargetByConfigFile(File configFile) {
    if (CollectionUtils.isNotEmpty(loadedTargets)) {
        return loadedTargets.stream().filter(target -> target.getConfigurationFile().equals(configFile))
                .findFirst().orElse(null);
    } else {/*from w ww .j av a2 s. c  o m*/
        return null;
    }
}

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

protected Target findLoadedTargetById(String id) {
    if (CollectionUtils.isNotEmpty(loadedTargets)) {
        return loadedTargets.stream().filter(target -> target.getId().equals(id)).findFirst().orElse(null);
    } else {// w w w  . j  a v a2  s. c o  m
        return null;
    }
}

From source file:org.craftercms.engine.controller.rest.RestScriptsController.java

protected String parseScriptUrlForVariables(SiteContext siteContext, String scriptUrl,
        Map<String, Object> variables) {
    ContentStoreService storeService = siteContext.getStoreService();
    if (!storeService.exists(siteContext.getContext(), scriptUrl) && urlTemplateScanner != null) {
        List<UriTemplate> urlTemplates = urlTemplateScanner.scan(siteContext);
        if (CollectionUtils.isNotEmpty(urlTemplates)) {
            for (UriTemplate template : urlTemplates) {
                if (template.matches(scriptUrl)) {
                    Map<String, String> pathVars = template.match(scriptUrl);
                    String actualScriptUrl = template.toString();

                    variables.put(GroovyScriptUtils.VARIABLE_PATH_VARS, pathVars);

                    return actualScriptUrl;
                }/*from  w w  w.  ja v  a  2s .c  om*/
            }
        }
    }

    return scriptUrl;
}

From source file:org.craftercms.engine.freemarker.RenderComponentDirective.java

protected Map<String, Object> executeScripts(SiteItem component, Map<String, Object> additionalModel,
        Environment env) throws TemplateException {
    List<String> scriptUrls = scriptResolver.getScriptUrls(component);
    if (CollectionUtils.isNotEmpty(scriptUrls)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Scripts associated to component " + component.getStoreUrl() + ": " + scriptUrls);
        }/* w w  w .  j a va  2 s . c o  m*/

        Map<String, Object> templateModel = new HashMap<>();
        Map<String, Object> scriptVariables = createScriptVariables(component, templateModel, additionalModel);
        SiteContext siteContext = SiteContext.getCurrent();

        if (siteContext != null) {
            ScriptFactory scriptFactory = siteContext.getScriptFactory();

            if (scriptFactory == null) {
                throw new IllegalStateException("No script factory associate to current site context '"
                        + siteContext.getSiteName() + "'");
            }

            for (String scriptUrl : scriptUrls) {
                Script script;
                try {
                    script = scriptFactory.getScript(scriptUrl);
                } catch (Exception e) {
                    throw new TemplateException("Unable to load script at '" + scriptUrl + "'", e, env);
                }

                executeScript(script, scriptVariables, env);
            }
        } else {
            throw new IllegalStateException("No current site context found");
        }

        return templateModel;
    } else {
        return null;
    }
}

From source file:org.craftercms.engine.navigation.impl.NavTreeBuilderImpl.java

protected List<NavItem> getNavSubItems(SiteItem siteItem, String currentPageUrl,
        Converter<SiteItem, NavItem> itemConverter) {
    List<SiteItem> childItems = siteItem.getChildItems();
    if (CollectionUtils.isNotEmpty(childItems)) {
        List<NavItem> navSubItems = new ArrayList<>();

        for (SiteItem childItem : childItems) {
            NavItem navSubItem = getNavItem(childItem, currentPageUrl, itemConverter);
            if (navSubItem != null && !navSubItems.contains(navSubItem)) {
                navSubItems.add(navSubItem);
            }/*from  ww  w. ja va2  s .  c o  m*/
        }

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

From source file:org.craftercms.engine.scripting.impl.ScriptUrlTemplateScannerImpl.java

@Override
public List<UriTemplate> scan(SiteContext siteContext) {
    Context context = siteContext.getContext();
    ContentStoreService storeService = siteContext.getStoreService();
    ScriptFactory scriptFactory = siteContext.getScriptFactory();
    List<String> scriptUrls = new ArrayList<>();
    List<UriTemplate> urlTemplates = new ArrayList<>();

    findScripts(context, storeService, scriptFactory, scriptsFolder, scriptUrls);

    if (CollectionUtils.isNotEmpty(scriptUrls)) {
        for (String scriptUrl : scriptUrls) {
            Matcher matcher = urlVariablePlaceholderPattern.matcher(scriptUrl);
            if (matcher.find()) {
                urlTemplates.add(new UriTemplate(scriptUrl));
            }//from   ww  w.j a  v a2s  . c o  m
        }
    }

    return urlTemplates;
}