diff --git a/pom.xml b/pom.xml index b66f69d..47427d0 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,11 @@ compile + + org.springframework.boot + spring-boot-starter-websocket + + org.springframework.boot spring-boot-test diff --git a/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java b/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java index 0ca3161..8fb2c9f 100644 --- a/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java +++ b/src/main/java/com/codesdream/ase/configure/ActivityFormConfigure.java @@ -11,7 +11,7 @@ import java.util.Set; @Component public class ActivityFormConfigure { - private static final Set stdActivityForm = new HashSet(){{ + private final HashSet stdActivityForm = new HashSet(){{ add("title"); add("creator"); add("type"); @@ -29,11 +29,8 @@ public class ActivityFormConfigure { add("assist-manager"); add("attendance"); }}; - public final static Map> stdActivityMap; - static { - stdActivityMap = new HashMap() {{ - put("activity", stdActivityForm); - }}; + public HashSet getStdActivityForm() { + return stdActivityForm; } } diff --git a/src/main/java/com/codesdream/ase/controller/ActivityController.java b/src/main/java/com/codesdream/ase/controller/ActivityController.java index 421f699..e299297 100644 --- a/src/main/java/com/codesdream/ase/controller/ActivityController.java +++ b/src/main/java/com/codesdream/ase/controller/ActivityController.java @@ -31,11 +31,12 @@ public class ActivityController { ASESpringUtil aseSpringUtil = new ASESpringUtil(); ActivityFormConfigure activityFormConfigure = aseSpringUtil.getBean(ActivityFormConfigure.class); WebFormValidator webFormValidator = aseSpringUtil.getBean(WebFormValidator.class); - HashMap 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"; } } + diff --git a/src/main/java/com/codesdream/ase/validator/WebFormValidator.java b/src/main/java/com/codesdream/ase/validator/WebFormValidator.java index 9ab4dc5..e710ce3 100644 --- a/src/main/java/com/codesdream/ase/validator/WebFormValidator.java +++ b/src/main/java/com/codesdream/ase/validator/WebFormValidator.java @@ -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 check(Map> stdFormMap, Map webFormMap){ + public boolean check(Collection stdForm, Map webFormMap){ - HashMap result = new HashMap(); - Set stdKey = stdFormMap.keySet(); - Set webKey = webFormMap.keySet(); - - for(String key : webKey){ - if(stdKey.contains(key)){ - Set stdSet = stdFormMap.get(key); - String[] webForm = webFormMap.get(key); - List webList = new ArrayList<>(); - Collections.addAll(webList, webForm); - if(stdSet.containsAll(webList)){ - result.put(key,true); - } - else result.put(key,false); - } + Collection webForm = webFormMap.keySet(); + if(stdForm.containsAll(webForm)){ + return true; } - - return result; + return false; } }