org.molgenis.data.Query.getRules()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.molgenis.data.Query.getRules方法的一些代码示例,展示了Query.getRules的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getRules方法的具体详情如下:
包路径:org.molgenis.data.Query
类名称:Query
方法名:getRules

Query.getRules介绍

暂无

代码示例

代码示例来源:origin: org.molgenis/molgenis-data-validation

/**
 * Validates query based on the given entity type, converts query values to the expected type if
 * necessary.
 *
 * @param query query
 * @param entityType entity type
 * @throws MolgenisValidationException if query is invalid
 */
public void validate(Query<? extends Entity> query, EntityType entityType) {
 query.getRules().forEach(queryRule -> validateQueryRule(queryRule, entityType));
}

代码示例来源:origin: org.molgenis/molgenis-data-postgresql

private static <E extends Entity> List<Attribute> getJoinQueryAttrs(
  EntityType entityType, Query<E> q) {
 List<Attribute> joinAttrs = Lists.newArrayList();
 getJoinQueryAttrsRec(entityType, q.getRules(), joinAttrs);
 return joinAttrs;
}

代码示例来源:origin: org.molgenis/molgenis-data-annotators

@Override
public Stream<Entity> findAll(Query<Entity> q)
{
  if (q.getRules().isEmpty()) return getIndex().values().stream();
  if ((q.getRules().size() != 1) || (q.getRules().get(0).getOperator() != Operator.EQUALS) || !targetAttributeName
      .equals(q.getRules().get(0).getField()))
  {
    throw new MolgenisDataException(
        "The only query allowed on this Repository is '" + targetAttributeName + " EQUALS'");
  }
  Entity result = getIndex().get(q.getRules().get(0).getValue());
  return result == null ? Stream.empty() : Stream.of(result);
}

代码示例来源:origin: org.molgenis/molgenis-data-annotators

@Override
public Stream<Entity> findAll(Query<Entity> q)
{
  if (q.getRules().isEmpty()) return getEntities().stream();
  if ((q.getRules().size() != 1) || (q.getRules().get(0).getOperator() != Operator.EQUALS))
  {
    throw new MolgenisDataException("The only query allowed on this Repository is gene EQUALS");
  }
  String geneSymbol = (String) q.getRules().get(0).getValue();
  List<Entity> entities = getEntitiesByGeneSymbol().get(geneSymbol);
  return entities != null ? entities.stream() : Stream.empty();
}

代码示例来源:origin: org.molgenis/molgenis-data-postgresql

/**
 * Determines whether a distinct select is required based on a given query.
 *
 * @param entityType entity meta data
 * @param q query
 * @param <E> entity type
 * @return <code>true</code> if a distinct select is required for SQL queries based on the given
 *     query
 * @throws UnknownAttributeException if query field refers to an attribute that does not exist in
 *     entity meta
 */
private static <E extends Entity> boolean isDistinctSelectRequired(
  EntityType entityType, Query<E> q) {
 return isDistinctSelectRequiredRec(entityType, q.getRules());
}

代码示例来源:origin: org.molgenis/molgenis-data-annotators

private static Optional<Object> getFirstEqualsValueFor(String attributeName, Query<Entity> q)
{
  return q.getRules()
      .stream()
      .filter(rule -> attributeName.equals(rule.getField()))
      .filter(rule -> rule.getOperator() == QueryRule.Operator.EQUALS)
      .findFirst()
      .map(QueryRule::getValue);
}

代码示例来源:origin: org.molgenis/molgenis-data-icd10

@Override
public Query<Entity> transformQuery(
  Query<Entity> query, String icd10EntityTypeId, String expandAttribute) {
 if (query != null && query.getRules() != null && !query.getRules().isEmpty()) {
  query
    .getRules()
    .forEach(
      rule ->
        Streams.stream(RULE_TRAVERSER.depthFirstPreOrder(rule))
          .filter(nestedRule -> isTransformableRule(nestedRule, expandAttribute))
          .forEach(nestedRule -> transformQueryRule(nestedRule, icd10EntityTypeId)));
 }
 return query;
}

代码示例来源:origin: org.molgenis/molgenis-data-annotators

private static Object getFirstEqualsValueFor(String attributeName, Query<Entity> q)
{
  return q.getRules().stream().filter(rule -> attributeName.equals(rule.getField())).findFirst().get().getValue();
}

代码示例来源:origin: org.molgenis/molgenis-data-annotators

@Override
public Stream<Entity> findAll(Query<Entity> q)
{
  if (q.getRules().isEmpty())
  {
    return getEntities().stream();
  }
  if ((q.getRules().size() != 1) || (q.getRules().get(0).getOperator() != Operator.EQUALS))
  {
    throw new MolgenisDataException("The only query allowed on this Repository is gene EQUALS");
  }
  String geneSymbol = (String) q.getRules().get(0).getValue();
  List<Entity> entities = getEntitiesByGeneSymbol().get(geneSymbol);
  return entities != null ? entities.stream() : Stream.empty();
}

代码示例来源:origin: org.molgenis/molgenis-data-annotators

/**
 * Examines a {@link Query} and finds the first {@link QueryRule} with operator {@link Operator#EQUALS} whose field
 * matches an attributeName. It returns the value of that first matching {@link QueryRule}.
 *
 * @param attributeName the query field name to match
 * @param q             the query to search in
 * @return the value from the first matching query rule
 */
private static Object getFirstEqualsValueFor(String attributeName, Query<Entity> q)
{
  return q.getRules()
      .stream()
      .filter(rule -> attributeName.equals(rule.getField()) && rule.getOperator() == Operator.EQUALS)
      .findFirst()
      .get()
      .getValue();
}

代码示例来源:origin: org.molgenis/molgenis-omx-biobankconnect

@RequestMapping(method = RequestMethod.POST, value = "/getmapping", produces = APPLICATION_JSON_VALUE)
@ResponseBody
public SearchResult getMappings(@RequestBody
Map<String, Object> request)
{
  if (request.get("dataSetIdentifier") == null) return new SearchResult("dataSetId cannot be null!");
  Object dataSetIdentifier = request.get("dataSetIdentifier");
  Object featureIds = request.get("featureIds");
  Query query = new QueryImpl();
  if (featureIds != null && !featureIds.toString().isEmpty())
  {
    if (query.getRules().size() > 0) query.or();
    for (Object featureId : (List<?>) featureIds)
    {
      query.eq(AsyncOntologyMatcher.STORE_MAPPING_FEATURE, featureId.toString());
    }
  }
  return searchService.search(new SearchRequest(dataSetIdentifier.toString(), query, null));
}

代码示例来源:origin: org.molgenis/molgenis-data-postgresql

/**
 * Produces SQL to count the number of entities that match the given query. Ignores query offset
 * and pagesize.
 *
 * @param q query
 * @param parameters prepared statement parameters
 * @return SQL string
 */
static <E extends Entity> String getSqlCount(
  EntityType entityType, Query<E> q, List<Object> parameters) {
 StringBuilder sqlBuilder = new StringBuilder("SELECT COUNT");
 String idAttribute = getColumnName(entityType.getIdAttribute());
 List<QueryRule> queryRules = q.getRules();
 if (queryRules == null || queryRules.isEmpty()) {
  sqlBuilder.append("(*) FROM ").append(getTableName(entityType));
 } else {
  boolean distinctSelectRequired = isDistinctSelectRequired(entityType, q);
  if (distinctSelectRequired) {
   // distinct count in case query contains one or more rules referring to MREF attributes.
   sqlBuilder.append("(DISTINCT this.").append(idAttribute).append(')');
  } else {
   sqlBuilder.append("(*)");
  }
  String from = getSqlFrom(entityType, q);
  String where = getSqlWhere(entityType, q, parameters, new AtomicInteger());
  sqlBuilder.append(from).append(" WHERE ").append(where);
 }
 return sqlBuilder.toString();
}

代码示例来源:origin: org.molgenis/molgenis-omx-biobankconnect

@Override
public Iterable<Entity> findAll(Query q)
{
  List<Entity> entities = new ArrayList<Entity>();
  if (q.getRules().size() > 0) q.and();
  q.eq(OntologyIndexRepository.ENTITY_TYPE, OntologyIndexRepository.TYPE_ONTOLOGY);
  for (Hit hit : searchService.search(new SearchRequest(null, q, null)).getSearchHits())
  {
    entities.add(new OntologyEntity(hit, getEntityMetaData(), ontologySerivce, searchService));
  }
  return entities;
}

代码示例来源:origin: org.molgenis/molgenis-data-rest

public Query<Entity> parseQueryString(Map<String, String[]> parameterMap) {
  QueryImpl<Entity> q = new QueryImpl<>();

  for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
   String paramName = entry.getKey();
   String[] paramValues = entry.getValue();

   if ((paramValues != null) && (paramValues.length > 0) && (paramValues[0] != null)) {
    if (paramName.equalsIgnoreCase("num")) {
     q.pageSize(DataConverter.toInt(paramValues[0]));
    } else if (paramName.equalsIgnoreCase("start")) {
     q.offset(DataConverter.toInt(paramValues[0]));
    } else if (paramName.equalsIgnoreCase("q")) {
     Query<Entity> query = molgenisRSQL.createQuery(paramValues[0], entityType);
     for (QueryRule rule : query.getRules()) {
      q.addRule(rule);
     }
    }
   }
  }

  return q;
 }
}

代码示例来源:origin: org.molgenis/molgenis-omx-biobankconnect

@Override
public Entity findOne(Query q)
{
  if (q.getRules().size() > 0) q.and();
  q.eq(OntologyIndexRepository.ENTITY_TYPE, OntologyIndexRepository.TYPE_ONTOLOGY);
  Hit hit = findOneInternal(null, q);
  if (hit != null) return new OntologyEntity(hit, getEntityMetaData(), ontologySerivce, searchService);
  return null;
}

代码示例来源:origin: org.molgenis/molgenis-omx-biobankconnect

@Override
public long count(Query q)
{
  if (q.getRules().size() > 0)
  {
    q.and();
  }
  q.eq(OntologyIndexRepository.ENTITY_TYPE, OntologyIndexRepository.TYPE_ONTOLOGY);
  return searchService.count(null, q.pageSize(Integer.MAX_VALUE).offset(Integer.MIN_VALUE));
}

代码示例来源:origin: org.molgenis/molgenis-omx-biobankconnect

@Override
public Entity findOne(Query q)
{
  if (q.getRules().size() > 0) q.and();
  q.eq(OntologyTermIndexRepository.ENTITY_TYPE, OntologyTermIndexRepository.TYPE_ONTOLOGYTERM);
  Hit hit = findOneInternal(AsyncOntologyIndexer.createOntologyTermDocumentType(ontologyIri), q);
  return hit != null ? new OntologyTermEntity(hit, getEntityMetaData(), searchService) : null;
}

代码示例来源:origin: org.molgenis/molgenis-omx-biobankconnect

@Override
public Iterable<Entity> findAll(Query q)
{
  List<Entity> entities = new ArrayList<Entity>();
  if (q.getRules().size() > 0) q.and();
  q.eq(OntologyTermQueryRepository.ENTITY_TYPE, OntologyTermQueryRepository.TYPE_ONTOLOGYTERM);
  for (Hit hit : searchService.search(
      new SearchRequest(AsyncOntologyIndexer.createOntologyTermDocumentType(ontologyIri), q, null))
      .getSearchHits())
  {
    entities.add(new OntologyTermEntity(hit, getEntityMetaData(), searchService));
  }
  return entities;
}

代码示例来源:origin: org.molgenis/molgenis-data-merge

/**
 * check if an entity for the common attributes already exists and if so, return it
 */
private Entity getMergedEntity(Repository repository, List<AttributeMetaData> commonAttributes, Entity entity)
{
  Query findMergedEntityQuery = new QueryImpl();
  for (AttributeMetaData attributeMetaData : commonAttributes)
  {
    if (!findMergedEntityQuery.getRules().isEmpty()) findMergedEntityQuery = findMergedEntityQuery.and();
    findMergedEntityQuery = findMergedEntityQuery.eq(attributeMetaData.getName(),
        entity.get(attributeMetaData.getName()));
  }
  Entity result = repository.findOne(findMergedEntityQuery);
  return result;
}

代码示例来源:origin: org.molgenis/molgenis-data-semanticsearch

public Explanation explain(Query<Entity> q, EntityType entityType, String documentId)
{
  String type = documentIdGenerator.generateId(entityType);
  ExplainRequestBuilder explainRequestBuilder = new ExplainRequestBuilder(client, DEFAULT_INDEX_NAME, type,
      documentId);
  QueryBuilder queryBuilder = queryGenerator.createQueryBuilder(q.getRules(), entityType);
  explainRequestBuilder.setQuery(queryBuilder);
  ExplainResponse explainResponse = explainRequestBuilder.get();
  if (explainResponse.hasExplanation())
  {
    if (LOG.isDebugEnabled())
    {
      LOG.debug(explainResponse.getExplanation().toString());
    }
    return explainResponse.getExplanation();
  }
  return null;
}

相关文章