You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.2 KiB
Java
70 lines
2.2 KiB
Java
package cokr.xit.fims.task;
|
|
|
|
import java.lang.reflect.Method;
|
|
import java.util.Set;
|
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
import org.springframework.lang.Nullable;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
|
import org.springframework.web.servlet.mvc.method.RequestMappingInfo.BuilderConfiguration;
|
|
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
|
|
|
public class TaskRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
|
|
|
|
@Override
|
|
@Nullable
|
|
public RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
|
|
|
RequestMappingInfo info = super.getMappingForMethod(method, handlerType);
|
|
|
|
Task task = AnnotatedElementUtils.findMergedAnnotation(method, Task.class);
|
|
|
|
if(task != null && info != null) {
|
|
return createRequestMappingInfo(task, method, info);
|
|
} else {
|
|
return info;
|
|
}
|
|
|
|
}
|
|
|
|
protected RequestMappingInfo createRequestMappingInfo(Task task, Method method,
|
|
RequestMappingInfo info) {
|
|
|
|
String[] prefix = task.value();
|
|
if(prefix[0].equals("ALL")) {
|
|
prefix = new String[] {"PVS","BPV","DPV","ECA","PES","DVS"};
|
|
} else if(prefix[0].equals("CMN")) {
|
|
prefix = new String[] {"","PVS","BPV","DPV","ECA","PES","DVS"};
|
|
}
|
|
|
|
RequestMapping rm = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
|
|
|
|
Set<String> olds0 = info.getPatternValues();
|
|
String[] olds = olds0.toArray(new String[olds0.size()]);
|
|
String[] news = new String[prefix.length*olds.length];
|
|
for(int i=0;i < prefix.length; i++) {
|
|
for(int j=0;j < olds.length; j++) {
|
|
String newPattern = (prefix[i].equals("") ? "" : "/")+prefix[i]+olds[j];
|
|
news[i*(olds.length)+j] = newPattern;
|
|
}
|
|
}
|
|
|
|
BuilderConfiguration bc = new RequestMappingInfo.BuilderConfiguration();
|
|
bc.setContentNegotiationManager(super.getContentNegotiationManager());
|
|
bc.setPatternParser(super.getPatternParser());
|
|
|
|
return RequestMappingInfo
|
|
.paths(super.resolveEmbeddedValuesInPatterns(news))
|
|
.mappingName(rm.name())
|
|
.methods(rm.method())
|
|
.params(rm.params())
|
|
.headers(rm.headers())
|
|
.consumes(rm.consumes())
|
|
.produces(rm.produces())
|
|
.options(bc)
|
|
.build();
|
|
|
|
}
|
|
}
|