Example usage for org.springframework.data.rest.webmvc RootResourceInformation getInvoker

List of usage examples for org.springframework.data.rest.webmvc RootResourceInformation getInvoker

Introduction

In this page you can find the example usage for org.springframework.data.rest.webmvc RootResourceInformation getInvoker.

Prototype

public RepositoryInvoker getInvoker() 

Source Link

Usage

From source file:org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.java

/**
 * Returns the object to be updated identified by the given id using the given {@link RootResourceInformation}.
 * /*from w  w w  . ja  va2s.  c om*/
 * @param id can be {@literal null}.
 * @param information must not be {@literal null}.
 * @return
 */
private static Object getObjectToUpdate(Serializable id, RootResourceInformation information) {

    if (id == null) {
        return null;
    }

    RepositoryInvoker invoker = information.getInvoker();
    return invoker.invokeFindOne(id);
}

From source file:org.lightadmin.core.web.RepositoryScopedSearchController.java

@RequestMapping(value = BASE_MAPPING + "/search/count", method = 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);
    }/*from   w ww  .  j a va2s  .com*/

    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);
}

From source file:org.lightadmin.core.web.RepositoryFilePropertyController.java

@RequestMapping(value = BASE_MAPPING + "/binary", method = GET)
public ResponseEntity<?> filePropertyValueOfEntity(RootResourceInformation repoRequest,
        @BackendId Serializable id, @PathVariable String property) throws Exception {
    PersistentEntity<?, ?> persistentEntity = repoRequest.getPersistentEntity();
    RepositoryInvoker invoker = repoRequest.getInvoker();

    Object domainObj = invoker.invokeFindOne(id);

    if (null == domainObj) {
        throw new ResourceNotFoundException();
    }/*from w ww .  j a  v a 2 s.c om*/

    PersistentProperty<?> prop = persistentEntity.getPersistentProperty(property);
    if (null == prop) {
        throw new ResourceNotFoundException();
    }

    if (isOfFileType(prop)) {
        return toResponseEntity(OK, new HttpHeaders(),
                new Resource<FilePropertyValue>(evaluateFilePropertyValue(domainObj, prop)));
    }

    return toEmptyResponse(METHOD_NOT_ALLOWED);
}

From source file:org.lightadmin.core.web.RepositoryFilePropertyController.java

@RequestMapping(value = BASE_MAPPING + "/file", method = DELETE)
public ResponseEntity<?> deleteFileOfPropertyOfEntity(RootResourceInformation repoRequest,
        @BackendId Serializable id, @PathVariable String property) throws Exception {
    PersistentEntity<?, ?> persistentEntity = repoRequest.getPersistentEntity();
    RepositoryInvoker invoker = repoRequest.getInvoker();

    Object domainObj = invoker.invokeFindOne(id);

    if (null == domainObj) {
        throw new ResourceNotFoundException();
    }//from   w ww .j  a v a  2 s.c o m

    PersistentProperty<?> prop = persistentEntity.getPersistentProperty(property);
    if (null == prop) {
        throw new ResourceNotFoundException();
    }

    if (!isOfFileType(prop)) {
        return toEmptyResponse(METHOD_NOT_ALLOWED);
    }

    fileResourceStorage().delete(domainObj, prop);

    invoker.invokeSave(domainObj);

    return toEmptyResponse(OK);
}

From source file:org.lightadmin.core.web.RepositoryFilePropertyController.java

@RequestMapping(value = BASE_MAPPING + "/file", method = GET)
public void filePropertyOfEntity(RootResourceInformation repoRequest, ServletResponse response,
        @BackendId Serializable id, @PathVariable String property) throws Exception {
    PersistentEntity<?, ?> persistentEntity = repoRequest.getPersistentEntity();
    RepositoryInvoker invoker = repoRequest.getInvoker();

    Object domainObj = invoker.invokeFindOne(id);

    if (null == domainObj) {
        throw new ResourceNotFoundException();
    }//  ww w.  j  a  v a 2  s .c o  m

    PersistentProperty<?> prop = persistentEntity.getPersistentProperty(property);
    if (null == prop) {
        throw new ResourceNotFoundException();
    }

    if (isOfFileType(prop)) {
        fileResourceLoader().downloadFile(domainObj, prop, (HttpServletResponse) response);
    }
}

From source file:org.lightadmin.core.web.RepositoryScopedSearchController.java

@RequestMapping(value = BASE_MAPPING + "/search", method = GET)
public ResponseEntity<?> filterEntities(
        DomainTypeAdministrationConfiguration domainTypeAdministrationConfiguration,
        RootResourceInformation repoRequest, PersistentEntityResourceAssembler assembler, WebRequest request,
        Pageable pageable, @PathVariable String scopeName) throws Exception {
    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;

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

        Object resources = resultToResources(page, assembler);

        return new ResponseEntity(resources, HttpStatus.OK);
    }/*ww w  .  java2 s.  c  om*/

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

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

        Object resources = resultToResources(page, assembler);

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

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

    Object resources = resultToResources(page, assembler);

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