org.springframework.data.rest.core.annotation.RepositoryRestResource Java Examples

The following examples show how to use org.springframework.data.rest.core.annotation.RepositoryRestResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RepositoryConfig.java    From entref-spring-boot with MIT License 5 votes vote down vote up
@Override
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
    // expose the ids for the given model types
    config.exposeIdsFor(Person.class);
    config.exposeIdsFor(Title.class);

    // configure how we find and load repositories to let us disable them at runtime with an environment variable
    config.setRepositoryDetectionStrategy(metadata -> {
        // if it's not exported, exclude it
        if (!metadata.getRepositoryInterface().getAnnotation(RepositoryRestResource.class).exported()) {
            return false;
        }

        String className = metadata.getRepositoryInterface().getName();
        String exclusionList = env.getProperty(Constants.ENV_EXCLUDE_FILTER);

        if (exclusionList != null && !exclusionList.isEmpty()) {
            for (String exclude : exclusionList.split(",")) {
                // see if we get any hits, treating the exclusion list entry as a regex pattern
                // note: this allows us to hit 'ClassA' even if it's really 'com.package.ClassA'
                if (Pattern.compile(exclude).matcher(className).find()) {
                    // exclude if we match
                    return false;
                }
            }
        }

        // default to allowing the repository
        return true;
    });
}
 
Example #2
Source File: RepositoryUtils.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public static String repositoryPath(RepositoryInformation info) {
	Class<?> clazz = info.getRepositoryInterface();
	RepositoryRestResource annotation = AnnotationUtils.findAnnotation(clazz,
			RepositoryRestResource.class);
	String path = annotation == null ? null : annotation.path().trim();
	path = StringUtils.hasText(path) ? path : English
			.plural(StringUtils.uncapitalize(info.getDomainType().getSimpleName()));
	return path;
}