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));
}
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);
}
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);
}
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;
}
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);
}
});
}
}
Aggregations