validator修改
This commit is contained in:
parent
0fc391e302
commit
66586efe6b
@ -11,7 +11,7 @@ import java.util.Set;
|
||||
@Component
|
||||
public class ActivityFormConfigure {
|
||||
|
||||
private static final Set<String> stdActivityForm = new HashSet(){{
|
||||
private final HashSet<String> stdActivityForm = new HashSet<String>(){{
|
||||
add("title");
|
||||
add("creator");
|
||||
add("type");
|
||||
@ -29,11 +29,8 @@ public class ActivityFormConfigure {
|
||||
add("assist-manager");
|
||||
add("attendance");
|
||||
}};
|
||||
public final static Map<String, HashSet<String>> stdActivityMap;
|
||||
|
||||
static {
|
||||
stdActivityMap = new HashMap() {{
|
||||
put("activity", stdActivityForm);
|
||||
}};
|
||||
public HashSet<String> getStdActivityForm() {
|
||||
return stdActivityForm;
|
||||
}
|
||||
}
|
||||
|
@ -31,11 +31,12 @@ public class ActivityController {
|
||||
ASESpringUtil aseSpringUtil = new ASESpringUtil();
|
||||
ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class);
|
||||
WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class);
|
||||
HashMap<String, Boolean> checkResult = webFormValidator.check(activityFormConfigure.stdActivityMap, parameterMap);
|
||||
if(checkResult.get("activity").equals(false)){
|
||||
if(!webFormValidator.check(activityFormConfigure.getStdActivityForm(), parameterMap)){
|
||||
throw new InvalidFormFormatException("Invalid activity form.");
|
||||
}
|
||||
|
||||
return "act_created";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,32 +8,12 @@ import java.util.*;
|
||||
@Component
|
||||
public class WebFormValidator {
|
||||
|
||||
/**
|
||||
* 传入标准表单所具有的属性set以及网页表单的属性set,确保map中的key和value一一对应
|
||||
* 检查的时候会将标准表单和网页表单两个map中key相同的value进行完全匹配比较
|
||||
* 返回一个map,不同表单有不同的合法情况
|
||||
* 支持一次处理多个表单,请务必保持对应表单的标准和网页map中的key一样
|
||||
* @return 封装在一个map里的不同表单对应的合法情况
|
||||
*/
|
||||
public HashMap<String, Boolean> check(Map<String, HashSet<String>> stdFormMap, Map<String, String[]> webFormMap){
|
||||
public boolean check(Collection<String> stdForm, Map<String, String[]> webFormMap){
|
||||
|
||||
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
|
||||
Set<String> stdKey = stdFormMap.keySet();
|
||||
Set<String> webKey = webFormMap.keySet();
|
||||
|
||||
for(String key : webKey){
|
||||
if(stdKey.contains(key)){
|
||||
Set<String> stdSet = stdFormMap.get(key);
|
||||
String[] webForm = webFormMap.get(key);
|
||||
List<String> webList = new ArrayList<>();
|
||||
Collections.addAll(webList, webForm);
|
||||
if(stdSet.containsAll(webList)){
|
||||
result.put(key,true);
|
||||
Collection<String> webForm = webFormMap.keySet();
|
||||
if(stdForm.containsAll(webForm)){
|
||||
return true;
|
||||
}
|
||||
else result.put(key,false);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user