/** * @author Oliver Gierke */ @RepositoryRestResource(excerptProjection = CustomerExcerpt.class) public interface CustomerRepository extends CrudRepository<Customer, Long> { }
@RestResource(rel = "by-location") Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable);
public AnnotationBasedResourceDescription(Class<?> type, ResourceDescription fallback) { Description description = AnnotationUtils.findAnnotation(type, Description.class); this.message = description == null ? null : description.value(); this.fallback = fallback; }
@Override public Path getPath() { Path fallback = domainTypeMapping.getPath(); if (repositoryAnnotation != null) { String path = repositoryAnnotation.path(); return StringUtils.hasText(path) ? new Path(path) : fallback; } if (annotation != null) { String path = annotation.path(); return StringUtils.hasText(path) ? new Path(path) : fallback; } return fallback; }
/** * Returns whether the given type was explicitly exported using {@link RepositoryRestResource} or * {@link RestResource}. In case no decision can be made based on the annotations, the fallback will be used. * * @param type must not be {@literal null}. * @param fallback * @return */ private static boolean isExplicitlyExported(Class<?> type, boolean fallback) { RepositoryRestResource restResource = AnnotationUtils.findAnnotation(type, RepositoryRestResource.class); if (restResource != null) { return restResource.exported(); } RestResource resource = AnnotationUtils.findAnnotation(type, RestResource.class); if (resource != null) { return resource.exported(); } return fallback; } }
@Override public String getRel() { String fallback = domainTypeMapping.getRel(); if (repositoryAnnotation != null) { String rel = repositoryAnnotation.collectionResourceRel(); return StringUtils.hasText(rel) ? rel : fallback; } if (annotation != null) { String rel = annotation.rel(); return StringUtils.hasText(rel) ? rel : fallback; } return fallback; }
@Override public ResourceDescription getItemResourceDescription() { ResourceDescription fallback = SimpleResourceDescription.defaultFor(getItemResourceRel()); if (annotation != null && StringUtils.hasText(annotation.description().value())) { return new AnnotationBasedResourceDescription(annotation.description(), fallback); } if (description != null) { return new AnnotationBasedResourceDescription(description, fallback); } return fallback; }
public static boolean findExported(Class<?> type) { RestResource anno = findAnnotation(type, RestResource.class); return anno == null || anno.exported(); }
@Override public Class<?> getExcerptProjection() { if (repositoryAnnotation == null) { return null; } Class<?> excerptProjection = repositoryAnnotation.excerptProjection(); return excerptProjection.equals(RepositoryRestResource.None.class) ? null : excerptProjection; } }
@Override public String getItemResourceRel() { String fallback = domainTypeMapping.getItemResourceRel(); if (repositoryAnnotation != null) { String rel = repositoryAnnotation.itemResourceRel(); return StringUtils.hasText(rel) ? rel : fallback; } return fallback; }
@Override public ResourceDescription getDescription() { ResourceDescription fallback = SimpleResourceDescription.defaultFor(getRel()); if (description != null) { return new AnnotationBasedResourceDescription(description, fallback); } if (annotation != null) { return new AnnotationBasedResourceDescription(annotation.description(), fallback); } return fallback; }
@RepositoryRestResource public interface UserRepository extends PagingAndSortingRepository<User, Long> { User findUserByUsername(@Param("username") String username); }
public static boolean findExported(Method method) { RestResource anno = findAnnotation(method, RestResource.class); return anno == null || anno.exported(); }
/** * Creates a new {@link AnnotationBasedResourceDescription} for the given {@link Description} and fallback. * * @param description must not be {@literal null}. * @param fallback must not be {@literal null}. */ public AnnotationBasedResourceDescription(Description description, ResourceDescription fallback) { Assert.notNull(description, "Description must not be null!"); Assert.notNull(fallback, "Fallback resource description must not be null!"); this.message = description.value(); this.fallback = fallback; }
@RepositoryRestResource public interface CartEventRepository extends JpaRepository<CartEvent, Long> { @Query(value = "SELECT c.*\n" + "FROM (\n" + " SELECT *\n" + " FROM cart_event\n" + " WHERE user_id = ?1 AND (cart_event_type = 3 OR cart_event_type = 2)\n" + " ORDER BY cart_event.created_at DESC\n" + " LIMIT 1\n" + " ) t\n" + " RIGHT JOIN cart_event c ON c.user_id = t.user_id\n" + "WHERE c.created_at BETWEEN coalesce(t.created_at, 0) AND 9223372036854775807 AND coalesce(t.id, -1) != c.id\n" + "ORDER BY c.created_at ASC", nativeQuery = true) Stream<CartEvent> getCartEventStreamByUser(Long userId); }
@Override public boolean isExported() { return annotation != null ? annotation.exported() : Modifier.isPublic(type.getModifiers()); }
/** * Repository to manage {@link Order} instances. * * @author Oliver Gierke */ @RepositoryRestResource(excerptProjection = OrderProjection.class) public interface OrderRepository extends PagingAndSortingRepository<Order, Long> { /** * Returns all {@link Order}s with the given {@link Status}. * * @param status must not be {@literal null}. * @return */ List<Order> findByStatus(@Param("status") Status status); }
private boolean exposes(Optional<Method> method) { return method.map(it -> { RestResource annotation = AnnotationUtils.findAnnotation(it, RestResource.class); return annotation == null ? exportedDefault : annotation.exported(); }).orElse(false); } }