org.apache.commons.collections.PredicateUtils Java Examples

The following examples show how to use org.apache.commons.collections.PredicateUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AgentInfoServiceImpl.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public Set<AgentInfo> getAgentsByApplicationNameWithoutStatus(String applicationName, long timestamp) {
    if (applicationName == null) {
        throw new NullPointerException("applicationName");
    }
    if (timestamp < 0) {
        throw new IllegalArgumentException("timestamp must not be less than 0");
    }

    List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
    List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIds, timestamp);
    CollectionUtils.filter(agentInfos, PredicateUtils.notNullPredicate());
    if (CollectionUtils.isEmpty(agentInfos)) {
        return Collections.emptySet();
    }
    return new HashSet<>(agentInfos);
}
 
Example #2
Source File: SearchProcessor.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected Predicate buildTraitPredict(Set<AtlasClassificationType> classificationTypes) {
    Predicate traitPredicate;
    AtlasClassificationType classificationType = null;
    if (CollectionUtils.isNotEmpty(classificationTypes)) {
        classificationType = classificationTypes.iterator().next();
    }

    if (classificationType == MATCH_ALL_CLASSIFICATION_TYPES) {
        traitPredicate = PredicateUtils.orPredicate(SearchPredicateUtil.getNotEmptyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY, null, List.class),
            SearchPredicateUtil.getNotEmptyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, null, List.class));
    } else if (classificationType == MATCH_ALL_NOT_CLASSIFIED) {
        traitPredicate = PredicateUtils.andPredicate(SearchPredicateUtil.getIsNullOrEmptyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY, null, List.class),
            SearchPredicateUtil.getIsNullOrEmptyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, null, List.class));
    } else if (context.isWildCardSearch()) {
        //For wildcard search __classificationNames which of String type is taken instead of _traitNames which is of Array type
        Set<String> classificationNames = context.getClassificationNames();
        List<Predicate> predicates = new ArrayList<>();

        classificationNames.forEach(classificationName -> {
            //No need to escape, as classification Names only support letters,numbers,space and underscore
            String regexString = getRegexString("\\|" + classificationName + "\\|");
            predicates.add(SearchPredicateUtil.getRegexPredicateGenerator().generatePredicate(CLASSIFICATION_NAMES_KEY, regexString, String.class));
            predicates.add(SearchPredicateUtil.getRegexPredicateGenerator().generatePredicate(PROPAGATED_CLASSIFICATION_NAMES_KEY, regexString, String.class));
        });

        traitPredicate = PredicateUtils.anyPredicate(predicates);
    } else {
        traitPredicate = PredicateUtils.orPredicate(SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(TRAIT_NAMES_PROPERTY_KEY, context.getClassificationTypeNames(), List.class),
            SearchPredicateUtil.getContainsAnyPredicateGenerator().generatePredicate(PROPAGATED_TRAIT_NAMES_PROPERTY_KEY, context.getClassificationTypeNames(), List.class));
    }
    return traitPredicate;
}
 
Example #3
Source File: FilterUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) {
    List<Predicate> predicates = new ArrayList<>();

    final String type         = searchFilter.getParam(SearchFilter.PARAM_TYPE);
    final String name         = searchFilter.getParam(SearchFilter.PARAM_NAME);
    final String supertype    = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
    final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);

    // Add filter for the type/category
    if (StringUtils.isNotBlank(type)) {
        predicates.add(getTypePredicate(type));
    }

    // Add filter for the name
    if (StringUtils.isNotBlank(name)) {
        predicates.add(getNamePredicate(name));
    }

    // Add filter for the supertype
    if (StringUtils.isNotBlank(supertype)) {
        predicates.add(getSuperTypePredicate(supertype));
    }

    // Add filter for the supertype negation
    if (StringUtils.isNotBlank(notSupertype)) {
        predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype)));
    }

    return PredicateUtils.allPredicate(predicates);
}
 
Example #4
Source File: FilterUtil.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static Predicate getPredicateFromSearchFilter(SearchFilter searchFilter) {
    List<Predicate> predicates = new ArrayList<>();

    final String       type           = searchFilter.getParam(SearchFilter.PARAM_TYPE);
    final String       name           = searchFilter.getParam(SearchFilter.PARAM_NAME);
    final String       supertype      = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
    final String       serviceType    = searchFilter.getParam(SearchFilter.PARAM_SERVICETYPE);
    final String       notSupertype   = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);
    final String       notServiceType = searchFilter.getParam(SearchFilter.PARAM_NOT_SERVICETYPE);
    final List<String> notNames       = searchFilter.getParams(SearchFilter.PARAM_NOT_NAME);

    // Add filter for the type/category
    if (StringUtils.isNotBlank(type)) {
        predicates.add(getTypePredicate(type));
    }

    // Add filter for the name
    if (StringUtils.isNotBlank(name)) {
        predicates.add(getNamePredicate(name));
    }

    // Add filter for the serviceType
    if(StringUtils.isNotBlank(serviceType)) {
        predicates.add(getServiceTypePredicate(serviceType));
    }

    // Add filter for the supertype
    if (StringUtils.isNotBlank(supertype)) {
        predicates.add(getSuperTypePredicate(supertype));
    }

    // Add filter for the supertype negation
    if (StringUtils.isNotBlank(notSupertype)) {
        predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype)));
    }

    // Add filter for the serviceType negation
    // NOTE: Creating code for the exclusion of multiple service types is currently useless.
    // In fact the getSearchFilter in TypeREST.java uses the HttpServletRequest.getParameter(key)
    // that if the key takes more values it takes only the first the value. Could be useful
    // to change the getSearchFilter to use getParameterValues instead of getParameter.
    if (StringUtils.isNotBlank(notServiceType)) {
        predicates.add(new NotPredicate(getServiceTypePredicate(notServiceType)));
    }


    // Add filter for the type negation
    if (CollectionUtils.isNotEmpty(notNames)) {
        for (String notName : notNames) {
            predicates.add(new NotPredicate(getNamePredicate(notName)));
        }
    }

    return PredicateUtils.allPredicate(predicates);
}
 
Example #5
Source File: HibernateXmlConverter.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param writer
 * @param includeHistory
 * @param session
 * @throws DataAccessException
 * @throws HibernateException
 */
private void writeObjects(final Writer writer, final boolean includeHistory, final Session session, final boolean preserveIds)
    throws DataAccessException, HibernateException
    {
  // Container für die Objekte
  final List<Object> all = new ArrayList<Object>();
  final XStream stream = initXStream(session, true);
  final XStream defaultXStream = initXStream(session, false);

  session.flush();
  // Alles laden
  final List<Class< ? >> entities = new ArrayList<Class< ? >>();
  entities.addAll(HibernateEntities.instance().getOrderedEntities());
  entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities());
  for (final Class< ? > entityClass : entities) {
    final String entitySimpleName = entityClass.getSimpleName();
    final String entityType = entityClass.getName();
    if (includeHistory == false && entityType.startsWith("de.micromata.hibernate.history.") == true) {
      // Skip history entries.
      continue;
    }
    List< ? > list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list();
    list = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
    final int size = list.size();
    log.info("Writing " + size + " objects");
    for (final Iterator< ? > it = list.iterator(); it.hasNext();) {
      final Object obj = it.next();
      if (log.isDebugEnabled()) {
        log.debug("loaded object " + obj);
      }
      Hibernate.initialize(obj);
      final Class< ? > targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
      final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass);
      if (classMetadata == null) {
        log.fatal("Can't init " + obj + " of type " + targetClass);
        continue;
      }
      // initalisierung des Objekts...
      defaultXStream.marshal(obj, new CompactWriter(new NullWriter()));

      if (preserveIds == false) {
        // Nun kann die ID gelöscht werden
        classMetadata.setIdentifier(obj, null, EntityMode.POJO);
      }
      if (log.isDebugEnabled()) {
        log.debug("loading evicted object " + obj);
      }
      if (this.ignoreFromTopLevelListing.contains(targetClass) == false) {
        all.add(obj);
      }
    }
  }
  // und schreiben
  try {
    writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
  } catch (final IOException ex) {
    // ignore, will fail on stream.marshal()
  }
  log.info("Wrote " + all.size() + " objects");
  final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy();
  stream.setMarshallingStrategy(marshallingStrategy);
  stream.marshal(all, new PrettyPrintWriter(writer));
    }
 
Example #6
Source File: LoginDefaultHandler.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
protected List< ? > selectUnique(final List< ? > list)
{
  final List< ? > result = (List< ? >) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
  return result;
}
 
Example #7
Source File: BaseDao.java    From projectforge-webapp with GNU General Public License v3.0 4 votes vote down vote up
protected List<O> selectUnique(final List<O> list)
{
  @SuppressWarnings("unchecked")
  final List<O> result = (List<O>) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
  return result;
}
 
Example #8
Source File: KmsKeyMgr.java    From ranger with Apache License 2.0 3 votes vote down vote up
private Predicate getPredicate(KeySearchFilter filter) {
	if(filter == null || filter.isEmpty()) {
		return null;
	}

	List<Predicate> predicates = new ArrayList<Predicate>();

	addPredicateForKeyName(filter.getParam(KeySearchFilter.KEY_NAME), predicates);
	
	Predicate ret = CollectionUtils.isEmpty(predicates) ? null : PredicateUtils.allPredicate(predicates);

	return ret;
}
 
Example #9
Source File: AbstractPredicateUtil.java    From ranger with Apache License 2.0 3 votes vote down vote up
public Predicate getPredicate(SearchFilter filter) {
	if(filter == null || filter.isEmpty()) {
		return null;
	}

	List<Predicate> predicates = new ArrayList<>();
	
	addPredicates(filter, predicates);

	Predicate ret = CollectionUtils.isEmpty(predicates) ? null : PredicateUtils.allPredicate(predicates);

	return ret;
}