All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ixortalk.assetmgmt.rest.AssetRepository Maven / Gradle / Ivy

The newest version!
/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2016-present IxorTalk CVBA
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.ixortalk.assetmgmt.rest;

import com.ixortalk.assetmgmt.domain.Asset;
import com.ixortalk.assetmgmt.domain.AssetId;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreAuthorize;

import java.util.List;

@RepositoryRestResource
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
public interface AssetRepository extends MongoRepository, AssetRepositoryCustom {

	@Override
    @PreAuthorize("permitAll()")
    @PostFilter("hasAnyRole('ROLE_ADMIN', 'ROLE_SCHEDULED_TASK') or hasAnyRole(filterObject.roles)")
    List findAll();

    @Override
    @PreAuthorize("permitAll()")
    @PostFilter("hasAnyRole('ROLE_ADMIN') or hasAnyRole(filterObject.roles)")
     List findAll(Example example);

    @Override
    @PreAuthorize("permitAll()")
    @Query("{roles: ?#{ hasRole('ROLE_ADMIN') ? {$exists:true} : {$in: @securityService.getAuthorities()} }}")
    Page findAll(Pageable pageable);
    
    @Override
    @PreAuthorize("permitAll()")
    @PostFilter("hasAnyRole('ROLE_ADMIN') or hasAnyRole(filterObject.roles)")
     List findAll(Example example, Sort sort);
    
    @Override
    @PreAuthorize("permitAll()")
    @PostFilter("hasAnyRole('ROLE_ADMIN') or hasAnyRole(filterObject.roles)")
    Iterable findAll(Iterable ids);
    
    @Override
    @PreAuthorize("permitAll()")
    @PostFilter("hasAnyRole('ROLE_ADMIN') or hasAnyRole(filterObject.roles)")
    List findAll(Sort sort);
    
    
    

    
    @Override
    @PreAuthorize("permitAll()")
    @PostAuthorize("hasAnyRole('ROLE_ADMIN') or (returnObject!=null and hasAnyRole(returnObject.roles))")
     S findOne(Example example);
    
    @Override
    @PreAuthorize("permitAll()")
    @PostAuthorize("hasAnyRole('ROLE_ADMIN') or (returnObject!=null and hasAnyRole(returnObject.roles))")
    Asset findOne(AssetId id);

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    Iterable findByRoles(@Param("role") String role);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    boolean exists(AssetId assetId);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
     boolean exists(Example example);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
     S save(S asset);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
     List save(Iterable entites);
    
    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
     S insert(S entity);
    
    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
     List insert(Iterable entities);
    
    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    void delete(AssetId assetId);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    void delete(Asset entity);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    void delete(Iterable entities);

    @Override
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    void deleteAll();
    
    @Override
    @PreAuthorize("permitAll()")
    long count();
    
    @Override
    @PreAuthorize("permitAll()")
     long count(Example example);

}