/** @see DATAREST-217 */ @Test public void defaultsSupportedHttpMethodsForItemResource() { assertThat( information.getSupportedMethods(ResourceType.ITEM), hasItems(GET, PUT, PATCH, DELETE)); assertThat(information.getSupportedMethods(ResourceType.ITEM), not(hasItems(POST))); assertThat(information.getSupportedMethods(COLLECTION), hasItems(GET, POST)); assertThat(information.getSupportedMethods(COLLECTION), not(hasItems(PUT, PATCH, DELETE))); }
@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); }
@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); }
/** @see DATAREST-217 */ @Test public void doesNotSupportPutOnItemResourceIfSaveIsNotExported() { when(invoker.exposesSave()).thenReturn(false); assertThat(information.supports(POST, ITEM), is(false)); }
/** @see DATAREST-217 */ @Test public void doesNotSupportDeleteOnItemResourceIfDeleteIsNotExported() { when(invoker.exposesDelete()).thenReturn(false); assertThat(information.supports(DELETE, ITEM), is(false)); }
/** @see DATAREST-217 */ @Test public void doesNotSupportGetOnItemResourceIfFindOneIsNotExported() { when(invoker.exposesFindOne()).thenReturn(false); assertThat(information.supports(GET, ITEM), is(false)); }