List of usage examples for org.apache.commons.collections CollectionUtils filter
public static void filter(Collection collection, Predicate predicate)
From source file:org.apache.ranger.plugin.store.file.TagFileStore.java
@Override public List<RangerServiceResource> getServiceResources(SearchFilter filter) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> TagFileStore.getServiceResources()"); }//ww w .ja v a2 s . c o m List<RangerServiceResource> ret = getAllResources(); if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) { CollectionUtils.filter(ret, predicateUtil.getPredicate(filter)); } if (LOG.isDebugEnabled()) { LOG.debug("<== TagFileStore.getServicesResources(): count=" + (ret == null ? 0 : ret.size())); } return ret; }
From source file:org.apache.ranger.plugin.store.file.TagFileStore.java
@Override public List<RangerTagResourceMap> getTagResourceMaps(SearchFilter filter) throws Exception { if (LOG.isDebugEnabled()) { LOG.debug("==> TagFileStore.getTagResourceMaps()"); }//from ww w. ja v a 2 s . c o m List<RangerTagResourceMap> ret = getAllTaggedResources(); if (CollectionUtils.isNotEmpty(ret) && filter != null && !filter.isEmpty()) { CollectionUtils.filter(ret, predicateUtil.getPredicate(filter)); } if (LOG.isDebugEnabled()) { LOG.debug("<== TagFileStore.getTagResourceMaps(): count=" + (ret == null ? 0 : ret.size())); } return ret; }
From source file:org.beangle.emsapp.security.action.MenuNavAction.java
@Override public String index() throws Exception { final String name = get("name"); final Long menuId = getLong("menu.id"); final Set<Menu> family; final Menu givenMenu; if (null != menuId) { givenMenu = entityDao.get(Menu.class, menuId); family = HierarchyEntityUtil.getFamily(givenMenu); } else {//ww w . j a va2 s . c o m family = null; givenMenu = null; } User user = entityDao.get(User.class, getUserId()); Long categoryId = getUserCategoryId(); List<MenuProfile> profile = getMenuProfile(categoryId); List<Menu> menus = Collections.emptyList(); if (null != profile) { menus = menuService.getMenus(profile, user); } CollectionUtils.filter(menus, new Predicate() { public boolean evaluate(Object object) { Menu amenu = (Menu) object; if (null != family && !family.contains(amenu)) return false; if (StringUtils.isNotEmpty(name)) { if (!amenu.getChildren().isEmpty()) return false; StringBuilder searchTarget = new StringBuilder( StrUtils.concat(amenu.getName(), amenu.getTitle(), amenu.getRemark())); for (Resource res : amenu.getResources()) { searchTarget.append(StrUtils.concat(res.getName(), res.getTitle(), res.getRemark())); } return searchTarget.toString().contains(name); } else return true; } }); if (StringUtils.isNotEmpty(name)) { HierarchyEntityUtil.addParent(menus, givenMenu); Collections.sort(menus); } List<Menu> menuPath = CollectUtils.newArrayList(); if (null != givenMenu) { // menus.retainAll(family); menus.remove(givenMenu); menuPath = HierarchyEntityUtil.getPath(givenMenu); } put("menuPath", menuPath); put("menus", menus); put("tops", HierarchyEntityUtil.getRoots(menus)); return forward(); }
From source file:org.broadleafcommerce.core.catalog.domain.CategoryImpl.java
@Override public List<CategorySearchFacet> getCumulativeSearchFacets() { List<CategorySearchFacet> returnCategoryFacets = new ArrayList<CategorySearchFacet>(); returnCategoryFacets.addAll(getSearchFacets()); Collections.sort(returnCategoryFacets, facetPositionComparator); final Collection<SearchFacet> facets = CollectionUtils.collect(returnCategoryFacets, new Transformer() { @Override/* w w w . j a v a 2 s . c om*/ public Object transform(Object input) { return ((CategorySearchFacet) input).getSearchFacet(); } }); // Add in parent facets unless they are excluded List<CategorySearchFacet> parentFacets = null; if (defaultParentCategory != null) { parentFacets = defaultParentCategory.getCumulativeSearchFacets(); CollectionUtils.filter(parentFacets, new Predicate() { @Override public boolean evaluate(Object arg) { CategorySearchFacet csf = (CategorySearchFacet) arg; return !getExcludedSearchFacets().contains(csf.getSearchFacet()) && !facets.contains(csf.getSearchFacet()); } }); } if (parentFacets != null) { returnCategoryFacets.addAll(parentFacets); } return returnCategoryFacets; }
From source file:org.broadleafcommerce.openadmin.web.service.FormBuilderServiceImpl.java
@Override public EntityForm buildMapForm(MapMetadata mapMd, final MapStructure mapStructure, ClassMetadata cmd, String parentId, EntityForm ef) throws ServiceException { ForeignKey foreignKey = (ForeignKey) mapMd.getPersistencePerspective().getPersistencePerspectiveItems() .get(PersistencePerspectiveItemType.FOREIGNKEY); ef.setEntityType(foreignKey.getForeignKeyClass()); Field keyField;/*from w w w.j a v a 2s .c o m*/ if (!mapMd.getForceFreeFormKeys()) { // We will use a combo field to render the key choices ComboField temp = new ComboField(); temp.withName("key").withFieldType("combo_field").withFriendlyName("Key"); if (mapMd.getKeys() != null) { // The keys can be explicitly set in the annotation... temp.setOptions(mapMd.getKeys()); } else { // Or they could be based on a different entity PersistencePackageRequest ppr = PersistencePackageRequest.standard() .withCeilingEntityClassname(mapMd.getMapKeyOptionEntityClass()); DynamicResultSet drs = adminEntityService.getRecords(ppr).getDynamicResultSet(); for (Entity entity : drs.getRecords()) { String keyValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityValueField()).getValue(); String keyDisplayValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityDisplayField()) .getValue(); temp.putOption(keyValue, keyDisplayValue); } } keyField = temp; } else { keyField = new Field().withName("key").withFieldType(SupportedFieldType.STRING.toString()) .withFriendlyName("Key"); } keyField.setRequired(true); ef.addMapKeyField(keyField); // Set the fields for this form List<Property> mapFormProperties; if (mapMd.isSimpleValue()) { ef.setIdProperty("key"); mapFormProperties = new ArrayList<Property>(); Property valueProp = cmd.getPMap().get("value"); mapFormProperties.add(valueProp); } else { mapFormProperties = new ArrayList<Property>(Arrays.asList(cmd.getProperties())); CollectionUtils.filter(mapFormProperties, new Predicate() { @Override public boolean evaluate(Object object) { Property p = (Property) object; return ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), mapStructure.getValueClassName()); } }); } setEntityFormFields(ef, mapFormProperties); Field f = new Field().withName("priorKey").withFieldType(SupportedFieldType.HIDDEN.toString()); ef.addHiddenField(f); ef.setParentId(parentId); return ef; }
From source file:org.brushingbits.jnap.common.bean.cloning.BeanCloner.java
private Collection<?> cloneCollection(Collection<?> collection, Class<?> type) { Collection<Object> collectionCopy = (Collection<Object>) BeanUtils.instantiate(type); for (Object item : collection) { collectionCopy.add(clone(item)); }/*from w w w.jav a 2s.c om*/ CollectionUtils.filter(collectionCopy, PredicateUtils.notNullPredicate()); if (collectionCopy.isEmpty()) { collectionCopy = null; } return collectionCopy; }
From source file:org.dasein.cloud.azure.network.AzureIpAddressSupport.java
/** * Removes the specified forwarding rule from the address with which it is associated. * * @param ruleId the rule to be removed/* www . j a v a 2s . co m*/ * @throws org.dasein.cloud.InternalException an internal error occurred inside the Dasein Cloud implementation * @throws org.dasein.cloud.CloudException an error occurred processing the request in the cloud * @throws org.dasein.cloud.OperationNotSupportedException this cloud provider does not support address forwarding */ @Override public void stopForwardToServer(@Nonnull final String ruleId, @Nonnull String serverId) throws InternalException, CloudException { PersistentVMRoleModel persistentVMRoleModel = getVMRole(serverId); if (persistentVMRoleModel == null) throw new InternalException("Cannot find Azure virtual machine with id: " + serverId); CollectionUtils.filter(persistentVMRoleModel.getConfigurationSets().get(0).getInputEndpoints(), new Predicate() { @Override public boolean evaluate(Object object) { return ((PersistentVMRoleModel.InputEndpoint) object).getName() .equalsIgnoreCase(ruleId) == false; } }); updateVMRole(serverId, persistentVMRoleModel); }
From source file:org.dasein.cloud.azure.platform.AzureSqlDatabaseSupport.java
@Override public Iterable<Database> listDatabases() throws CloudException, InternalException { ArrayList<Database> databases = new ArrayList<Database>(); HttpUriRequest httpUriRequest = new AzureSQLDatabaseSupportRequests(this.provider).listServersNonGen() .build();//w ww.j av a 2s.c om ServersModel serversModel = new AzureRequester(provider, httpUriRequest) .withXmlProcessor(ServersModel.class).execute(); if (serversModel == null || serversModel.getServers() == null) return databases; List<ServerModel> servers = serversModel.getServers(); CollectionUtils.filter(servers, new Predicate() { @Override public boolean evaluate(Object object) { return provider.getContext().getRegionId().equalsIgnoreCase(((ServerModel) object).getLocation()); } }); for (ServerModel serverModel : servers) { HttpUriRequest serverHttpUriRequest = new AzureSQLDatabaseSupportRequests(this.provider) .listDatabases(serverModel.getName()).build(); DatabaseServiceResourcesModel databaseServiceResourcesModel = new AzureRequester(provider, serverHttpUriRequest).withXmlProcessor(DatabaseServiceResourcesModel.class).execute(); if (databaseServiceResourcesModel == null) continue; for (DatabaseServiceResourceModel databaseModel : databaseServiceResourcesModel .getDatabaseServiceResourceModels()) { if (!databaseModel.getName().equalsIgnoreCase("master")) databases.add(databaseFrom(databaseModel, serverModel.getName())); } } return databases; }
From source file:org.dasein.cloud.azure.platform.AzureSqlDatabaseSupport.java
@Override public Iterable<DatabaseBackup> listBackups(final String forOptionalProviderDatabaseId) throws CloudException, InternalException { final ArrayList<DatabaseBackup> backups = new ArrayList<DatabaseBackup>(); if (forOptionalProviderDatabaseId == null) { HttpUriRequest httpUriRequest = new AzureSQLDatabaseSupportRequests(this.provider).listServers() .build();//w ww . j a va2 s . co m ServerServiceResourcesModel serversModel = new AzureRequester(provider, httpUriRequest) .withXmlProcessor(ServerServiceResourcesModel.class).execute(); if (serversModel == null) return backups; CollectionUtils.forAllDo(serversModel.getServerServiceResourcesModels(), new Closure() { @Override public void execute(Object input) { final ServerServiceResourceModel serverModel = (ServerServiceResourceModel) input; backups.addAll(getBackupsForServer(serverModel.getName())); } }); } else { List<String> providerDBIdParts = Arrays.asList(forOptionalProviderDatabaseId.split(":")); if (providerDBIdParts.size() != 2) throw new InternalException("Invalid provider database id"); final String serverName = providerDBIdParts.get(0); final String databaseName = providerDBIdParts.get(1); backups.addAll(getBackupsForServer(serverName)); CollectionUtils.filter(backups, new Predicate() { @Override public boolean evaluate(Object object) { DatabaseBackup backup = (DatabaseBackup) object; return backup.getProviderDatabaseId() .equalsIgnoreCase(String.format("%s:%s", serverName, databaseName)); } }); } return backups; }
From source file:org.ebayopensource.turmeric.eclipse.ui.views.registry.TypeLibraryContentProvider.java
/** * {@inheritDoc}/*from w ww. j a v a 2 s. c o m*/ */ @Override public Object[] getChildren(Object parentElement) { // this is the root. final List<IRegistryTreeNode> children = new ArrayList<IRegistryTreeNode>(); if (parentElement instanceof TypeTreeRoot) { // first level for (String typeLibraryCategory : UIActivator.getCategories()) { children.add(new CategoryTreeNode(typeLibraryCategory, (TypeTreeRoot) parentElement)); } } else if (parentElement instanceof CategoryTreeNode) { final CategoryTreeNode parentNode = (CategoryTreeNode) parentElement; // this is second level SOATypeRegistry typeRegistry = parentNode.getTypeTreeRoot().getTypeRegistry(); try { final List<TypeLibraryType> libs = typeRegistry.getAllTypeLibraries(); final List<TypeLibraryType> clonedList = new ArrayList<TypeLibraryType>(libs); // filtering out the non category elements CollectionUtils.filter(clonedList, getPredicate(((CategoryTreeNode) parentElement).getCategory())); for (TypeLibraryType type : clonedList) { children.add(new TypeLibraryTreeNode(parentNode, type)); } } catch (Exception e) { SOALogger.getLogger().error(e); } } return children.toArray(); }