List of usage examples for org.apache.commons.collections4 Transformer Transformer
Transformer
From source file:org.apache.syncope.core.workflow.activiti.SyncopeUserQueryImpl.java
private void execute() { if (username != null) { org.apache.syncope.core.persistence.api.entity.user.User user = userDAO.findByUsername(username); if (user == null) { result = Collections.<User>emptyList(); } else if (memberOf == null || userDAO.findAllGroupNames(user).contains(memberOf)) { result = Collections.singletonList(fromSyncopeUser(user)); }/*from w w w. ja v a 2 s. c o m*/ } if (memberOf != null) { Group group = groupDAO.findByName(memberOf); if (group == null) { result = Collections.<User>emptyList(); } else { result = new ArrayList<>(); List<UMembership> memberships = groupDAO.findUMemberships(group); for (UMembership membership : memberships) { User user = fromSyncopeUser(membership.getLeftEnd()); if (!result.contains(user)) { result.add(user); } } } } // THIS CAN BE *VERY* DANGEROUS if (result == null) { result = CollectionUtils.collect(userDAO.findAll(), new Transformer<org.apache.syncope.core.persistence.api.entity.user.User, User>() { @Override public User transform(final org.apache.syncope.core.persistence.api.entity.user.User user) { return fromSyncopeUser(user); } }, new ArrayList<User>()); } }
From source file:org.apache.syncope.fit.core.reference.AuthenticationITCase.java
@Test public void testUserSearch() { UserTO userTO = UserITCase.getUniqueSampleTO("testusersearch@test.org"); userTO.getRoles().add(1L);//w ww . j a va 2 s. c o m userTO = createUser(userTO); assertNotNull(userTO); // 1. user assigned to role 1, with search entitlement on realms /odd and /even: won't find anything with // root realm UserService userService2 = clientFactory.create(userTO.getUsername(), "password123") .getService(UserService.class); PagedResult<UserTO> matchedUsers = userService2 .search(SyncopeClient.getAnySearchQueryBuilder().realm(SyncopeConstants.ROOT_REALM) .fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("key").query()).build()); assertNotNull(matchedUsers); assertFalse(matchedUsers.getResult().isEmpty()); Set<Long> matchedUserKeys = CollectionUtils.collect(matchedUsers.getResult(), new Transformer<UserTO, Long>() { @Override public Long transform(final UserTO input) { return input.getKey(); } }, new HashSet<Long>()); assertTrue(matchedUserKeys.contains(1L)); assertFalse(matchedUserKeys.contains(2L)); assertFalse(matchedUserKeys.contains(5L)); // 2. user assigned to role 4, with search entitlement on realm /even/two UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class); matchedUsers = userService3.search(SyncopeClient.getAnySearchQueryBuilder().realm("/even/two") .fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("loginDate").query()).build()); assertNotNull(matchedUsers); assertTrue(CollectionUtils.matchesAll(matchedUsers.getResult(), new Predicate<UserTO>() { @Override public boolean evaluate(final UserTO matched) { return "/even/two".equals(matched.getRealm()); } })); }
From source file:org.broadleafcommerce.common.i18n.service.TranslationBatchReadCache.java
public static void addToCache(List<Translation> translations) { Collection<Element> translationCacheElements = CollectionUtils.collect(translations, new Transformer<Translation, Element>() { @Override/* w ww.j a v a 2s .co m*/ public Element transform(Translation input) { return new Element(buildCacheKey(input), input); } }); getCache().putAll(translationCacheElements); }
From source file:org.jenkinsci.plugins.drupal.builders.DrupalReviewBuilder.java
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException { // Make sure logs directory exists. File logsDir = new File(build.getWorkspace().getRemote(), logs); if (!logsDir.exists()) { listener.getLogger().println("[DRUPAL] Creating logs directory " + logs); logsDir.mkdir();// w w w.j a v a 2 s . com } // Download and enable Coder if necessary. final File rootDir = new File(build.getWorkspace().getRemote(), root); DrushInvocation drush = new DrushInvocation(new FilePath(rootDir), build.getWorkspace(), launcher, listener, build.getEnvironment(listener)); if (drush.isModuleInstalled("coder", false)) { listener.getLogger().println("[DRUPAL] Coder already exists"); } else { listener.getLogger().println("[DRUPAL] Coder does not exist. Downloading Coder..."); drush.download(CODER_RELEASE, "modules"); } if (drush.isModuleInstalled("coder_review", true)) { listener.getLogger().println("[DRUPAL] Coder is already enabled"); } else { listener.getLogger().println("[DRUPAL] Coder is not enabled. Enabling Coder..."); drush.enable("coder_review"); } Collection<String> reviews = new HashSet<String>(); if (this.style) reviews.add("style"); if (this.comment) reviews.add("comment"); if (this.sql) reviews.add("sql"); if (this.security) reviews.add("security"); if (this.i18n) reviews.add("i18n"); // Remove projects the user wants to exclude. // **/*.info matches all modules, themes and installation profiles. // Installation profiles cannot be reviewed and will be just ignored by Coder. FileSet fileSet = Util.createFileSet(rootDir, "**/*.info", except); DirectoryScanner scanner = fileSet.getDirectoryScanner(); Collection<String> projects = Arrays.asList(scanner.getIncludedFiles()); // Transform sites/all/modules/mymodule/mymodule.module into mymodule. CollectionUtils.transform(projects, new Transformer<String, String>() { @Override public String transform(String project) { return FilenameUtils.getBaseName(project); } }); // Run code review. drush.coderReview(logsDir, reviews, projects, ignoresPass); return true; }
From source file:org.killbill.billing.plugin.simpletax.internal.TaxCodeService.java
/** * Enumerate configured tax codes for the items of a given invoice. The * order of configured tax codes is preserved. * <p>/*from ww w . j a v a 2s . co m*/ * Final resolution is not done here because it represents custom logic that * is regulation-dependent. * * @param invoice * the invoice the items of which need to be taxed. * @return An immutable multi-map of unique applicable tax codes, grouped by * the identifiers of their related invoice items. Never * {@code null}, and guaranteed not having any {@code null} values. * @throws NullPointerException * when {@code invoice} is {@code null}. */ @Nonnull public SetMultimap<UUID, TaxCode> resolveTaxCodesFromConfig(Invoice invoice) { ImmutableSetMultimap.Builder<UUID, TaxCode> taxCodesOfInvoiceItems = ImmutableSetMultimap.builder(); // This lazy map helps us in building a cache for the values we've // already met, and allows us an easy-to-understand syntax below. Map<String, Product> productOfPlanName = lazyMap(new HashMap<String, Product>(), new Transformer<String, Product>() { @Override public Product transform(String planName) { try { Plan plan = catalog.get().findCurrentPlan(planName); return plan.getProduct(); } catch (CatalogApiException notFound) { return null; } } }); for (InvoiceItem invoiceItem : invoice.getInvoiceItems()) { String planName = invoiceItem.getPlanName(); if (planName == null) { continue; } Product product = productOfPlanName.get(planName); if (product == null) { continue; } Set<TaxCode> taxCodes = cfg.getConfiguredTaxCodes(product.getName()); if (taxCodes.isEmpty()) { continue; } taxCodesOfInvoiceItems.putAll(invoiceItem.getId(), taxCodes); } return taxCodesOfInvoiceItems.build(); }
From source file:org.molasdin.wbase.collections.list.ExtendedListDecorator.java
@SuppressWarnings("unchecked") public void sort(final String property, Order order) { if (decorated().isEmpty()) { return;//from w ww . jav a 2 s.c om } T item = decorated().get(0); Comparator<T> tmp = null; if (ReflectionHelper.hasFunction(property, item)) { final Transformer<T, Object> transformer = new Transformer<T, Object>() { @Override public Object transform(T o) { return ReflectionHelper.functionValue(property, o); } }; Object val = transformer.transform(item); final boolean isNatural = ReflectionHelper.supportsNaturalOrdering(val); tmp = new Comparator<T>() { @Override public int compare(T o1, T o2) { Object firstResult = transformer.transform(o1); Object secondResult = transformer.transform(o2); if (isNatural) { Comparable f = (Comparable) firstResult; Comparable s = (Comparable) secondResult; return f.compareTo(s); } String f = ConvertUtils.convert(firstResult); String s = ConvertUtils.convert(secondResult); return f.compareTo(s); } }; } else if (PropertyUtils.isReadable(item, property)) { tmp = new BeanComparator(property); } else { throw new RuntimeException("No property"); } Collections.sort(decorated(), tmp); }
From source file:org.peercast.pecaport.NetworkDeviceManager.java
public Collection<NetworkInterfaceInfo.Wifi> getWifiInterfaces() { final WifiInfo activeWifiInfo = mWifiManager.getConnectionInfo(); if (activeWifiInfo == null) return Collections.emptyList(); //Log.d(TAG, "getConfiguredNetworks: "+mWifiManager.getConfiguredNetworks()); return CollectionUtils.collect(mWifiManager.getConfiguredNetworks(), new Transformer<WifiConfiguration, NetworkInterfaceInfo.Wifi>() { @Override//from w ww.j a v a 2 s . com public NetworkInterfaceInfo.Wifi transform(WifiConfiguration config) { return new NetworkInterfaceInfo.Wifi(activeWifiInfo, config); } }); }
From source file:org.peercast.pecaport.PecaPortPreferences.java
public Collection<NetworkIdentity> getAllDisabledNetworks() { Set<String> disabled = getNewStringSet(PREF_DISABLED_NETWORKS); return CollectionUtils.collect(disabled, new Transformer<String, NetworkIdentity>() { @Override//from w w w . ja v a 2 s . co m public NetworkIdentity transform(String input) { return new NetworkIdentity(input); } }); }
From source file:org.settings4j.util.ELConnectorWrapper.java
/** * Usage: <code>${connectors.string['xyz']}</code> returns the first founded Value in all Connectors: * <code>connector.getString("xyz");</code>. * * @return the first founded Value in all connectors *//*from w w w. j a v a 2 s. c o m*/ public Map<String, String> getString() { final Transformer<String, String> transformer = new Transformer<String, String>() { @Override public String transform(final String key) { if (key != null) { for (Connector connector : ELConnectorWrapper.this.connectors) { final String result = connector.getString(key); if (result != null) { return result; } } } return null; } }; return LazyMap.lazyMap(new HashMap<String, String>(), transformer); }
From source file:org.settings4j.util.ELConnectorWrapper.java
/** * Usage: <code>${connectors.content['xyz']}</code> returns the first founded Value in all Connectors: * <code>connector.getContent("xyz");</code>. * * @return the first founded Value in all connectors */// w w w . ja va 2 s . c o m public Map<String, byte[]> getContent() { final Transformer<String, byte[]> transformer = new Transformer<String, byte[]>() { // SuppressWarnings PMD.ReturnEmptyArrayRatherThanNull: returning null for this byte-Arrays is OK. @Override @SuppressWarnings("PMD.ReturnEmptyArrayRatherThanNull") public byte[] transform(final String key) { if (key != null) { for (Connector connector : ELConnectorWrapper.this.connectors) { final byte[] result = connector.getContent(key); if (result != null) { return result; } } } return null; } }; return LazyMap.lazyMap(new HashMap<String, byte[]>(), transformer); }