Search in sources :

Example 21 with Predicate

use of org.apache.commons.collections.Predicate in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method searchTypesDef.

@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
    for (AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }
    for (AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }
    for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }
    for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }
    return typesDef;
}
Also used : AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Predicate(org.apache.commons.collections.Predicate)

Example 22 with Predicate

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

the class DefaultConfigurationResourceResolvingStrategy method findConfigRefs.

/**
     * Searches the resource hierarchy upwards for all config references and returns them.
     * @param refs List to add found resources to
     * @param startResource Resource to start searching
     */
@SuppressWarnings("unchecked")
private Iterator<String> findConfigRefs(final Resource startResource, final Collection<String> bucketNames) {
    // collect all context path resources (but filter out those without config reference)
    final Iterator<ContextResource> contextResources = new FilterIterator(contextPathStrategy.findContextResources(startResource), new Predicate() {

        @Override
        public boolean evaluate(Object object) {
            ContextResource contextResource = (ContextResource) object;
            return StringUtils.isNotBlank(contextResource.getConfigRef());
        }
    });
    // get config resource path for each context resource, filter out items where not reference could be resolved
    final Iterator<String> configPaths = new Iterator<String>() {

        private final List<ContextResource> relativePaths = new ArrayList<>();

        private String next = seek();

        private String useFromRelativePathsWith;

        private String seek() {
            String val = null;
            while (val == null && (useFromRelativePathsWith != null || contextResources.hasNext())) {
                if (useFromRelativePathsWith != null) {
                    final ContextResource contextResource = relativePaths.remove(relativePaths.size() - 1);
                    val = checkPath(contextResource, useFromRelativePathsWith + "/" + contextResource.getConfigRef(), bucketNames);
                    if (val != null) {
                        log.trace("+ Found reference for context path {}: {}", contextResource.getResource().getPath(), val);
                    }
                    if (relativePaths.isEmpty()) {
                        useFromRelativePathsWith = null;
                    }
                } else {
                    final ContextResource contextResource = contextResources.next();
                    val = contextResource.getConfigRef();
                    // if absolute path found we are (probably) done
                    if (val != null && val.startsWith("/")) {
                        val = checkPath(contextResource, val, bucketNames);
                    }
                    if (val != null) {
                        final boolean isAbsolute = val.startsWith("/");
                        if (isAbsolute && !relativePaths.isEmpty()) {
                            useFromRelativePathsWith = val;
                            val = null;
                        } else if (!isAbsolute) {
                            relativePaths.add(0, contextResource);
                            val = null;
                        }
                    }
                    if (val != null) {
                        log.trace("+ Found reference for context path {}: {}", contextResource.getResource().getPath(), val);
                    }
                }
            }
            if (val == null && !relativePaths.isEmpty()) {
                log.error("Relative references not used as no absolute reference was found: {}", relativePaths);
            }
            return val;
        }

        @Override
        public boolean hasNext() {
            return next != null;
        }

        @Override
        public String next() {
            if (next == null) {
                throw new NoSuchElementException();
            }
            final String result = next;
            next = seek();
            return result;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
    // expand paths and eliminate duplicates
    return new PathEliminateDuplicatesIterator(new PathParentExpandIterator(config.configPath(), configPaths));
}
Also used : Predicate(org.apache.commons.collections.Predicate) ContextResource(org.apache.sling.caconfig.resource.spi.ContextResource) PathEliminateDuplicatesIterator(org.apache.sling.caconfig.resource.impl.util.PathEliminateDuplicatesIterator) PathEliminateDuplicatesIterator(org.apache.sling.caconfig.resource.impl.util.PathEliminateDuplicatesIterator) Iterator(java.util.Iterator) ArrayIterator(org.apache.commons.collections.iterators.ArrayIterator) PathParentExpandIterator(org.apache.sling.caconfig.resource.impl.util.PathParentExpandIterator) FilterIterator(org.apache.commons.collections.iterators.FilterIterator) FilterIterator(org.apache.commons.collections.iterators.FilterIterator) ArrayList(java.util.ArrayList) List(java.util.List) PathParentExpandIterator(org.apache.sling.caconfig.resource.impl.util.PathParentExpandIterator) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Predicate (org.apache.commons.collections.Predicate)22 ArrayList (java.util.ArrayList)9 LoanAccountDetailsDto (org.mifos.dto.domain.LoanAccountDetailsDto)3 Iterator (java.util.Iterator)2 List (java.util.List)2 Resource (org.apache.sling.api.resource.Resource)2 MultiInstanceofPredicate (org.jumpmind.db.util.MultiInstanceofPredicate)2 LoanBO (org.mifos.accounts.loan.business.LoanBO)2 RestParameter (com.iggroup.oss.restdoclet.doclet.type.RestParameter)1 Uri (com.iggroup.oss.restdoclet.doclet.type.Uri)1 NameValuePair (com.iggroup.oss.restdoclet.doclet.util.NameValuePair)1 ParameterNamePredicate (com.iggroup.oss.restdoclet.doclet.util.ParameterNamePredicate)1 RequestMappingParamsParser (com.iggroup.oss.restdoclet.doclet.util.RequestMappingParamsParser)1 AnnotationValue (com.sun.javadoc.AnnotationValue)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 DependencyMaterialInstance (com.thoughtworks.go.domain.materials.dependency.DependencyMaterialInstance)1 File (java.io.File)1 WeakReference (java.lang.ref.WeakReference)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1