use of org.hisp.dhis.common.DhisApiVersion 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());
}
Aggregations