コード例 #1
0
  @RequestMapping(value = BASE_MAPPING + "/search", method = RequestMethod.GET)
  public ResponseEntity<?> filterEntities(
      DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration,
      RootResourceInformation repoRequest,
      PersistentEntityResourceAssembler assembler,
      WebRequest request,
      Pageable pageable,
      @PathVariable String scopeName)
      throws Exception {
    DynamicRepositoryInvoker repositoryInvoker =
        (DynamicRepositoryInvoker) repoRequest.getInvoker();
    Set<FieldMetadata> listViewFields =
        domainTypeAdministrationConfiguration.getListViewFragment().getFields();
    PersistentEntity<?, ?> persistentEntity = repoRequest.getPersistentEntity();

    DynamicPersistentEntityResourceAssembler dynamicPersistentEntityResourceAssembler =
        DynamicPersistentEntityResourceAssembler.wrap(assembler, listViewFields, false);

    final ScopeMetadata scope =
        domainTypeAdministrationConfiguration.getScopes().getScope(scopeName);

    final Specification filterSpecification = specificationFromRequest(request, persistentEntity);

    if (isPredicateScope(scope)) {
      final PredicateScopeMetadata predicateScope = (PredicateScopeMetadata) scope;

      final Page page =
          findBySpecificationAndPredicate(
              repositoryInvoker, filterSpecification, predicateScope.predicate(), pageable);

      Object resources = resultToResources(page, dynamicPersistentEntityResourceAssembler);

      return new ResponseEntity<>(resources, HttpStatus.OK);
    }

    if (isSpecificationScope(scope)) {
      final Specification scopeSpecification =
          ((ScopeMetadataUtils.SpecificationScopeMetadata) scope).specification();

      Page page =
          findItemsBySpecification(
              repositoryInvoker, and(scopeSpecification, filterSpecification), pageable);

      Object resources = resultToResources(page, dynamicPersistentEntityResourceAssembler);

      return new ResponseEntity<>(resources, HttpStatus.OK);
    }

    Page page = findItemsBySpecification(repositoryInvoker, filterSpecification, pageable);

    Object resources = resultToResources(page, dynamicPersistentEntityResourceAssembler);

    return new ResponseEntity<>(resources, HttpStatus.OK);
  }
コード例 #2
0
  @RequestMapping(value = BASE_MAPPING + "/search/count", method = RequestMethod.GET)
  public ResponseEntity<?> countItems(
      DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration,
      RootResourceInformation repoRequest,
      WebRequest request,
      @PathVariable String scopeName) {
    DynamicRepositoryInvoker repositoryInvoker =
        (DynamicRepositoryInvoker) repoRequest.getInvoker();

    PersistentEntity<?, ?> persistentEntity = repoRequest.getPersistentEntity();

    final ScopeMetadata scope =
        domainTypeAdministrationConfiguration.getScopes().getScope(scopeName);

    final Specification filterSpecification = specificationFromRequest(request, persistentEntity);

    if (isPredicateScope(scope)) {
      final PredicateScopeMetadata predicateScope = (PredicateScopeMetadata) scope;

      return new ResponseEntity<>(
          countItemsBySpecificationAndPredicate(
              repositoryInvoker, filterSpecification, predicateScope.predicate()),
          HttpStatus.OK);
    }

    if (isSpecificationScope(scope)) {
      final Specification scopeSpecification =
          ((ScopeMetadataUtils.SpecificationScopeMetadata) scope).specification();

      return new ResponseEntity<>(
          countItemsBySpecification(
              repositoryInvoker, and(scopeSpecification, filterSpecification)),
          HttpStatus.OK);
    }

    return new ResponseEntity<>(
        countItemsBySpecification(repositoryInvoker, filterSpecification), HttpStatus.OK);
  }