org.molgenis.data.Query类的使用及代码示例

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

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

Query介绍

暂无

代码示例

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

public static Query<Entity> createQuery(Locus locus)
{
  return QueryImpl.EQ(VcfAttributes.CHROM, locus.getChrom()).and().eq(VcfAttributes.POS, locus.getPos());
}

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

public void populate() {
  dataService
    .query(ENTITY_TYPE_META_DATA, EntityType.class)
    .eq(BACKEND, POSTGRESQL)
    .findAll()
    .forEach(entityTypeRegistry::registerEntityType);
 }
}

代码示例来源: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-data-postgresql

@Override
public Iterator<Repository<Entity>> iterator() {
 return dataService
   .query(ENTITY_TYPE_META_DATA, EntityType.class)
   .eq(BACKEND, POSTGRESQL)
   .and()
   .eq(IS_ABSTRACT, false)
   .fetch(getEntityTypeFetch())
   .findAll()
   .map(this::getRepository)
   .iterator();
}

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

@Override
public Repository<Entity> getRepository(String id) {
 EntityType entityType =
   dataService
     .query(ENTITY_TYPE_META_DATA, EntityType.class)
     .eq(BACKEND, POSTGRESQL)
     .and()
     .eq(ID, id)
     .and()
     .eq(IS_ABSTRACT, false)
     .fetch(getEntityTypeFetch())
     .findOne();
 return getRepository(entityType);
}

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

private Optional<User> getUser(OidcUser oidcUser, OidcUserRequest userRequest) {
 OidcUserMapping oidcUserMapping =
   dataService
     .query(OIDC_USER_MAPPING, OidcUserMapping.class)
     .eq(OIDC_CLIENT, userRequest.getClientRegistration().getRegistrationId())
     .and()
     .eq(OIDC_USERNAME, oidcUser.getSubject())
     .findOne();
 return oidcUserMapping != null ? Optional.of(oidcUserMapping.getUser()) : Optional.empty();
}

代码示例来源:origin: org.molgenis/molgenis-ontology-core

/**
 * Retrieves an ontology with a specific IRI.
 *
 * @param iri the IRI of the ontology
 */
public Ontology getOntology(String iri) {
 org.molgenis.ontology.core.meta.Ontology ontology =
   dataService
     .query(ONTOLOGY, org.molgenis.ontology.core.meta.Ontology.class)
     .eq(ONTOLOGY_IRI, iri)
     .findOne();
 return toOntology(ontology);
}

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

public Hit findOntologyTerm(String ontologyIri, String ontologyTermIri, String nodePath)
{
  Query q = new QueryImpl().eq(OntologyTermIndexRepository.NODE_PATH, nodePath).and()
      .eq(OntologyTermIndexRepository.ONTOLOGY_TERM_IRI, ontologyTermIri).pageSize(5000);
  String documentType = AsyncOntologyIndexer.createOntologyTermDocumentType(ontologyIri);
  SearchResult result = searchService.search(new SearchRequest(documentType, q, null));
  for (Hit hit : result.getSearchHits())
  {
    if (hit.getColumnValueMap().get(OntologyTermIndexRepository.NODE_PATH).toString().equals(nodePath)) return hit;
  }
  return new Hit(null, documentType, Collections.<String, Object> emptyMap());
}

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

private Multimap<String, Attribute> getDefaultValueMap(EntityType entityType) {
 Multimap<String, Attribute> defaultValueMultiMap = LinkedHashMultimap.create();
 dataService
   .query(ATTRIBUTE_META_DATA, Attribute.class)
   .eq(REF_ENTITY_TYPE, entityType.getIdValue())
   .and()
   .not()
   .eq(DEFAULT_VALUE, null)
   .findAll()
   .forEach(
     attribute -> {
      if (EntityTypeUtils.isSingleReferenceType(attribute)) {
       Entity defaultEntityValue = (Entity) getDefaultTypedValue(attribute);
       defaultValueMultiMap.put(defaultEntityValue.getIdValue().toString(), attribute);
      } else if (EntityTypeUtils.isMultipleReferenceType(attribute)) {
       @SuppressWarnings("unchecked")
       Iterable<Entity> defaultEntitiesValue =
         (Iterable<Entity>) getDefaultTypedValue(attribute);
       defaultEntitiesValue.forEach(
         defaultEntityValue ->
           defaultValueMultiMap.put(
             defaultEntityValue.getIdValue().toString(), attribute));
      }
     });
 return defaultValueMultiMap;
}

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

/**
  * Cleans up successful IndexJobExecutions that finished longer than five minutes ago. delay for a
  * minute to allow the transaction manager to become available
  */
 @Scheduled(initialDelay = 1 * 60 * 1000, fixedRate = 5 * 60 * 1000)
 public void cleanupJobExecutions() {
  runAsSystem(
    () -> {
     LOG.trace("Clean up Index job executions...");
     Instant fiveMinutesAgo = Instant.now().minus(5, ChronoUnit.MINUTES);
     boolean indexJobExecutionExists =
       dataService.hasRepository(IndexJobExecutionMeta.INDEX_JOB_EXECUTION);
     if (indexJobExecutionExists) {
      Stream<Entity> executions =
        dataService
          .getRepository(IndexJobExecutionMeta.INDEX_JOB_EXECUTION)
          .query()
          .lt(END_DATE, fiveMinutesAgo)
          .and()
          .eq(STATUS, SUCCESS.toString())
          .findAll();
      dataService.delete(IndexJobExecutionMeta.INDEX_JOB_EXECUTION, executions);
      LOG.debug("Cleaned up Index job executions.");
     } else {
      LOG.warn("{} does not exist", IndexJobExecutionMeta.INDEX_JOB_EXECUTION);
     }
    });
 }
}

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

@RequestMapping(method = RequestMethod.POST, value = "/allattributes", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public SearchResult getAllAttributes(@RequestBody
Map<String, Object> request)
{
  if (request.get("dataSetId") == null) return new SearchResult("dataSetId cannot be null!");
  Object dataSetId = request.get("dataSetId");
  Object queryString = request.get("queryString");
  Object approximate = (request.get("approximate") == null) ? false : request.get("approximate");
  DataSet dataSet = dataService.findOne(DataSet.ENTITY_NAME, dataSetId, DataSet.class);
  Query query = new QueryImpl();
  if (request.get("query") != null)
  {
    query = new Gson().fromJson(request.get("query").toString(), QueryImpl.class);
  }
  query.eq("type", "observablefeature");
  if (queryString != null && !queryString.toString().isEmpty())
  {
    if ((boolean) approximate)
    {
      query.and().like(ObservableFeature.NAME.toLowerCase(), queryString.toString());
    }
    else query.and().search(queryString.toString());
  }
  return searchService
      .search(new SearchRequest("protocolTree-" + dataSet.getProtocolUsed().getId(), query, null));
}

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

private void bootstrap(SystemEntityType systemEntityType) {
 dataService
   .query(systemEntityType.getId())
   .eq(STATUS, RUNNING)
   .or()
   .eq(STATUS, PENDING)
   .findAll()
   .forEach(this::setFailed);
}

代码示例来源: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-omx-protocolviewer

public void addUserRule(Query q)
{
  MolgenisUser user = getCurrentUser();
  if (user.getSuperuser())
  {
    return;
  }
  q.eq(StudyDataRequest.MOLGENISUSER, user);
}

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

@Override
public Iterable<String> getEntityTypeIds() {
 return dataService
     .query(ENTITY_TYPE_META_DATA, EntityType.class)
     .eq(BACKEND, POSTGRESQL)
     .fetch(getEntityTypeFetch())
     .findAll()
     .map(EntityType::getId)
   ::iterator;
}

代码示例来源:origin: org.molgenis/molgenis-core-ui

@GetMapping(value = "/latest", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Entity> findLastJobs() {
 final List<Entity> jobs = new ArrayList<>();
 Instant weekAgo = Instant.now().minus(7, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS);
 User currentUser = userAccountService.getCurrentUser();
 dataService
   .getMeta()
   .getEntityTypes()
   .filter(this::isAllowedJobExecutionEntityType)
   .forEach(
     e -> {
      Query<Entity> q =
        dataService.query(e.getId()).ge(JobExecutionMetaData.SUBMISSION_DATE, weekAgo);
      if (!currentUser.isSuperuser()) {
       q.and().eq(USER, currentUser.getUsername());
      }
      dataService.findAll(e.getId(), q).forEach(jobs::add);
     });
 jobs.sort(
   (job1, job2) ->
     job2.getInstant(SUBMISSION_DATE).compareTo(job1.getInstant(SUBMISSION_DATE)));
 if (jobs.size() > MAX_JOBS_TO_RETURN) {
  return jobs.subList(0, MAX_JOBS_TO_RETURN);
 }
 return jobs;
}

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

private List<SortaJobExecution> getJobsForCurrentUser() {
 final List<SortaJobExecution> jobs = new ArrayList<>();
 User currentUser = userAccountService.getCurrentUser();
 Query<SortaJobExecution> query =
   dataService
     .query(SORTA_JOB_EXECUTION, SortaJobExecution.class)
     .eq(JobExecutionMetaData.USER, currentUser.getUsername());
 query.sort().on(JobExecutionMetaData.START_DATE, DESC);
 RunAsSystemAspect.runAsSystem(
   () ->
     query
       .findAll()
       .forEach(
         job -> {
          // TODO: fetch the user as well
          job.set(JobExecutionMetaData.USER, currentUser.getUsername());
          jobs.add(job);
         }));
 return jobs;
}

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

protected Stream<Entity> queryDataSet(String segmentId, int browserStart, int browserStop, String dataSet,
    int maxbins)
{
  String chromosomeAttribute = config.getAttributeNameForAttributeNameArray(GenomicDataSettings.Meta.ATTRS_CHROM,
      dataService.getEntityType(dataSet));
  String posAttr = config.getAttributeNameForAttributeNameArray(GenomicDataSettings.Meta.ATTRS_POS,
      dataService.getEntityType(dataSet));
  String stopAttr = config.getAttributeNameForAttributeNameArray(GenomicDataSettings.Meta.ATTRS_STOP,
      dataService.getEntityType(dataSet));
  //Query for chromosome
  Query<Entity> q = new QueryImpl<>().eq(chromosomeAttribute, segmentId);
  //Add postion queryparts, those should be nested
  q.and().nest();
  //Add start position to queryparts
  q.le(posAttr, browserStop);
  //If stop is configured: add stop querypart, else the position should also be greater than browserstart
  if (stopAttr != "")
  {
    q.and().ge(stopAttr, browserStart);
  }
  else
  {
    q.and().ge(posAttr, browserStart);
  }
  q.unnest();
  //add pagesize based on maxbins of das query
  q.pageSize(maxbins);
  return dataService.findAll(dataSet, q);
}

代码示例来源: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;
}

相关文章