Example usage for org.springframework.data.repository.support RepositoryInvoker invokeSave

List of usage examples for org.springframework.data.repository.support RepositoryInvoker invokeSave

Introduction

In this page you can find the example usage for org.springframework.data.repository.support RepositoryInvoker invokeSave.

Prototype

<T> T invokeSave(T object);

Source Link

Document

Invokes the method equivalent to org.springframework.data.repository.CrudRepository#save(Object) on the repository.

Usage

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();
    }// w  w  w. j a v  a 2 s  .  co  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);
}