Search in sources :

Example 1 with Transformer

use of org.apache.commons.collections.Transformer in project head by mifos.

the class BranchReportStaffingLevelSummaryHelperIntegrationTest method assertStaffingLevelSummaries.

private void assertStaffingLevelSummaries(BranchReportBO branchReport) {
    Set<BranchReportStaffingLevelSummaryBO> staffingLevelSummaries = branchReport.getStaffingLevelSummaries();
    Assert.assertEquals(1, staffingLevelSummaries.size());
    Collection retrievedRolenames = CollectionUtils.collect(staffingLevelSummaries, new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((BranchReportStaffingLevelSummaryBO) input).getTitleName();
        }
    });
    Assert.assertEquals(1, retrievedRolenames.size());
    Assert.assertTrue(retrievedRolenames.contains(BranchReportStaffingLevelSummaryBO.TOTAL_STAFF_ROLE_NAME));
}
Also used : Transformer(org.apache.commons.collections.Transformer) Collection(java.util.Collection) BranchReportStaffingLevelSummaryBO(org.mifos.reports.branchreport.BranchReportStaffingLevelSummaryBO)

Example 2 with Transformer

use of org.apache.commons.collections.Transformer in project head by mifos.

the class BranchReportLoanArrearsAgingHelperIntegrationTest method assertLoanArrearsAgingPopulated.

private void assertLoanArrearsAgingPopulated(Set<BranchReportLoanArrearsAgingBO> loanArrearsAgingSummaries) {
    Assert.assertNotNull(loanArrearsAgingSummaries);
    Collection foundPeriods = CollectionUtils.collect(loanArrearsAgingSummaries, new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((BranchReportLoanArrearsAgingBO) input).getAgingPeriod();
        }
    });
    assertSameCollections(expectedPeriods, foundPeriods);
}
Also used : Transformer(org.apache.commons.collections.Transformer) Collection(java.util.Collection)

Example 3 with Transformer

use of org.apache.commons.collections.Transformer in project sling by apache.

the class ConfigurationBuilderImpl method convert.

@SuppressWarnings("unchecked")
private <T> T convert(final Iterator<Resource> resourceInhertianceChain, final Class<T> clazz, final Converter<T> converter, final String name, final boolean isCollection) {
    Resource configResource = null;
    String conversionName = name;
    if (resourceInhertianceChain != null) {
        // apply persistence transformation
        Iterator<Resource> transformedResources = IteratorUtils.transformedIterator(resourceInhertianceChain, new Transformer() {

            @Override
            public Object transform(Object input) {
                if (isCollection) {
                    return configurationPersistenceStrategy.getCollectionItemResource((Resource) input);
                } else {
                    return configurationPersistenceStrategy.getResource((Resource) input);
                }
            }
        });
        // apply resource inheritance
        configResource = configurationInheritanceStrategy.getResource(transformedResources);
        // apply overrides
        configResource = configurationOverrideMultiplexer.overrideProperties(contentResource.getPath(), name, configResource);
        // build name
        if (configResource != null && isCollection) {
            conversionName = conversionName + "/" + configResource.getName();
        }
    }
    if (log.isTraceEnabled() && configResource != null) {
        log.trace("+ Found config resource for context path " + contentResource.getPath() + ": " + configResource.getPath() + " " + MapUtil.traceOutput(configResource.getValueMap()));
    }
    return converter.convert(configResource, clazz, conversionName, isCollection);
}
Also used : Transformer(org.apache.commons.collections.Transformer) Resource(org.apache.sling.api.resource.Resource)

Example 4 with Transformer

use of org.apache.commons.collections.Transformer in project sling by apache.

the class DefaultConfigurationResourceResolvingStrategy method getResourceInheritanceChainInternal.

@SuppressWarnings("unchecked")
private Iterator<Resource> getResourceInheritanceChainInternal(final Collection<String> bucketNames, final String configName, final Iterator<String> paths, final ResourceResolver resourceResolver) {
    // find all matching items among all configured paths
    Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() {

        @Override
        public Object transform(Object input) {
            String path = (String) input;
            for (String bucketName : bucketNames) {
                final String name = bucketName + "/" + configName;
                final String configPath = buildResourcePath(path, name);
                Resource resource = resourceResolver.getResource(configPath);
                if (resource != null) {
                    log.trace("+ Found matching config resource for inheritance chain: {}", configPath);
                    return resource;
                } else {
                    log.trace("- No matching config resource for inheritance chain: {}", configPath);
                }
            }
            return null;
        }
    });
    Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources, PredicateUtils.notNullPredicate());
    if (result.hasNext()) {
        return result;
    }
    return null;
}
Also used : Transformer(org.apache.commons.collections.Transformer) Resource(org.apache.sling.api.resource.Resource) ContextResource(org.apache.sling.caconfig.resource.spi.ContextResource)

Example 5 with Transformer

use of org.apache.commons.collections.Transformer in project sling by apache.

the class ContentFileResourceMapper method getChildren.

@SuppressWarnings("unchecked")
@Override
public Iterator<Resource> getChildren(final ResourceResolver resolver, final Resource parent) {
    if (contentFileExtensions.isEmpty()) {
        return null;
    }
    final String parentPath = parent.getPath();
    ContentFile parentContentFile = parent.adaptTo(ContentFile.class);
    // not a FsResource, try to create one from the resource
    if (parentContentFile == null) {
        parentContentFile = getFile(parentPath, null);
        if (parentContentFile == null) {
            // check if parent is a file resource that contains a file content resource
            File parentFile = parent.adaptTo(File.class);
            if (parentFile != null && parentFile.isDirectory()) {
                List<Resource> childResources = new ArrayList<>();
                for (File file : parentFile.listFiles()) {
                    String filenameSuffix = contentFileExtensions.getSuffix(file);
                    if (filenameSuffix != null && !isNodeDescriptor(file)) {
                        String path = parentPath + "/" + StringUtils.substringBeforeLast(file.getName(), filenameSuffix);
                        ContentFile contentFile = new ContentFile(file, path, null, contentFileCache);
                        childResources.add(new ContentFileResource(resolver, contentFile));
                    }
                }
                if (!childResources.isEmpty()) {
                    return childResources.iterator();
                }
            }
            // no children here
            return null;
        }
    }
    // get child resources from content fragments in content file
    List<ContentFile> children = new ArrayList<>();
    if (parentContentFile.hasContent()) {
        Iterator<Map.Entry<String, ContentElement>> childMaps = parentContentFile.getChildren();
        while (childMaps.hasNext()) {
            Map.Entry<String, ContentElement> entry = childMaps.next();
            children.add(parentContentFile.navigateToRelative(entry.getKey()));
        }
    }
    if (children.isEmpty()) {
        return null;
    } else {
        return IteratorUtils.transformedIterator(children.iterator(), new Transformer() {

            @Override
            public Object transform(Object input) {
                ContentFile contentFile = (ContentFile) input;
                return new ContentFileResource(resolver, contentFile);
            }
        });
    }
}
Also used : Transformer(org.apache.commons.collections.Transformer) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) ContentElement(org.apache.sling.fsprovider.internal.parser.ContentElement) File(java.io.File) Map(java.util.Map)

Aggregations

Transformer (org.apache.commons.collections.Transformer)38 ChainedTransformer (org.apache.commons.collections.functors.ChainedTransformer)20 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)16 SearchControls (javax.naming.directory.SearchControls)16 DefaultLdapUserRoleListService (org.pentaho.platform.plugin.services.security.userrole.ldap.DefaultLdapUserRoleListService)16 GenericLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.GenericLdapSearch)16 LdapSearchParamsFactoryImpl (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactoryImpl)16 SearchResultToAttrValueList (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.SearchResultToAttrValueList)16 LdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearch)13 LdapSearchParamsFactory (org.pentaho.platform.plugin.services.security.userrole.ldap.search.LdapSearchParamsFactory)13 UnionizingLdapSearch (org.pentaho.platform.plugin.services.security.userrole.ldap.search.UnionizingLdapSearch)13 List (java.util.List)11 Map (java.util.Map)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 ConstantTransformer (org.apache.commons.collections.functors.ConstantTransformer)5 GrantedAuthorityToString (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.GrantedAuthorityToString)5 StringToGrantedAuthority (org.pentaho.platform.plugin.services.security.userrole.ldap.transform.StringToGrantedAuthority)5 Resource (org.apache.sling.api.resource.Resource)4