Search in sources :

Example 11 with PatternsRequestCondition

use of org.springframework.web.servlet.mvc.condition.PatternsRequestCondition in project dhis2-core by dhis2.

the class CustomRequestMappingHandlerMapping method getMappingForMethod.

@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
    RequestMappingInfo info = super.getMappingForMethod(method, handlerType);
    if (info == null) {
        return null;
    }
    ApiVersion typeApiVersion = AnnotationUtils.findAnnotation(handlerType, ApiVersion.class);
    ApiVersion methodApiVersion = AnnotationUtils.findAnnotation(method, ApiVersion.class);
    if (typeApiVersion == null && methodApiVersion == null) {
        return info;
    }
    RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
    if (methodsCondition.getMethods().isEmpty()) {
        methodsCondition = new RequestMethodsRequestCondition(RequestMethod.GET);
    }
    Set<String> rqmPatterns = info.getPatternsCondition().getPatterns();
    Set<String> patterns = new HashSet<>();
    Set<DhisApiVersion> versions = getVersions(typeApiVersion, methodApiVersion);
    for (String pattern : rqmPatterns) {
        versions.stream().filter(version -> !version.isIgnore()).forEach(version -> {
            if (!pattern.startsWith(version.getVersionString())) {
                if (pattern.startsWith("/")) {
                    patterns.add("/" + version.getVersion() + pattern);
                } else {
                    patterns.add("/" + version.getVersion() + "/" + pattern);
                }
            } else {
                patterns.add(pattern);
            }
        });
    }
    PatternsRequestCondition patternsRequestCondition = new PatternsRequestCondition(patterns.toArray(new String[] {}), null, null, true, true, null);
    return new RequestMappingInfo(null, patternsRequestCondition, methodsCondition, info.getParamsCondition(), info.getHeadersCondition(), info.getConsumesCondition(), info.getProducesCondition(), info.getCustomCondition());
}
Also used : DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) HashSet(java.util.HashSet) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) Arrays(java.util.Arrays) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) Method(java.lang.reflect.Method) DhisApiVersion(org.hisp.dhis.common.DhisApiVersion) ApiVersion(org.hisp.dhis.webapi.mvc.annotation.ApiVersion) PatternsRequestCondition(org.springframework.web.servlet.mvc.condition.PatternsRequestCondition) RequestMappingInfo(org.springframework.web.servlet.mvc.method.RequestMappingInfo) RequestMethodsRequestCondition(org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition) HashSet(java.util.HashSet)

Aggregations

PatternsRequestCondition (org.springframework.web.servlet.mvc.condition.PatternsRequestCondition)11 RequestMethodsRequestCondition (org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition)6 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)6 ParamsRequestCondition (org.springframework.web.servlet.mvc.condition.ParamsRequestCondition)5 ConsumesRequestCondition (org.springframework.web.servlet.mvc.condition.ConsumesRequestCondition)4 HeadersRequestCondition (org.springframework.web.servlet.mvc.condition.HeadersRequestCondition)4 ProducesRequestCondition (org.springframework.web.servlet.mvc.condition.ProducesRequestCondition)4 HashSet (java.util.HashSet)2 Set (java.util.Set)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2 RequestConditionHolder (org.springframework.web.servlet.mvc.condition.RequestConditionHolder)2 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ExtensiveDomain (io.leopard.vhost.ExtensiveDomain)1 ExtensiveDomainRequestCondition (io.leopard.web.mvc.condition.ExtensiveDomainRequestCondition)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1