Example usage for org.apache.commons.collections CollectionUtils select

List of usage examples for org.apache.commons.collections CollectionUtils select

Introduction

In this page you can find the example usage for org.apache.commons.collections CollectionUtils select.

Prototype

public static void select(Collection inputCollection, Predicate predicate, Collection outputCollection) 

Source Link

Document

Selects all elements from input collection which match the given predicate and adds them to outputCollection.

Usage

From source file:org.jbpm.kie.services.impl.RuntimeDataServiceImpl.java

public ProcessDefinition getProcessesByDeploymentIdProcessId(String deploymentId, String processId) {
    List<ProcessDefinition> outputCollection = new ArrayList<ProcessDefinition>();
    CollectionUtils.select(availableProcesses,
            new ByDeploymentIdProcessIdPredicate(deploymentId, processId, identityProvider.getRoles(), true),
            outputCollection);//from   w  w w  . ja  v a  2 s . c om

    if (!outputCollection.isEmpty()) {
        return outputCollection.iterator().next();
    }
    return null;
}

From source file:org.jbpm.kie.services.impl.RuntimeDataServiceImpl.java

public Collection<ProcessDefinition> getProcessesByFilter(String filter, QueryContext queryContext) {
    List<ProcessDefinition> outputCollection = new ArrayList<ProcessDefinition>();
    CollectionUtils.select(availableProcesses,
            new RegExPredicate("(?i)^.*" + filter + ".*$", identityProvider.getRoles()), outputCollection);

    applySorting(outputCollection, queryContext);
    return applyPaginition(outputCollection, queryContext);
}

From source file:org.jbpm.kie.services.impl.RuntimeDataServiceImpl.java

public Collection<ProcessDefinition> getProcessesById(String processId) {

    Collection<ProcessDefinition> outputCollection = new HashSet<ProcessDefinition>();
    CollectionUtils.select(availableProcesses, new ByProcessIdPredicate(processId, identityProvider.getRoles()),
            outputCollection);//from   w w w .ja  v a 2 s.  c om

    return outputCollection;
}

From source file:org.jbpm.kie.services.impl.RuntimeDataServiceImpl.java

public Collection<ProcessDefinition> getProcesses(QueryContext queryContext) {
    List<ProcessDefinition> outputCollection = new ArrayList<ProcessDefinition>();
    CollectionUtils.select(availableProcesses, new SecurePredicate(identityProvider.getRoles(), false),
            outputCollection);/*from w w  w  . ja va  2s  .  c  om*/

    applySorting(outputCollection, queryContext);
    return applyPaginition(outputCollection, queryContext);
}

From source file:org.jmesa.core.filter.SimpleRowFilter.java

@Override
public Collection<?> filterItems(Collection<?> items, Limit limit) {

    FilterSet filterSet = limit.getFilterSet();
    boolean filtered = filterSet.isFiltered();

    if (filtered) {
        Collection<?> collection = new ArrayList<Object>();
        Map<Filter, FilterMatcher> filterMatchers = getFilterMatchers(items, filterSet);
        Predicate filterPredicate = getPredicate(filterMatchers, filterSet);
        CollectionUtils.select(items, filterPredicate, collection);

        return collection;
    }//from  w  w  w .j  a v  a2 s .  com

    return items;
}

From source file:org.kuali.mobility.dining.service.DiningServiceImpl.java

@GET
@Path("/diningHallGroupsByCampus")
@Override/*from   w ww.  j a v a 2  s .co  m*/
public List<DiningHallGroup> getDiningHallGroupsByCampus(@QueryParam(value = "campus") String campus) {
    List<DiningHallGroup> diningHallGroups = new ArrayList<DiningHallGroup>();
    try {
        CollectionUtils.select(getDao().getDiningHallGroups(), new DiningHallCampusPredicate(campus),
                diningHallGroups);
    } catch (Exception e) {
        DiningHallGroup diningHallGroup = new DiningHallGroup();
        ErrorMessage error = new ErrorMessage();
        error.setName("No Dining Hall Groups Found");
        error.setDescription("No dining hall group found for " + campus + ".");
        List<ErrorMessage> errors = new ArrayList<ErrorMessage>();
        //diningHallGroup.setErrors(errors);
        diningHallGroups.add(diningHallGroup);
    }
    //Collections.sort( diningHalls, new DiningHallComparitor() );
    return diningHallGroups;
}

From source file:org.kuali.mobility.dining.service.DiningServiceImpl.java

@GET
@Path("/diningHallGroupsByBuilding")
@Override/*from www . ja  v  a2 s .  c o m*/
public List<DiningHallGroup> getDiningHallGroupsByBuilding(
        @QueryParam(value = "buildingName") String buildingName) {
    List<DiningHallGroup> diningHallGroups = new ArrayList<DiningHallGroup>();
    try {
        CollectionUtils.select(getDao().getDiningHallGroups(), new DiningHallBuildingPredicate(buildingName),
                diningHallGroups);
    } catch (Exception e) {
        DiningHallGroup diningHallGroup = new DiningHallGroup();
        ErrorMessage error = new ErrorMessage();
        error.setName("No Dining Halls Found");
        error.setDescription("No dining hall found for " + buildingName + ".");
        List<ErrorMessage> errors = new ArrayList<ErrorMessage>();
        //            diningHallGroup.setErrors(errors);
        diningHallGroups.add(diningHallGroup);
    }
    return diningHallGroups;
}

From source file:org.onexus.ui.api.viewers.DefaultViewersManager.java

@Override
public List<IViewerCreator> getViewerCreators(Resource resource) {

    if (resource == null) {
        return Collections.emptyList();
    }//from   w w w .  ja  v a  2s  .  c o  m

    List<IViewerCreator> result = new ArrayList<IViewerCreator>();
    CollectionUtils.select(viewerCreators, new VisiblePredicate(resource), result);
    Collections.sort(result, VIEWER_CREATOR_COMPRATOR);

    return result;

}

From source file:org.onexus.ui.api.wizards.DefaultWizardsManager.java

@Override
public List<IWizardCreator> getWizardCreators(Resource resource) {

    if (resource == null) {
        return Collections.emptyList();
    }/*from   www. j a v  a2  s.c o m*/

    List<IWizardCreator> result = new ArrayList<IWizardCreator>();
    CollectionUtils.select(wizardCreators, new VisiblePredicate(resource), result);
    Collections.sort(result, WIZARD_CREATOR_COMPRATOR);

    return result;
}

From source file:org.onexus.website.api.pages.browser.BrowserPage.java

@Override
protected void onBeforeRender() {

    VisibleTabs visibleTabs = new VisibleTabs();

    // Tabs can change when we fix/unfix entities
    addOrReplace(new ListView<TabGroup>("tabs", visibleTabs) {

        @Override//from  w w w.jav a 2  s. com
        protected void populateItem(ListItem<TabGroup> item) {

            TabGroup tabGroup = item.getModelObject();

            if (tabGroup.hasSubMenu()) {

                WebMarkupContainer link = new WebMarkupContainer("link");
                link.add(new AttributeModifier("class", "dropdown-toggle"));
                link.add(new AttributeModifier("data-toggle", "dropdown"));
                link.add(new AttributeModifier("href", "#"));

                if (tabGroup.containsTab(getStatus().getCurrentTabId())) {
                    item.add(new AttributeModifier("class", "dropdown active"));

                    TabConfig currentTab = getConfig().getTab(getStatus().getCurrentTabId());
                    String tabTitle = StringUtils.abbreviate(currentTab.getTitle(), 14);
                    String currentLabel = "<div style=\"position:relative;\"><div style=\"white-space: nowrap; position:absolute; left:13px; top: 13px; font-size: 9px;\"><em>"
                            + tabTitle + "</em></div></div>";
                    link.add(new Label("label",
                            currentLabel + "<b class='caret'></b>&nbsp;" + tabGroup.getGroupLabel())
                                    .setEscapeModelStrings(false));

                } else {
                    item.add(new AttributeModifier("class", "dropdown"));
                    link.add(new Label("label", "<b class='caret'></b>&nbsp;" + tabGroup.getGroupLabel())
                            .setEscapeModelStrings(false));
                }
                item.add(link);

                WebMarkupContainer submenu = new WebMarkupContainer("submenu");
                submenu.add(new ListView<TabConfig>("item", tabGroup.getTabConfigs()) {

                    @Override
                    protected void populateItem(ListItem<TabConfig> item) {

                        TabConfig tab = item.getModelObject();

                        BrowserPageLink<String> link = new BrowserPageLink<String>("link",
                                Model.of(tab.getId())) {

                            @Override
                            public void onClick(AjaxRequestTarget target) {
                                getStatus().setCurrentTabId(getModelObject());
                                sendEvent(EventTabSelected.EVENT);
                            }

                        };

                        if (!Strings.isEmpty(tab.getHelp())) {
                            item.add(new AttributeModifier("rel", "tooltip"));
                            item.add(new AttributeModifier("data-placement", "right"));
                            item.add(new AttributeModifier("title", tab.getHelp()));
                        }

                        link.add(new Label("label", tab.getTitle()));
                        item.add(link);

                        if (isCurrentTab(tab.getId())) {
                            item.add(new AttributeModifier("class", new Model<String>("active")));
                        }

                    }
                });
                item.add(submenu);

            } else {

                TabConfig tab = tabGroup.getTabConfigs().get(0);
                BrowserPageLink<String> link = new BrowserPageLink<String>("link", Model.of(tab.getId())) {

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        getStatus().setCurrentTabId(getModelObject());
                        sendEvent(EventTabSelected.EVENT);
                    }

                };

                if (!Strings.isEmpty(tab.getHelp())) {
                    link.add(new AttributeModifier("rel", "tooltip"));
                    link.add(new AttributeModifier("title", tab.getHelp()));
                }

                link.add(new Label("label", tab.getTitle()));
                item.add(link);

                if (isCurrentTab(tab.getId())) {
                    item.add(new AttributeModifier("class", new Model<String>("active")));
                }

                item.add(new WebMarkupContainer("submenu").setVisible(false));

            }

        }

    });

    // Check if the current selected tab is visible.
    String currentTabId = getStatus().getCurrentTabId();

    // Set a current tab if there is no one.
    if (currentTabId == null) {

        List<TabConfig> tabs = getConfig().getTabs();
        if (tabs != null && !tabs.isEmpty()) {
            currentTabId = tabs.get(0).getId();
            getStatus().setCurrentTabId(currentTabId);

            // Init currentPage
            //TODO This is not a good solution
            PageParameters pageParameters = getPage().getPageParameters();
            pageParameters.set(Website.PARAMETER_CURRENT_PAGE, getConfig().getId());
            pageParameters.set("ptab", currentTabId);
            setResponsePage(Website.class, pageParameters);
        }

    }

    List<TabGroup> tabs = visibleTabs.getObject();
    boolean hiddenTab = true;
    for (TabGroup tab : tabs) {
        if (tab.containsTab(currentTabId)) {
            hiddenTab = false;
        }
    }

    if (hiddenTab && !tabs.isEmpty()) {
        TabConfig firstTab = tabs.get(0).getTabConfigs().get(0);
        getStatus().setCurrentTabId(firstTab.getId());
    }

    List<String> views = new ArrayList<String>();
    if (getCurrentTab().getViews() != null) {
        for (ViewConfig view : getCurrentTab().getViews()) {
            views.add(view.getTitle());
        }
    }

    if (getStatus().getCurrentView() == null && views.size() > 0) {
        getStatus().setCurrentView(views.get(0));
    }

    // Check that the current view is visible
    List<ViewConfig> filteredViews = new ArrayList<ViewConfig>();
    VisiblePredicate predicate = new VisiblePredicate(getStatus().getORI().getParent(),
            getStatus().getEntitySelections());
    CollectionUtils.select(getCurrentTab().getViews(), predicate, filteredViews);

    boolean visibleView = false;
    String currentView = getStatus().getCurrentView();
    for (ViewConfig view : filteredViews) {
        if (view.getTitle().equals(currentView)) {
            visibleView = true;
            break;
        }
    }

    if (!visibleView) {
        getStatus().setCurrentView(filteredViews.get(0).getTitle());
    }

    ViewConfig viewConfig = null;
    if (getCurrentTab().getViews() != null) {
        for (ViewConfig view : getCurrentTab().getViews()) {
            if (view.getTitle().equals(getStatus().getCurrentView())) {
                viewConfig = view;
                break;
            }
        }
    }

    if (viewConfig == null) {
        addOrReplace(new EmptyPanel("content"));
    } else {
        if (viewConfig.getLeft() != null && viewConfig.getTop() != null) {
            addOrReplace(new TopleftLayout("content", viewConfig, getModel()));
        } else if (viewConfig.getLeft() != null) {
            addOrReplace(new LeftMainLayout("content", viewConfig, getModel()));
        } else if (viewConfig.getTop() != null || viewConfig.getTopRight() != null) {
            addOrReplace(new TopmainLayout("content", viewConfig, getModel()));
        } else {
            addOrReplace(new SingleLayout("content", viewConfig, getModel()));
        }
    }

    boolean visible = !isEmbed();
    get("selection").setVisible(visible);
    get("tabs").setVisible(visible);
    //TODO viewSelector.setVisible(visible && views.size() > 1);

    super.onBeforeRender();
}