DATAREST-1294 - Polishing.

Aligned with general request attribute naming conventions and prefixed the one we now use with the class' name. Altered the local attribute name to EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH.

Renamed the constant holding the name from …_KEY to …_ATTRIBUTE.
This commit is contained in:
Oliver Gierke
2018-10-18 15:58:31 +02:00
parent 3f0eb17dcf
commit 33c156dae0
2 changed files with 8 additions and 5 deletions

View File

@@ -65,7 +65,8 @@ import org.springframework.web.util.pattern.PathPatternParser;
public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping {
private static final PathPatternParser PARSER = new PathPatternParser();
static final String EFFECTIVE_LOOKUP_PATH_KEY = "EFFECTIVE_REPOSITORY_LOOKUP_PATH";
static final String EFFECTIVE_LOOKUP_PATH_ATTRIBUTE = RepositoryRestHandlerMapping.class.getName()
+ ".EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH";
private final ResourceMappings mappings;
private final RepositoryRestConfiguration configuration;
@@ -248,8 +249,9 @@ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping {
}
/**
* Exposes the effective repository resource lookup path as request attribute via {@link #EFFECTIVE_LOOKUP_PATH_KEY},
* i.e. {@code /people/search/\{search\}} instead of {@code /\{repository\}/search/\{search\}}.
* Exposes the effective repository resource lookup path as request attribute via
* {@link #EFFECTIVE_LOOKUP_PATH_ATTRIBUTE}, i.e. {@code /people/search/\{search\}} instead of
* {@code /\{repository\}/search/\{search\}}.
*
* @param method must not be {@literal null}.
* @param request must not be {@literal null}.
@@ -264,7 +266,8 @@ public class RepositoryRestHandlerMapping extends BasePathAwareHandlerMapping {
.getPatterns() //
.iterator().next();
request.setAttribute(EFFECTIVE_LOOKUP_PATH_KEY, PARSER.parse(pattern.replace("/{repository}", repositoryBasePath)));
request.setAttribute(EFFECTIVE_LOOKUP_PATH_ATTRIBUTE,
PARSER.parse(pattern.replace("/{repository}", repositoryBasePath)));
}
/**

View File

@@ -281,7 +281,7 @@ public class RepositoryRestHandlerMappingUnitTests {
handlerMapping.afterPropertiesSet();
handlerMapping.lookupHandlerMethod("/people/search/findByLastnameLike", mockRequest);
assertThat(mockRequest.getAttribute(RepositoryRestHandlerMapping.EFFECTIVE_LOOKUP_PATH_KEY)) //
assertThat(mockRequest.getAttribute(RepositoryRestHandlerMapping.EFFECTIVE_LOOKUP_PATH_ATTRIBUTE)) //
.isInstanceOfSatisfying(PathPattern.class, it -> {
assertThat(it.getPatternString()).isEqualTo("/people/search/{search}");
});